RequestAutoSoulShot.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.model.L2ItemInstance;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.ExAutoSoulShot;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.0.0.0 $ $Date: 2005/07/11 15:29:30 $
  27. */
  28. public final class RequestAutoSoulShot extends L2GameClientPacket
  29. {
  30. private static final String _C__CF_REQUESTAUTOSOULSHOT = "[C] D0:0D RequestAutoSoulShot";
  31. private static Logger _log = Logger.getLogger(RequestAutoSoulShot.class.getName());
  32. // format cd
  33. private int _itemId;
  34. private int _type; // 1 = on : 0 = off;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _itemId = readD();
  39. _type = readD();
  40. }
  41. @Override
  42. protected void runImpl()
  43. {
  44. L2PcInstance activeChar = getClient().getActiveChar();
  45. if (activeChar == null)
  46. return;
  47. if (activeChar.getPrivateStoreType() == 0 && activeChar.getActiveRequester() == null && !activeChar.isDead())
  48. {
  49. if (Config.DEBUG)
  50. _log.fine("AutoSoulShot:" + _itemId);
  51. L2ItemInstance item = activeChar.getInventory().getItemByItemId(_itemId);
  52. if (item == null)
  53. return;
  54. if (_type == 1)
  55. {
  56. if (!activeChar.getInventory().canManipulateWithItemId(item.getItemId()))
  57. {
  58. activeChar.sendMessage("Cannot use this item.");
  59. return;
  60. }
  61. // Fishingshots are not automatic on retail
  62. if (_itemId < 6535 || _itemId > 6540)
  63. {
  64. // Attempt to charge first shot on activation
  65. if (_itemId == 6645 || _itemId == 6646 || _itemId == 6647 || _itemId == 20332 || _itemId == 20333 || _itemId == 20334)
  66. {
  67. if (activeChar.getPet() != null)
  68. {
  69. if (item.getEtcItem().getHandlerName().equals("BeastSoulShot"))
  70. {
  71. if (activeChar.getPet().getSoulShotsPerHit() > item.getCount())
  72. {
  73. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  74. return;
  75. }
  76. }
  77. else
  78. {
  79. if (activeChar.getPet().getSpiritShotsPerHit() > item.getCount())
  80. {
  81. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  82. return;
  83. }
  84. }
  85. activeChar.addAutoSoulShot(_itemId);
  86. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  87. // start the auto soulshot use
  88. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  89. sm.addItemName(item);// Update Message by rocknow
  90. activeChar.sendPacket(sm);
  91. activeChar.rechargeAutoSoulShot(true, true, true);
  92. }
  93. else
  94. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_SERVITOR_CANNOT_AUTOMATE_USE));
  95. }
  96. else
  97. {
  98. if (activeChar.getActiveWeaponItem() != activeChar.getFistsWeaponItem()
  99. && item.getItem().getCrystalType() == activeChar.getActiveWeaponItem().getItemGradeSPlus())
  100. {
  101. activeChar.addAutoSoulShot(_itemId);
  102. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  103. }
  104. else
  105. {
  106. if ((_itemId >= 2509 && _itemId <= 2514) || (_itemId >= 3947 && _itemId <= 3952) || _itemId == 5790 || (_itemId >= 22072 && _itemId <= 22081))
  107. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH));
  108. else
  109. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SOULSHOTS_GRADE_MISMATCH));
  110. activeChar.addAutoSoulShot(_itemId);
  111. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  112. }
  113. // start the auto soulshot use
  114. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  115. sm.addItemName(item);// Update Message by rocknow
  116. activeChar.sendPacket(sm);
  117. activeChar.rechargeAutoSoulShot(true, true, false);
  118. }
  119. }
  120. }
  121. else if (_type == 0)
  122. {
  123. activeChar.removeAutoSoulShot(_itemId);
  124. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  125. // cancel the auto soulshot use
  126. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  127. sm.addItemName(item);// Update Message by rocknow
  128. activeChar.sendPacket(sm);
  129. }
  130. }
  131. }
  132. /*
  133. * (non-Javadoc)
  134. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  135. */
  136. @Override
  137. public String getType()
  138. {
  139. return _C__CF_REQUESTAUTOSOULSHOT;
  140. }
  141. @Override
  142. protected boolean triggersOnActionRequest()
  143. {
  144. return false;
  145. }
  146. }