SoulShots.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.skills.Stats;
  25. import net.sf.l2j.gameserver.templates.L2Item;
  26. import net.sf.l2j.gameserver.templates.L2Weapon;
  27. import net.sf.l2j.gameserver.util.Broadcast;
  28. /**
  29. * This class ...
  30. *
  31. * @version $Revision: 1.2.4.4 $ $Date: 2005/03/27 15:30:07 $
  32. */
  33. public class SoulShots implements IItemHandler
  34. {
  35. // All the item IDs that this handler knows.
  36. private static final int[] ITEM_IDS =
  37. {
  38. 5789, 1835, 1463, 1464, 1465, 1466, 1467
  39. };
  40. private static final int[] SKILL_IDS =
  41. {
  42. 2039, 2150, 2151, 2152, 2153, 2154, 2154
  43. };
  44. /**
  45. *
  46. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  47. */
  48. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  49. {
  50. if (!(playable instanceof L2PcInstance))
  51. return;
  52. L2PcInstance activeChar = (L2PcInstance) playable;
  53. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  54. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  55. int itemId = item.getItemId();
  56. // Check if Soul shot can be used
  57. if (weaponInst == null || weaponItem.getSoulShotCount() == 0)
  58. {
  59. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  60. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SOULSHOTS));
  61. return;
  62. }
  63. // Check for correct grade
  64. int weaponGrade = weaponItem.getCrystalType();
  65. if ((weaponGrade == L2Item.CRYSTAL_NONE && itemId != 5789 && itemId != 1835) || (weaponGrade == L2Item.CRYSTAL_D && itemId != 1463) || (weaponGrade == L2Item.CRYSTAL_C && itemId != 1464)
  66. || (weaponGrade == L2Item.CRYSTAL_B && itemId != 1465) || (weaponGrade == L2Item.CRYSTAL_A && itemId != 1466) || (weaponGrade == L2Item.CRYSTAL_S && itemId != 1467) || (weaponGrade == L2Item.CRYSTAL_S80 && itemId != 1467))
  67. {
  68. if (!activeChar.getAutoSoulShot().containsKey(itemId))
  69. activeChar.sendPacket(new SystemMessage(SystemMessageId.SOULSHOTS_GRADE_MISMATCH));
  70. return;
  71. }
  72. activeChar.soulShotLock.lock();
  73. try
  74. {
  75. // Check if Soul shot is already active
  76. if (weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  77. return;
  78. // Consume Soul shots if player has enough of them
  79. int saSSCount = (int) activeChar.getStat().calcStat(Stats.SOULSHOT_COUNT, 0, null, null);
  80. int SSCount = saSSCount == 0 ? weaponItem.getSoulShotCount() : saSSCount;
  81. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), SSCount, null, false))
  82. {
  83. if (activeChar.getAutoSoulShot().containsKey(itemId))
  84. {
  85. activeChar.removeAutoSoulShot(itemId);
  86. activeChar.sendPacket(new ExAutoSoulShot(itemId, 0));
  87. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  88. sm.addString(item.getItem().getName());
  89. activeChar.sendPacket(sm);
  90. }
  91. else
  92. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS));
  93. return;
  94. }
  95. // Charge soul shot
  96. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_SOULSHOT);
  97. }
  98. finally
  99. {
  100. activeChar.soulShotLock.unlock();
  101. }
  102. // Send message to client
  103. activeChar.sendPacket(new SystemMessage(SystemMessageId.ENABLED_SOULSHOT));
  104. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, SKILL_IDS[weaponGrade], 1, 0, 0), 360000);
  105. }
  106. /**
  107. *
  108. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  109. */
  110. public int[] getItemIds()
  111. {
  112. return ITEM_IDS;
  113. }
  114. }