Skip to content

Consumable Item

PHONGNGYUEN1 edited this page Aug 21, 2024 · 15 revisions

Consumable Items is a subclass of Abstract Item class. Consumable items represent items in game that have limited amount of uses. Other classes such as Potions, Artefacts and Food will be subclasses of this class.

  • The ConsumableItem class represents the subclass from Abstract Item. Consumable items represent items in the game that have a limited amount of uses. Other classes such as Potions, Artefacts and Food will be subclasses of this class. These subclasses will have to override the useItem function to implement their effects towards the player's stats

  • Unlike other infintie items, Consumable items will have a limited quantity of uses which is decreased for every time the item is used (i.e. there are 3 potions and potions are used 3 times, thus, the quantity of potions is now 0 and the player can no longer use the item until they acquire more).

  • For managing the quantity, the function @useItem has been modified to update the quantity count for each call. The effects for each consumable item will be later implemented in its subclasses.

#Expected Behaviour

  • After @useItem has been applied to the Consumable item it will decrease quantity. If the quantity has reached 0, a @ConsumableException will be thrown.

Other subclasses of Consumable Items include:

Usage

This class overrides the useItem function by subtracting the quantity for each function call.

 @Override
 public void useItem(ItemUsageContext context) {
     if (super.isEmpty()) {
        throw new ConsumedException();
     }
     this.quantity--;
 }

Items can be deemed consumable if they have a quantity greater than 0. Once items reach quantity of zero they are removed from the Inventory

Clone this wiki locally