Class InventoryComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.InventoryComponent
A component intended to be used by the player to track their inventory.
Currently, has functionality for indexing, getting, setting, and removing
from
the players inventory, also stores the processor amount.
Can also be used as a more generic component for other entities.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionInventoryComponent
(int processor) Constructs an inventory for the player and a beginning currency amount to start with. -
Method Summary
Modifier and TypeMethodDescriptionAdds an item to the next free inventory position for the player to hold i.e.void
addProcessor
(int processor) Adds to the player's processors.get
(int index) Returns the item at the given index.Get the current itemGet the WeaponsStatsComponent for the current itemReturns the current item that is being selectedint
Gets the currently equipped slotReturns a copy of the players current inventory.int
getter method for the keycard levelint
Returns the player's processor's.int
getSize()
Returns the number of items currently in the inventorygetTex
(int index) Returns the texture for the item at the given indexReturns a copy of the current inventory textureshasProcessor
(int processor) Returns if the player has a certain amount of processor's.isEmpty()
Checks if the current inventory is empty or notboolean
isFull()
Returns true if the players inventory is full, false otherwiseremove
(int index) Removes the item at the given index (must be between 0 and 4) and replaces it with null value.void
Removes the current item if there is one selectedvoid
setCurrItem
(Entity item) Set the current itemvoid
setEquippedSlot
(int slotIndex) setEquippedSlot(int slotIndex) equips the player with the weapon at slotIndexsets the provided item to the inventory in positions 0 to 4 to be the given item.void
setKeycardLevel
(int level) setter method for the keycard levelvoid
setProcessor
(int processor) Sets the player's processor's.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(int processor) Constructs an inventory for the player and a beginning currency amount to start with.- Parameters:
processor
- The number of processors that the inventory is starting with
-
-
Method Details
-
setKeycardLevel
public void setKeycardLevel(int level) setter method for the keycard level- Parameters:
level
- level to set the keycard to
-
getKeycardLevel
public int getKeycardLevel()getter method for the keycard level- Returns:
- the current keycard level
-
getInventory
Returns a copy of the players current inventory.- Returns:
- An
ArrayList<Entity>
containing the entities in the players inventory.
-
getTextures
Returns a copy of the current inventory textures- Returns:
- An
ArrayList<String>
containing the texture paths of the players inventory
-
getSize
public int getSize()Returns the number of items currently in the inventory- Returns:
- The number of items in the inventory
-
get
Returns the item at the given index.- Parameters:
index
- The position of the item in the players inventory (0..4)- Returns:
- The item at the given position, NULL if nothing there or index not in [0,4]
-
getTex
Returns the texture for the item at the given index- Parameters:
index
- The position of the item in the players inventory (0..4)- Returns:
- The item at the given position, NULL if nothing there or index not in [0,4]
-
getCurrSlot
Returns the current item that is being selected- Returns:
- The item that is currently being selected
-
addItem
Adds an item to the next free inventory position for the player to hold i.e. addItem(d) [a, b, _, c] -> [a, b, _, c, d]- Parameters:
item
- An item to store in the players inventory- Returns:
- true if successful, false otherwise
-
setItem
sets the provided item to the inventory in positions 0 to 4 to be the given item.- Parameters:
index
- The index of the inventory 0 to 4item
- An item to store in the players inventory- Returns:
- true if the item was successfully set, false otherwise or if something is already there
-
remove
Removes the item at the given index (must be between 0 and 4) and replaces it with null value.- Parameters:
index
- the position of the item to be removed.- Returns:
- true if successful, false otherwise
-
isEmpty
Checks if the current inventory is empty or not- Returns:
- true if the inventory is empty, false otherwise
-
isFull
public boolean isFull()Returns true if the players inventory is full, false otherwise- Returns:
- true if the inventory is full, false otherwise
-
getProcessor
public int getProcessor()Returns the player's processor's.- Returns:
- how much processor player has
-
hasProcessor
Returns if the player has a certain amount of processor's.- Parameters:
processor
- required amount of processor's- Returns:
- player has greater than or equal to the required amount of processor's
-
setProcessor
public void setProcessor(int processor) Sets the player's processor's. Processor's has a minimum bound of 0.- Parameters:
processor
- processor
-
addProcessor
public void addProcessor(int processor) Adds to the player's processors. The amount added can be negative.- Parameters:
processor
- processor to add
-
getCurrItemStats
Get the WeaponsStatsComponent for the current item- Returns:
- Weapon Stats of current item
-
setCurrItem
Set the current item -
getCurrItem
Get the current item- Returns:
- the current item
-
setEquippedSlot
public void setEquippedSlot(int slotIndex) setEquippedSlot(int slotIndex) equips the player with the weapon at slotIndex- Parameters:
slotIndex
- is the index of the slot from which the player wants to equip the weapon from
-
getEquippedSlot
public int getEquippedSlot()Gets the currently equipped slot- Returns:
- the slot index that is currently equipped
-
removeCurrItem
public void removeCurrItem()Removes the current item if there is one selected
-