Aura Pickup and Application - UQdeco2800/2022-studio-2 GitHub Wiki

Summary

This wiki page will explain the implementation of how the auras are picked up and how they are applied to the player's weapon.

Pickup Up an Aura

AuraPickupComponent

**Located in: ** source/core/src/main/com/deco2800/game/components/CombatItemsComponents/AuraPickupComponent.java AuraPickupComponent is a new class created that extends ItemPickupComponent (which is made by our team and initially named WeaponPickupComponent last sprint, but changed to ItemPickupComponent by Team02 with consent to allow everything to be picked up, not just weapons) which allows the player entity to pickup auras from the map.

First, a collision listener is created under create() to listen for instances when the buff is colliding with another entity. If a collision is detected, the pickUp() method is called.

    @Override
    public void create() {
        logger = LoggerFactory.getLogger(AuraPickupComponent.class);
        entity.getEvents().addListener("collisionStart", this::pickUp);
    }

Upon collision with an entity, the pickUp() method gets called and the if statement checks if the entity colliding with the aura entity on the map is the player entity. This is done by getting the fixture of the player entity, as below

Fixture f = ServiceLocator.getGameArea().getPlayer().getComponent(HitboxComponent.class).getFixture();

and comparing it to the other fixture (the fixture that is colliding the aura) to see if they are the same.

if (other == f) {

If they are the same, more checks are done before the aura is being picked up. As per the code below, the player is checked so that it has a weapon equipped currently, and also there are no auras currently applied to the weapon.

if ((weapon = ServiceLocator.getGameArea().getPlayer().getComponent(InventoryComponent.class).getEquipable(0)) != null
            && ServiceLocator.getGameArea().getPlayer().getComponent(WeaponAuraManager.class).auraApplied == null) 

If the checks pass, the aura is removed from the map using the removeAuraOnMap() function below in the gameAreas ForestGameArea or UndergroundGameArea

    public static void removeAuraOnMap(Entity entityToRemove) {

        entityToRemove.setEnabled(false);
        auraOnMap.remove(entityToRemove);

        Gdx.app.postRunnable(() -> entityToRemove.dispose());
    }

Then, the aura is applied to the player's currently equipped weapon, with more details about it in the next section.

ServiceLocator.getGameArea().getPlayer().getComponent(WeaponAuraManager.class)
                        .applyAura(entity, weapon);

Aura Application

WeaponAuraManager

Located in: source/core/src/main/com/deco2800/game/components/CombatItemsComponents/WeaponAuraManager.java

WeaponAuraManager is a component that is tied to the player as a way to manage the aura applied to the equipped weapon of the player.

The aura is applied to the weapon when the applyAura method in this component is called, which takes in two parameters. The first parameter is the aura that will be applied and the second is the weapon that would take that aura.

public void applyAura(Entity aura, Entity weapon)

In the method, the auraEndTime variable is set to the time when the aura will end. It gets the aura duration from the WeaponAuraComponent that is tied to the aura when the aura is created through the AuraFactory.

auraEndTime = System.currentTimeMillis() + aura.getComponent(WeaponAuraComponent.class).getAuraDuration();

Below shows the constructor for WeaponAuraComponent that takes in a auraDuration parameter that is used here.

    public WeaponAuraComponent(int auraDuration, double dmgMultiplier, double cdMultiplier, String description) {
        setAuraDuration(auraDuration);
        setDmgMultiplier(dmgMultiplier);
        setCdMultiplier(cdMultiplier);
        setDescription(description);
    }

The auraApplied parameter is then set to the aura in the parameter.

auraApplied = aura;

Then, the weapon's stats are modified with the aura's stats by extracting the aura stats through the getter methods in the WeaponAuraComponent of the aura.

weaponStats = weapon.getComponent(PhysicalWeaponStatsComponent.class);
weaponStats.setDamage(weaponStats.getDamage() * aura.getComponent(WeaponAuraComponent.class).getDmgMultiplier());
weaponStats.setCoolDown(weaponStats.getCoolDown() * aura.getComponent(WeaponAuraComponent.class).getCdMultiplier());

In the same method, there is also a line, which will be explained in more detail later.

entity.getComponent(BuffDisplayComponent.class).setBuff(aura.getComponent(TextureRenderComponent.class).getTexturePath());

In the update() method, a check is made every frame instance to check if there is a weapon equipped, and if so, call checkAuraEffect

    @Override
    public void update() {
        if (entity.getComponent(InventoryComponent.class).getEquipable(0) != null) {
            checkAuraEffect();
        }
    }

In the checkAuraEffect method, it checks if there is an aura applied currently, and if the aura is expired, revert the weapon stats to the default weapon stats (by dividing the aura stats). If the aura is expired, it also sets the auraApplied to null and auraEndtime to 0.

    public void checkAuraEffect() {
        if (auraApplied != null && System.currentTimeMillis() > auraEndTime) {
            weaponStats.setDamage(weaponStats.getDamage() / auraApplied.getComponent(WeaponAuraComponent.class).getDmgMultiplier());
            weaponStats.setCoolDown(weaponStats.getCoolDown() / auraApplied.getComponent(WeaponAuraComponent.class).getCdMultiplier());
            auraApplied = null;
            auraEndTime = 0;
            //stops showing the applied buff in the UI
            entity.getComponent(BuffDisplayComponent.class).clearBuff();
        }
    }

In the checkAuraEffect and applyAura methods, it pre-empts the existence of a BuffDisplayComponent class. Lets talk about that.

Displaying Currently Applied Aura Indicator

BuffDisplayComponent

Located in: source/core/src/main/com/deco2800/game/components/CombatItemsComponents/BuffDisplayComponent.java_

BuffDisplayComponent is a component that displays the currently applied aura on the screen, as simple as that. This is to indicate to the player that there is an aura applied to their weapon currently.

In the setBuff method, which is called in applyAura, it takes in a filename parameter, which would be the texture path of the buff, scales it to the right size, and adds it to the table, that is then placed at the top of the screen.

    public void setBuff(String filename) {
        buff = new Image(ServiceLocator.getResourceService().getAsset(filename, Texture.class));
        buff.scaleBy(1.2F);
        hasBuff = true;
        table.add(buff);
    }

Method below is addActors() which positions the actors on the stage using a table that would contain the buff image. This is called in the create() method of the component.

    private void addActors() {
        // Creates a new table
        table = new Table();
        // Places table at top of the screen
        table.top();
        table.setFillParent(true);
        // Sets padding of table
        table.padTop(50f);

        table.add(buff);
        stage.addActor(table);
    }

When the aura expires, the clearBuff() method is called. It sets the buff image to be null, and clears the table. Which would dispose the image of the buff on the display.

    public void clearBuff() {
        buff = null;
        hasBuff = false;
        table.clear();
    }

Justification of Integration

This is implemented with compliments to our aura code logic that was implemented in Sprint 1 to finally allow the auras to make changes to the combat components of the player, which if done correctly, will improve the game experience. As an example, before a boss fight, at the entrance, a buff can be spawned so that the player will have a easier time fighting the boss. Or, when the player gets hit by the boss, the player's weapon will get applied a debuff, which will make the boss fights harder. Therefore, the player will have more motivation to try to dodge the attacks of the enemy, which will then promote the use of the Dodge functionality

Back to Combat Items Contents Page

Author

  • Eugene Chong
  • GitHub: @eugene2341
  • Discord: gene#0005
  • Slack: Eugene Chong