Class InventoryComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.player.InventoryComponent
- All Implemented Interfaces:
Inventory
A component intended to be used by the player to track their inventory.
Currently only stores the gold amount but can be extended for more advanced functionality such as storing items.
Can also be used as a more generic component for other entities.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int id) Add an item with a specified idboolean
add
(int id, int num) Add several of this itemboolean
Add an item with a specified idboolean
Add several of this itemvoid
addGold
(int gold) Deprecated.boolean
contains
(int id) Check if a specific item is present in the backpackboolean
Check if a specific item is present in the backpackint
count
(int id) Quantity of a specific itemint
Quantity of a specific itemvoid
create()
Called when the entity is created and registered.int
getGold()
Deprecated.Deprecated.hasGold
(int gold) Deprecated.boolean
remove
(int id) remove a specified itemboolean
remove
(int id, int num) boolean
remove a specified itemboolean
void
setGold
(int gold) Deprecated.Methods inherited from class com.deco2800.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
inventoryHashMap
Deprecated.
-
-
Constructor Details
-
InventoryComponent
public InventoryComponent() -
InventoryComponent
Deprecated.
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
contains
public boolean contains(int id) Description copied from interface:Inventory
Check if a specific item is present in the backpack -
contains
Description copied from interface:Inventory
Check if a specific item is present in the backpack -
count
public int count(int id) Description copied from interface:Inventory
Quantity of a specific item -
count
Description copied from interface:Inventory
Quantity of a specific item -
add
public boolean add(int id) Description copied from interface:Inventory
Add an item with a specified id -
add
public boolean add(int id, int num) Description copied from interface:Inventory
Add several of this item -
add
Description copied from interface:Inventory
Add an item with a specified id -
add
Description copied from interface:Inventory
Add several of this item -
remove
public boolean remove(int id) Description copied from interface:Inventory
remove a specified item -
remove
Description copied from interface:Inventory
remove a specified item -
remove
public boolean remove(int id, int num) -
remove
-
getInStockItemIds
- Specified by:
getInStockItemIds
in interfaceInventory
-
getInventory
Deprecated. -
getGold
Deprecated.Returns the player's gold.- Returns:
- entity's health
-
hasGold
Deprecated.Returns if the player has a certain amount of gold.- Parameters:
gold
- required amount of gold- Returns:
- player has greater than or equal to the required amount of gold
-
setGold
Deprecated.Sets the player's gold. Gold has a minimum bound of 0.- Parameters:
gold
- gold
-
addGold
Deprecated.Adds to the player's gold. The amount added can be negative.- Parameters:
gold
- gold to add
-