SpiritShot.java 4.7 KB

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