BeastSpiritShot.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.L2Summon;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.holders.SkillHolder;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  26. import com.l2jserver.gameserver.util.Broadcast;
  27. /**
  28. * Beast SpiritShot Handler
  29. * @author Tempy
  30. */
  31. public class BeastSpiritShot implements IItemHandler
  32. {
  33. @Override
  34. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  35. {
  36. if (!playable.isPlayer())
  37. {
  38. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  39. return false;
  40. }
  41. L2PcInstance activeOwner = playable.getActingPlayer();
  42. L2Summon activePet = activeOwner.getPet();
  43. if (activePet == null)
  44. {
  45. activeOwner.sendPacket(SystemMessageId.PETS_ARE_NOT_AVAILABLE_AT_THIS_TIME);
  46. return false;
  47. }
  48. if (activePet.isDead())
  49. {
  50. activeOwner.sendPacket(SystemMessageId.SOULSHOTS_AND_SPIRITSHOTS_ARE_NOT_AVAILABLE_FOR_A_DEAD_PET);
  51. return false;
  52. }
  53. final int itemId = item.getItemId();
  54. final boolean isBlessed = ((itemId == 6647) || (itemId == 20334)); // TODO: Unhardcode these!
  55. final short shotConsumption = activePet.getSpiritShotsPerHit();
  56. final SkillHolder[] skills = item.getItem().getSkills();
  57. if (skills == null)
  58. {
  59. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  60. return false;
  61. }
  62. long shotCount = item.getCount();
  63. if (shotCount < shotConsumption)
  64. {
  65. // Not enough SpiritShots to use.
  66. if (!activeOwner.disableAutoShot(itemId))
  67. {
  68. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITHOTS_FOR_PET);
  69. }
  70. return false;
  71. }
  72. if (activePet.isChargedShot(isBlessed ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS))
  73. {
  74. // shots are already active.
  75. return false;
  76. }
  77. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  78. {
  79. if (!activeOwner.disableAutoShot(itemId))
  80. {
  81. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITHOTS_FOR_PET);
  82. }
  83. return false;
  84. }
  85. // Pet uses the power of spirit.
  86. activeOwner.sendPacket(SystemMessageId.PET_USE_SPIRITSHOT);
  87. activePet.setChargedShot(isBlessed ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, true);
  88. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activePet, activePet, skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0), 600);
  89. return true;
  90. }
  91. }