Class Inventory

java.lang.Object
com.adventure.models.Inventory

public class Inventory extends Object
Class used to handle an inventory of items.
  • Constructor Details

    • Inventory

      public Inventory(int maxWeight)
      Default constructor.
      • currentWeight: 0
      • attackItem: hands
      • defenceItem: hands
      Parameters:
      maxWeight - Max weight the inventory can have.
  • Method Details

    • getEquipedAttackItem

      public AttackItem getEquipedAttackItem()
      Get the equipped attack item.
      Returns:
      AttackItem equipped.
    • getEquipedDefenceItem

      public DefenceItem getEquipedDefenceItem()
      Get the equipped defence item.
      Returns:
      DefenceItem equipped.
    • getMaxWeight

      public int getMaxWeight()
      Get the value of max weight the inventory can handle.
      Returns:
      max weight of the inventory.
    • getCurrentWeight

      public int getCurrentWeight()
      Get the value of the current weight in the inventory.
      Returns:
      current weight in the inventory.
    • getItems

      public ArrayList<Item> getItems()
      Get a copy of the ArrayList containing all the items.
      Returns:
      ArrayList with all items of the inventory.
    • setMaxWeight

      public void setMaxWeight(int maxWeight)
      Set max weight the inventory can hold.
      Parameters:
      maxWeight - value of max weight.
    • setCurrentWeight

      public void setCurrentWeight(int currentWeight)
      Set the current weight in the inventory.
      Parameters:
      currentWeight - value of the current weight.
    • setItems

      public void setItems(ArrayList<Item> items) throws TooMuchWeightException
      Set all items in the inventory.
      Parameters:
      items - ArrayList containing all the items.
      Throws:
      TooMuchWeightException - If the weight is over maxWeight.
    • equipItem

      public void equipItem(Equipable equipable)
      Equip an equipable item
      Parameters:
      equipable - Item to equip
    • unequipItem

      public void unequipItem(Inventory.EquipType type)
      Unequip an attack or defense item
      Parameters:
      type - Type of the item to unequip (ATTACK or DEFENSE)
    • addItem

      public void addItem(Item item)
      Add item to the inventory
      Parameters:
      item - Item to add
      Throws:
      TooMuchWeightException - The item weights too much for the current inventory
    • itemsByName

      public ArrayList<Item> itemsByName(String name)
      Method to obtain an item instance from its name
      Parameters:
      name - Name of the item to search
      Returns:
      ArrayList with all the items with the same name
    • dropItem

      public Item dropItem(Item item)
      Drop an item and remove it from the inventory
      Parameters:
      item - Item to be removed
    • dropItem

      public Item dropItem(String itemName)
      Drop an item and remove it from the inventory
      Parameters:
      itemName - Item to remove.
      Returns:
      The removed item.
      Throws:
      NoSuchElementException - If the item is not present.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object