BlessedSpiritShot.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 BlessedSpiritShot 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 Blessed SpiritShot can be used
  37. if (weaponInst == null || weaponItem == 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 Blessed SpiritShot is already active (it can be charged over SpiritShot)
  44. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  45. return false;
  46. // Check for correct grade
  47. final int weaponGrade = weaponItem.getCrystalType();
  48. boolean gradeCheck = true;
  49. switch (weaponGrade)
  50. {
  51. case L2Item.CRYSTAL_NONE:
  52. if (itemId != 3947)
  53. gradeCheck = false;
  54. break;
  55. case L2Item.CRYSTAL_D:
  56. if (itemId != 3948 && itemId != 22072)
  57. gradeCheck = false;
  58. break;
  59. case L2Item.CRYSTAL_C:
  60. if (itemId != 3949 && itemId != 22073)
  61. gradeCheck = false;
  62. break;
  63. case L2Item.CRYSTAL_B:
  64. if (itemId != 3950 && itemId != 22074)
  65. gradeCheck = false;
  66. break;
  67. case L2Item.CRYSTAL_A:
  68. if (itemId != 3951 && itemId != 22075)
  69. gradeCheck = false;
  70. break;
  71. case L2Item.CRYSTAL_S:
  72. case L2Item.CRYSTAL_S80:
  73. case L2Item.CRYSTAL_S84:
  74. if (itemId != 3952 && itemId != 22076)
  75. gradeCheck = false;
  76. break;
  77. }
  78. if (!gradeCheck)
  79. {
  80. if (!activeChar.getAutoSoulShot().contains(itemId))
  81. activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH);
  82. return false;
  83. }
  84. // Consume Blessed SpiritShot if player has enough of them
  85. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  86. {
  87. if (!activeChar.disableAutoShot(itemId))
  88. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS);
  89. return false;
  90. }
  91. // Charge Blessed SpiritShot
  92. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  93. // Send message to client
  94. activeChar.sendPacket(SystemMessageId.ENABLED_SPIRITSHOT);
  95. int skillId = 0;
  96. switch (itemId)
  97. {
  98. case 3947:
  99. skillId=2061;
  100. break;
  101. case 3948:
  102. skillId=2160;
  103. break;
  104. case 3949:
  105. skillId=2161;
  106. break;
  107. case 3950:
  108. skillId=2162;
  109. break;
  110. case 3951:
  111. skillId=2163;
  112. break;
  113. case 3952:
  114. skillId=2164;
  115. break;
  116. case 22072:
  117. skillId=26050;
  118. break;
  119. case 22073:
  120. skillId=26051;
  121. break;
  122. case 22074:
  123. skillId=26052;
  124. break;
  125. case 22075:
  126. skillId=26053;
  127. break;
  128. case 22076:
  129. skillId=26054;
  130. break;
  131. }
  132. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skillId, 1, 0, 0), 360000);
  133. return true;
  134. }
  135. }