BeastSpiritShot.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.items.instance.L2ItemInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  24. import com.l2jserver.gameserver.util.Broadcast;
  25. /**
  26. * Beast SpiritShot Handler
  27. * @author Tempy
  28. */
  29. public class BeastSpiritShot implements IItemHandler
  30. {
  31. @Override
  32. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  33. {
  34. if (playable == null)
  35. return false;
  36. L2PcInstance activeOwner = playable.getActingPlayer();
  37. if (playable instanceof L2Summon)
  38. {
  39. activeOwner.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  40. return false;
  41. }
  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. int itemId = item.getItemId();
  54. boolean isBlessed = (itemId == 6647 || itemId == 20334);
  55. short shotConsumption = activePet.getSpiritShotsPerHit();
  56. long shotCount = item.getCount();
  57. if (!(shotCount > shotConsumption))
  58. {
  59. // Not enough SpiritShots to use.
  60. if (!activeOwner.disableAutoShot(itemId))
  61. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITHOTS_FOR_PET);
  62. return false;
  63. }
  64. L2ItemInstance weaponInst = null;
  65. if (activePet instanceof L2PetInstance)
  66. weaponInst = ((L2PetInstance) activePet).getActiveWeaponInstance();
  67. if (weaponInst == null)
  68. {
  69. if (activePet.getChargedSpiritShot() != L2ItemInstance.CHARGED_NONE)
  70. return false;
  71. if (isBlessed)
  72. activePet.setChargedSpiritShot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  73. else
  74. activePet.setChargedSpiritShot(L2ItemInstance.CHARGED_SPIRITSHOT);
  75. }
  76. else
  77. {
  78. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  79. {
  80. // SpiritShots are already active.
  81. return false;
  82. }
  83. if (isBlessed)
  84. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  85. else
  86. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_SPIRITSHOT);
  87. }
  88. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  89. {
  90. if (!activeOwner.disableAutoShot(itemId))
  91. activeOwner.sendPacket(SystemMessageId.NOT_ENOUGH_SPIRITHOTS_FOR_PET);
  92. return false;
  93. }
  94. // Pet uses the power of spirit.
  95. activeOwner.sendPacket(SystemMessageId.PET_USE_SPIRITSHOT);
  96. int skillId = 0;
  97. switch (itemId)
  98. {
  99. case 6646:
  100. skillId = 2008;
  101. break;
  102. case 6647:
  103. skillId = 2009;
  104. break;
  105. case 20333:
  106. skillId = 22037;
  107. break;
  108. case 20334:
  109. skillId = 22038;
  110. break;
  111. }
  112. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activePet, activePet, skillId, 1, 0, 0), 360000/*600*/);
  113. return true;
  114. }
  115. }