SpiritShot.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.actor.L2Playable;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.holders.SkillHolder;
  21. import com.l2jserver.gameserver.model.items.L2Weapon;
  22. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  26. import com.l2jserver.gameserver.util.Broadcast;
  27. public class SpiritShot implements IItemHandler
  28. {
  29. @Override
  30. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  31. {
  32. if (!playable.isPlayer())
  33. {
  34. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  35. return false;
  36. }
  37. final L2PcInstance activeChar = (L2PcInstance) playable;
  38. final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  39. final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  40. final SkillHolder[] skills = item.getItem().getSkills();
  41. int itemId = item.getItemId();
  42. if (skills == null)
  43. {
  44. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  45. return false;
  46. }
  47. // Check if Spirit shot can be used
  48. if (weaponInst == null || weaponItem.getSpiritShotCount() == 0)
  49. {
  50. if (!activeChar.getAutoSoulShot().contains(itemId))
  51. activeChar.sendPacket(SystemMessageId.CANNOT_USE_SPIRITSHOTS);
  52. return false;
  53. }
  54. // Check if Spirit shot is already active
  55. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  56. return false;
  57. boolean gradeCheck = item.isEtcItem() && item.getEtcItem().getDefaultAction() == L2ActionType.spiritshot && weaponInst.getItem().getItemGradeSPlus() == item.getItem().getItemGradeSPlus();
  58. if (!gradeCheck)
  59. {
  60. if (!activeChar.getAutoSoulShot().contains(itemId))
  61. activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH);
  62. return false;
  63. }
  64. // Consume Spirit shot if player has enough of them
  65. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  66. {
  67. if (!activeChar.disableAutoShot(itemId))
  68. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS);
  69. return false;
  70. }
  71. // Charge Spirit shot
  72. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_SPIRITSHOT);
  73. // Send message to client
  74. activeChar.sendPacket(SystemMessageId.ENABLED_SPIRITSHOT);
  75. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0), 2000);
  76. return true;
  77. }
  78. }