AbstractItemPacket.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2004-2015 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.serverpackets;
  20. import com.l2jserver.gameserver.model.ItemInfo;
  21. import com.l2jserver.gameserver.model.TradeItem;
  22. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. /**
  25. * @author UnAfraid
  26. */
  27. public abstract class AbstractItemPacket extends L2GameServerPacket
  28. {
  29. protected void writeItem(TradeItem item)
  30. {
  31. writeItem(new ItemInfo(item));
  32. }
  33. protected void writeItem(L2ItemInstance item)
  34. {
  35. writeItem(new ItemInfo(item));
  36. }
  37. protected void writeItem(ItemInfo item)
  38. {
  39. writeD(item.getObjectId()); // ObjectId
  40. writeD(item.getItem().getDisplayId()); // ItemId
  41. writeD(item.getLocation()); // T1
  42. writeQ(item.getCount()); // Quantity
  43. writeH(item.getItem().getType2()); // Item Type 2 : 00-weapon, 01-shield/armor, 02-ring/earring/necklace, 03-questitem, 04-adena, 05-item
  44. writeH(item.getCustomType1()); // Filler (always 0)
  45. writeH(item.getEquipped()); // Equipped : 00-No, 01-yes
  46. 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
  47. writeH(item.getEnchant()); // Enchant level (pet level shown in control item)
  48. writeH(item.getCustomType2()); // Pet name exists or not shown in control item
  49. writeD(item.getAugmentationBonus());
  50. writeD(item.getMana());
  51. writeD(item.getTime());
  52. writeItemElementalAndEnchant(item);
  53. }
  54. protected void writeItemElementalAndEnchant(ItemInfo item)
  55. {
  56. writeH(item.getAttackElementType());
  57. writeH(item.getAttackElementPower());
  58. for (byte i = 0; i < 6; i++)
  59. {
  60. writeH(item.getElementDefAttr(i));
  61. }
  62. // Enchant Effects
  63. for (int op : item.getEnchantOptions())
  64. {
  65. writeH(op);
  66. }
  67. }
  68. protected void writeInventoryBlock(PcInventory inventory)
  69. {
  70. if (inventory.hasInventoryBlock())
  71. {
  72. writeH(inventory.getBlockItems().length);
  73. writeC(inventory.getBlockMode());
  74. for (int i : inventory.getBlockItems())
  75. {
  76. writeD(i);
  77. }
  78. }
  79. else
  80. {
  81. writeH(0x00);
  82. }
  83. }
  84. }