SpawnItem.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.L2Object;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. public final class SpawnItem extends L2GameServerPacket
  23. {
  24. private final int _objectId;
  25. private int _itemId;
  26. private final int _x, _y, _z;
  27. private int _stackable;
  28. private long _count;
  29. public SpawnItem(L2Object obj)
  30. {
  31. _objectId = obj.getObjectId();
  32. _x = obj.getX();
  33. _y = obj.getY();
  34. _z = obj.getZ();
  35. if (obj instanceof L2ItemInstance)
  36. {
  37. L2ItemInstance item = (L2ItemInstance) obj;
  38. _itemId = item.getDisplayId();
  39. _stackable = item.isStackable() ? 0x01 : 0x00;
  40. _count = item.getCount();
  41. }
  42. else
  43. {
  44. _itemId = obj.getPoly().getPolyId();
  45. _stackable = 0;
  46. _count = 1;
  47. }
  48. }
  49. @Override
  50. protected final void writeImpl()
  51. {
  52. writeC(0x05);
  53. writeD(_objectId);
  54. writeD(_itemId);
  55. writeD(_x);
  56. writeD(_y);
  57. writeD(_z);
  58. // only show item count if it is a stackable item
  59. writeD(_stackable);
  60. writeQ(_count);
  61. writeD(0x00); // c2
  62. writeD(0x00); // freya unk
  63. }
  64. }