RequestWithDrawPremiumItem.java 3.4 KB

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