BeastSpiritShot.java 4.1 KB

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