|
@@ -59,8 +59,7 @@ public abstract class ItemContainer
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the ownerID of the inventory
|
|
|
|
- * @return int
|
|
|
|
|
|
+ * @return int the owner object Id
|
|
*/
|
|
*/
|
|
public int getOwnerId()
|
|
public int getOwnerId()
|
|
{
|
|
{
|
|
@@ -68,8 +67,7 @@ public abstract class ItemContainer
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the quantity of items in the inventory
|
|
|
|
- * @return int
|
|
|
|
|
|
+ * @return the quantity of items in the inventory
|
|
*/
|
|
*/
|
|
public int getSize()
|
|
public int getSize()
|
|
{
|
|
{
|
|
@@ -77,8 +75,7 @@ public abstract class ItemContainer
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the list of items in inventory
|
|
|
|
- * @return L2ItemInstance : items in inventory
|
|
|
|
|
|
+ * @return the items in inventory
|
|
*/
|
|
*/
|
|
public L2ItemInstance[] getItems()
|
|
public L2ItemInstance[] getItems()
|
|
{
|
|
{
|
|
@@ -86,79 +83,76 @@ public abstract class ItemContainer
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the item from inventory by using its <B>itemId</B><BR><BR>
|
|
|
|
- *
|
|
|
|
- * @param itemId : int designating the ID of the item
|
|
|
|
- * @return L2ItemInstance designating the item or null if not found in inventory
|
|
|
|
|
|
+ * @param itemId the item Id
|
|
|
|
+ * @return the item from inventory by itemId
|
|
*/
|
|
*/
|
|
public L2ItemInstance getItemByItemId(int itemId)
|
|
public L2ItemInstance getItemByItemId(int itemId)
|
|
{
|
|
{
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
- if (item != null && item.getItemId() == itemId)
|
|
|
|
|
|
+ {
|
|
|
|
+ if ((item != null) && (item.getItemId() == itemId))
|
|
|
|
+ {
|
|
return item;
|
|
return item;
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the item's list from inventory by using its <B>itemId</B><BR><BR>
|
|
|
|
- *
|
|
|
|
- * @param itemId : int designating the ID of the item
|
|
|
|
- * @return List<L2ItemInstance> designating the items list (empty list if not found)
|
|
|
|
|
|
+ * @param itemId the item Id
|
|
|
|
+ * @return the items list from inventory by using its itemId
|
|
*/
|
|
*/
|
|
public List<L2ItemInstance> getItemsByItemId(int itemId)
|
|
public List<L2ItemInstance> getItemsByItemId(int itemId)
|
|
{
|
|
{
|
|
List<L2ItemInstance> returnList = new FastList<>();
|
|
List<L2ItemInstance> returnList = new FastList<>();
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
{
|
|
{
|
|
- if (item != null && item.getItemId() == itemId)
|
|
|
|
|
|
+ if ((item != null) && (item.getItemId() == itemId))
|
|
{
|
|
{
|
|
returnList.add(item);
|
|
returnList.add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
return returnList;
|
|
return returnList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the item from inventory by using its <B>itemId</B><BR><BR>
|
|
|
|
- *
|
|
|
|
- * @param itemId : int designating the ID of the item
|
|
|
|
- * @param itemToIgnore : used during a loop, to avoid returning the same item
|
|
|
|
- * @return L2ItemInstance designating the item or null if not found in inventory
|
|
|
|
|
|
+ * @param itemId the item Id
|
|
|
|
+ * @param itemToIgnore used during the loop, to avoid returning the same item
|
|
|
|
+ * @return the item from inventory by itemId
|
|
*/
|
|
*/
|
|
public L2ItemInstance getItemByItemId(int itemId, L2ItemInstance itemToIgnore)
|
|
public L2ItemInstance getItemByItemId(int itemId, L2ItemInstance itemToIgnore)
|
|
{
|
|
{
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
- if (item != null && item.getItemId() == itemId && !item.equals(itemToIgnore))
|
|
|
|
|
|
+ {
|
|
|
|
+ if ((item != null) && (item.getItemId() == itemId) && !item.equals(itemToIgnore))
|
|
|
|
+ {
|
|
return item;
|
|
return item;
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns item from inventory by using its <B>objectId</B>
|
|
|
|
- * @param objectId : int designating the ID of the object
|
|
|
|
- * @return L2ItemInstance designating the item or null if not found in inventory
|
|
|
|
|
|
+ * @param objectId the item object Id
|
|
|
|
+ * @return item from inventory by objectId
|
|
*/
|
|
*/
|
|
public L2ItemInstance getItemByObjectId(int objectId)
|
|
public L2ItemInstance getItemByObjectId(int objectId)
|
|
{
|
|
{
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
{
|
|
{
|
|
- if (item == null)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- if (item.getObjectId() == objectId)
|
|
|
|
|
|
+ if ((item != null) && item.getObjectId() == objectId)
|
|
|
|
+ {
|
|
return item;
|
|
return item;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param itemId
|
|
|
|
- * @param enchantLevel
|
|
|
|
- * @return
|
|
|
|
- * @see com.l2jserver.gameserver.model.itemcontainer.ItemContainer#getInventoryItemCount(int, int, boolean)
|
|
|
|
|
|
+ * Gets the inventory item count by item Id and enchant level including equipped items.
|
|
|
|
+ * @param itemId the item Id
|
|
|
|
+ * @param enchantLevel the item enchant level, use -1 to match any enchant level
|
|
|
|
+ * @return the inventory item count
|
|
*/
|
|
*/
|
|
public long getInventoryItemCount(int itemId, int enchantLevel)
|
|
public long getInventoryItemCount(int itemId, int enchantLevel)
|
|
{
|
|
{
|
|
@@ -166,24 +160,39 @@ public abstract class ItemContainer
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets count of item in the inventory
|
|
|
|
- * @param itemId : Item to look for
|
|
|
|
- * @param enchantLevel : enchant level to match on, or -1 for ANY enchant level
|
|
|
|
- * @param includeEquipped : include equipped items
|
|
|
|
- * @return int corresponding to the number of items matching the above conditions.
|
|
|
|
|
|
+ * Gets the inventory item count by item Id and enchant level, may include equipped items.
|
|
|
|
+ * @param itemId the item Id
|
|
|
|
+ * @param enchantLevel the item enchant level, use -1 to match any enchant level
|
|
|
|
+ * @param includeEquipped if {@code true} includes equipped items in the result
|
|
|
|
+ * @return the inventory item count
|
|
*/
|
|
*/
|
|
public long getInventoryItemCount(int itemId, int enchantLevel, boolean includeEquipped)
|
|
public long getInventoryItemCount(int itemId, int enchantLevel, boolean includeEquipped)
|
|
{
|
|
{
|
|
long count = 0;
|
|
long count = 0;
|
|
|
|
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
- if (item.getItemId() == itemId && ((item.getEnchantLevel() == enchantLevel) || (enchantLevel < 0)) && (includeEquipped || !item.isEquipped()))
|
|
|
|
- //if (item.isAvailable((L2PcInstance)getOwner(), true) || item.getItem().getType2() == 3)//available or quest item
|
|
|
|
|
|
+ {
|
|
|
|
+ if ((item.getItemId() == itemId) && ((item.getEnchantLevel() == enchantLevel) || (enchantLevel < 0)) && (includeEquipped || !item.isEquipped()))
|
|
|
|
+ {
|
|
if (item.isStackable())
|
|
if (item.isStackable())
|
|
|
|
+ {
|
|
|
|
+ // FIXME: Zoey76: if there are more than one stacks of the same item Id
|
|
|
|
+ // it will return the count of the last one, if is not possible to
|
|
|
|
+ // have more than one stacks of the same item Id,
|
|
|
|
+ // it will continue iterating over all items
|
|
|
|
+ // possible fixes:
|
|
|
|
+ // count += item.getCount();
|
|
|
|
+ // or
|
|
|
|
+ // count = item.getCount();
|
|
|
|
+ // break;
|
|
count = item.getCount();
|
|
count = item.getCount();
|
|
|
|
+ }
|
|
else
|
|
else
|
|
|
|
+ {
|
|
count++;
|
|
count++;
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -200,7 +209,7 @@ public abstract class ItemContainer
|
|
L2ItemInstance olditem = getItemByItemId(item.getItemId());
|
|
L2ItemInstance olditem = getItemByItemId(item.getItemId());
|
|
|
|
|
|
// If stackable item is found in inventory just add to current quantity
|
|
// If stackable item is found in inventory just add to current quantity
|
|
- if (olditem != null && olditem.isStackable())
|
|
|
|
|
|
+ if ((olditem != null) && olditem.isStackable())
|
|
{
|
|
{
|
|
long count = item.getCount();
|
|
long count = item.getCount();
|
|
olditem.changeCount(process, count, actor, reference);
|
|
olditem.changeCount(process, count, actor, reference);
|
|
@@ -212,14 +221,18 @@ public abstract class ItemContainer
|
|
item = olditem;
|
|
item = olditem;
|
|
|
|
|
|
// Updates database
|
|
// Updates database
|
|
- if (item.getItemId() == PcInventory.ADENA_ID && count < 10000 * Config.RATE_DROP_ITEMS_ID.get(PcInventory.ADENA_ID))
|
|
|
|
|
|
+ if ((item.getItemId() == PcInventory.ADENA_ID) && (count < (10000 * Config.RATE_DROP_ITEMS_ID.get(PcInventory.ADENA_ID))))
|
|
{
|
|
{
|
|
// Small adena changes won't be saved to database all the time
|
|
// Small adena changes won't be saved to database all the time
|
|
- if (GameTimeController.getGameTicks() % 5 == 0)
|
|
|
|
|
|
+ if ((GameTimeController.getGameTicks() % 5) == 0)
|
|
|
|
+ {
|
|
item.updateDatabase();
|
|
item.updateDatabase();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
|
|
+ {
|
|
item.updateDatabase();
|
|
item.updateDatabase();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// If item hasn't be found in inventory, create new one
|
|
// If item hasn't be found in inventory, create new one
|
|
else
|
|
else
|
|
@@ -253,21 +266,25 @@ public abstract class ItemContainer
|
|
L2ItemInstance item = getItemByItemId(itemId);
|
|
L2ItemInstance item = getItemByItemId(itemId);
|
|
|
|
|
|
// If stackable item is found in inventory just add to current quantity
|
|
// If stackable item is found in inventory just add to current quantity
|
|
- if (item != null && item.isStackable())
|
|
|
|
|
|
+ if ((item != null) && item.isStackable())
|
|
{
|
|
{
|
|
item.changeCount(process, count, actor, reference);
|
|
item.changeCount(process, count, actor, reference);
|
|
item.setLastChange(L2ItemInstance.MODIFIED);
|
|
item.setLastChange(L2ItemInstance.MODIFIED);
|
|
// Updates database
|
|
// Updates database
|
|
- // If Adena drop rate is nor present it will be x1.
|
|
|
|
|
|
+ // If Adena drop rate is not present it will be x1.
|
|
float adenaRate = Config.RATE_DROP_ITEMS_ID.containsKey(PcInventory.ADENA_ID) ? Config.RATE_DROP_ITEMS_ID.get(PcInventory.ADENA_ID) : 1;
|
|
float adenaRate = Config.RATE_DROP_ITEMS_ID.containsKey(PcInventory.ADENA_ID) ? Config.RATE_DROP_ITEMS_ID.get(PcInventory.ADENA_ID) : 1;
|
|
- if (itemId == PcInventory.ADENA_ID && count < 10000 * adenaRate)
|
|
|
|
|
|
+ if ((itemId == PcInventory.ADENA_ID) && (count < (10000 * adenaRate)))
|
|
{
|
|
{
|
|
// Small adena changes won't be saved to database all the time
|
|
// Small adena changes won't be saved to database all the time
|
|
- if (GameTimeController.getGameTicks() % 5 == 0)
|
|
|
|
|
|
+ if ((GameTimeController.getGameTicks() % 5) == 0)
|
|
|
|
+ {
|
|
item.updateDatabase();
|
|
item.updateDatabase();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
|
|
+ {
|
|
item.updateDatabase();
|
|
item.updateDatabase();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// If item hasn't be found in inventory, create new one
|
|
// If item hasn't be found in inventory, create new one
|
|
else
|
|
else
|
|
@@ -293,7 +310,9 @@ public abstract class ItemContainer
|
|
|
|
|
|
// If stackable, end loop as entire count is included in 1 instance of item
|
|
// If stackable, end loop as entire count is included in 1 instance of item
|
|
if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP)
|
|
if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP)
|
|
|
|
+ {
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -335,10 +354,12 @@ public abstract class ItemContainer
|
|
|
|
|
|
// Check if requested quantity is available
|
|
// Check if requested quantity is available
|
|
if (count > sourceitem.getCount())
|
|
if (count > sourceitem.getCount())
|
|
|
|
+ {
|
|
count = sourceitem.getCount();
|
|
count = sourceitem.getCount();
|
|
|
|
+ }
|
|
|
|
|
|
// If possible, move entire item object
|
|
// If possible, move entire item object
|
|
- if (sourceitem.getCount() == count && targetitem == null)
|
|
|
|
|
|
+ if ((sourceitem.getCount() == count) && (targetitem == null))
|
|
{
|
|
{
|
|
removeItem(sourceitem);
|
|
removeItem(sourceitem);
|
|
target.addItem(process, sourceitem, actor, reference);
|
|
target.addItem(process, sourceitem, actor, reference);
|
|
@@ -351,7 +372,7 @@ public abstract class ItemContainer
|
|
sourceitem.changeCount(process, -count, actor, reference);
|
|
sourceitem.changeCount(process, -count, actor, reference);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- // Otherwise destroy old item
|
|
|
|
|
|
+ // Otherwise destroy old item
|
|
{
|
|
{
|
|
removeItem(sourceitem);
|
|
removeItem(sourceitem);
|
|
ItemTable.getInstance().destroyItem(process, sourceitem, actor, reference);
|
|
ItemTable.getInstance().destroyItem(process, sourceitem, actor, reference);
|
|
@@ -362,7 +383,7 @@ public abstract class ItemContainer
|
|
targetitem.changeCount(process, count, actor, reference);
|
|
targetitem.changeCount(process, count, actor, reference);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- // Otherwise add new item
|
|
|
|
|
|
+ // Otherwise add new item
|
|
{
|
|
{
|
|
targetitem = target.addItem(process, sourceitem.getItemId(), count, actor, reference);
|
|
targetitem = target.addItem(process, sourceitem.getItemId(), count, actor, reference);
|
|
}
|
|
}
|
|
@@ -370,10 +391,14 @@ public abstract class ItemContainer
|
|
|
|
|
|
// Updates database
|
|
// Updates database
|
|
sourceitem.updateDatabase(true);
|
|
sourceitem.updateDatabase(true);
|
|
- if (targetitem != sourceitem && targetitem != null)
|
|
|
|
|
|
+ if ((targetitem != sourceitem) && (targetitem != null))
|
|
|
|
+ {
|
|
targetitem.updateDatabase();
|
|
targetitem.updateDatabase();
|
|
|
|
+ }
|
|
if (sourceitem.isAugmented())
|
|
if (sourceitem.isAugmented())
|
|
|
|
+ {
|
|
sourceitem.getAugmentation().removeBonus(actor);
|
|
sourceitem.getAugmentation().removeBonus(actor);
|
|
|
|
+ }
|
|
refreshWeight();
|
|
refreshWeight();
|
|
target.refreshWeight();
|
|
target.refreshWeight();
|
|
}
|
|
}
|
|
@@ -397,7 +422,7 @@ public abstract class ItemContainer
|
|
* Destroy item from inventory and updates database
|
|
* Destroy item from inventory and updates database
|
|
* @param process : String Identifier of process triggering this action
|
|
* @param process : String Identifier of process triggering this action
|
|
* @param item : L2ItemInstance to be destroyed
|
|
* @param item : L2ItemInstance to be destroyed
|
|
- * @param count
|
|
|
|
|
|
+ * @param count
|
|
* @param actor : L2PcInstance Player requesting the item destroy
|
|
* @param actor : L2PcInstance Player requesting the item destroy
|
|
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
|
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
|
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
|
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
|
@@ -413,7 +438,7 @@ public abstract class ItemContainer
|
|
item.setLastChange(L2ItemInstance.MODIFIED);
|
|
item.setLastChange(L2ItemInstance.MODIFIED);
|
|
|
|
|
|
// don't update often for untraced items
|
|
// don't update often for untraced items
|
|
- if (process != null || GameTimeController.getGameTicks() % 10 == 0)
|
|
|
|
|
|
+ if ((process != null) || ((GameTimeController.getGameTicks() % 10) == 0))
|
|
{
|
|
{
|
|
item.updateDatabase();
|
|
item.updateDatabase();
|
|
}
|
|
}
|
|
@@ -423,11 +448,15 @@ public abstract class ItemContainer
|
|
else
|
|
else
|
|
{
|
|
{
|
|
if (item.getCount() < count)
|
|
if (item.getCount() < count)
|
|
|
|
+ {
|
|
return null;
|
|
return null;
|
|
|
|
+ }
|
|
|
|
|
|
- boolean removed = this.removeItem(item);
|
|
|
|
|
|
+ boolean removed = removeItem(item);
|
|
if (!removed)
|
|
if (!removed)
|
|
|
|
+ {
|
|
return null;
|
|
return null;
|
|
|
|
+ }
|
|
|
|
|
|
ItemTable.getInstance().destroyItem(process, item, actor, reference);
|
|
ItemTable.getInstance().destroyItem(process, item, actor, reference);
|
|
|
|
|
|
@@ -487,7 +516,9 @@ public abstract class ItemContainer
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
{
|
|
{
|
|
if (item != null)
|
|
if (item != null)
|
|
|
|
+ {
|
|
destroyItem(process, item, actor, reference);
|
|
destroyItem(process, item, actor, reference);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -499,7 +530,7 @@ public abstract class ItemContainer
|
|
long count = 0;
|
|
long count = 0;
|
|
for (L2ItemInstance item : _items)
|
|
for (L2ItemInstance item : _items)
|
|
{
|
|
{
|
|
- if (item != null && item.getItemId() == PcInventory.ADENA_ID)
|
|
|
|
|
|
+ if ((item != null) && (item.getItemId() == PcInventory.ADENA_ID))
|
|
{
|
|
{
|
|
count = item.getCount();
|
|
count = item.getCount();
|
|
return count;
|
|
return count;
|
|
@@ -520,7 +551,7 @@ public abstract class ItemContainer
|
|
/**
|
|
/**
|
|
* Removes item from inventory for further adjustments.
|
|
* Removes item from inventory for further adjustments.
|
|
* @param item : L2ItemInstance to be removed from inventory
|
|
* @param item : L2ItemInstance to be removed from inventory
|
|
- * @return
|
|
|
|
|
|
+ * @return
|
|
*/
|
|
*/
|
|
protected boolean removeItem(L2ItemInstance item)
|
|
protected boolean removeItem(L2ItemInstance item)
|
|
{
|
|
{
|
|
@@ -587,17 +618,23 @@ public abstract class ItemContainer
|
|
{
|
|
{
|
|
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
|
|
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
|
|
if (item == null)
|
|
if (item == null)
|
|
|
|
+ {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
|
|
|
|
L2World.getInstance().storeObject(item);
|
|
L2World.getInstance().storeObject(item);
|
|
|
|
|
|
L2PcInstance owner = getOwner() == null ? null : getOwner().getActingPlayer();
|
|
L2PcInstance owner = getOwner() == null ? null : getOwner().getActingPlayer();
|
|
|
|
|
|
// If stackable item is found in inventory just add to current quantity
|
|
// If stackable item is found in inventory just add to current quantity
|
|
- if (item.isStackable() && getItemByItemId(item.getItemId()) != null)
|
|
|
|
|
|
+ if (item.isStackable() && (getItemByItemId(item.getItemId()) != null))
|
|
|
|
+ {
|
|
addItem("Restore", item, owner, null);
|
|
addItem("Restore", item, owner, null);
|
|
|
|
+ }
|
|
else
|
|
else
|
|
|
|
+ {
|
|
addItem(item);
|
|
addItem(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
refreshWeight();
|
|
refreshWeight();
|