2
0

InventoryUpdate.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.serverpackets;
  16. import java.util.List;
  17. import java.util.logging.Logger;
  18. import javolution.util.FastList;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.gameserver.model.ItemInfo;
  21. import net.sf.l2j.gameserver.model.L2ItemInstance;
  22. /**
  23. *
  24. * 37 // Packet Identifier <BR>
  25. * 01 00 // Number of ItemInfo Trame of the Packet <BR><BR>
  26. *
  27. * 03 00 // Update type : 01-add, 02-modify, 03-remove <BR>
  28. * 04 00 // Item Type 1 : 00-weapon/ring/earring/necklace, 01-armor/shield, 04-item/questitem/adena <BR>
  29. * c6 37 50 40 // ObjectId <BR>
  30. * cd 09 00 00 // ItemId <BR>
  31. * 05 00 00 00 // Quantity <BR>
  32. * 05 00 // Item Type 2 : 00-weapon, 01-shield/armor, 02-ring/earring/necklace, 03-questitem, 04-adena, 05-item <BR>
  33. * 00 00 // Filler (always 0) <BR>
  34. * 00 00 // Equipped : 00-No, 01-yes <BR>
  35. * 00 00 // Slot : 0006-lr.ear, 0008-neck, 0030-lr.finger, 0040-head, 0100-l.hand, 0200-gloves, 0400-chest, 0800-pants, 1000-feet, 4000-r.hand, 8000-r.hand <BR>
  36. * 00 00 // Enchant level (pet level shown in control item) <BR>
  37. * 00 00 // Pet name exists or not shown in control item <BR><BR><BR>
  38. *
  39. *
  40. * format h (hh dddhhhh hh) revision 377 <BR>
  41. * format h (hh dddhhhd hh) revision 415 <BR><BR>
  42. *
  43. * @version $Revision: 1.3.2.2.2.4 $ $Date: 2005/03/27 15:29:39 $
  44. * Rebuild 23.2.2006 by Advi
  45. */
  46. public class InventoryUpdate extends L2GameServerPacket
  47. {
  48. private static Logger _log = Logger.getLogger(InventoryUpdate.class.getName());
  49. private static final String _S__37_INVENTORYUPDATE = "[S] 21 InventoryUpdate";
  50. private List<ItemInfo> _items;
  51. public InventoryUpdate()
  52. {
  53. _items = new FastList<ItemInfo>();
  54. if (Config.DEBUG)
  55. {
  56. showDebug();
  57. }
  58. }
  59. /**
  60. * @param items
  61. */
  62. public InventoryUpdate(List<ItemInfo> items)
  63. {
  64. _items = items;
  65. if (Config.DEBUG)
  66. {
  67. showDebug();
  68. }
  69. }
  70. public void addItem(L2ItemInstance item) { if (item != null) _items.add(new ItemInfo(item)); }
  71. public void addNewItem(L2ItemInstance item) { if (item != null) _items.add(new ItemInfo(item, 1)); }
  72. public void addModifiedItem(L2ItemInstance item) { if (item != null) _items.add(new ItemInfo(item, 2)); }
  73. public void addRemovedItem(L2ItemInstance item) { if (item != null) _items.add(new ItemInfo(item, 3)); }
  74. public void addItems(List<L2ItemInstance> items) { if (items != null) for (L2ItemInstance item : items) if (item != null) _items.add(new ItemInfo(item)); }
  75. private void showDebug()
  76. {
  77. for (ItemInfo item : _items)
  78. {
  79. _log.fine("oid:" + Integer.toHexString(item.getObjectId()) +
  80. " item:" + item.getItem().getName()+" last change:" + item.getChange());
  81. }
  82. }
  83. @Override
  84. protected final void writeImpl()
  85. {
  86. writeC(0x21);
  87. int count = _items.size();
  88. writeH(count);
  89. for (ItemInfo item : _items)
  90. {
  91. writeH(item.getChange()); // Update type : 01-add, 02-modify, 03-remove
  92. writeH(item.getItem().getType1()); // Item Type 1 : 00-weapon/ring/earring/necklace, 01-armor/shield, 04-item/questitem/adena
  93. writeD(item.getObjectId()); // ObjectId
  94. writeD(item.getItem().getItemId()); // ItemId
  95. writeD(item.getLocation()); // T1
  96. writeD(item.getCount()); // Quantity
  97. writeH(item.getItem().getType2()); // Item Type 2 : 00-weapon, 01-shield/armor, 02-ring/earring/necklace, 03-questitem, 04-adena, 05-item
  98. writeH(item.getCustomType1()); // Filler (always 0)
  99. writeH(item.getEquipped()); // Equipped : 00-No, 01-yes
  100. writeD(item.getItem().getBodyPart()); // Slot : 0006-lr.ear, 0008-neck, 0030-lr.finger, 0040-head, 0100-l.hand, 0200-gloves, 0400-chest, 0800-pants, 1000-feet, 4000-r.hand, 8000-r.hand
  101. writeH(item.getEnchant()); // Enchant level (pet level shown in control item)
  102. writeH(item.getCustomType2()); // Pet name exists or not shown in control item
  103. writeD(item.getAugmentationBonus());
  104. writeD(item.getMana());
  105. // T1
  106. writeD(item.getAttackAttrElement());
  107. writeD(item.getAttackAttrElementVal());
  108. writeD(item.getDefAttrFire());
  109. writeD(item.getDefAttrWater());
  110. writeD(item.getDefAttrWind());
  111. writeD(item.getDefAttrEarth());
  112. writeD(item.getDefAttrHoly());
  113. writeD(item.getDefAttrUnholy());
  114. }
  115. }
  116. /* (non-Javadoc)
  117. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  118. */
  119. @Override
  120. public String getType()
  121. {
  122. return _S__37_INVENTORYUPDATE;
  123. }
  124. }