BlessedSpiritShot.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. public class BlessedSpiritShot implements IItemHandler
  29. {
  30. @Override
  31. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  32. {
  33. if (!playable.isPlayer())
  34. {
  35. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  36. return false;
  37. }
  38. L2PcInstance activeChar = (L2PcInstance) playable;
  39. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  40. L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  41. final SkillHolder[] skills = item.getItem().getSkills();
  42. int itemId = item.getItemId();
  43. if (skills == null)
  44. {
  45. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  46. return false;
  47. }
  48. // Check if Blessed SpiritShot can be used
  49. if ((weaponInst == null) || (weaponItem == null) || (weaponItem.getSpiritShotCount() == 0))
  50. {
  51. if (!activeChar.getAutoSoulShot().contains(itemId))
  52. {
  53. activeChar.sendPacket(SystemMessageId.CANNOT_USE_SPIRITSHOTS);
  54. }
  55. return false;
  56. }
  57. // Check if Blessed SpiritShot is already active (it can be charged over SpiritShot)
  58. if (activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS))
  59. {
  60. return false;
  61. }
  62. // Check for correct grade
  63. boolean gradeCheck = item.isEtcItem() && (item.getEtcItem().getDefaultAction() == L2ActionType.spiritshot) && (weaponInst.getItem().getItemGradeSPlus() == item.getItem().getItemGradeSPlus());
  64. if (!gradeCheck)
  65. {
  66. if (!activeChar.getAutoSoulShot().contains(itemId))
  67. {
  68. activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH);
  69. }
  70. return false;
  71. }
  72. // Consume Blessed SpiritShot if player has enough of them
  73. if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
  74. {
  75. if (!activeChar.disableAutoShot(itemId))
  76. {
  77. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS);
  78. }
  79. return false;
  80. }
  81. // Send message to client
  82. activeChar.sendPacket(SystemMessageId.ENABLED_SPIRITSHOT);
  83. activeChar.setChargedShot(ShotType.BLESSED_SPIRITSHOTS, true);
  84. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0), 600);
  85. return true;
  86. }
  87. }