RequestGiveItemToPet.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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))
  45. return;
  46. // Alt game - Karma punishment
  47. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && player.getKarma() > 0)
  48. return;
  49. if (player.getPrivateStoreType() != 0)
  50. {
  51. player.sendMessage("Cannot exchange items while trading");
  52. return;
  53. }
  54. // Exploit Fix for Hero weapons Uses pet Inventory to buy New One.
  55. // [L2JOneo]
  56. L2ItemInstance item = player.getInventory().getItemByObjectId(_objectId);
  57. if (item == null)
  58. return;
  59. if (item.isHeroItem())
  60. {
  61. player.sendMessage("Duo To Hero Weapons Protection u Canot Use Pet's Inventory");
  62. return;
  63. }
  64. if (item.isAugmented())
  65. return;
  66. L2PetInstance pet = (L2PetInstance) player.getPet();
  67. if (pet.isDead())
  68. {
  69. sendPacket(new SystemMessage(SystemMessageId.CANNOT_GIVE_ITEMS_TO_DEAD_PET));
  70. return;
  71. }
  72. if (_amount < 0)
  73. {
  74. return;
  75. }
  76. if (player.transferItem("Transfer", _objectId, _amount, pet.getInventory(), pet) == null)
  77. {
  78. _log.warning("Invalid item transfer request: " + pet.getName() + "(pet) --> " + player.getName());
  79. }
  80. }
  81. @Override
  82. public String getType()
  83. {
  84. return REQUESTCIVEITEMTOPET__C__8B;
  85. }
  86. }