BlessedSpiritShot.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.network.serverpackets.ExAutoSoulShot;
  22. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  23. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  24. import net.sf.l2j.gameserver.templates.L2Item;
  25. import net.sf.l2j.gameserver.templates.L2Weapon;
  26. import net.sf.l2j.gameserver.util.Broadcast;
  27. /**
  28. * This class ...
  29. *
  30. * @version $Revision: 1.1.2.1.2.5 $ $Date: 2005/03/27 15:30:07 $
  31. */
  32. public class BlessedSpiritShot implements IItemHandler
  33. {
  34. // all the items ids that this handler knows
  35. private static final int[] ITEM_IDS =
  36. {
  37. 3947, 3948, 3949, 3950, 3951, 3952
  38. };
  39. private static final int[] SKILL_IDS =
  40. {
  41. 2061, 2160, 2161, 2162, 2163, 2164, 2164
  42. };
  43. /**
  44. *
  45. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  46. */
  47. public synchronized void useItem(L2PlayableInstance playable, L2ItemInstance item)
  48. {
  49. if (!(playable instanceof L2PcInstance))
  50. return;
  51. L2PcInstance activeChar = (L2PcInstance) playable;
  52. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  53. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  54. int itemId = item.getItemId();
  55. if (activeChar.isInOlympiadMode())
  56. {
  57. SystemMessage sm = new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  58. sm.addString(item.getItemName());
  59. activeChar.sendPacket(sm);
  60. sm = null;
  61. return;
  62. }
  63. // Check if Blessed SpiritShot can be used
  64. if (weaponInst == null || weaponItem.getSpiritShotCount() == 0)
  65. {
  66. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  67. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SPIRITSHOTS));
  68. return;
  69. }
  70. // Check if Blessed SpiritShot is already active (it can be charged over SpiritShot)
  71. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  72. return;
  73. // Check for correct grade
  74. int weaponGrade = weaponItem.getCrystalType();
  75. if ((weaponGrade == L2Item.CRYSTAL_NONE && itemId != 3947) || (weaponGrade == L2Item.CRYSTAL_D && itemId != 3948) || (weaponGrade == L2Item.CRYSTAL_C && itemId != 3949) || (weaponGrade == L2Item.CRYSTAL_B && itemId != 3950)
  76. || (weaponGrade == L2Item.CRYSTAL_A && itemId != 3951) || (weaponGrade == L2Item.CRYSTAL_S && itemId != 3952) || (weaponGrade == L2Item.CRYSTAL_S80 && itemId != 3952))
  77. {
  78. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  79. activeChar.sendPacket(new SystemMessage(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH));
  80. return;
  81. }
  82. // Consume Blessed SpiritShot if player has enough of them
  83. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  84. {
  85. if (activeChar.getAutoSoulShot().containsKey(itemId))
  86. {
  87. activeChar.removeAutoSoulShot(itemId);
  88. activeChar.sendPacket(new ExAutoSoulShot(itemId, 0));
  89. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  90. sm.addString(item.getItem().getName());
  91. activeChar.sendPacket(sm);
  92. }
  93. else
  94. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS));
  95. return;
  96. }
  97. // Charge Blessed SpiritShot
  98. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  99. // Send message to client
  100. activeChar.sendPacket(new SystemMessage(SystemMessageId.ENABLED_SPIRITSHOT));
  101. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, SKILL_IDS[weaponGrade], 1, 0, 0), 360000);
  102. }
  103. /**
  104. *
  105. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  106. */
  107. public int[] getItemIds()
  108. {
  109. return ITEM_IDS;
  110. }
  111. }