RequestAutoSoulShot.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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] CF 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. activeChar.addAutoSoulShot(_itemId);
  65. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  66. // start the auto soulshot use
  67. SystemMessage sm = new SystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  68. sm.addItemName(item);// Update Message by rocknow
  69. activeChar.sendPacket(sm);
  70. activeChar.rechargeAutoSoulShot(true, true, true);
  71. }
  72. else
  73. activeChar.sendPacket(new SystemMessage(SystemMessageId.NO_SERVITOR_CANNOT_AUTOMATE_USE));
  74. }
  75. else
  76. {
  77. if (activeChar.getActiveWeaponItem() != activeChar.getFistsWeaponItem()
  78. && item.getItem().getCrystalType() == activeChar.getActiveWeaponItem().getItemGradeSPlus())
  79. {
  80. activeChar.addAutoSoulShot(_itemId);
  81. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  82. }
  83. else
  84. {
  85. if ((_itemId >= 2509 && _itemId <= 2514) || (_itemId >= 3947 && _itemId <= 3952) || _itemId == 5790 || (_itemId >= 22072 && _itemId <= 22081))
  86. activeChar.sendPacket(new SystemMessage(SystemMessageId.SPIRITSHOTS_GRADE_MISMATCH));
  87. else
  88. activeChar.sendPacket(new SystemMessage(SystemMessageId.SOULSHOTS_GRADE_MISMATCH));
  89. activeChar.addAutoSoulShot(_itemId);
  90. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  91. }
  92. // start the auto soulshot use
  93. SystemMessage sm = new SystemMessage(SystemMessageId.USE_OF_S1_WILL_BE_AUTO);
  94. sm.addItemName(item);// Update Message by rocknow
  95. activeChar.sendPacket(sm);
  96. activeChar.rechargeAutoSoulShot(true, true, false);
  97. }
  98. }
  99. }
  100. else if (_type == 0)
  101. {
  102. activeChar.removeAutoSoulShot(_itemId);
  103. activeChar.sendPacket(new ExAutoSoulShot(_itemId, _type));
  104. // cancel the auto soulshot use
  105. SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
  106. sm.addItemName(item);// Update Message by rocknow
  107. activeChar.sendPacket(sm);
  108. }
  109. }
  110. }
  111. /*
  112. * (non-Javadoc)
  113. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  114. */
  115. @Override
  116. public String getType()
  117. {
  118. return _C__CF_REQUESTAUTOSOULSHOT;
  119. }
  120. }