ScrollOfResurrection.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 com.l2jserver.gameserver.datatables.SkillTable;
  17. import com.l2jserver.gameserver.handler.IItemHandler;
  18. import com.l2jserver.gameserver.instancemanager.CastleManager;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Playable;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  24. import com.l2jserver.gameserver.model.entity.Castle;
  25. import com.l2jserver.gameserver.model.entity.TvTEvent;
  26. import com.l2jserver.gameserver.model.item.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. /**
  31. * This class ...
  32. *
  33. * @version $Revision: 1.1.2.2.2.7 $ $Date: 2005/04/05 19:41:13 $
  34. */
  35. public class ScrollOfResurrection implements IItemHandler
  36. {
  37. /**
  38. *
  39. * @see com.l2jserver.gameserver.handler.IItemHandler#useItem(com.l2jserver.gameserver.model.actor.L2Playable, com.l2jserver.gameserver.model.L2ItemInstance, boolean)
  40. */
  41. public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  42. {
  43. if (!(playable instanceof L2PcInstance))
  44. return;
  45. L2PcInstance activeChar = (L2PcInstance) playable;
  46. if (!TvTEvent.onScrollUse(playable.getObjectId()))
  47. {
  48. playable.sendPacket(ActionFailed.STATIC_PACKET);
  49. return;
  50. }
  51. if (activeChar.isSitting())
  52. {
  53. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANT_MOVE_SITTING));
  54. return;
  55. }
  56. if (activeChar.isMovementDisabled())
  57. return;
  58. int itemId = item.getItemId();
  59. //boolean blessedScroll = (itemId != 737);
  60. boolean petScroll = (itemId == 6387);
  61. // SoR Animation section
  62. L2Character target = (L2Character) activeChar.getTarget();
  63. if (target != null && target.isDead())
  64. {
  65. L2PcInstance targetPlayer = null;
  66. if (target instanceof L2PcInstance)
  67. targetPlayer = (L2PcInstance) target;
  68. L2PetInstance targetPet = null;
  69. if (target instanceof L2PetInstance)
  70. targetPet = (L2PetInstance) target;
  71. if (targetPlayer != null || targetPet != null)
  72. {
  73. boolean condGood = true;
  74. //check target is not in a active siege zone
  75. Castle castle = null;
  76. if (targetPlayer != null)
  77. castle = CastleManager.getInstance().getCastle(targetPlayer.getX(), targetPlayer.getY(), targetPlayer.getZ());
  78. else
  79. castle = CastleManager.getInstance().getCastle(targetPet.getOwner().getX(), targetPet.getOwner().getY(), targetPet.getOwner().getZ());
  80. if (castle != null && castle.getSiege().getIsInProgress())
  81. {
  82. condGood = false;
  83. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE));
  84. }
  85. if (targetPet != null)
  86. {
  87. if (targetPet.getOwner() != activeChar)
  88. {
  89. if (targetPet.getOwner().isReviveRequested())
  90. {
  91. if (targetPet.getOwner().isRevivingPet())
  92. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  93. else
  94. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_RES_PET2)); // A pet cannot be resurrected while it's owner is in the process of resurrecting.
  95. condGood = false;
  96. }
  97. }
  98. }
  99. else
  100. {
  101. if (targetPlayer.isFestivalParticipant()) // Check to see if the current player target is in a festival.
  102. {
  103. condGood = false;
  104. activeChar.sendMessage("You may not resurrect participants in a festival.");
  105. }
  106. if (targetPlayer.isReviveRequested())
  107. {
  108. if (targetPlayer.isRevivingPet())
  109. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MASTER_CANNOT_RES)); // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
  110. else
  111. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  112. condGood = false;
  113. }
  114. else if (petScroll)
  115. {
  116. condGood = false;
  117. activeChar.sendMessage("You do not have the correct scroll");
  118. }
  119. }
  120. if (condGood)
  121. {
  122. if (!activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false))
  123. return;
  124. int skillId = 0;
  125. int skillLevel = 1;
  126. switch (itemId)
  127. {
  128. case 737:
  129. skillId = 2014;
  130. break; // Scroll of Resurrection
  131. case 3936:
  132. skillId = 2049;
  133. break; // Blessed Scroll of Resurrection
  134. case 3959:
  135. skillId = 2062;
  136. break; // L2Day - Blessed Scroll of Resurrection
  137. case 6387:
  138. skillId = 2179;
  139. break; // Blessed Scroll of Resurrection: For Pets
  140. case 9157:
  141. skillId = 2321;
  142. break; // Blessed Scroll of Resurrection Event
  143. case 10150:
  144. skillId = 2393;
  145. break; // Blessed Scroll of Battlefield Resurrection
  146. case 13259:
  147. skillId = 2596;
  148. break; // Gran Kain's Blessed Scroll of Resurrection
  149. }
  150. if (skillId != 0)
  151. {
  152. L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);
  153. activeChar.useMagic(skill, true, true);
  154. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED);
  155. sm.addItemName(item);
  156. activeChar.sendPacket(sm);
  157. }
  158. }
  159. }
  160. }
  161. else
  162. {
  163. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  164. }
  165. }
  166. }