L2SkillSummon.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. if (player == activeChar)
  115. player.addCubic(_npcId, getLevel(), getPower(), getActivationTime(), getActivationChance(), false);
  116. else // given by other player
  117. player.addCubic(_npcId, getLevel(), getPower(), getActivationTime(), getActivationChance(), true);
  118. player.broadcastUserInfo();
  119. }
  120. }
  121. return;
  122. }
  123. else //normal cubic skill
  124. {
  125. int mastery = activeChar.getSkillLevel(L2Skill.SKILL_CUBIC_MASTERY);
  126. if (mastery < 0)
  127. mastery = 0;
  128. if (activeChar.getCubics().size() > mastery) {
  129. if (Config.DEBUG)
  130. _log.fine("player can't summon any more cubics. ignore summon skill");
  131. activeChar.sendPacket(new SystemMessage(SystemMessageId.CUBIC_SUMMONING_FAILED));
  132. return;
  133. }
  134. if (activeChar.getCubics().containsKey(_npcId))
  135. {
  136. activeChar.sendMessage("You already have such cubic");
  137. return;
  138. }
  139. activeChar.addCubic(_npcId, getLevel(), getPower(), getActivationTime(), getActivationChance(), false);
  140. activeChar.broadcastUserInfo();
  141. return;
  142. }
  143. }
  144. if (activeChar.getPet() != null || activeChar.isMounted()) {
  145. if (Config.DEBUG)
  146. _log.fine("player has a pet already. ignore summon skill");
  147. return;
  148. }
  149. L2SummonInstance summon;
  150. L2NpcTemplate summonTemplate = NpcTable.getInstance().getTemplate(_npcId);
  151. if (summonTemplate == null)
  152. {
  153. _log.warning("Summon attempt for nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
  154. return; // npcID doesn't exist
  155. }
  156. if (summonTemplate.type.equalsIgnoreCase("L2SiegeSummon"))
  157. summon = new L2SiegeSummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  158. else
  159. summon = new L2SummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  160. summon.setName(summonTemplate.name);
  161. summon.setTitle(activeChar.getName());
  162. summon.setExpPenalty(_expPenalty);
  163. if (summon.getLevel() >= Experience.LEVEL.length)
  164. {
  165. summon.getStat().setExp(Experience.LEVEL[Experience.LEVEL.length - 1]);
  166. _log.warning("Summon ("+summon.getName()+") NpcID: "+summon.getNpcId()+" has a level above 75. Please rectify.");
  167. }
  168. else
  169. {
  170. summon.getStat().setExp(Experience.LEVEL[(summon.getLevel() % Experience.LEVEL.length)]);
  171. }
  172. summon.setCurrentHp(summon.getMaxHp());
  173. summon.setCurrentMp(summon.getMaxMp());
  174. summon.setHeading(activeChar.getHeading());
  175. summon.setRunning();
  176. activeChar.setPet(summon);
  177. L2World.getInstance().storeObject(summon);
  178. summon.spawnMe(activeChar.getX()+50, activeChar.getY()+100, activeChar.getZ());
  179. }
  180. }