RequestWithDrawPremiumItem.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 com.l2jserver.Config;
  17. import com.l2jserver.gameserver.model.L2PremiumItem;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.serverpackets.ExGetPremiumItemList;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. import com.l2jserver.gameserver.util.Util;
  23. /**
  24. ** @author Gnacik
  25. */
  26. public final class RequestWithDrawPremiumItem extends L2GameClientPacket
  27. {
  28. private static final String _C__D0_52_REQUESTWITHDRAWPREMIUMITEM = "[C] D0:52 RequestWithDrawPremiumItem";
  29. private int _itemNum;
  30. private int _charId;
  31. private long _itemcount;
  32. @Override
  33. protected void readImpl()
  34. {
  35. _itemNum = readD();
  36. _charId = readD();
  37. _itemcount = readQ();
  38. }
  39. @Override
  40. protected void runImpl()
  41. {
  42. final L2PcInstance activeChar = getClient().getActiveChar();
  43. if (activeChar == null)
  44. return;
  45. if (_itemcount <= 0)
  46. return;
  47. if (activeChar.getObjectId() != _charId)
  48. {
  49. Util.handleIllegalPlayerAction(activeChar, "[RequestWithDrawPremiumItem] Incorrect owner, Player: " + activeChar.getName(), Config.DEFAULT_PUNISH);
  50. return;
  51. }
  52. if (activeChar.getPremiumItemList().isEmpty())
  53. {
  54. Util.handleIllegalPlayerAction(activeChar, "[RequestWithDrawPremiumItem] Player: " + activeChar.getName() + " try to get item with empty list!", Config.DEFAULT_PUNISH);
  55. return;
  56. }
  57. if (activeChar.getWeightPenalty() >= 3 || !activeChar.isInventoryUnder80(false))
  58. {
  59. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_RECEIVE_THE_VITAMIN_ITEM));
  60. return;
  61. }
  62. if (activeChar.isProcessingTransaction())
  63. {
  64. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_RECEIVE_A_VITAMIN_ITEM_DURING_AN_EXCHANGE));
  65. return;
  66. }
  67. L2PremiumItem _item = activeChar.getPremiumItemList().get(_itemNum);
  68. if (_item == null)
  69. return;
  70. if (_item.getCount() < _itemcount)
  71. return;
  72. activeChar.addItem("PremiumItem", _item.getItemId(), _itemcount, null, true);
  73. if(_itemcount < _item.getCount() )
  74. {
  75. activeChar.getPremiumItemList().get(_itemNum).updateCount(_item.getCount()-_itemcount);
  76. activeChar.updatePremiumItem(_itemNum, _item.getCount()-_itemcount);
  77. }
  78. else
  79. {
  80. activeChar.getPremiumItemList().remove(_itemNum);
  81. activeChar.deletePremiumItem(_itemNum);
  82. }
  83. if(activeChar.getPremiumItemList().isEmpty())
  84. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.THERE_ARE_NO_MORE_VITAMIN_ITEMS_TO_BE_FOUND));
  85. else
  86. activeChar.sendPacket(new ExGetPremiumItemList(activeChar));
  87. }
  88. @Override
  89. public String getType()
  90. {
  91. return _C__D0_52_REQUESTWITHDRAWPREMIUMITEM;
  92. }
  93. }