return addItem(newItem, true, true);
}
private L2ItemInstance addItem(L2ItemInstance newItem, boolean dbUpdate, boolean log)
{
L2Character owner = getOwner();
if(owner == null || newItem == null)
{
return null;
}
if(newItem.isHerb() && !owner.getPlayer().isGM())
{
Util.handleIllegalPlayerAction(owner.getPlayer(), "tried to pickup herb into inventory", "Inventory[179]", 1);
return null;
}
if(newItem.getCount() < 0)
{
_log.warning("AddItem: count < 0 owner:" + owner.getName());
Thread.dumpStack();
return null;
}
L2ItemInstance result = newItem;
boolean stackableFound = false;
if(log)
{
Log.add("Inventory|" + owner.getName() + "|Get item|" + result.getItemId() + "|" + result.getCount() + "|" + result.getObjectId(), "items");
}
// If stackable, search item in inventory in order to add to current quantity
if(newItem.isStackable())
{
int itemId = newItem.getItemId();
L2ItemInstance old = getItemByItemId(itemId);
if(old != null)
{
// add new item quantity to existing stack
old.setCount(old.getCount() + newItem.getCount());
// reset new item to null
if(log)
{
Log.add("Inventory|" + owner.getName() + "|join item from-to|" + result.getItemId() + "|" + newItem.getObjectId() + "|" + old.getObjectId(), "items");
}
newItem.setCount(0);
newItem.setOwnerId(0);
newItem.setLocation(ItemLocation.VOID);
newItem.removeFromDb(true);
newItem.deleteMe();
stackableFound = true;
sendModifyItem(old);
// update old item in inventory and destroy new item
old.updateDatabase();
result = old;
}
}
// If item hasn't be found in inventory
if(!stackableFound)
{
// Add item in inventory
if(getItemByObjectId(newItem.getObjectId()) == null)
{
getItemsList().add(newItem);
if(!newItem.isEquipable() && newItem.getItem() instanceof L2EtcItem && !newItem.isStackable() && (newItem.getStatFuncs() != null || newItem.getItem().getAttachedSkills() != null))
{
if(_listenedItems == null)
{
_listenedItems = new GCSArray<L2ItemInstance>();
}
_listenedItems.add(newItem);
for(PaperdollListener listener : _paperdollListeners)
{
listener.notifyEquipped(-1, newItem);
}
}
}
else if(log)
{
Log.add("Inventory|" + owner.getName() + "|add double link to item in inventory list!|" + newItem.getItemId() + "|" + newItem.getObjectId(), "items");
}
if(newItem.getOwnerId() != owner.getPlayer().getObjectId() || dbUpdate)
{
newItem.setOwnerId(owner.getPlayer().getObjectId());
newItem.setLocation(getBaseLocation(), findSlot(0));
sendNewItem(newItem);
}
// If database wanted to be updated, update item
if(dbUpdate)
{
newItem.updateDatabase();
}
}
if(dbUpdate && result.isCursed() && owner.isPlayer())
{
CursedWeaponsManager.getInstance().checkPlayer((L2Player) owner, result);
}
refreshWeight();
return result;