RequestAutoSoulShot.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. // Fishingshots are not automatic on retail
  57. if (_itemId < 6535 || _itemId > 6540)
  58. {
  59. // Attempt to charge first shot on activation
  60. if (_itemId == 6645 || _itemId == 6646 || _itemId == 6647 || _itemId == 20332 || _itemId == 20333 || _itemId == 20334)
  61. {
  62. if (activeChar.getPet() != null)
  63. {
  64. if (item.getEtcItem().getHandlerName().equals("BeastSoulShot"))
  65. {
  66. if (activeChar.getPet().getSoulShotsPerHit() > item.getCount())
  67. {
  68. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  69. return;
  70. }
  71. }
  72. else
  73. {
  74. if (activeChar.getPet().getSpiritShotsPerHit() > item.getCount())
  75. {
  76. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS_FOR_PET));
  77. return;
  78. }
  79. }
  80. activeChar.addAutoSoulShot(_itemId);
  81. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  82. // start the auto soulshot use
  83. SystemMessage sm = new SystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  84. sm.addItemName(item);// Update Message by rocknow
  85. activeChar.sendPacket(sm);
  86. activeChar.rechargeAutoSoulShot(true, true, true);
  87. }
  88. else
  89. activeChar.sendPacket(new SystemMessage(SystemMessageId.NO_SERVITOR_CANNOT_AUTOMATE_USE));
  90. }
  91. else
  92. {
  93. if (activeChar.getActiveWeaponItem() != activeChar.getFistsWeaponItem()
  94. && item.getItem().getCrystalType() == activeChar.getActiveWeaponItem().getItemGradeSPlus())
  95. {
  96. activeChar.addAutoSoulShot(_itemId);
  97. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  98. }
  99. else
  100. {
  101. if ((_itemId >= 2509 && _itemId <= 2514) || (_itemId >= 3947 && _itemId <= 3952) || _itemId == 5790 || (_itemId >= 22072 && _itemId <= 22081))
  102. activeChar.sendPacket(new SystemMessage(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH));
  103. else
  104. activeChar.sendPacket(new SystemMessage(SystemMessageId.SOULSHOTS_GRADE_MISMATCH));
  105. activeChar.addAutoSoulShot(_itemId);
  106. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  107. }
  108. // start the auto soulshot use
  109. SystemMessage sm = new SystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  110. sm.addItemName(item);// Update Message by rocknow
  111. activeChar.sendPacket(sm);
  112. activeChar.rechargeAutoSoulShot(true, true, false);
  113. }
  114. }
  115. }
  116. else if (_type == 0)
  117. {
  118. activeChar.removeAutoSoulShot(_itemId);
  119. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  120. // cancel the auto soulshot use
  121. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  122. sm.addItemName(item);// Update Message by rocknow
  123. activeChar.sendPacket(sm);
  124. }
  125. }
  126. }
  127. /*
  128. * (non-Javadoc)
  129. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  130. */
  131. @Override
  132. public String getType()
  133. {
  134. return _C__CF_REQUESTAUTOSOULSHOT;
  135. }
  136. @Override
  137. protected boolean triggersOnActionRequest()
  138. {
  139. return false;
  140. }
  141. }