Class InventoryComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.player.InventoryComponent
All Implemented Interfaces:
Inventory

public class InventoryComponent extends Component implements 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 Details

  • Constructor Details

    • InventoryComponent

      public InventoryComponent()
    • InventoryComponent

      @Deprecated public InventoryComponent(int gold)
      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.
      Overrides:
      create in class Component
    • contains

      public boolean contains(int id)
      Description copied from interface: Inventory
      Check if a specific item is present in the backpack
      Specified by:
      contains in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if the quantity of the item in stock is greater than zero
    • contains

      public boolean contains(String itemName)
      Description copied from interface: Inventory
      Check if a specific item is present in the backpack
      Specified by:
      contains in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if the quantity of the item in stock is greater than zero
    • count

      public int count(int id)
      Description copied from interface: Inventory
      Quantity of a specific item
      Specified by:
      count in interface Inventory
      Parameters:
      id - item id
      Returns:
      the quantity of the item or -1 if the item id is not exist.
    • count

      public int count(String itemName)
      Description copied from interface: Inventory
      Quantity of a specific item
      Specified by:
      count in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      the quantity of the item or -1 if the item name is not exist.
    • add

      public boolean add(int id)
      Description copied from interface: Inventory
      Add an item with a specified id
      Specified by:
      add in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if add successfully
    • add

      public boolean add(int id, int num)
      Description copied from interface: Inventory
      Add several of this item
      Specified by:
      add in interface Inventory
      Parameters:
      id - item id
      num - the number of the added item
      Returns:
    • add

      public boolean add(String itemName)
      Description copied from interface: Inventory
      Add an item with a specified id
      Specified by:
      add in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if add successfully
    • add

      public boolean add(String itemName, int num)
      Description copied from interface: Inventory
      Add several of this item
      Specified by:
      add in interface Inventory
      Parameters:
      itemName - item name
      num - the number of the added item
      Returns:
    • remove

      public boolean remove(int id)
      Description copied from interface: Inventory
      remove a specified item
      Specified by:
      remove in interface Inventory
      Parameters:
      id - item id
      Returns:
      true if remove successfully
    • remove

      public boolean remove(String itemName)
      Description copied from interface: Inventory
      remove a specified item
      Specified by:
      remove in interface Inventory
      Parameters:
      itemName - item name
      Returns:
      true if remove successfully
    • remove

      public boolean remove(int id, int num)
      Specified by:
      remove in interface Inventory
    • remove

      public boolean remove(String itemName, int num)
      Specified by:
      remove in interface Inventory
    • getInStockItemIds

      public List<Integer> getInStockItemIds()
      Specified by:
      getInStockItemIds in interface Inventory
    • getInventory

      @Deprecated public HashMap<Integer,Integer> getInventory()
      Deprecated.
    • getGold

      @Deprecated public int getGold()
      Deprecated.
      Returns the player's gold.
      Returns:
      entity's health
    • hasGold

      @Deprecated public Boolean hasGold(int gold)
      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 public void setGold(int gold)
      Deprecated.
      Sets the player's gold. Gold has a minimum bound of 0.
      Parameters:
      gold - gold
    • addGold

      @Deprecated public void addGold(int gold)
      Deprecated.
      Adds to the player's gold. The amount added can be negative.
      Parameters:
      gold - gold to add