2
0

L2SkillSummon.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.skills.l2skills;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.datatables.NpcTable;
  18. import net.sf.l2j.gameserver.idfactory.IdFactory;
  19. import net.sf.l2j.gameserver.model.L2Character;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.L2Skill;
  22. import net.sf.l2j.gameserver.model.L2World;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2CubicInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeSummonInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  27. import net.sf.l2j.gameserver.model.base.Experience;
  28. import net.sf.l2j.gameserver.network.SystemMessageId;
  29. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  30. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  31. import net.sf.l2j.gameserver.templates.StatsSet;
  32. public class L2SkillSummon extends L2Skill {
  33. private int _npcId;
  34. private float _expPenalty;
  35. private boolean _isCubic;
  36. public L2SkillSummon(StatsSet set) {
  37. super(set);
  38. _npcId = set.getInteger("npcId", 0); // default for undescribed skills
  39. _expPenalty = set.getFloat ("expPenalty", 0.f);
  40. _isCubic = set.getBool ("isCubic", false);
  41. }
  42. public boolean checkCondition(L2Character activeChar)
  43. {
  44. if (activeChar instanceof L2PcInstance)
  45. {
  46. L2PcInstance player = (L2PcInstance)activeChar;
  47. if (_isCubic) {
  48. if (getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  49. {
  50. return true; //Player is always able to cast mass cubic skill
  51. }
  52. int mastery = player.getSkillLevel(L2Skill.SKILL_CUBIC_MASTERY);
  53. if (mastery < 0)
  54. mastery = 0;
  55. int count = player.getCubics().size();
  56. if (count > mastery) {
  57. SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  58. sm.addString("You already have "+count+" cubic(s).");
  59. activeChar.sendPacket(sm);
  60. return false;
  61. }
  62. } else {
  63. if (player.inObserverMode())
  64. return false;
  65. if (player.getPet() != null)
  66. {
  67. SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  68. sm.addString("You already have a pet.");
  69. activeChar.sendPacket(sm);
  70. return false;
  71. }
  72. }
  73. }
  74. return super.checkCondition(activeChar, null, false);
  75. }
  76. @Override
  77. public void useSkill(L2Character caster, L2Object[] targets) {
  78. if (caster.isAlikeDead() || !(caster instanceof L2PcInstance))
  79. return;
  80. L2PcInstance activeChar = (L2PcInstance) caster;
  81. if (_npcId == 0) {
  82. SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
  83. sm.addString("Summon skill "+getId()+" not described yet");
  84. activeChar.sendPacket(sm);
  85. return;
  86. }
  87. if (_isCubic) {
  88. if (targets.length > 1) //Mass cubic skill
  89. {
  90. for (L2Object obj: targets)
  91. {
  92. if (!(obj instanceof L2PcInstance)) continue;
  93. L2PcInstance player = ((L2PcInstance)obj);
  94. int mastery = player.getSkillLevel(L2Skill.SKILL_CUBIC_MASTERY);
  95. if (mastery < 0)
  96. mastery = 0;
  97. if (mastery == 0 && player.getCubics().size() > 0)
  98. {
  99. //Player can have only 1 cubic - we shuld replace old cubic with new one
  100. for (L2CubicInstance c: player.getCubics().values())
  101. {
  102. c.stopAction();
  103. c = null;
  104. }
  105. player.getCubics().clear();
  106. }
  107. if (player.getCubics().size() > mastery) continue;
  108. if (player.getCubics().containsKey(_npcId))
  109. {
  110. player.sendMessage("You already have such cubic");
  111. }
  112. else
  113. {
  114. player.addCubic(_npcId, getLevel());
  115. player.broadcastUserInfo();
  116. }
  117. }
  118. return;
  119. }
  120. else //normal cubic skill
  121. {
  122. int mastery = activeChar.getSkillLevel(L2Skill.SKILL_CUBIC_MASTERY);
  123. if (mastery < 0)
  124. mastery = 0;
  125. if (activeChar.getCubics().size() > mastery) {
  126. if (Config.DEBUG)
  127. _log.fine("player can't summon any more cubics. ignore summon skill");
  128. activeChar.sendPacket(new SystemMessage(SystemMessageId.CUBIC_SUMMONING_FAILED));
  129. return;
  130. }
  131. if (activeChar.getCubics().containsKey(_npcId))
  132. {
  133. activeChar.sendMessage("You already have such cubic");
  134. return;
  135. }
  136. activeChar.addCubic(_npcId, getLevel());
  137. activeChar.broadcastUserInfo();
  138. return;
  139. }
  140. }
  141. if (activeChar.getPet() != null || activeChar.isMounted()) {
  142. if (Config.DEBUG)
  143. _log.fine("player has a pet already. ignore summon skill");
  144. return;
  145. }
  146. L2SummonInstance summon;
  147. L2NpcTemplate summonTemplate = NpcTable.getInstance().getTemplate(_npcId);
  148. if (summonTemplate.type.equalsIgnoreCase("L2SiegeSummon"))
  149. summon = new L2SiegeSummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  150. else
  151. summon = new L2SummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  152. summon.setName(summonTemplate.name);
  153. summon.setTitle(activeChar.getName());
  154. summon.setExpPenalty(_expPenalty);
  155. if (summon.getLevel() >= Experience.LEVEL.length)
  156. {
  157. summon.getStat().setExp(Experience.LEVEL[Experience.LEVEL.length - 1]);
  158. _log.warning("Summon ("+summon.getName()+") NpcID: "+summon.getNpcId()+" has a level above 75. Please rectify.");
  159. }
  160. else
  161. {
  162. summon.getStat().setExp(Experience.LEVEL[(summon.getLevel() % Experience.LEVEL.length)]);
  163. }
  164. summon.setCurrentHp(summon.getMaxHp());
  165. summon.setCurrentMp(summon.getMaxMp());
  166. summon.setHeading(activeChar.getHeading());
  167. summon.setRunning();
  168. activeChar.setPet(summon);
  169. L2World.getInstance().storeObject(summon);
  170. summon.spawnMe(activeChar.getX()+50, activeChar.getY()+100, activeChar.getZ());
  171. }
  172. }