RequestGetItemFromPet.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.util.Util;
  25. /**
  26. * This class ...
  27. * @version $Revision: 1.3.4.4 $ $Date: 2005/03/29 23:15:33 $
  28. */
  29. public final class RequestGetItemFromPet extends L2GameClientPacket
  30. {
  31. private static final String _C__2C_REQUESTGETITEMFROMPET = "[C] 2C RequestGetItemFromPet";
  32. private int _objectId;
  33. private long _amount;
  34. @SuppressWarnings("unused")
  35. private int _unknown;
  36. @Override
  37. protected void readImpl()
  38. {
  39. _objectId = readD();
  40. _amount = readQ();
  41. _unknown = readD();// = 0 for most trades
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. final L2PcInstance player = getClient().getActiveChar();
  47. if ((_amount <= 0) || (player == null) || !player.hasPet())
  48. {
  49. return;
  50. }
  51. if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("getfrompet"))
  52. {
  53. player.sendMessage("You get items from pet too fast.");
  54. return;
  55. }
  56. final L2PetInstance pet = (L2PetInstance) player.getSummon();
  57. if (player.getActiveEnchantItemId() != L2PcInstance.ID_NONE)
  58. {
  59. return;
  60. }
  61. final L2ItemInstance item = pet.getInventory().getItemByObjectId(_objectId);
  62. if (item == null)
  63. {
  64. return;
  65. }
  66. if (_amount > item.getCount())
  67. {
  68. Util.handleIllegalPlayerAction(player, getClass().getSimpleName() + ": Character " + player.getName() + " of account " + player.getAccountName() + " tried to get item with oid " + _objectId + " from pet but has invalid count " + _amount + " item count: " + item.getCount(), Config.DEFAULT_PUNISH);
  69. return;
  70. }
  71. if (pet.transferItem("Transfer", _objectId, _amount, player.getInventory(), player, pet) == null)
  72. {
  73. _log.warning("Invalid item transfer request: " + pet.getName() + "(pet) --> " + player.getName());
  74. }
  75. }
  76. @Override
  77. public String getType()
  78. {
  79. return _C__2C_REQUESTGETITEMFROMPET;
  80. }
  81. }