Class InventoryComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.InventoryComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
A component intended to be used by the player to track their inventory.
Currently untested, but forms the basis for the UI which will be implemented soon:tm:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
String representing the event that the inventory has been updated -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new InventoryComponent with a given maximum size.InventoryComponent
(List<Entity> items) Creates a new InventoryComponent with a given list of items. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addItem
(ItemComponent itemComponent) Adds an item to the Player's inventoryboolean
Adds an item to the Player's inventoryboolean
addMultipleItem
(int count, Entity item, int place) Adds an item to the Player's inventoryint
Retrieves the held item index of the Player.Retrieves the held item of the Player.Returns the HashMap of the String and Entity of the item in the inventory Created only for use in ItemSlot at the momentint
Returns the maximum size of the inventory.getItem
(int position) Function to get the item of a specific position in Inventory.Returns the HashMap of the String and the count of the item in the inventorygetItemCount
(int i) Returns the count of an item in the inventoryint
getItemCount
(Entity item) Returns the count of an item in the inventoryint
getItemCount
(String item) Returns the count of an item in the inventorygetItemName
(int position) Function to get the item of a specific position in Inventory.Returns the HashMap of the Position and the String of the item in the inventoryReturns if the player has a certain item or not.Returns if the player has a certain item or notboolean
isFull()
Checks if the inventory is full.int
Get the total number of Different Items in the inventoryvoid
loadInventory
(HashMap<String, Integer> itemCount, HashMap<String, Entity> heldItemsEntity, HashMap<Integer, String> itemPlace) Returns the count of an item in the inventoryvoid
read
(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue inv) Reads the InventoryComponent from a Json object.void
boolean
removeItem
(Entity item) Removes an item from the Player's Inventoryboolean
removeItem
(String itemName) Removes an item from the Player's Inventory with the givenString
name.boolean
removePosition
(int position) void
setHeldItem
(int index) Sets the held item for the Player.void
setHeldItemsEntity
(HashMap<String, Entity> heldItemsEntity) Sets the HashMap of the String and Entity of the item in the inventoryvoid
setInventory
(List<Entity> items) Sets the player's inventory to a given list of items.boolean
setInventorySize
(int size) Sets the maximum size of the inventory.void
setItemCount
(HashMap<String, Integer> allCount) Sets the HashMap of the String and the count of the item in the inventoryvoid
setItemPlace
(HashMap<Integer, String> itemPlace) Sets the HashMap of the Position and the String of the item in the inventoryboolean
setPosition
(Entity entity) Add Item to the first available position in the inventoryboolean
setPosition
(Entity entity, int position) add position of an entity into the HashList, with a specific positionboolean
swapPosition
(int pos1, int pos2) Function to get the exchange the position of two specific item in Inventory.void
Switches the 10 item slots in the inventory where the next item is automatically added.void
write
(com.badlogic.gdx.utils.Json json) Writes the InventoryComponent to a Json object.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
UPDATE_INVENTORY
String representing the event that the inventory has been updated- See Also:
-
-
Constructor Details
-
InventoryComponent
Creates a new InventoryComponent with a given list of items.- Parameters:
items
- List of Entities to be added to inventory
-
InventoryComponent
public InventoryComponent()Creates a new InventoryComponent with a given maximum size.
-
-
Method Details
-
getForbiddenItems
-
setInventorySize
public boolean setInventorySize(int size) Sets the maximum size of the inventory.- Parameters:
size
- The new maximum size of the inventory.- Returns:
- true if the size was set successfully, false otherwise.
-
getInventorySize
public int getInventorySize()Returns the maximum size of the inventory.- Returns:
- The maximum size of the inventory.
-
isFull
public boolean isFull()Checks if the inventory is full. Currently holding 30 types of Items- Returns:
- true if the inventory is full, false otherwise.
-
getItemCount
Returns the HashMap of the String and the count of the item in the inventory- Returns:
- HashMap of items and their count
-
setItemCount
Sets the HashMap of the String and the count of the item in the inventory- Parameters:
allCount
-
-
getItemPlace
Returns the HashMap of the Position and the String of the item in the inventory- Returns:
- HashMap of itemPlace
-
setItemPlace
Sets the HashMap of the Position and the String of the item in the inventory- Parameters:
itemPlace
- HashMap of itemPlace
-
getHeldItemsEntity
Returns the HashMap of the String and Entity of the item in the inventory Created only for use in ItemSlot at the moment- Returns:
- HashMap of held items
-
setHeldItemsEntity
Sets the HashMap of the String and Entity of the item in the inventory- Parameters:
heldItemsEntity
-
-
getItemCount
Returns the count of an item in the inventory- Parameters:
item
- Passing the Item name of the item- Returns:
- integer representation of count
-
hasItem
Returns if the player has a certain item or not.- Parameters:
item
- Entity to be checked- Returns:
- boolean representing if the item is on the character
-
hasItem
Returns if the player has a certain item or not- Parameters:
item
- String to be checked- Returns:
- boolean representing if the item is on the character
-
lastItemIndex
public int lastItemIndex()Get the total number of Different Items in the inventory- Returns:
- integer representing the total number of different items in the inventory
-
setInventory
Sets the player's inventory to a given list of items. Old inventory is cleared.- Parameters:
items
- List of Entities to be added to inventory
-
getItem
Function to get the item of a specific position in Inventory. Starts at 0- Parameters:
position
- position of the item in inventory- Returns:
- entity for that position in inventory
-
getItemName
Function to get the item of a specific position in Inventory. Starts at 0- Parameters:
position
- position of the item in inventory- Returns:
- entity for that position in inventory
-
swapPosition
public boolean swapPosition(int pos1, int pos2) Function to get the exchange the position of two specific item in Inventory.- Parameters:
pos1
- position of first Inventory Itempos2
- position of second Inventory Item
-
setPosition
add position of an entity into the HashList, with a specific position- Parameters:
entity
- entity to be addedposition
- position of the entity- Returns:
- boolean representing if the item was added successfully
-
setPosition
Add Item to the first available position in the inventory- Parameters:
entity
- entity to be added- Returns:
- boolean representing if the item was added successfully
-
removePosition
public boolean removePosition(int position) -
addItem
Adds an item to the Player's inventory- Parameters:
itemComponent
- ItemComponent to be added- Returns:
- boolean representing if the item was added successfully
-
addMultipleItem
Adds an item to the Player's inventory- Parameters:
count
- number of items to be addeditem
- ItemComponent to be added- Returns:
- boolean representing if the item was added successfully
-
addItem
Adds an item to the Player's inventory- Parameters:
item
- Entity to add- Returns:
- boolean representing if the item was added successfully
-
removeItem
Removes an item from the Player's Inventory- Parameters:
item
- item to be removed- Returns:
- boolean representing if the item was removed successfully
-
removeItem
Removes an item from the Player's Inventory with the givenString
name.- Parameters:
itemName
- the name of the item to be removed- Returns:
- boolean representing if the item was removed successfully
-
removeAll
-
getHeldItem
Retrieves the held item of the Player.- Returns:
- The Entity representing the held item.
-
setHeldItem
public void setHeldItem(int index) Sets the held item for the Player.- Parameters:
index
- The index of the item in the inventory to be set as the held item.
-
getHeldIndex
public int getHeldIndex()Retrieves the held item index of the Player.- Returns:
- The Entity representing the held item.
-
getItemCount
Returns the count of an item in the inventory- Parameters:
item
- Entity that is an item to find the counted of- Returns:
- integer representation of count
-
switchTab
public void switchTab()Switches the 10 item slots in the inventory where the next item is automatically added. -
getItemCount
Returns the count of an item in the inventory- Parameters:
i
- position of the item in inventory- Returns:
- integer representation of count
-
loadInventory
public void loadInventory(HashMap<String, Integer> itemCount, HashMap<String, Entity> heldItemsEntity, HashMap<Integer, String> itemPlace) Returns the count of an item in the inventory- Parameters:
itemCount
- HashMap of the String and the count of the item in the inventoryheldItemsEntity
- HashMap of the String and Entity of the item in the inventoryitemPlace
- HashMap of the Position and the String of the item in the inventory
-
write
public void write(com.badlogic.gdx.utils.Json json) Writes the InventoryComponent to a Json object. -
read
public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue inv) Reads the InventoryComponent from a Json object.
-