BeastSpiritShot.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.handler.IItemHandler;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.L2Summon;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2BabyPetInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.network.serverpackets.ExAutoSoulShot;
  25. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. import net.sf.l2j.gameserver.templates.L2Weapon;
  28. import net.sf.l2j.gameserver.util.Broadcast;
  29. /**
  30. * Beast SpiritShot Handler
  31. *
  32. * @author Tempy
  33. */
  34. public class BeastSpiritShot implements IItemHandler
  35. {
  36. // All the item IDs that this handler knows.
  37. private static final int[] ITEM_IDS =
  38. {
  39. 6646, 6647
  40. };
  41. /**
  42. *
  43. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  44. */
  45. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  46. {
  47. if (playable == null)
  48. return;
  49. L2PcInstance activeOwner = null;
  50. if (playable instanceof L2Summon)
  51. {
  52. activeOwner = ((L2Summon) playable).getOwner();
  53. activeOwner.sendPacket(new SystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
  54. return;
  55. }
  56. else if (playable instanceof L2PcInstance)
  57. {
  58. activeOwner = (L2PcInstance) playable;
  59. }
  60. if (activeOwner == null)
  61. return;
  62. L2Summon activePet = activeOwner.getPet();
  63. if (activePet == null)
  64. {
  65. activeOwner.sendPacket(new SystemMessage(SystemMessageId.PETS_ARE_NOT_AVAILABLE_AT_THIS_TIME));
  66. return;
  67. }
  68. if (activePet.isDead())
  69. {
  70. activeOwner.sendPacket(new SystemMessage(SystemMessageId.SOULSHOTS_AND_SPIRITSHOTS_ARE_NOT_AVAILABLE_FOR_A_DEAD_PET));
  71. return;
  72. }
  73. int itemId = item.getItemId();
  74. boolean isBlessed = (itemId == 6647);
  75. int shotConsumption = 1;
  76. L2ItemInstance weaponInst = null;
  77. L2Weapon weaponItem = null;
  78. if ((activePet instanceof L2PetInstance) && !(activePet instanceof L2BabyPetInstance))
  79. {
  80. weaponInst = ((L2PetInstance) activePet).getActiveWeaponInstance();
  81. weaponItem = ((L2PetInstance) activePet).getActiveWeaponItem();
  82. if (weaponInst == null)
  83. {
  84. activeOwner.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SPIRITSHOTS));
  85. return;
  86. }
  87. if (weaponInst.getChargedSpiritshot() != L2ItemInstance.CHARGED_NONE)
  88. {
  89. // SpiritShots are already active.
  90. return;
  91. }
  92. int shotCount = item.getCount();
  93. shotConsumption = weaponItem.getSpiritShotCount();
  94. if (shotConsumption == 0)
  95. {
  96. activeOwner.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SPIRITSHOTS));
  97. return;
  98. }
  99. if (!(shotCount > shotConsumption))
  100. {
  101. // Not enough SpiritShots to use.
  102. activeOwner.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SPIRITHOTS_FOR_PET));
  103. return;
  104. }
  105. if (isBlessed)
  106. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  107. else
  108. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_SPIRITSHOT);
  109. }
  110. else
  111. {
  112. if (activePet.getChargedSpiritShot() != L2ItemInstance.CHARGED_NONE)
  113. return;
  114. if (isBlessed)
  115. activePet.setChargedSpiritShot(L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT);
  116. else
  117. activePet.setChargedSpiritShot(L2ItemInstance.CHARGED_SPIRITSHOT);
  118. }
  119. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  120. {
  121. if (activeOwner.getAutoSoulShot().containsKey(itemId))
  122. {
  123. activeOwner.removeAutoSoulShot(itemId);
  124. activeOwner.sendPacket(new ExAutoSoulShot(itemId, 0));
  125. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  126. sm.addString(item.getItem().getName());
  127. activeOwner.sendPacket(sm);
  128. return;
  129. }
  130. activeOwner.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SPIRITSHOTS));
  131. return;
  132. }
  133. // Pet uses the power of spirit.
  134. activeOwner.sendPacket(new SystemMessage(SystemMessageId.PET_USE_THE_POWER_OF_SPIRIT));
  135. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activePet, activePet, isBlessed ? 2009 : 2008, 1, 0, 0), 360000/*600*/);
  136. }
  137. /**
  138. *
  139. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  140. */
  141. public int[] getItemIds()
  142. {
  143. return ITEM_IDS;
  144. }
  145. }