CallPc.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.SevenSigns;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  25. import com.l2jserver.gameserver.model.effects.L2Effect;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.entity.Instance;
  28. import com.l2jserver.gameserver.model.entity.TvTEvent;
  29. import com.l2jserver.gameserver.model.holders.SummonRequestHolder;
  30. import com.l2jserver.gameserver.model.stats.Env;
  31. import com.l2jserver.gameserver.model.zone.ZoneId;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  34. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  35. /**
  36. * Call Pc effect implementation.
  37. * @author Adry_85
  38. */
  39. public class CallPc extends L2Effect
  40. {
  41. private static int _itemId;
  42. private static int _itemCount;
  43. public CallPc(Env env, EffectTemplate template)
  44. {
  45. super(env, template);
  46. _itemId = template.getParameters().getInt("itemId", 0);
  47. _itemCount = template.getParameters().getInt("itemCount", 0);
  48. }
  49. @Override
  50. public L2EffectType getEffectType()
  51. {
  52. return L2EffectType.NONE;
  53. }
  54. @Override
  55. public boolean isInstant()
  56. {
  57. return true;
  58. }
  59. @Override
  60. public boolean onStart()
  61. {
  62. if (getEffected() == getEffector())
  63. {
  64. return false;
  65. }
  66. L2PcInstance target = getEffected().getActingPlayer();
  67. L2PcInstance activeChar = getEffector().getActingPlayer();
  68. if (checkSummonTargetStatus(target, activeChar))
  69. {
  70. if ((_itemId != 0) && (_itemCount != 0))
  71. {
  72. if (target.getInventory().getInventoryItemCount(_itemId, 0) < _itemCount)
  73. {
  74. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_REQUIRED_FOR_SUMMONING);
  75. sm.addItemName(_itemId);
  76. target.sendPacket(sm);
  77. return false;
  78. }
  79. target.getInventory().destroyItemByItemId("Consume", _itemId, _itemCount, activeChar, target);
  80. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED);
  81. sm.addItemName(_itemId);
  82. target.sendPacket(sm);
  83. }
  84. target.addScript(new SummonRequestHolder(activeChar, getSkill()));
  85. final ConfirmDlg confirm = new ConfirmDlg(SystemMessageId.C1_WISHES_TO_SUMMON_YOU_FROM_S2_DO_YOU_ACCEPT.getId());
  86. confirm.addCharName(activeChar);
  87. confirm.addZoneName(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  88. confirm.addTime(30000);
  89. confirm.addRequesterId(activeChar.getObjectId());
  90. target.sendPacket(confirm);
  91. return true;
  92. }
  93. return false;
  94. }
  95. public static boolean checkSummonTargetStatus(L2PcInstance target, L2PcInstance activeChar)
  96. {
  97. if (target == activeChar)
  98. {
  99. return false;
  100. }
  101. if (target.isAlikeDead())
  102. {
  103. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED);
  104. sm.addPcName(target);
  105. activeChar.sendPacket(sm);
  106. return false;
  107. }
  108. if (target.isInStoreMode())
  109. {
  110. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED);
  111. sm.addPcName(target);
  112. activeChar.sendPacket(sm);
  113. return false;
  114. }
  115. if (target.isRooted() || target.isInCombat())
  116. {
  117. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED);
  118. sm.addPcName(target);
  119. activeChar.sendPacket(sm);
  120. return false;
  121. }
  122. if (target.isInOlympiadMode())
  123. {
  124. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD);
  125. return false;
  126. }
  127. if (target.isFestivalParticipant() || target.isFlyingMounted() || target.isCombatFlagEquipped() || !TvTEvent.onEscapeUse(target.getObjectId()))
  128. {
  129. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  130. return false;
  131. }
  132. if (target.inObserverMode())
  133. {
  134. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_STATE_FORBIDS_SUMMONING);
  135. sm.addCharName(target);
  136. activeChar.sendPacket(sm);
  137. return false;
  138. }
  139. if (target.isInsideZone(ZoneId.NO_SUMMON_FRIEND) || target.isInsideZone(ZoneId.JAIL))
  140. {
  141. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IN_SUMMON_BLOCKING_AREA);
  142. sm.addString(target.getName());
  143. activeChar.sendPacket(sm);
  144. return false;
  145. }
  146. if (activeChar.getInstanceId() > 0)
  147. {
  148. Instance summonerInstance = InstanceManager.getInstance().getInstance(activeChar.getInstanceId());
  149. if (!Config.ALLOW_SUMMON_TO_INSTANCE || !summonerInstance.isSummonAllowed())
  150. {
  151. activeChar.sendPacket(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION);
  152. return false;
  153. }
  154. }
  155. // TODO: on retail character can enter 7s dungeon with summon friend, but should be teleported away by mobs, because currently this is not working in L2J we do not allowing summoning.
  156. if (activeChar.isIn7sDungeon())
  157. {
  158. int targetCabal = SevenSigns.getInstance().getPlayerCabal(target.getObjectId());
  159. if (SevenSigns.getInstance().isSealValidationPeriod())
  160. {
  161. if (targetCabal != SevenSigns.getInstance().getCabalHighestScore())
  162. {
  163. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  164. return false;
  165. }
  166. }
  167. else if (targetCabal == SevenSigns.CABAL_NULL)
  168. {
  169. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  170. return false;
  171. }
  172. }
  173. return true;
  174. }
  175. }