SummonFriend.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.handler.skillhandlers;
  16. import java.util.List;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.handler.ISkillHandler;
  19. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  20. import net.sf.l2j.gameserver.model.L2Character;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.L2World;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  26. import net.sf.l2j.gameserver.network.SystemMessageId;
  27. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  28. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  29. import net.sf.l2j.gameserver.templates.L2SkillType;
  30. import net.sf.l2j.gameserver.util.Util;
  31. /**
  32. * @authors BiTi, Sami
  33. *
  34. */
  35. public class SummonFriend implements ISkillHandler
  36. {
  37. //private static Logger _log = Logger.getLogger(SummonFriend.class.getName());
  38. private static final L2SkillType[] SKILL_IDS =
  39. {
  40. L2SkillType.SUMMON_FRIEND
  41. };
  42. /**
  43. *
  44. * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
  45. */
  46. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  47. {
  48. if (!(activeChar instanceof L2PcInstance))
  49. return; // currently not implemented for others
  50. L2PcInstance activePlayer = (L2PcInstance) activeChar;
  51. if (activePlayer.isInOlympiadMode())
  52. {
  53. activePlayer.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  54. return;
  55. }
  56. // Checks summoner not in arenas, siege zones, jail
  57. if (activePlayer.isInsideZone(L2Character.ZONE_PVP))
  58. {
  59. activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_SUMMON_IN_COMBAT));
  60. return;
  61. }
  62. if (GrandBossManager.getInstance().getZone(activePlayer) != null && !activePlayer.isGM())
  63. {
  64. activePlayer.sendMessage("You may not use Summon Friend Skill inside a Boss Zone.");
  65. activePlayer.sendPacket(ActionFailed.STATIC_PACKET);
  66. return;
  67. }
  68. // check for summoner not in raid areas
  69. List<L2Object> objects = L2World.getInstance().getVisibleObjects(activeChar, 5000);
  70. if (objects != null)
  71. {
  72. for (L2Object object : objects)
  73. {
  74. if (object instanceof L2RaidBossInstance)
  75. {
  76. activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION));
  77. return;
  78. }
  79. }
  80. }
  81. try
  82. {
  83. for (int index = 0; index < targets.length; index++)
  84. {
  85. if (!(targets[index] instanceof L2Character))
  86. continue;
  87. L2Character target = (L2Character) targets[index];
  88. if (activeChar == target)
  89. continue;
  90. if (target instanceof L2PcInstance)
  91. {
  92. L2PcInstance targetChar = (L2PcInstance) target;
  93. // CHECK TARGET CONDITIONS
  94. if (targetChar.isAlikeDead())
  95. {
  96. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED);
  97. sm.addPcName(targetChar);
  98. activeChar.sendPacket(sm);
  99. continue;
  100. }
  101. if (targetChar.isInStoreMode())
  102. {
  103. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED);
  104. sm.addPcName(targetChar);
  105. activeChar.sendPacket(sm);
  106. continue;
  107. }
  108. // Target cannot be in combat (or dead, but that's checked by TARGET_PARTY)
  109. if (targetChar.isRooted() || targetChar.isInCombat())
  110. {
  111. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED);
  112. sm.addPcName(targetChar);
  113. activeChar.sendPacket(sm);
  114. continue;
  115. }
  116. // Check for the the target's Inside Boss Zone
  117. if (GrandBossManager.getInstance().getZone(targetChar) != null && !targetChar.isGM())
  118. {
  119. // SystemMessage doesn't exist?!
  120. activeChar.sendMessage("Cant summon target inside boss zone.");
  121. continue;
  122. }
  123. // Check for the the target's festival status
  124. if (targetChar.isInOlympiadMode())
  125. {
  126. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD));
  127. continue;
  128. }
  129. // Check for the the target's festival status
  130. if (targetChar.isFestivalParticipant())
  131. {
  132. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
  133. continue;
  134. }
  135. // Check for the target's jail status, arenas and siege zones
  136. if (targetChar.isInsideZone(L2Character.ZONE_PVP))
  137. {
  138. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
  139. continue;
  140. }
  141. // Requires a Summoning Crystal
  142. if (skill.getTargetConsume() != 0)
  143. if (targetChar.getInventory().getInventoryItemCount(skill.getTargetConsumeId(), 0) < skill.getTargetConsume())
  144. {
  145. ((L2PcInstance) activeChar).sendMessage("Your target cannot be summoned while he hasn't got enough Summoning Crystal");
  146. targetChar.sendMessage("You cannot be summoned while you haven't got enough Summoning Crystal");
  147. continue;
  148. }
  149. if (!Util.checkIfInRange(0, activeChar, target, false))
  150. {
  151. if (skill.getTargetConsume() != 0)
  152. targetChar.getInventory().destroyItemByItemId("Consume", skill.getTargetConsumeId(), skill.getTargetConsume(), targetChar, activeChar);
  153. targetChar.sendMessage("You are summoned to a party member.");
  154. targetChar.teleToLocation(activeChar.getX(), activeChar.getY(), activeChar.getZ(), true);
  155. }
  156. else
  157. {
  158. }
  159. }
  160. }
  161. }
  162. catch (Throwable e)
  163. {
  164. if (Config.DEBUG)
  165. e.printStackTrace();
  166. }
  167. }
  168. /**
  169. *
  170. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  171. */
  172. public L2SkillType[] getSkillIds()
  173. {
  174. return SKILL_IDS;
  175. }
  176. }