BeastSoulShot.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 SoulShot Handler
  31. *
  32. * @author Tempy
  33. */
  34. public class BeastSoulShot implements IItemHandler
  35. {
  36. // All the item IDs that this handler knows.
  37. private static final int[] ITEM_IDS =
  38. {
  39. 6645
  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 = 6645;
  74. int shotConsumption = 1;
  75. L2ItemInstance weaponInst = null;
  76. L2Weapon weaponItem = null;
  77. if ((activePet instanceof L2PetInstance) && !(activePet instanceof L2BabyPetInstance))
  78. {
  79. weaponInst = ((L2PetInstance) activePet).getActiveWeaponInstance();
  80. weaponItem = ((L2PetInstance) activePet).getActiveWeaponItem();
  81. if (weaponInst == null)
  82. {
  83. activeOwner.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SOULSHOTS));
  84. return;
  85. }
  86. if (weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  87. {
  88. // SoulShots are already active.
  89. return;
  90. }
  91. int shotCount = item.getCount();
  92. shotConsumption = weaponItem.getSoulShotCount();
  93. if (shotConsumption == 0)
  94. {
  95. activeOwner.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SOULSHOTS));
  96. return;
  97. }
  98. if (!(shotCount > shotConsumption))
  99. {
  100. // Not enough Soulshots to use.
  101. activeOwner.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  102. return;
  103. }
  104. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_SOULSHOT);
  105. }
  106. else
  107. {
  108. if (activePet.getChargedSoulShot() != L2ItemInstance.CHARGED_NONE)
  109. return;
  110. activePet.setChargedSoulShot(L2ItemInstance.CHARGED_SOULSHOT);
  111. }
  112. // If the player doesn't have enough beast soulshot remaining, remove any auto soulshot task.
  113. if (!activeOwner.destroyItemWithoutTrace("Consume", item.getObjectId(), shotConsumption, null, false))
  114. {
  115. if (activeOwner.getAutoSoulShot().containsKey(itemId))
  116. {
  117. activeOwner.removeAutoSoulShot(itemId);
  118. activeOwner.sendPacket(new ExAutoSoulShot(itemId, 0));
  119. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  120. sm.addString(item.getItem().getName());
  121. activeOwner.sendPacket(sm);
  122. return;
  123. }
  124. activeOwner.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS));
  125. return;
  126. }
  127. // Pet uses the power of spirit.
  128. activeOwner.sendPacket(new SystemMessage(SystemMessageId.PET_USE_THE_POWER_OF_SPIRIT));
  129. Broadcast.toSelfAndKnownPlayersInRadius(activeOwner, new MagicSkillUse(activePet, activePet, 2033, 1, 0, 0), 360000/*600*/);
  130. }
  131. /**
  132. *
  133. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  134. */
  135. public int[] getItemIds()
  136. {
  137. return ITEM_IDS;
  138. }
  139. }