Skip to content

Defense_Potion

Phong (Nicole) Nguyen edited this page Oct 16, 2024 · 6 revisions

Usage

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.

Expected Behaviour

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.

Creating Defense Potion

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;
    }

useItem override

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 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.setDefense(stats.getDefense() - this.effectAmount);
    }

Defense potion image

Defence potion created by @PHONGNGUYEN1

Clone this wiki locally