private static void addItemInfo(MaplePacketLittleEndianWriter mplew, IItem item, boolean shortPos, boolean zeroPosition) {
Random rand = new Random();
boolean cash = false;
boolean ring = false;
IEquip equip = null;
if (item.getType() == IItem.EQUIP) {
equip = (IEquip) item;
if (equip.getRingId() > -1) {
ring = true;
}
}
byte pos = zeroPosition ? 0 : item.getPosition();
if (pos != 0) {
if (shortPos) {
mplew.writeShort(pos);
} else {
pos = (byte)Math.abs(pos);
if (pos > 100 || (item.getType() == MapleInventoryType.EQUIPPED.getType() && ring)) pos -= 100;
mplew.write(pos);
}
}
boolean isEquip = (item.getItemId() / 1000000 == 1);
boolean isPet = (item.getItemId() / 1000000 == 5);
mplew.writeInt(item.getItemId());
if (cash) {
mplew.write(1);
mplew.writeLong(rand.nextLong()); // Cash Item ID/SN
mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2)));
} else if (ring) {
mplew.write(1);
mplew.writeLong(equip.getRingId());
mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2)));
} else if (isPet) {
mplew.write(1); // we use unique id like rings here
mplew.writeLong(item.getPetId());
mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2)));
MaplePet pet = MaplePet.loadFromDb(item.getItemId(), item.getPosition(), item.getPetId());
String petname = pet.getName();
mplew.writeAsciiString(petname, 13);
mplew.write(pet.getLevel());
mplew.writeShort(pet.getCloseness());
mplew.write(pet.getFullness());
mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2))); // TODO: expirations
return;
} else {
mplew.write(0);
mplew.writeLong(rand.nextLong()); // Non-NX don't expire, so.. random 8 byte long here
}
if (isEquip) {
mplew.write(equip.getUpgradeSlots());
mplew.write(equip.getLevel());
mplew.writeShort(equip.getStr());
mplew.writeShort(equip.getDex());
mplew.writeShort(equip.getInt());
mplew.writeShort(equip.getLuk());
mplew.writeShort(equip.getHp());
mplew.writeShort(equip.getMp());
mplew.writeShort(equip.getWatk());
mplew.writeShort(equip.getMatk());
mplew.writeShort(equip.getWdef());
mplew.writeShort(equip.getMdef());
mplew.writeShort(equip.getAcc());
mplew.writeShort(equip.getAvoid());
mplew.writeShort(equip.getHands());
mplew.writeShort(equip.getSpeed());
mplew.writeShort(equip.getJump());
} else {
mplew.writeShort(item.getQuantity());
}
}