Class ConsumableItem

java.lang.Object
com.csse3200.game.inventory.items.AbstractItem
com.csse3200.game.inventory.items.ConsumableItem
Direct Known Subclasses:
AbstractFood, HealingPotion, TimedUseItem, UniversalLootBox

public abstract class ConsumableItem extends AbstractItem
Base class for consumable type items that can be used by a player.

This includes items that have limited uses until it is depleted (removed) from the inventory, e.g. weapons with a durability or single use items such as food or potion.

  • Constructor Details

    • ConsumableItem

      protected ConsumableItem(String name, int itemCode, int limit, int quantity)
      Constructs a ConsumableItem with given initial starting quantity and stack limit.

      Note - a consumable item cannot be created without a limit/quantity specified.

      Parameters:
      name - the name of the item
      itemCode - the item code
      limit - the stack limit of the item
      quantity - the initial quantity for this item
  • Method Details

    • useItem

      public void useItem(ItemUsageContext context)
      Reduces quantity of item by 1.

      Sub-classes MUST override this function and call super.useItem()

      Specified by:
      useItem in class AbstractItem
      Parameters:
      context - the relevant ItemUsageContext for this item to be used
      Throws:
      ConsumedException - if the item has already been consumed and cannot be used.