Class InventoryComponent

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

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

      public ArrayList<Entity> getInventory()
      Returns a copy of the players current inventory.
      Returns:
      An ArrayList<Entity> containing the entities in the players inventory.
    • getTextures

      public ArrayList<String> 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

      public Entity get(int index)
      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

      public String getTex(int index)
      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

      public Entity getCurrSlot()
      Returns the current item that is being selected
      Returns:
      The item that is currently being selected
    • addItem

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

      public Boolean setItem(int index, Entity item)
      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 4
      item - 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

      public Boolean remove(int index)
      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

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

      public Boolean hasProcessor(int processor)
      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

      public WeaponsStatsComponent getCurrItemStats()
      Get the WeaponsStatsComponent for the current item
      Returns:
      Weapon Stats of current item
    • setCurrItem

      public void setCurrItem(Entity item)
      Set the current item
    • getCurrItem

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