BlessedSpiritShot.java 4.8 KB

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