Recently I created a topic, where Eric helped me solve my problem with my cashinventory. But now I have another problem ... when I transfer my item to the cash inventory, it returns me null.
I did a little analysis and noticed that the error starts here:
When it does this search, it returns me a null item, so would my findByCashId?
GetCashId function:
Is the getCashId function responsible for returning a value equal to the cashId generated by the client?
This is my question, or in this case I need to create a uniqueid system (same I saw in some sources)?
Code im CashOperation:
I did a little analysis and noticed that the error starts here:
Code:
IItem item = mi.findByCashId (cashId);
When it does this search, it returns me a null item, so would my findByCashId?
Code:
public IItem findByCashId(int cashId) {
for (IItem item : inventory.values()) {
if ((item.getPetId() > -1 ? item.getPetId() : item.getCashId()) == cashId)
return item;
}
return null;
}
GetCashId function:
Code:
@Override
public int getCashId() {
if (cashId == 0)
cashId = new Random().nextInt(Integer.MAX_VALUE) + 1;
/* This is not really unique but the chance to have 2 items
* with the same Cash Id is so low that we just don't care.
*/
return cashId;
}
Is the getCashId function responsible for returning a value equal to the cashId generated by the client?
This is my question, or in this case I need to create a uniqueid system (same I saw in some sources)?
Code im CashOperation:
Code:
int cashId = slea.readInt();
slea.skip(4);
MapleInventory mi = chr.getInventory(MapleInventoryType.getByType(slea.readByte()));
IItem item = mi.findByCashId(cashId);
if (item == null)
return;
cs.addToInventory(item);
mi.removeSlot(item.getPosition());
c.getSession().write(MaplePacketCreator.putIntoCashInventory(item, c.getAccID()));