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

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

    • UPDATE_INVENTORY

      public static final String UPDATE_INVENTORY
      String representing the event that the inventory has been updated
      See Also:
  • Constructor Details

    • InventoryComponent

      public InventoryComponent(List<Entity> items)
      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

      public static List<String> 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

      public HashMap<String,Integer> getItemCount()
      Returns the HashMap of the String and the count of the item in the inventory
      Returns:
      HashMap of items and their count
    • setItemCount

      public void setItemCount(HashMap<String,Integer> allCount)
      Sets the HashMap of the String and the count of the item in the inventory
      Parameters:
      allCount -
    • getItemPlace

      public HashMap<Integer,String> getItemPlace()
      Returns the HashMap of the Position and the String of the item in the inventory
      Returns:
      HashMap of itemPlace
    • setItemPlace

      public void setItemPlace(HashMap<Integer,String> itemPlace)
      Sets the HashMap of the Position and the String of the item in the inventory
      Parameters:
      itemPlace - HashMap of itemPlace
    • getHeldItemsEntity

      public HashMap<String,Entity> 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

      public void setHeldItemsEntity(HashMap<String,Entity> heldItemsEntity)
      Sets the HashMap of the String and Entity of the item in the inventory
      Parameters:
      heldItemsEntity -
    • getItemCount

      public int getItemCount(String item)
      Returns the count of an item in the inventory
      Parameters:
      item - Passing the Item name of the item
      Returns:
      integer representation of count
    • hasItem

      public Boolean hasItem(Entity item)
      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

      public Boolean hasItem(String item)
      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

      public void setInventory(List<Entity> items)
      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

      public Entity getItem(int position)
      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

      public String getItemName(int position)
      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 Item
      pos2 - position of second Inventory Item
    • setPosition

      public boolean setPosition(Entity entity, int position)
      add position of an entity into the HashList, with a specific position
      Parameters:
      entity - entity to be added
      position - position of the entity
      Returns:
      boolean representing if the item was added successfully
    • setPosition

      public boolean setPosition(Entity entity)
      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

      public boolean addItem(ItemComponent itemComponent)
      Adds an item to the Player's inventory
      Parameters:
      itemComponent - ItemComponent to be added
      Returns:
      boolean representing if the item was added successfully
    • addMultipleItem

      public boolean addMultipleItem(int count, Entity item, int place)
      Adds an item to the Player's inventory
      Parameters:
      count - number of items to be added
      item - ItemComponent to be added
      Returns:
      boolean representing if the item was added successfully
    • addItem

      public boolean addItem(Entity item)
      Adds an item to the Player's inventory
      Parameters:
      item - Entity to add
      Returns:
      boolean representing if the item was added successfully
    • removeItem

      public boolean removeItem(Entity item)
      Removes an item from the Player's Inventory
      Parameters:
      item - item to be removed
      Returns:
      boolean representing if the item was removed successfully
    • removeItem

      public boolean removeItem(String itemName)
      Removes an item from the Player's Inventory with the given String name.
      Parameters:
      itemName - the name of the item to be removed
      Returns:
      boolean representing if the item was removed successfully
    • removeAll

      public void removeAll(Entity item)
    • getHeldItem

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

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

      public Integer getItemCount(int i)
      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 inventory
      heldItemsEntity - HashMap of the String and Entity of the item in the inventory
      itemPlace - 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.
      Specified by:
      write in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      write in class Component
      Parameters:
      json - The Json object to write to.
    • read

      public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue inv)
      Reads the InventoryComponent from a Json object.
      Specified by:
      read in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      read in class Component
      Parameters:
      json - The Json object to read from.
      inv - The JsonValue to read from.