-
Notifications
You must be signed in to change notification settings - Fork 1
Defense_Potion
Defense 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 defense 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.
The item should be able to increase the player's defence stat by 25 and then remove the effects it applied when combat is over.
the creation of the potion is written in the following class.
public DefensePotion(int quantity) {
super("Defense Potion", 53, 3, quantity, 25, DURATION, MSG);
this.setTexturePath(PATH);
this.setDescription("This is a defense potion");
this.onlyCombatItem = true;
}
the use item function is overridden to include the effects of defense and access the player stats to modify them. Before the potion is to update the defense it keeps a local copy of the original stats.
@Override
public void useItem(ItemUsageContext context) {
super.useItem(context);
context.player.getComponent(CombatStatsComponent.class).addDefense(this.effectAmount);
}
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.setDefense(stats.getDefense() - this.effectAmount);
}
created by @PHONGNGUYEN1