SpiritShot.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 SpiritShot implements IItemHandler
  33. {
  34. // All the item IDs that this handler knows.
  35. private static final int[] ITEM_IDS =
  36. {
  37. 5790, 2509, 2510, 2511, 2512, 2513, 2514
  38. };
  39. private static final int[] SKILL_IDS =
  40. {
  41. 2061, 2155, 2156, 2157, 2158, 2159, 2159
  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. // Check if Spirit shot can be used
  56. if (weaponInst == null || weaponItem.getSpiritShotCount() == 0)
  57. {
  58. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  59. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SPIRITSHOTS));
  60. return;
  61. }
  62. // Check if Spirit shot is already active
  63. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  64. return;
  65. // Check for correct grade
  66. int weaponGrade = weaponItem.getCrystalType();
  67. if ((weaponGrade == L2Item.CRYSTAL_NONE && itemId != 5790 && itemId != 2509) || (weaponGrade == L2Item.CRYSTAL_D && itemId != 2510) || (weaponGrade == L2Item.CRYSTAL_C && itemId != 2511)
  68. || (weaponGrade == L2Item.CRYSTAL_B && itemId != 2512) || (weaponGrade == L2Item.CRYSTAL_A && itemId != 2513) || (weaponGrade == L2Item.CRYSTAL_S && itemId != 2514) || (weaponGrade == L2Item.CRYSTAL_S80 && itemId != 2514))
  69. {
  70. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  71. activeChar.sendPacket(new SystemMessage(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH));
  72. return;
  73. }
  74. // Consume Spirit shot if player has enough of them
  75. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  76. {
  77. if (activeChar.getAutoSoulShot().containsKey(itemId))
  78. {
  79. activeChar.removeAutoSoulShot(itemId);
  80. activeChar.sendPacket(new ExAutoSoulShot(itemId, 0));
  81. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  82. sm.addString(item.getItem().getName());
  83. activeChar.sendPacket(sm);
  84. }
  85. else
  86. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS));
  87. return;
  88. }
  89. // Charge Spirit shot
  90. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_SPIRITSHOT);
  91. // Send message to client
  92. activeChar.sendPacket(new SystemMessage(SystemMessageId.ENABLED_SPIRITSHOT));
  93. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, SKILL_IDS[weaponGrade], 1, 0, 0), 360000);
  94. }
  95. /**
  96. *
  97. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  98. */
  99. public int[] getItemIds()
  100. {
  101. return ITEM_IDS;
  102. }
  103. }