SoulShots.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 java.util.logging.Level;
  17. import com.l2jserver.gameserver.handler.IItemHandler;
  18. import com.l2jserver.gameserver.model.ShotType;
  19. import com.l2jserver.gameserver.model.actor.L2Playable;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.holders.SkillHolder;
  22. import com.l2jserver.gameserver.model.items.L2Weapon;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  27. import com.l2jserver.gameserver.util.Broadcast;
  28. import com.l2jserver.util.Rnd;
  29. public class SoulShots implements IItemHandler
  30. {
  31. @Override
  32. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  33. {
  34. if (!playable.isPlayer())
  35. {
  36. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  37. return false;
  38. }
  39. final L2PcInstance activeChar = playable.getActingPlayer();
  40. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  41. final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  42. final SkillHolder[] skills = item.getItem().getSkills();
  43. int itemId = item.getItemId();
  44. if (skills == null)
  45. {
  46. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  47. return false;
  48. }
  49. // Check if Soul shot can be used
  50. if ((weaponInst == null) || (weaponItem.getSoulShotCount() == 0))
  51. {
  52. if (!activeChar.getAutoSoulShot().contains(itemId))
  53. {
  54. activeChar.sendPacket(SystemMessageId.CANNOT_USE_SOULSHOTS);
  55. }
  56. return false;
  57. }
  58. boolean gradeCheck = item.isEtcItem() && (item.getEtcItem().getDefaultAction() == L2ActionType.soulshot) && (weaponInst.getItem().getItemGradeSPlus() == item.getItem().getItemGradeSPlus());
  59. if (!gradeCheck)
  60. {
  61. if (!activeChar.getAutoSoulShot().contains(itemId))
  62. {
  63. activeChar.sendPacket(SystemMessageId.SOULSHOTS_GRADE_MISMATCH);
  64. }
  65. return false;
  66. }
  67. activeChar.soulShotLock.lock();
  68. try
  69. {
  70. // Check if Soul shot is already active
  71. if (activeChar.isChargedShot(ShotType.SOULSHOTS))
  72. {
  73. return false;
  74. }
  75. // Consume Soul shots if player has enough of them
  76. int SSCount = weaponItem.getSoulShotCount();
  77. if ((weaponItem.getReducedSoulShot() > 0) && (Rnd.get(100) < weaponItem.getReducedSoulShotChance()))
  78. {
  79. SSCount = weaponItem.getReducedSoulShot();
  80. }
  81. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), SSCount, null, false))
  82. {
  83. if (!activeChar.disableAutoShot(itemId))
  84. {
  85. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS);
  86. }
  87. return false;
  88. }
  89. // Charge soul shot
  90. weaponInst.setChargedShot(ShotType.SOULSHOTS, true);
  91. }
  92. finally
  93. {
  94. activeChar.soulShotLock.unlock();
  95. }
  96. // Send message to client
  97. activeChar.sendPacket(SystemMessageId.ENABLED_SOULSHOT);
  98. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0), 600);
  99. return true;
  100. }
  101. }