SpawnItem.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 net.sf.l2j.gameserver.model.L2ItemInstance;
  17. import net.sf.l2j.gameserver.model.L2Object;
  18. /**
  19. * 15
  20. * ee cc 11 43 object id
  21. * 39 00 00 00 item id
  22. * 8f 14 00 00 x
  23. * b7 f1 00 00 y
  24. * 60 f2 ff ff z
  25. * 01 00 00 00 show item count
  26. * 7a 00 00 00 count .
  27. *
  28. * format dddddddd
  29. *
  30. * @version $Revision: 1.3.2.1.2.3 $ $Date: 2005/03/27 15:29:39 $
  31. */
  32. public final class SpawnItem extends L2GameServerPacket
  33. {
  34. private static final String _S__15_SPAWNITEM = "[S] 05 SpawnItem";
  35. private int _objectId;
  36. private int _itemId;
  37. private int _x, _y, _z;
  38. private int _stackable, _count;
  39. public SpawnItem(L2Object obj)
  40. {
  41. _objectId = obj.getObjectId();
  42. _x = obj.getX();
  43. _y = obj.getY();
  44. _z = obj.getZ();
  45. if (obj instanceof L2ItemInstance)
  46. {
  47. L2ItemInstance item = (L2ItemInstance) obj;
  48. _itemId = item.getItemId();
  49. _stackable = item.isStackable() ? 0x01 : 0x00;
  50. _count = item.getCount();
  51. }
  52. else
  53. {
  54. _itemId = obj.getPoly().getPolyId();
  55. _stackable = 0;
  56. _count = 1;
  57. }
  58. }
  59. @Override
  60. protected final void writeImpl()
  61. {
  62. writeC(0x05);
  63. writeD(_objectId);
  64. writeD(_itemId);
  65. writeD(_x);
  66. writeD(_y);
  67. writeD(_z);
  68. // only show item count if it is a stackable item
  69. writeD(_stackable);
  70. writeD(_count);
  71. writeD(0x00); //c2
  72. }
  73. /* (non-Javadoc)
  74. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  75. */
  76. @Override
  77. public String getType()
  78. {
  79. return _S__15_SPAWNITEM;
  80. }
  81. }