Armour Implementation - UQdeco2800/2022-studio-2 GitHub Wiki

This wiki page will give a brief explanation of armour, how they work, and what they do.

Armour Creation

The code below handles the creation of different armour types and generates them based on their name, as well as assigning them a texture. Following this, it also takes the stats implemented in the config files to be given to the armour. This section simply focuses on creating stats, and using uploaded images for the textures of the armour.

public enum ArmourType {
        baseArmour,
        slowDiamond,
        fastLeather,
        damageReturner
    }

public static Entity createArmour(ArmourType type) {
        Entity armour = createBaseArmour();
        ArmourConfig config = getConfig(type);
        String texturePath = getTexture(type);
        armour.addComponent(new TextureRenderComponent(texturePath));
        armour.getComponent(ArmourStatsComponent.class).setArmourStats(
                config.phyResistance,
                config.durability,
                config.vitality,
                config.dmgReturn,
                config.weight,
                config.materials);
        armour.getComponent(TextureRenderComponent.class).scaleEntity();
        armour.scaleHeight(5f);
        return armour;
    }

Making Armour have effect on player

The code below works by using the stats of the armour from the config files and turning that into an effect which directly impacts the player in some way, whether it be through speed, damage reduction, or stamina. This works by using the createModifier() function, then inputting the stat the player wants to change and the the value of the stat on the item.

private void applyArmourEffect(Entity armour) {
    ArmourStatsComponent armourStats = armour.getComponent(ArmourStatsComponent.class);
    PlayerModifier pmComponent = entity.getComponent(PlayerModifier.class);
    //Applying the weight of the armour to player
    pmComponent.createModifier(PlayerModifier.MOVESPEED, (float)armourStats.getWeight(), true, 0);
    //Applying the physical resistance of the armour to player
    pmComponent.createModifier(PlayerModifier.DMGREDUCTION, (float)armourStats.getPhyResistance(), true, 0);
    pmComponent.createModifier(PlayerModifier.STAMINAMAX, (float)armourStats.getVitality(), true, 0);
  }

Placing Armour in the World

The following code places an already existent armour into the world space

private void spawnBaseArmour() {
    Entity baseArmour = ArmourFactory.createArmour(ArmourFactory.ArmourType.baseArmour);
    armourOnMap.add(baseArmour);
    spawnEntityAt(baseArmour, new GridPoint2(2,20), true, false);
  }

Author

Lachlan McDonald GitHub: @Lukeyone Discord: merty009 #1029

Co-Author Li-Sung Ou GitHub: @PeterOu8