RequestAutoSoulShot.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.enums.PrivateStoreType;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.ExAutoSoulShot;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * This class ...
  29. * @version $Revision: 1.0.0.0 $ $Date: 2005/07/11 15:29:30 $
  30. */
  31. public final class RequestAutoSoulShot extends L2GameClientPacket
  32. {
  33. private static final String _C__D0_0D_REQUESTAUTOSOULSHOT = "[C] D0:0D RequestAutoSoulShot";
  34. // format cd
  35. private int _itemId;
  36. private int _type; // 1 = on : 0 = off;
  37. @Override
  38. protected void readImpl()
  39. {
  40. _itemId = readD();
  41. _type = readD();
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. final L2PcInstance activeChar = getClient().getActiveChar();
  47. if (activeChar == null)
  48. {
  49. return;
  50. }
  51. if ((activeChar.getPrivateStoreType() == PrivateStoreType.NONE) && (activeChar.getActiveRequester() == null) && !activeChar.isDead())
  52. {
  53. if (Config.DEBUG)
  54. {
  55. _log.fine("AutoSoulShot:" + _itemId);
  56. }
  57. final L2ItemInstance item = activeChar.getInventory().getItemByItemId(_itemId);
  58. if (item == null)
  59. {
  60. return;
  61. }
  62. if (_type == 1)
  63. {
  64. if (!activeChar.getInventory().canManipulateWithItemId(item.getId()))
  65. {
  66. activeChar.sendMessage("Cannot use this item.");
  67. return;
  68. }
  69. // Fishingshots are not automatic on retail
  70. if ((_itemId < 6535) || (_itemId > 6540))
  71. {
  72. // Attempt to charge first shot on activation
  73. if ((_itemId == 6645) || (_itemId == 6646) || (_itemId == 6647) || (_itemId == 20332) || (_itemId == 20333) || (_itemId == 20334))
  74. {
  75. if (activeChar.hasSummon())
  76. {
  77. if (item.getEtcItem().getHandlerName().equals("BeastSoulShot"))
  78. {
  79. if (activeChar.getSummon().getSoulShotsPerHit() > item.getCount())
  80. {
  81. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET);
  82. return;
  83. }
  84. }
  85. else
  86. {
  87. if (activeChar.getSummon().getSpiritShotsPerHit() > item.getCount())
  88. {
  89. activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET);
  90. return;
  91. }
  92. }
  93. activeChar.addAutoSoulShot(_itemId);
  94. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  95. // start the auto soulshot use
  96. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  97. sm.addItemName(item);
  98. activeChar.sendPacket(sm);
  99. activeChar.rechargeShots(true, true);
  100. activeChar.getSummon().rechargeShots(true, true);
  101. }
  102. else
  103. {
  104. activeChar.sendPacket(SystemMessageId.NO_SERVITOR_CANNOT_AUTOMATE_USE);
  105. }
  106. }
  107. else
  108. {
  109. if ((activeChar.getActiveWeaponItem() != activeChar.getFistsWeaponItem()) && (item.getItem().getCrystalType() == activeChar.getActiveWeaponItem().getItemGradeSPlus()))
  110. {
  111. activeChar.addAutoSoulShot(_itemId);
  112. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  113. }
  114. else
  115. {
  116. if (((_itemId >= 2509) && (_itemId <= 2514)) || ((_itemId >= 3947) && (_itemId <= 3952)) || (_itemId == 5790) || ((_itemId >= 22072) && (_itemId <= 22081)))
  117. {
  118. activeChar.sendPacket(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH);
  119. }
  120. else
  121. {
  122. activeChar.sendPacket(SystemMessageId.SOULSHOTS_GRADE_MISMATCH);
  123. }
  124. activeChar.addAutoSoulShot(_itemId);
  125. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  126. }
  127. // start the auto soulshot use
  128. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  129. sm.addItemName(item);
  130. activeChar.sendPacket(sm);
  131. activeChar.rechargeShots(true, true);
  132. }
  133. }
  134. }
  135. else if (_type == 0)
  136. {
  137. activeChar.removeAutoSoulShot(_itemId);
  138. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  139. // cancel the auto soulshot use
  140. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  141. sm.addItemName(item);
  142. activeChar.sendPacket(sm);
  143. }
  144. }
  145. }
  146. @Override
  147. public String getType()
  148. {
  149. return _C__D0_0D_REQUESTAUTOSOULSHOT;
  150. }
  151. @Override
  152. protected boolean triggersOnActionRequest()
  153. {
  154. return false;
  155. }
  156. }