SoulShots.java 4.8 KB

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