CallPc.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (C) 2004-2015 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.StatsSet;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.conditions.Condition;
  26. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  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.skills.BuffInfo;
  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 final class CallPc extends AbstractEffect
  40. {
  41. private final int _itemId;
  42. private final int _itemCount;
  43. public CallPc(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  44. {
  45. super(attachCond, applyCond, set, params);
  46. _itemId = params.getInt("itemId", 0);
  47. _itemCount = params.getInt("itemCount", 0);
  48. }
  49. @Override
  50. public boolean isInstant()
  51. {
  52. return true;
  53. }
  54. @Override
  55. public void onStart(BuffInfo info)
  56. {
  57. if (info.getEffected() == info.getEffector())
  58. {
  59. return;
  60. }
  61. L2PcInstance target = info.getEffected().getActingPlayer();
  62. L2PcInstance activeChar = info.getEffector().getActingPlayer();
  63. if (checkSummonTargetStatus(target, activeChar))
  64. {
  65. if ((_itemId != 0) && (_itemCount != 0))
  66. {
  67. if (target.getInventory().getInventoryItemCount(_itemId, 0) < _itemCount)
  68. {
  69. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_REQUIRED_FOR_SUMMONING);
  70. sm.addItemName(_itemId);
  71. target.sendPacket(sm);
  72. return;
  73. }
  74. target.getInventory().destroyItemByItemId("Consume", _itemId, _itemCount, activeChar, target);
  75. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED);
  76. sm.addItemName(_itemId);
  77. target.sendPacket(sm);
  78. }
  79. target.addScript(new SummonRequestHolder(activeChar, info.getSkill()));
  80. final ConfirmDlg confirm = new ConfirmDlg(SystemMessageId.C1_WISHES_TO_SUMMON_YOU_FROM_S2_DO_YOU_ACCEPT.getId());
  81. confirm.addCharName(activeChar);
  82. confirm.addZoneName(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  83. confirm.addTime(30000);
  84. confirm.addRequesterId(activeChar.getObjectId());
  85. target.sendPacket(confirm);
  86. }
  87. }
  88. public static boolean checkSummonTargetStatus(L2PcInstance target, L2PcInstance activeChar)
  89. {
  90. if (target == activeChar)
  91. {
  92. return false;
  93. }
  94. if (target.isAlikeDead())
  95. {
  96. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED);
  97. sm.addPcName(target);
  98. activeChar.sendPacket(sm);
  99. return false;
  100. }
  101. if (target.isInStoreMode())
  102. {
  103. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED);
  104. sm.addPcName(target);
  105. activeChar.sendPacket(sm);
  106. return false;
  107. }
  108. if (target.isRooted() || target.isInCombat())
  109. {
  110. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED);
  111. sm.addPcName(target);
  112. activeChar.sendPacket(sm);
  113. return false;
  114. }
  115. if (target.isInOlympiadMode())
  116. {
  117. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD);
  118. return false;
  119. }
  120. if (target.isFestivalParticipant() || target.isFlyingMounted() || target.isCombatFlagEquipped() || !TvTEvent.onEscapeUse(target.getObjectId()))
  121. {
  122. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  123. return false;
  124. }
  125. if (target.inObserverMode())
  126. {
  127. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_STATE_FORBIDS_SUMMONING);
  128. sm.addCharName(target);
  129. activeChar.sendPacket(sm);
  130. return false;
  131. }
  132. if (target.isInsideZone(ZoneId.NO_SUMMON_FRIEND) || target.isInsideZone(ZoneId.JAIL))
  133. {
  134. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IN_SUMMON_BLOCKING_AREA);
  135. sm.addString(target.getName());
  136. activeChar.sendPacket(sm);
  137. return false;
  138. }
  139. if (activeChar.getInstanceId() > 0)
  140. {
  141. Instance summonerInstance = InstanceManager.getInstance().getInstance(activeChar.getInstanceId());
  142. if (!Config.ALLOW_SUMMON_IN_INSTANCE || !summonerInstance.isSummonAllowed())
  143. {
  144. activeChar.sendPacket(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION);
  145. return false;
  146. }
  147. }
  148. // 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.
  149. if (activeChar.isIn7sDungeon())
  150. {
  151. int targetCabal = SevenSigns.getInstance().getPlayerCabal(target.getObjectId());
  152. if (SevenSigns.getInstance().isSealValidationPeriod())
  153. {
  154. if (targetCabal != SevenSigns.getInstance().getCabalHighestScore())
  155. {
  156. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  157. return false;
  158. }
  159. }
  160. else if (targetCabal == SevenSigns.CABAL_NULL)
  161. {
  162. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  163. return false;
  164. }
  165. }
  166. return true;
  167. }
  168. }