Class InventoryComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.player.InventoryComponent

public class InventoryComponent extends Component
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.
  • Constructor Details

    • InventoryComponent

      public InventoryComponent()
  • Method Details

    • getInventory

      public List<Entity> getInventory()
      Returns the current inventory
      Returns:
      inventory items
    • setCombatAnimator

      public void setCombatAnimator(Entity combatAnimator)
      Set the animator for weapons
      Parameters:
      combatAnimator - animation handler
    • registerAnimation

      public void registerAnimation(Entity weapon)
      Register animation component for the weapon (IMPLEMENT ARMOUR ANIMATION)
      Parameters:
      weapon - Entity
    • cancelAnimation

      public void cancelAnimation()
      Cancel the animation registered for equipped weapon
    • hasItem

      public boolean hasItem(Entity item, List<Entity> storage)
      Checks if there is an item with the same type in the storage
      Parameters:
      item - the Entity to be checked
      storage - the List of storage(e.g. can be quick bar, inventory)
      Returns:
      true if there is a same kind of Entity, false otherwise
    • getItemIndex

      public int getItemIndex(Entity item, List<Entity> storage)
      Returns the index in the storage if there is one with the same Entity type
      Parameters:
      item - item to be found
      storage - 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

      public void addItem(Entity item)
      Adds an item to player's inventory.
      Parameters:
      item - item to add
    • sortInventory

      public void sortInventory(int index, List<Entity> list, int[] quantity)
      Sort the item quantity array once an item is removed from the inventory.
      Parameters:
      index - index of the item
      list - the list of the inventory storage
      quantity - the quantity array of corresponding inventory
    • removeItem

      public boolean removeItem(Entity item)
      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

      public void removeItem(EntityTypes type)
      Removes an item to player's inventory.
      Parameters:
      type - type of the item that is to be removed
    • getItemQuantity

      public int getItemQuantity(Entity item)
      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

      public void applyWeaponEffect(Entity weapon, boolean equip)
      Modify the player's stat according to the weapon stat. Credit to Team 4
      Parameters:
      weapon - the weapon that is going to be equipped on
      equip - boolean to determine equip or unequip item
    • applyArmourEffect

      public void applyArmourEffect(Entity armour, boolean equip)
      Modify the player's stat according to the armour stat.
      Parameters:
      armour - the armour that is equipped
      equip - boolean to determine equip or unequip item
    • getEquipable

      public Entity getEquipable(int index)
      Returns the item at the given index or
      Parameters:
      index - the index of the item
      Returns:
      entity
      Requires:
      equipables[index] != null
    • getEquipables

      public Entity[] 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

      public boolean equipItem(Entity item)
      Equip the item and apply effect of the item to the player.
      Parameters:
      item - the item to be equipped
    • swapItem

      public void swapItem(Entity item)
      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

      public List<Entity> 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

      public boolean itemEquals(Entity item, Entity other)
      Check if two items are the same kind
      Parameters:
      item - the item to be checked
      other - the comparison item
      Returns:
      true if two items are the same type, false otherwise
    • addQuickBarItems

      public boolean addQuickBarItems(Entity potion)
      Adding potion to the quickbar.
      Parameters:
      potion - the potion to be added
    • getPotionIndex

      public int getPotionIndex(Entity potion)
      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