Remedy.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.handler.IItemHandler;
  17. import net.sf.l2j.gameserver.model.L2Effect;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  24. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.templates.L2SkillType;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision: 1.1.2.4 $ $Date: 2005/04/06 16:13:51 $
  30. */
  31. public class Remedy implements IItemHandler
  32. {
  33. private static int[] ITEM_IDS =
  34. {
  35. 1831, 1832, 1833, 1834, 3889
  36. };
  37. /**
  38. *
  39. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  40. */
  41. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  42. {
  43. L2PcInstance activeChar;
  44. if (playable instanceof L2PcInstance)
  45. activeChar = (L2PcInstance) playable;
  46. else if (playable instanceof L2PetInstance)
  47. activeChar = ((L2PetInstance) playable).getOwner();
  48. else
  49. return;
  50. if (activeChar.isInOlympiadMode())
  51. {
  52. activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  53. return;
  54. }
  55. int itemId = item.getItemId();
  56. switch (itemId)
  57. {
  58. case 1831: // antidote
  59. {
  60. L2Effect[] effects = activeChar.getAllEffects();
  61. for (L2Effect e : effects)
  62. {
  63. if (e.getSkill().getSkillType() == L2SkillType.POISON && e.getSkill().getLevel() <= 3)
  64. {
  65. e.exit();
  66. break;
  67. }
  68. }
  69. MagicSkillUse MSU = new MagicSkillUse(playable, playable, 2042, 1, 0, 0);
  70. activeChar.sendPacket(MSU);
  71. activeChar.broadcastPacket(MSU);
  72. playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  73. break;
  74. }
  75. case 1832: // advanced antidote
  76. {
  77. L2Effect[] effects = activeChar.getAllEffects();
  78. for (L2Effect e : effects)
  79. {
  80. if (e.getSkill().getSkillType() == L2SkillType.POISON && e.getSkill().getLevel() <= 7)
  81. {
  82. e.exit();
  83. break;
  84. }
  85. }
  86. MagicSkillUse MSU = new MagicSkillUse(playable, playable, 2043, 1, 0, 0);
  87. activeChar.sendPacket(MSU);
  88. activeChar.broadcastPacket(MSU);
  89. playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  90. break;
  91. }
  92. case 1833: // bandage
  93. {
  94. L2Effect[] effects = activeChar.getAllEffects();
  95. for (L2Effect e : effects)
  96. {
  97. if (e.getSkill().getSkillType() == L2SkillType.BLEED && e.getSkill().getLevel() <= 3)
  98. {
  99. e.exit();
  100. break;
  101. }
  102. }
  103. MagicSkillUse MSU = new MagicSkillUse(playable, playable, 34, 1, 0, 0);
  104. activeChar.sendPacket(MSU);
  105. activeChar.broadcastPacket(MSU);
  106. playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  107. break;
  108. }
  109. case 1834: // emergency dressing
  110. {
  111. L2Effect[] effects = activeChar.getAllEffects();
  112. for (L2Effect e : effects)
  113. {
  114. if (e.getSkill().getSkillType() == L2SkillType.BLEED && e.getSkill().getLevel() <= 7)
  115. {
  116. e.exit();
  117. break;
  118. }
  119. }
  120. MagicSkillUse MSU = new MagicSkillUse(playable, playable, 2045, 1, 0, 0);
  121. activeChar.sendPacket(MSU);
  122. activeChar.broadcastPacket(MSU);
  123. playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  124. break;
  125. }
  126. case 3889: // potion of recovery
  127. {
  128. L2Effect[] effects = activeChar.getAllEffects();
  129. for (L2Effect e : effects)
  130. {
  131. if (e.getSkill().getId() == 4082)
  132. e.exit();
  133. }
  134. activeChar.setIsImmobilized(false);
  135. if (activeChar.getFirstEffect(L2Effect.EffectType.ROOT) == null)
  136. activeChar.stopRooting(null);
  137. MagicSkillUse MSU = new MagicSkillUse(playable, playable, 2042, 1, 0, 0);
  138. activeChar.sendPacket(MSU);
  139. activeChar.broadcastPacket(MSU);
  140. playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  141. break;
  142. }
  143. }
  144. }
  145. /**
  146. *
  147. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  148. */
  149. public int[] getItemIds()
  150. {
  151. return ITEM_IDS;
  152. }
  153. }