Class ConsumableItem
java.lang.Object
com.csse3200.game.inventory.items.AbstractItem
com.csse3200.game.inventory.items.ConsumableItem
- Direct Known Subclasses:
AbstractFood
,HealingPotion
,TimedUseItem
,UniversalLootBox
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.
-
Field Summary
Fields inherited from class com.csse3200.game.inventory.items.AbstractItem
description, itemCode, limit, name, onlyCombatItem, onlyMapItem, quantity
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ConsumableItem
(String name, int itemCode, int limit, int quantity) Constructs a ConsumableItem with given initial starting quantity and stack limit. -
Method Summary
Modifier and TypeMethodDescriptionvoid
useItem
(ItemUsageContext context) Reduces quantity of item by 1.Methods inherited from class com.csse3200.game.inventory.items.AbstractItem
add, getDescription, getItemCode, getLimit, getName, getQuantity, getTexturePath, isEmpty, numAddable, onlyCombatItem, onlyMapItem, setDescription, setTexturePath
-
Constructor Details
-
ConsumableItem
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 itemitemCode
- the item codelimit
- the stack limit of the itemquantity
- the initial quantity for this item
-
-
Method Details
-
useItem
Reduces quantity of item by 1.Sub-classes MUST override this function and call super.useItem()
- Specified by:
useItem
in classAbstractItem
- Parameters:
context
- the relevantItemUsageContext
for this item to be used- Throws:
ConsumedException
- if the item has already been consumed and cannot be used.
-