BeastSoulShot.java 3.4 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.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 SoulShot Handler
  28. * @author Tempy
  29. */
  30. public class BeastSoulShot 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. final L2PcInstance activeOwner = playable.getActingPlayer();
  41. if (!activeOwner.hasSummon())
  42. {
  43. activeOwner.sendPacket(SystemMessageId.PETS_ARE_NOT_AVAILABLE_AT_THIS_TIME);
  44. return false;
  45. }
  46. if (activeOwner.getSummon().isDead())
  47. {
  48. activeOwner.sendPacket(SystemMessageId.SOULSHOTS_AND_SPIRITSHOTS_ARE_NOT_AVAILABLE_FOR_A_DEAD_PET);
  49. return false;
  50. }
  51. final int itemId = item.getItemId();
  52. final short shotConsumption = activeOwner.getSummon().getSoulShotsPerHit();
  53. final long shotCount = item.getCount();
  54. final SkillHolder[] skills = item.getItem().getSkills();
  55. if (skills == null)
  56. {
  57. _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
  58. return false;
  59. }
  60. if (shotCount < shotConsumption)
  61. {
  62. // Not enough Soulshots to use.
  63. if (!activeOwner.disableAutoShot(itemId))
  64. {
  65. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET);
  66. }
  67. return false;
  68. }
  69. if (activeOwner.getSummon().isChargedShot(ShotType.SOULSHOTS))
  70. {
  71. // SoulShots are already active.
  72. return false;
  73. }
  74. // If the player doesn't have enough beast soulshot remaining, remove any auto soulshot task.
  75. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  76. {
  77. if (!activeOwner.disableAutoShot(itemId))
  78. {
  79. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET);
  80. }
  81. return false;
  82. }
  83. // Pet uses the power of spirit.
  84. activeOwner.sendPacket(SystemMessageId.PET_USE_SPIRITSHOT);
  85. activeOwner.getSummon().setChargedShot(ShotType.SOULSHOTS, true);
  86. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activeOwner.getSummon(), activeOwner.getSummon(), skills[0].getSkillId(), skills[0].getSkillLvl(), 0, 0), 600);
  87. return true;
  88. }
  89. }