Class InventoryComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.player.InventoryComponent
A component intended to be used by the player to track their inventory.
Can also be used as a more generic component for other entities.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an item to player's inventory.boolean
addQuickBarItems
(Entity potion) Adding potion to the quickbar.void
applyArmourEffect
(Entity armour, boolean equip) Modify the player's stat according to the armour stat.void
applyWeaponEffect
(Entity weapon, boolean equip) Modify the player's stat according to the weapon stat.void
Cancel the animation registered for equipped weaponvoid
consumePotion
(int inputIndex) Consume the potion from quickbar based on the input index.boolean
Equip the item and apply effect of the item to the player.getEquipable
(int index) Returns the item at the given index orEntity[]
Returns the items the player equippedReturns the current inventoryint
getItemIndex
(Entity item, List<Entity> storage) Returns the index in the storage if there is one with the same Entity typeint
getItemQuantity
(int index) Returns the item's quantityint
getItemQuantity
(Entity item) Returns the item's quantityint
getPotionIndex
(Entity potion) Returns the index of the potion in the quickbar.Returns the current quick bar itemsint[]
Returns the current quantity of all potions in the quick barboolean
Checks if there is an item with the same type in the storageboolean
itemEquals
(Entity item, Entity other) Check if two items are the same kindvoid
registerAnimation
(Entity weapon) Register animation component for the weapon (IMPLEMENT ARMOUR ANIMATION)boolean
removeEquipable
(int itemSlot) Remove the item in the given itemSlot.void
removeItem
(int index) Removes an item to player's inventory.boolean
removeItem
(Entity item) Removes an item from the player's inventory.void
removeItem
(EntityTypes type) Removes an item to player's inventory.void
removePotion
(int inputIndex) Removes the potion from the quickbar based on the input indexvoid
setCombatAnimator
(Entity combatAnimator) Set the animator for weaponsvoid
setPotionQuantity
(int index, int quantity) Set the quantity of the potion based on its index on the quick barvoid
sortInventory
(int index, List<Entity> list, int[] quantity) Sort the item quantity array once an item is removed from the inventory.void
Swap the item in equipablevoid
Displays the inventory menu if it is not opened.boolean
unequipItem
(int itemSlot) Unequips the item in the given item slot.Methods inherited from class com.deco2800.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
InventoryComponent
public InventoryComponent()
-
-
Method Details
-
getInventory
Returns the current inventory- Returns:
- inventory items
-
setCombatAnimator
Set the animator for weapons- Parameters:
combatAnimator
- animation handler
-
registerAnimation
Register animation component for the weapon (IMPLEMENT ARMOUR ANIMATION)- Parameters:
weapon
- Entity
-
cancelAnimation
public void cancelAnimation()Cancel the animation registered for equipped weapon -
hasItem
Checks if there is an item with the same type in the storage- Parameters:
item
- the Entity to be checkedstorage
- the List of storage(e.g. can be quick bar, inventory)- Returns:
- true if there is a same kind of Entity, false otherwise
-
getItemIndex
Returns the index in the storage if there is one with the same Entity type- Parameters:
item
- item to be foundstorage
- the List of storage(e.g. can be quick bar, inventory)- Returns:
- index of the item, or -1 if item is not in the storage
-
addItem
Adds an item to player's inventory.- Parameters:
item
- item to add
-
sortInventory
Sort the item quantity array once an item is removed from the inventory.- Parameters:
index
- index of the itemlist
- the list of the inventory storagequantity
- the quantity array of corresponding inventory
-
removeItem
Removes an item from the player's inventory.- Parameters:
item
- item to remove- Requires:
- getItemQuantity(item) >= 1
-
removeItem
public void removeItem(int index) Removes an item to player's inventory.- Parameters:
index
- item's index stored in inventory- Requires:
- inventory.indexOf(index) != -1 and getItemQuantity(index) >= 1
-
removeItem
Removes an item to player's inventory.- Parameters:
type
- type of the item that is to be removed
-
getItemQuantity
Returns the item's quantity- Parameters:
item
- item to be checked- Returns:
- item's quantity
- Requires:
- inventory.contains(item) == true
-
getItemQuantity
public int getItemQuantity(int index) Returns the item's quantity- Parameters:
index
- item's index stored in inventory- Returns:
- item's quantity
- Requires:
- inventory.indexOf(index) != -1
-
applyWeaponEffect
Modify the player's stat according to the weapon stat. Credit to Team 4- Parameters:
weapon
- the weapon that is going to be equipped onequip
- boolean to determine equip or unequip item
-
applyArmourEffect
Modify the player's stat according to the armour stat.- Parameters:
armour
- the armour that is equippedequip
- boolean to determine equip or unequip item
-
getEquipable
Returns the item at the given index or- Parameters:
index
- the index of the item- Returns:
- entity
- Requires:
- equipables[index] != null
-
getEquipables
Returns the items the player equipped- Returns:
- the equipable array
-
removeEquipable
public boolean removeEquipable(int itemSlot) Remove the item in the given itemSlot.- Parameters:
itemSlot
- int- Returns:
- true if the item is correctly removed, false otherwise
-
equipItem
Equip the item and apply effect of the item to the player.- Parameters:
item
- the item to be equipped
-
swapItem
Swap the item in equipable- Parameters:
item
- the item to be swapped in- Requires:
- getEquipables().size() > 1 AND item.checkEntityType(ARMOUR || WEAPON)
-
unequipItem
public boolean unequipItem(int itemSlot) Unequips the item in the given item slot. Does nothing if the inventory is full.- Parameters:
itemSlot
- the index of the item slot- Requires:
- itemSlot >= 0 and itemSlot less than or equal to 1
-
toggleInventoryDisplay
public void toggleInventoryDisplay()Displays the inventory menu if it is not opened. Closes it otherwise.- Requires:
- the player is created and has an InventoryComponent.
-
getQuickBarItems
Returns the current quick bar items- Returns:
- quick bar items
-
getQuickBarQuantity
public int[] getQuickBarQuantity()Returns the current quantity of all potions in the quick bar- Returns:
- quantity array
-
itemEquals
Check if two items are the same kind- Parameters:
item
- the item to be checkedother
- the comparison item- Returns:
- true if two items are the same type, false otherwise
-
addQuickBarItems
Adding potion to the quickbar.- Parameters:
potion
- the potion to be added
-
getPotionIndex
Returns the index of the potion in the quickbar.- Parameters:
potion
- the potion in the quickbar.- Returns:
- index of the potion, -1 if potion does not exist
-
removePotion
public void removePotion(int inputIndex) Removes the potion from the quickbar based on the input index- Parameters:
inputIndex
- the index that is returned from user actions
-
setPotionQuantity
public void setPotionQuantity(int index, int quantity) Set the quantity of the potion based on its index on the quick bar- Parameters:
index
- index of the potion
-
consumePotion
public void consumePotion(int inputIndex) Consume the potion from quickbar based on the input index.- Parameters:
inputIndex
- the index that is returned from user actions
-