RequestGiveItemToPet.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  21. import net.sf.l2j.gameserver.network.SystemMessageId;
  22. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.3.2.1.2.5 $ $Date: 2005/03/29 23:15:33 $
  27. */
  28. public final class RequestGiveItemToPet extends L2GameClientPacket
  29. {
  30. private static final String REQUESTCIVEITEMTOPET__C__8B = "[C] 8B RequestGiveItemToPet";
  31. private static Logger _log = Logger.getLogger(RequestGetItemFromPet.class.getName());
  32. private int _objectId;
  33. private int _amount;
  34. @Override
  35. protected void readImpl()
  36. {
  37. _objectId = readD();
  38. _amount = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance player = getClient().getActiveChar();
  44. if (player == null || !(player.getPet() instanceof L2PetInstance)) return;
  45. // Alt game - Karma punishment
  46. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && player.getKarma() > 0) return;
  47. if (player.getPrivateStoreType() != 0)
  48. {
  49. player.sendMessage("Cannot exchange items while trading");
  50. return;
  51. }
  52. // Exploit Fix for Hero weapons Uses pet Inventory to buy New One.
  53. // [L2JOneo]
  54. L2ItemInstance item = player.getInventory().getItemByObjectId(_objectId);
  55. if (item == null) return;
  56. if (item.isHeroItem())
  57. {
  58. player.sendMessage("Duo To Hero Weapons Protection u Canot Use Pet's Inventory");
  59. return;
  60. }
  61. L2PetInstance pet = (L2PetInstance)player.getPet();
  62. if (pet.isDead())
  63. {
  64. sendPacket(new SystemMessage(SystemMessageId.CANNOT_GIVE_ITEMS_TO_DEAD_PET));
  65. return;
  66. }
  67. if(_amount < 0)
  68. {
  69. return;
  70. }
  71. if (player.transferItem("Transfer", _objectId, _amount, pet.getInventory(), 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 REQUESTCIVEITEMTOPET__C__8B;
  80. }
  81. }