TimedUsedItems - UQcsse3200/2024-studio-2 GitHub Wiki
TimedUsedItems are the items with one timed use-only effect. For instance, if defence and attack potions (Combat use only items) are used in combat, the effects will last through the period of the combat, once finished it player will revert back to its original stats. Some of the items such as Defense and Attack potions can only be used during combat while items such as speed Potions is available only on map.
Expected Behaviour:
- To manage the effects of the function
useItem()
has been modified to apply the effects for each call. The effects for each consumable item will be later implemented in its subclasses. This - To update and revert the effects changes from
useItem()
the functionupdate()
is called inInventoryInterface
- Usage Tracking: The class tracks the number of uses left for the potion. Each use tracks the number of uses left for the potion. Each use decreases the available quantity, eventually rendering the potion useless once the quantity reaches zero.
- Items that are part of TimeusedItems are:
The function update()
is an abstract function that updates the stats to the original state after using the TimedUsedItens. This function will be called in the InventoryInterface
and the items used before will be updated in the previously used potion list to keep track of them.
public abstract void update(ItemUsageContext context);
the method updatePotions()
handles updating the player stats back to the original state after the potion has been used for one round.
public void updatePotions(ItemUsageContext context) {
//unsure if this is intended behaviour but previous behaviour could only be false.
if (potions.isEmpty()) { return;}
Deque<Integer> removals = new ArrayDeque<>();
// Find all items to remove
for (int i = 0; i < potions.size(); i++) {
TimedUseItem potion = potions.get(i);
if (potion.onlyCombatItem()) {
potions.get(i).update(context);
removals.addFirst(i); // Equivalent to stack.push(i)
}
}
// Remove those items
while (!removals.isEmpty()) {
int i = removals.removeFirst(); // Equivalent to stack.pop()
potions.remove(i);
}
}
This feature ensures that potions will only last after one time of use on a map or combat and will revert effects. For instance, when a player uses speed in the map the effects will last until they enter combat, causing the effects to automatically update and return to the original speed. As for Defense and attack potions they will last for the entire combat when used and then will revert once combat is finished. The combat is over or the player enters combat