SummonFriend.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.L2Skill.SkillType;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  27. import net.sf.l2j.gameserver.network.SystemMessageId;
  28. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  29. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  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 SkillType[] SKILL_IDS = {SkillType.SUMMON_FRIEND};
  39. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  40. {
  41. if (!(activeChar instanceof L2PcInstance)) return; // currently not implemented for others
  42. L2PcInstance activePlayer = (L2PcInstance)activeChar;
  43. if (activePlayer.isInOlympiadMode())
  44. {
  45. activePlayer.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  46. return;
  47. }
  48. // Checks summoner not in arenas, siege zones, jail
  49. if (activePlayer.isInsideZone(L2Character.ZONE_PVP))
  50. {
  51. activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_SUMMON_IN_COMBAT));
  52. return;
  53. }
  54. if (GrandBossManager.getInstance().getZone(activePlayer) != null && !activePlayer.isGM())
  55. {
  56. activePlayer.sendMessage("You may not use Summon Friend Skill inside a Boss Zone.");
  57. activePlayer.sendPacket(ActionFailed.STATIC_PACKET);
  58. return;
  59. }
  60. // check for summoner not in raid areas
  61. List<L2Object> objects = L2World.getInstance().getVisibleObjects(activeChar, 5000);
  62. if (objects != null)
  63. {
  64. for (L2Object object : objects)
  65. {
  66. if (object instanceof L2RaidBossInstance)
  67. {
  68. activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION));
  69. return;
  70. }
  71. }
  72. }
  73. try
  74. {
  75. for (int index = 0; index < targets.length; index++)
  76. {
  77. if (!(targets[index] instanceof L2Character))
  78. continue;
  79. L2Character target = (L2Character)targets[index];
  80. if (activeChar == target) continue;
  81. if (target instanceof L2PcInstance)
  82. {
  83. L2PcInstance targetChar = (L2PcInstance)target;
  84. // CHECK TARGET CONDITIONS
  85. //This message naturally doesn't bring up a box...
  86. //$s1 wishes to summon you from $s2. Do you accept?
  87. //SystemMessage sm2 = new SystemMessage(SystemMessageId.S1_WISHES_TO_SUMMON_YOU_FROM_S2_DO_YOU_ACCEPT);
  88. //sm2.addString(activeChar.getName());
  89. //String nearestTown = MapRegionTable.getInstance().getClosestTownName(activeChar);
  90. //sm2.addString(nearestTown);
  91. //targetChar.sendPacket(sm2);
  92. // is in same party (not necessary any more)
  93. // if (!(targetChar.getParty() != null && targetChar.getParty().getPartyMembers().contains(activeChar)))
  94. // continue;
  95. if (targetChar.isAlikeDead())
  96. {
  97. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED);
  98. sm.addPcName(targetChar);
  99. activeChar.sendPacket(sm);
  100. continue;
  101. }
  102. if (targetChar.isInStoreMode())
  103. {
  104. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED);
  105. sm.addPcName(targetChar);
  106. activeChar.sendPacket(sm);
  107. continue;
  108. }
  109. // Target cannot be in combat (or dead, but that's checked by TARGET_PARTY)
  110. if (targetChar.isRooted() || targetChar.isInCombat())
  111. {
  112. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED);
  113. sm.addPcName(targetChar);
  114. activeChar.sendPacket(sm);
  115. continue;
  116. }
  117. // Check for the the target's Inside Boss Zone
  118. if (GrandBossManager.getInstance().getZone(targetChar) != null && !targetChar.isGM())
  119. {
  120. // SystemMessage doesn't exist?!
  121. activeChar.sendMessage("Cant summon target inside boss zone.");
  122. continue;
  123. }
  124. // Check for the the target's festival status
  125. if (targetChar.isInOlympiadMode()) {
  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. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
  132. continue;
  133. }
  134. // Check for the target's jail status, arenas and siege zones
  135. if (targetChar.isInsideZone(L2Character.ZONE_PVP))
  136. {
  137. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
  138. continue;
  139. }
  140. // Requires a Summoning Crystal
  141. if(skill.getTargetConsume() != 0)
  142. if (targetChar.getInventory().getInventoryItemCount(skill.getTargetConsumeId(), 0) < skill.getTargetConsume())
  143. {
  144. ((L2PcInstance)activeChar).sendMessage("Your target cannot be summoned while he hasn't got enough Summoning Crystal");
  145. targetChar.sendMessage("You cannot be summoned while you haven't got enough Summoning Crystal");
  146. continue;
  147. }
  148. if (!Util.checkIfInRange(0, activeChar, target, false))
  149. {
  150. if(skill.getTargetConsume() != 0)
  151. targetChar.getInventory().destroyItemByItemId("Consume", skill.getTargetConsumeId(), skill.getTargetConsume(), targetChar, activeChar);
  152. targetChar.sendMessage("You are summoned to a party member.");
  153. targetChar.teleToLocation(activeChar.getX(),activeChar.getY(),activeChar.getZ(), true);
  154. }
  155. else
  156. {
  157. }
  158. }
  159. }
  160. } catch (Throwable e) {
  161. if (Config.DEBUG) e.printStackTrace();
  162. }
  163. }
  164. public SkillType[] getSkillIds()
  165. {
  166. return SKILL_IDS;
  167. }
  168. }