SoulShots.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.skills.Stats;
  25. import com.l2jserver.gameserver.util.Broadcast;
  26. public class SoulShots implements IItemHandler
  27. {
  28. public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  29. {
  30. if (!(playable instanceof L2PcInstance))
  31. {
  32. return;
  33. }
  34. final L2PcInstance activeChar = playable.getActingPlayer();
  35. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  36. final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  37. final int itemId = item.getItemId();
  38. // Check if Soul shot can be used
  39. if ((weaponInst == null) || (weaponItem.getSoulShotCount() == 0))
  40. {
  41. if (!activeChar.getAutoSoulShot().contains(itemId))
  42. {
  43. activeChar.sendPacket(SystemMessageId.CANNOT_USE_SOULSHOTS);
  44. }
  45. return;
  46. }
  47. boolean gradeCheck = true;
  48. final int weaponGrade = weaponItem.getCrystalType();
  49. switch (weaponGrade)
  50. {
  51. case L2Item.CRYSTAL_NONE:
  52. if ((itemId != 5789) && (itemId != 1835))
  53. {
  54. gradeCheck = false;
  55. }
  56. break;
  57. case L2Item.CRYSTAL_D:
  58. if ((itemId != 1463) && (itemId != 22082))
  59. {
  60. gradeCheck = false;
  61. }
  62. break;
  63. case L2Item.CRYSTAL_C:
  64. if ((itemId != 1464) && (itemId != 22083))
  65. {
  66. gradeCheck = false;
  67. }
  68. break;
  69. case L2Item.CRYSTAL_B:
  70. if ((itemId != 1465) && (itemId != 22084))
  71. {
  72. gradeCheck = false;
  73. }
  74. break;
  75. case L2Item.CRYSTAL_A:
  76. if ((itemId != 1466) && (itemId != 22085))
  77. {
  78. gradeCheck = false;
  79. }
  80. break;
  81. case L2Item.CRYSTAL_S:
  82. case L2Item.CRYSTAL_S80:
  83. case L2Item.CRYSTAL_S84:
  84. if ((itemId != 1467) && (itemId != 22086))
  85. {
  86. gradeCheck = false;
  87. }
  88. break;
  89. }
  90. if (!gradeCheck)
  91. {
  92. if (!activeChar.getAutoSoulShot().contains(itemId))
  93. {
  94. activeChar.sendPacket(SystemMessageId.SOULSHOTS_GRADE_MISMATCH);
  95. }
  96. return;
  97. }
  98. activeChar.soulShotLock.lock();
  99. try
  100. {
  101. // Check if Soul shot is already active
  102. if (weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  103. {
  104. return;
  105. }
  106. // Consume Soul shots if player has enough of them
  107. final int saSSCount = (int) activeChar.getStat().calcStat(Stats.SOULSHOT_COUNT, 0, null, null);
  108. final int SSCount = saSSCount == 0 ? weaponItem.getSoulShotCount() : saSSCount;
  109. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), SSCount, null, false))
  110. {
  111. if (!activeChar.disableAutoShot(itemId))
  112. {
  113. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS);
  114. }
  115. return;
  116. }
  117. // Charge soul shot
  118. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_SOULSHOT);
  119. }
  120. finally
  121. {
  122. activeChar.soulShotLock.unlock();
  123. }
  124. int skillId = 0;
  125. switch (itemId)
  126. {
  127. case 1835:
  128. case 5789:
  129. skillId = 2039;
  130. break;
  131. case 1463:
  132. skillId = 2150;
  133. break;
  134. case 1464:
  135. skillId = 2151;
  136. break;
  137. case 1465:
  138. skillId = 2152;
  139. break;
  140. case 1466:
  141. skillId = 2153;
  142. break;
  143. case 1467:
  144. skillId = 2154;
  145. break;
  146. case 22082:
  147. skillId = 26060;
  148. break;
  149. case 22083:
  150. skillId = 26061;
  151. break;
  152. case 22084:
  153. skillId = 26062;
  154. break;
  155. case 22085:
  156. skillId = 26063;
  157. break;
  158. case 22086:
  159. skillId = 26064;
  160. break;
  161. }
  162. // Send message to client
  163. activeChar.sendPacket(SystemMessageId.ENABLED_SOULSHOT);
  164. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skillId, 1, 0, 0), 360000);
  165. }
  166. }