Class InventoryComponent
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumLogical groupings for items held by the player. -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, empty component with three empty bags.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDirect(InventoryComponent.Bag bag, String itemId, int amount) Adds the specified item directly into the given bag without applying any collectable effects or config lookups.voidaddItem(InventoryComponent.Bag bag, String itemId) Deprecated.voidAdds one instance of the given item to the inventory via addItemsvoidAdds one instance of the given item and passes per-instance effect params.voidaddItems(InventoryComponent.Bag bag, String itemId, int amount) Deprecated.voidAddsamountinstances of itemId to the specified bag.booleanexistsAnywhere(String itemId) Returns true if the item exists in ANY bag (count > 0).intintgetItemCount(InventoryComponent.Bag bag, String itemId) Returns the stack count for itemId in the given bag.intgetItemCount(String itemId) Deprecated.Prefer bagged version: getItemCount(Bag.INVENTORY, itemId).intintDeprecated.Prefer bagged version: getTotalCount(Bag.INVENTORY).booleanhasItem(InventoryComponent.Bag bag, String itemId) booleanDeprecated.Prefer bagged version: hasItem(Bag.INVENTORY, itemId).Turns the contents of the bags of the inventory into a readable string - used for shell commands.voidremoveItem(InventoryComponent.Bag bag, String itemId) Removes all instances of itemId from the specified bag.voidremoveItem(String itemId) Deprecated.Prefer bagged version: removeItem(Bag.INVENTORY, itemId).voidClears all items from the specified bag.voidsetInventory(Map<String, Integer> inventory) Add all items from a passed inventory.voidsetUpgrades(Map<String, Integer> upgrades) Add all passed upgrades.booleanuseItem(InventoryComponent.Bag bag, String itemId) Consumes one instance of itemId from the specified bag (if present).voidDeprecated.Prefer bagged version: useItem(Bag.INVENTORY, itemId).intuseItems(InventoryComponent.Bag bag, String itemId, int amount) Consumes up to "amount" instances of itemId from the specified bag Consumes a specified number of items from the inventory.voidDeprecated.Prefer bagged version: useItems(Bag.INVENTORY, itemId, amount).Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
InventoryComponent
public InventoryComponent()Creates a new, empty component with three empty bags. -
InventoryComponent
Copy constructor. Creates deep copies of the three internal maps.- Parameters:
other- another InventoryComponent to copy- Throws:
NullPointerException- if other is null
-
-
Method Details
-
getInventory
- Returns:
- unmodifiable view of the INVENTORY bag
-
getUpgrades
- Returns:
- unmodifiable view of the UPGRADES bag
-
getObjectives
- Returns:
- unmodifiable view of the OBJECTIVES bag
-
getInventoryCopy
- Returns:
- copy of the INVENTORY bag
-
getUpgradesCopy
- Returns:
- copy of the UPGRADES bag
-
setInventory
Add all items from a passed inventory.- Parameters:
inventory- - passed inventory.
-
setUpgrades
Add all passed upgrades.- Parameters:
upgrades- - passed upgrades.
-
addItem
Adds one instance of the given item to the inventory via addItems- Parameters:
itemId- non-null item identifier (e.g., "key:door")- Throws:
NullPointerException- if itemId is null
-
addItems
Addsamountinstances of itemId to the specified bag.- Parameters:
itemId- non-null item identifieramount- number of instances to add (must be >= 0)- Throws:
NullPointerException- if bag or itemId is nullIllegalArgumentException- if amount is negative
-
addItem
Adds one instance of the given item and passes per-instance effect params. If the item is auto-consumable, effects are applied with the provided params. If non-auto, it’s stored normally.- Parameters:
itemId- item identifier (e.g., "objective")effectParams- effectType -> (key -> value), e.g. {"objective":{"target":"dash"}}
-
addItem
Deprecated.Add a single item to a specific bag. -
addItems
Deprecated.Add multiple items to a specific bag.If the config is non-auto-consumable, items are stored in the given
bag. If the config is auto-consumable, effects are applied immediately (the bag is ignored), exactlyamounttimes.- Parameters:
bag- destination bag (must not be null) for non-auto-consumablesitemId- item id (must not be null)amount- number of items to add (must be > 0)- Throws:
NullPointerException- ifbagoritemIdis nullIllegalArgumentException- ifamount/le 0 or no config is found
-
addDirect
Adds the specified item directly into the given bag without applying any collectable effects or config lookups.Intended for internal use by effects (e.g., upgrades) that must place tokens in inventory without re-triggering the effect pipeline.
- Parameters:
bag- the inventory bag to add the item toitemId- the identifier of the item to addamount- how many items to add (must be > 0)- Throws:
NullPointerException- ifitemIdis nullIllegalArgumentException- ifamount <= 0
-
hasItem
- Parameters:
bag- which bag to queryitemId- non-null identifier- Returns:
- true if the bag contains at least one instance
- Throws:
NullPointerException- if bag or itemId is null
-
getItemCount
Returns the stack count for itemId in the given bag.- Parameters:
bag- which bag to queryitemId- non-null identifier- Returns:
- count (0 if absent)
- Throws:
NullPointerException- if bag or itemId is null
-
getTotalCount
- Parameters:
bag- which bag to query- Returns:
- total count of all instances stored in the bag
- Throws:
NullPointerException- if bag is null
-
removeItem
Removes all instances of itemId from the specified bag.- Parameters:
bag- which bag to modifyitemId- non-null identifier to remove- Throws:
NullPointerException- if bag or itemId is null
-
resetBag
Clears all items from the specified bag. Uses one instance ofitemId.Decrements inventory item count by 1 if the item is present in the inventory and the number of items is > 0. Also applies its effect(s)
- Parameters:
bag- which bag to clear- Throws:
NullPointerException- if bag is null
-
useItem
Consumes one instance of itemId from the specified bag (if present).- Parameters:
bag- which bag to modifyitemId- non-null identifier to decrement- Returns:
- true if one instance was consumed; false if none were available
- Throws:
NullPointerException- if bag or itemId is null
-
useItems
Consumes up to "amount" instances of itemId from the specified bag Consumes a specified number of items from the inventory.This method will decrement the count of the given
itemIduntil either the requestedamounthas been used or the available quantity is depleted. If the item does not exist in the inventory or has a count of zero, no changes occur. Looks up the item's config and applies its effects. If no effect can be applied (e.g., using a heart at full HP), the item is not consumed.- Parameters:
bag- which bag to modifyitemId- non-null identifier to decrementamount- desired number to consume (must be >= 0)- Returns:
- the number of instances actually consumed (0..amount)
- Throws:
NullPointerException- if bag or itemId is nullIllegalArgumentException- if amount is negative
-
existsAnywhere
Returns true if the item exists in ANY bag (count > 0).- Parameters:
itemId- non-null identifier- Returns:
- true if present in inventory OR upgrades OR objectives
- Throws:
NullPointerException- if itemId is null
-
getGrandTotalCount
public int getGrandTotalCount()- Returns:
- total count across all bags (inventory + upgrades + objectives)
-
hasItem
Deprecated.Prefer bagged version: hasItem(Bag.INVENTORY, itemId). -
getItemCount
Deprecated.Prefer bagged version: getItemCount(Bag.INVENTORY, itemId). -
getTotalItemCount
Deprecated.Prefer bagged version: getTotalCount(Bag.INVENTORY). -
removeItem
Deprecated.Prefer bagged version: removeItem(Bag.INVENTORY, itemId). -
useItem
Deprecated.Prefer bagged version: useItem(Bag.INVENTORY, itemId). -
useItems
Deprecated.Prefer bagged version: useItems(Bag.INVENTORY, itemId, amount). -
printItems
Turns the contents of the bags of the inventory into a readable string - used for shell commands.- Returns:
- String - The constructed string of bag contents
-