Speed_Potion - UQcsse3200/2024-studio-2 GitHub Wiki
Usage
Speed potions are a subclass of the TimedUsedItems class. This item provides values for the quantity, limit, texture, name, item code and effects for this specific item. The speed potion's purpose is to increase the stats by 25 and then update the stats once one-time usage is complete. This potion cannot be used on a map and is solely used for combat only. This allows the player to travel on the map faster. When the player enters Combat the speed will revert to its original speed.
Expected Behaviour
The item should be able to increase the player's strength stat by 25 and then remove the effects it applied when combat is over.
Creating Speed Potion
the creation of the potion is written in the following class.
public SpeedPotion(int quantity) {
super("Speed Potion", 55, 3, quantity, 25, DURATION, MSG);
this.setTexturePath(PATH);
this.setDescription("This is a speed potion");
this.onlyCombatItem = true;
}
useItem override
the use item function is overridden to include the effects of speed and access the player stats to modify them. Before the potion is to update the speed it keeps a local copy of the original stats.
@Override
public void useItem(ItemUsageContext context) {
super.useItem(context);
context.player.getComponent(CombatStatsComponent.class).addSpeed(this.effectAmount);
}
update override
update()
function is overridden and changes the current stats to the original stats. As mentioned before the original stats recorded will be used to replace the current stats after the potion is applied
@Override
public void update(ItemUsageContext context) {
CombatStatsComponent stats = context.player.getComponent(CombatStatsComponent.class);
stats.setSpeed(stats.getSpeed() - this.effectAmount);
}