RequestSaveInventoryOrder.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.ArrayList;
  17. import java.util.List;
  18. import net.sf.l2j.gameserver.model.Inventory;
  19. import net.sf.l2j.gameserver.model.L2ItemInstance;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance.ItemLocation;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. /**
  23. * Format:(ch) d[dd]
  24. *
  25. * @author -Wooden-
  26. */
  27. public final class RequestSaveInventoryOrder extends L2GameClientPacket
  28. {
  29. private List<InventoryOrder> _order;
  30. /** client limit */
  31. private static final int LIMIT = 125;
  32. /**
  33. * @see net.sf.l2j.gameserver.clientpackets.L2GameClientPacket#readImpl()
  34. */
  35. @Override
  36. protected void readImpl()
  37. {
  38. int sz = readD();
  39. sz = Math.min(sz, LIMIT);
  40. _order = new ArrayList<InventoryOrder>(sz);
  41. for (int i = 0; i < sz; i++)
  42. {
  43. int objectId = readD();
  44. int order = readD();
  45. _order.add(new InventoryOrder(objectId, order));
  46. }
  47. }
  48. /**
  49. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#runImpl()
  50. */
  51. @Override
  52. protected void runImpl()
  53. {
  54. L2PcInstance player = this.getClient().getActiveChar();
  55. if (player != null)
  56. {
  57. Inventory inventory = player.getInventory();
  58. for (InventoryOrder order : _order)
  59. {
  60. L2ItemInstance item = inventory.getItemByObjectId(order.objectID);
  61. if (item != null && item.getLocation() == ItemLocation.INVENTORY)
  62. {
  63. item.setLocation(ItemLocation.INVENTORY, order.order);
  64. }
  65. }
  66. }
  67. }
  68. /**
  69. * @see net.sf.l2j.gameserver.BasePacket#getType()
  70. */
  71. @Override
  72. public String getType()
  73. {
  74. return "[C] D0:49 RequestSaveInventoryOrder";
  75. }
  76. private class InventoryOrder
  77. {
  78. int order;
  79. int objectID;
  80. /**
  81. *
  82. */
  83. public InventoryOrder(int id, int ord)
  84. {
  85. objectID = id;
  86. order = ord;
  87. }
  88. }
  89. }