BeastSoulShot.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 com.l2jserver.gameserver.handler.IItemHandler;
  17. import com.l2jserver.gameserver.model.actor.L2Playable;
  18. import com.l2jserver.gameserver.model.actor.L2Summon;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  21. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.util.Broadcast;
  26. /**
  27. * Beast SoulShot Handler
  28. *
  29. * @author Tempy
  30. */
  31. public class BeastSoulShot implements IItemHandler
  32. {
  33. /**
  34. *
  35. * @see com.l2jserver.gameserver.handler.IItemHandler#useItem(com.l2jserver.gameserver.model.actor.L2Playable, com.l2jserver.gameserver.model.L2ItemInstance, boolean)
  36. */
  37. public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. if (playable == null)
  40. return;
  41. L2PcInstance activeOwner = null;
  42. if (playable instanceof L2Summon)
  43. {
  44. activeOwner = ((L2Summon) playable).getOwner();
  45. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
  46. return;
  47. }
  48. else if (playable instanceof L2PcInstance)
  49. activeOwner = (L2PcInstance) playable;
  50. if (activeOwner == null)
  51. return;
  52. L2Summon activePet = activeOwner.getPet();
  53. if (activePet == null)
  54. {
  55. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PETS_ARE_NOT_AVAILABLE_AT_THIS_TIME));
  56. return;
  57. }
  58. if (activePet.isDead())
  59. {
  60. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SOULSHOTS_AND_SPIRITSHOTS_ARE_NOT_AVAILABLE_FOR_A_DEAD_PET));
  61. return;
  62. }
  63. int itemId = item.getItemId();
  64. short shotConsumption = activePet.getSoulShotsPerHit();
  65. long shotCount = item.getCount();
  66. if (!(shotCount > shotConsumption))
  67. {
  68. // Not enough Soulshots to use.
  69. if (!activeOwner.disableAutoShot(itemId))
  70. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  71. return;
  72. }
  73. L2ItemInstance weaponInst = null;
  74. if (activePet instanceof L2PetInstance)
  75. weaponInst = ((L2PetInstance) activePet).getActiveWeaponInstance();
  76. if (weaponInst == null)
  77. {
  78. if (activePet.getChargedSoulShot() != L2ItemInstance.CHARGED_NONE)
  79. return;
  80. activePet.setChargedSoulShot(L2ItemInstance.CHARGED_SOULSHOT);
  81. }
  82. else
  83. {
  84. if (weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  85. {
  86. // SoulShots are already active.
  87. return;
  88. }
  89. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_SOULSHOT);
  90. }
  91. // If the player doesn't have enough beast soulshot remaining, remove any auto soulshot task.
  92. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  93. {
  94. if (!activeOwner.disableAutoShot(itemId))
  95. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  96. return;
  97. }
  98. // Pet uses the power of spirit.
  99. activeOwner.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_USE_SPIRITSHOT));
  100. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activePet, activePet, itemId == 6645 ? 2033 : 22036, 1, 0, 0), 360000/*600*/);
  101. }
  102. }