SpiritShot.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 handlers.itemhandlers;
  16. import com.l2jserver.gameserver.handler.IItemHandler;
  17. import com.l2jserver.gameserver.model.actor.L2Playable;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.items.L2Item;
  20. import com.l2jserver.gameserver.model.items.L2Weapon;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  24. import com.l2jserver.gameserver.util.Broadcast;
  25. public class SpiritShot implements IItemHandler
  26. {
  27. @Override
  28. public synchronized boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  29. {
  30. if (!(playable instanceof L2PcInstance))
  31. return false;
  32. L2PcInstance activeChar = (L2PcInstance) playable;
  33. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  34. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  35. int itemId = item.getItemId();
  36. // Check if Spirit shot can be used
  37. if (weaponInst == null || weaponItem.getSpiritShotCount() == 0)
  38. {
  39. if (!activeChar.getAutoSoulShot().contains(itemId))
  40. activeChar.sendPacket(SystemMessageId.CANNOT_USE_SPIRITSHOTS);
  41. return false;
  42. }
  43. // Check if Spirit shot is already active
  44. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  45. return false;
  46. final int weaponGrade = weaponItem.getCrystalType();
  47. boolean gradeCheck = true;
  48. switch (weaponGrade)
  49. {
  50. case L2Item.CRYSTAL_NONE:
  51. if (itemId != 5790 && itemId != 2509)
  52. gradeCheck = false;
  53. break;
  54. case L2Item.CRYSTAL_D:
  55. if (itemId != 2510 && itemId != 22077)
  56. gradeCheck = false;
  57. break;
  58. case L2Item.CRYSTAL_C:
  59. if (itemId != 2511 && itemId != 22078)
  60. gradeCheck = false;
  61. break;
  62. case L2Item.CRYSTAL_B:
  63. if (itemId != 2512 && itemId != 22079)
  64. gradeCheck = false;
  65. break;
  66. case L2Item.CRYSTAL_A:
  67. if (itemId != 2513 && itemId != 22080)
  68. gradeCheck = false;
  69. break;
  70. case L2Item.CRYSTAL_S:
  71. case L2Item.CRYSTAL_S80:
  72. case L2Item.CRYSTAL_S84:
  73. if (itemId != 2514 && itemId != 22081)
  74. gradeCheck = false;
  75. break;
  76. }
  77. if (!gradeCheck)
  78. {
  79. if (!activeChar.getAutoSoulShot().contains(itemId))
  80. activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH);
  81. return false;
  82. }
  83. // Consume Spirit shot if player has enough of them
  84. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  85. {
  86. if (!activeChar.disableAutoShot(itemId))
  87. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS);
  88. return false;
  89. }
  90. // Charge Spirit shot
  91. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_SPIRITSHOT);
  92. int skillId = 0;
  93. switch (itemId)
  94. {
  95. case 2509:
  96. case 5790:
  97. skillId=2061;
  98. break;
  99. case 2510:
  100. skillId=2155;
  101. break;
  102. case 2511:
  103. skillId=2156;
  104. break;
  105. case 2512:
  106. skillId=2157;
  107. break;
  108. case 2513:
  109. skillId=2158;
  110. break;
  111. case 2514:
  112. skillId=2159;
  113. break;
  114. case 22077:
  115. skillId=26055;
  116. break;
  117. case 22078:
  118. skillId=26056;
  119. break;
  120. case 22079:
  121. skillId=26057;
  122. break;
  123. case 22080:
  124. skillId=26058;
  125. break;
  126. case 22081:
  127. skillId=26059;
  128. break;
  129. }
  130. // Send message to client
  131. activeChar.sendPacket(SystemMessageId.ENABLED_SPIRITSHOT);
  132. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skillId, 1, 0, 0), 360000);
  133. return true;
  134. }
  135. }