Attack_Potion - UQcsse3200/2024-studio-2 GitHub Wiki
Usage
Attack 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 attack 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. If potion is used outside of combat the dialogue msg that the potion cannot be used on the map will appear and prevent players from using the potion as described in Inventory
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 Attack Potion
the creation of the potion is written in the following class.
public AttackPotion(int quantity) {
super("Attack Potion", 53, 3, quantity, 25, DURATION, MSG);
this.setTexturePath(PATH);
this.setDescription("This is a attack potion");
this.onlyCombatItem = true;
}
useItem override
the use item function is overridden to include the effects of attack and access the player stats to modify them. Before the potion is to update the attack it keeps a local copy of the original stats.
@Override
public void useItem(ItemUsageContext context) {
super.useItem(context);
context.player.getComponent(CombatStatsComponent.class).addStrength(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 was applied
@Override
public void update(ItemUsageContext context) {
CombatStatsComponent stats = context.player.getComponent(CombatStatsComponent.class);
stats.setStrength(stats.getStrength() - this.effectAmount);
}