ScrollOfResurrection.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.itemhandlers;
  20. import java.util.logging.Level;
  21. import com.l2jserver.gameserver.handler.IItemHandler;
  22. import com.l2jserver.gameserver.instancemanager.CastleManager;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  27. import com.l2jserver.gameserver.model.entity.Castle;
  28. import com.l2jserver.gameserver.model.entity.TvTEvent;
  29. import com.l2jserver.gameserver.model.holders.SkillHolder;
  30. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  33. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  34. public class ScrollOfResurrection implements IItemHandler
  35. {
  36. @Override
  37. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. if (!playable.isPlayer())
  40. {
  41. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  42. return false;
  43. }
  44. if (!TvTEvent.onScrollUse(playable.getObjectId()))
  45. {
  46. playable.sendPacket(ActionFailed.STATIC_PACKET);
  47. return false;
  48. }
  49. final L2PcInstance activeChar = playable.getActingPlayer();
  50. if (activeChar.isSitting())
  51. {
  52. activeChar.sendPacket(SystemMessageId.CANT_MOVE_SITTING);
  53. return false;
  54. }
  55. if (activeChar.isMovementDisabled())
  56. {
  57. return false;
  58. }
  59. final int itemId = item.getItemId();
  60. final boolean petScroll = (itemId == 6387);
  61. final SkillHolder[] skills = item.getItem().getSkills();
  62. if (skills == null)
  63. {
  64. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  65. return false;
  66. }
  67. // SoR Animation section
  68. final L2Character target = (L2Character) activeChar.getTarget();
  69. if ((target == null) || !target.isDead())
  70. {
  71. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  72. return false;
  73. }
  74. L2PcInstance targetPlayer = null;
  75. if (target instanceof L2PcInstance)
  76. {
  77. targetPlayer = (L2PcInstance) target;
  78. }
  79. L2PetInstance targetPet = null;
  80. if (target instanceof L2PetInstance)
  81. {
  82. targetPet = (L2PetInstance) target;
  83. }
  84. if ((targetPlayer != null) || (targetPet != null))
  85. {
  86. boolean condGood = true;
  87. // check target is not in a active siege zone
  88. Castle castle = null;
  89. if (targetPlayer != null)
  90. {
  91. castle = CastleManager.getInstance().getCastle(targetPlayer.getX(), targetPlayer.getY(), targetPlayer.getZ());
  92. }
  93. else if (targetPet != null)
  94. {
  95. castle = CastleManager.getInstance().getCastle(targetPet.getOwner().getX(), targetPet.getOwner().getY(), targetPet.getOwner().getZ());
  96. }
  97. if ((castle != null) && castle.getSiege().getIsInProgress())
  98. {
  99. condGood = false;
  100. activeChar.sendPacket(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE);
  101. }
  102. if (targetPet != null)
  103. {
  104. if (targetPet.getOwner() != activeChar)
  105. {
  106. if (targetPet.getOwner().isReviveRequested())
  107. {
  108. if (targetPet.getOwner().isRevivingPet())
  109. {
  110. activeChar.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED); // Resurrection is already been proposed.
  111. }
  112. else
  113. {
  114. activeChar.sendPacket(SystemMessageId.CANNOT_RES_PET2); // A pet cannot be resurrected while it's owner is in the process of resurrecting.
  115. }
  116. condGood = false;
  117. }
  118. }
  119. }
  120. else if (targetPlayer != null)
  121. {
  122. if (targetPlayer.isFestivalParticipant()) // Check to see if the current player target is in a festival.
  123. {
  124. condGood = false;
  125. activeChar.sendMessage("You may not resurrect participants in a festival.");
  126. }
  127. if (targetPlayer.isReviveRequested())
  128. {
  129. if (targetPlayer.isRevivingPet())
  130. {
  131. activeChar.sendPacket(SystemMessageId.MASTER_CANNOT_RES); // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
  132. }
  133. else
  134. {
  135. activeChar.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED); // Resurrection is already been proposed.
  136. }
  137. condGood = false;
  138. }
  139. else if (petScroll)
  140. {
  141. condGood = false;
  142. activeChar.sendMessage("You do not have the correct scroll");
  143. }
  144. }
  145. if (condGood)
  146. {
  147. if (!activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false))
  148. {
  149. return false;
  150. }
  151. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED);
  152. sm.addItemName(item);
  153. activeChar.sendPacket(sm);
  154. for (SkillHolder sk : skills)
  155. {
  156. activeChar.useMagic(sk.getSkill(), true, true);
  157. }
  158. return true;
  159. }
  160. }
  161. return false;
  162. }
  163. }