L2SkillSummon.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.network.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. {
  34. private int _npcId;
  35. private float _expPenalty;
  36. public L2SkillSummon(StatsSet set)
  37. {
  38. super(set);
  39. _npcId = set.getInteger("npcId", 0); // default for undescribed skills
  40. _expPenalty = set.getFloat ("expPenalty", 0.f);
  41. }
  42. public boolean checkCondition(L2Character activeChar)
  43. {
  44. if (activeChar instanceof L2PcInstance)
  45. {
  46. L2PcInstance player = (L2PcInstance)activeChar;
  47. if (isCubic())
  48. {
  49. if (getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  50. {
  51. return true; //Player is always able to cast mass cubic skill
  52. }
  53. int mastery = player.getSkillLevel(L2Skill.SKILL_CUBIC_MASTERY);
  54. if (mastery < 0)
  55. mastery = 0;
  56. int count = player.getCubics().size();
  57. if (count > mastery)
  58. {
  59. activeChar.sendMessage("You already have "+count+" cubic(s).");
  60. return false;
  61. }
  62. }
  63. else
  64. {
  65. if (player.inObserverMode())
  66. return false;
  67. if (player.getPet() != null)
  68. {
  69. activeChar.sendMessage("You already have a pet.");
  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. {
  83. activeChar.sendMessage("Summon skill "+getId()+" not described yet");
  84. return;
  85. }
  86. if (isCubic())
  87. {
  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(), getPower(), getActivationTime(), getActivationChance());
  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(), getPower(), getActivationTime(), getActivationChance());
  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 == null)
  149. {
  150. _log.warning("Summon attempt for nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
  151. return; // npcID doesn't exist
  152. }
  153. if (summonTemplate.type.equalsIgnoreCase("L2SiegeSummon"))
  154. summon = new L2SiegeSummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  155. else
  156. summon = new L2SummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  157. summon.setName(summonTemplate.name);
  158. summon.setTitle(activeChar.getName());
  159. summon.setExpPenalty(_expPenalty);
  160. if (summon.getLevel() >= Experience.LEVEL.length)
  161. {
  162. summon.getStat().setExp(Experience.LEVEL[Experience.LEVEL.length - 1]);
  163. _log.warning("Summon ("+summon.getName()+") NpcID: "+summon.getNpcId()+" has a level above 75. Please rectify.");
  164. }
  165. else
  166. {
  167. summon.getStat().setExp(Experience.LEVEL[(summon.getLevel() % Experience.LEVEL.length)]);
  168. }
  169. summon.setCurrentHp(summon.getMaxHp());
  170. summon.setCurrentMp(summon.getMaxMp());
  171. summon.setHeading(activeChar.getHeading());
  172. summon.setRunning();
  173. activeChar.setPet(summon);
  174. L2World.getInstance().storeObject(summon);
  175. summon.spawnMe(activeChar.getX()+50, activeChar.getY()+100, activeChar.getZ());
  176. }
  177. }