RequestGiveItemToPet.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright © 2004-2019 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.enums.PrivateStoreType;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  24. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * This class ...
  29. * @version $Revision: 1.3.2.1.2.5 $ $Date: 2005/03/29 23:15:33 $
  30. */
  31. public final class RequestGiveItemToPet extends L2GameClientPacket
  32. {
  33. private static final String _C__95_REQUESTCIVEITEMTOPET = "[C] 95 RequestGiveItemToPet";
  34. private int _objectId;
  35. private long _amount;
  36. @Override
  37. protected void readImpl()
  38. {
  39. _objectId = readD();
  40. _amount = readQ();
  41. }
  42. @Override
  43. protected void runImpl()
  44. {
  45. final L2PcInstance player = getClient().getActiveChar();
  46. if ((_amount <= 0) || (player == null) || !player.hasPet())
  47. {
  48. return;
  49. }
  50. if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("giveitemtopet"))
  51. {
  52. player.sendMessage("You are giving items to pet too fast.");
  53. return;
  54. }
  55. if (player.getActiveEnchantItemId() != L2PcInstance.ID_NONE)
  56. {
  57. return;
  58. }
  59. // Alt game - Karma punishment
  60. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && (player.getKarma() > 0))
  61. {
  62. return;
  63. }
  64. if (player.getPrivateStoreType() != PrivateStoreType.NONE)
  65. {
  66. player.sendMessage("You cannot exchange items while trading.");
  67. return;
  68. }
  69. final L2ItemInstance item = player.getInventory().getItemByObjectId(_objectId);
  70. if (item == null)
  71. {
  72. return;
  73. }
  74. if (_amount > item.getCount())
  75. {
  76. Util.handleIllegalPlayerAction(player, getClass().getSimpleName() + ": Character " + player.getName() + " of account " + player.getAccountName() + //
  77. " tried to get item with oid " + _objectId + " from pet but has invalid count " + _amount + " item count: " + item.getCount(), Config.DEFAULT_PUNISH);
  78. return;
  79. }
  80. if (item.isAugmented())
  81. {
  82. return;
  83. }
  84. if (item.isHeroItem() || !item.isDropable() || !item.isDestroyable() || !item.isTradeable())
  85. {
  86. player.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  87. return;
  88. }
  89. final L2PetInstance pet = (L2PetInstance) player.getSummon();
  90. if (pet.isDead())
  91. {
  92. player.sendPacket(SystemMessageId.CANNOT_GIVE_ITEMS_TO_DEAD_PET);
  93. return;
  94. }
  95. if (!pet.getInventory().validateCapacity(item))
  96. {
  97. player.sendPacket(SystemMessageId.YOUR_PET_CANNOT_CARRY_ANY_MORE_ITEMS);
  98. return;
  99. }
  100. if (!pet.getInventory().validateWeight(item, _amount))
  101. {
  102. player.sendPacket(SystemMessageId.UNABLE_TO_PLACE_ITEM_YOUR_PET_IS_TOO_ENCUMBERED);
  103. return;
  104. }
  105. if (player.transferItem("Transfer", _objectId, _amount, pet.getInventory(), pet) == null)
  106. {
  107. _log.warning("Invalid item transfer request: " + pet.getName() + "(pet) --> " + player.getName());
  108. }
  109. }
  110. @Override
  111. public String getType()
  112. {
  113. return _C__95_REQUESTCIVEITEMTOPET;
  114. }
  115. }