ScrollOfResurrection.java 6.1 KB

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