SoulCrystals.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.ThreadPoolManager;
  17. import net.sf.l2j.gameserver.datatables.SkillTable;
  18. import net.sf.l2j.gameserver.handler.IItemHandler;
  19. import net.sf.l2j.gameserver.model.L2Attackable;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  26. import net.sf.l2j.gameserver.network.SystemMessageId;
  27. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  28. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  29. /**
  30. * This class ...
  31. *
  32. * @version $Revision: 1.2.4 $ $Date: 2005/08/14 21:31:07 $
  33. */
  34. public class SoulCrystals implements IItemHandler
  35. {
  36. // First line is for Red Soul Crystals, second is Green and third is Blue Soul Crystals,
  37. // ordered by ascending level, from 0 to 13...
  38. private static final int[] ITEM_IDS =
  39. {
  40. 4629, 4630, 4631, 4632, 4633, 4634, 4635,
  41. 4636, 4637, 4638, 4639, 5577, 5580, 5908,
  42. 9570, 4640, 4641, 4642, 4643, 4644, 4645,
  43. 4646, 4647, 4648, 4649, 4650, 5578, 5581,
  44. 5911, 9572, 4651, 4652, 4653, 4654, 4655,
  45. 4656, 4657, 4658, 4659, 4660, 4661, 5579,
  46. 5582, 5914, 9571
  47. };
  48. /**
  49. *
  50. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  51. */
  52. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  53. {
  54. if (!(playable instanceof L2PcInstance))
  55. return;
  56. L2PcInstance activeChar = (L2PcInstance) playable;
  57. L2Object target = activeChar.getTarget();
  58. if (!(target instanceof L2MonsterInstance))
  59. {
  60. // Send a System Message to the caster
  61. SystemMessage sm = new SystemMessage(SystemMessageId.INCORRECT_TARGET);
  62. activeChar.sendPacket(sm);
  63. // Send a Server->Client packet ActionFailed to the L2PcInstance
  64. ActionFailed af = ActionFailed.STATIC_PACKET;
  65. activeChar.sendPacket(af);
  66. return;
  67. }
  68. // u can use soul crystal only when target hp goes below 50%
  69. if (((L2MonsterInstance) target).getCurrentHp() > ((L2MonsterInstance) target).getMaxHp() / 2.0)
  70. {
  71. ActionFailed af = ActionFailed.STATIC_PACKET;
  72. activeChar.sendPacket(af);
  73. return;
  74. }
  75. int crystalId = item.getItemId();
  76. // Soul Crystal Casting section
  77. L2Skill skill = SkillTable.getInstance().getInfo(2096, 1);
  78. activeChar.useMagic(skill, false, true);
  79. // End Soul Crystal Casting section
  80. // Continue execution later
  81. CrystalFinalizer cf = new CrystalFinalizer(activeChar, target, crystalId);
  82. ThreadPoolManager.getInstance().scheduleEffect(cf, skill.getHitTime());
  83. }
  84. static class CrystalFinalizer implements Runnable
  85. {
  86. private L2PcInstance _activeChar;
  87. private L2Attackable _target;
  88. private int _crystalId;
  89. CrystalFinalizer(L2PcInstance activeChar, L2Object target, int crystalId)
  90. {
  91. _activeChar = activeChar;
  92. _target = (L2Attackable) target;
  93. _crystalId = crystalId;
  94. }
  95. public void run()
  96. {
  97. if (_activeChar.isDead() || _target.isDead())
  98. return;
  99. _activeChar.enableAllSkills();
  100. try
  101. {
  102. _target.addAbsorber(_activeChar, _crystalId);
  103. _activeChar.setTarget(_target);
  104. }
  105. catch (Throwable e)
  106. {
  107. e.printStackTrace();
  108. }
  109. }
  110. }
  111. /**
  112. *
  113. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  114. */
  115. public int[] getItemIds()
  116. {
  117. return ITEM_IDS;
  118. }
  119. }