ScrollOfResurrection.java 5.4 KB

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