Sprint 4: Armour Coding - UQdeco2800/2022-studio-2 GitHub Wiki

Code

The code focused on implementing the functionality for ApplyArmourEffect which allows armour to work as intended with Damage Reduction and Damage Return

public void applyArmourEffect(Entity armour, boolean equip) { ArmourStatsComponent armourStats; PlayerModifier pmComponent = entity.getComponent(PlayerModifier.class); //Applying the weight of the armour to player if ((armourStats = armour.getComponent(ArmourStatsComponent.class)) != null) { if (equip) { pmComponent.createModifier(PlayerModifier.MOVESPEED, (-(float) armourStats.getWeight() / 10), false, 0); pmComponent.createModifier(PlayerModifier.DMGREDUCTION, (float)armourStats.getPhyResistance(), false, 0); pmComponent.createModifier(PlayerModifier.DMGRETURN, (float)armourStats.getDmgReturn(), false, 0); } else { pmComponent.createModifier(PlayerModifier.MOVESPEED, 3 * (float) armourStats.getWeight() / 10, false, 0); pmComponent.createModifier(PlayerModifier.DMGREDUCTION, -(float)armourStats.getPhyResistance(), false, 0); } } }

This code allows the player to be affected by the different modifiers applied to them by the different Armour attributes.

Further implementation moved some of the functionality associated with hit() to be moved to setHealth() in CombatStatsComponent. This was to allow the damage return to function properly without damaging other aspects of the game.

public void setHealth(int health) { if(health < 0) this.health = 0; else if(health > 100) this.health = 100; else this.health = health;

if (entity != null) {
  entity.getEvents().trigger("updateHealth", this.health);
}

`Boolean checkDead = this.isDead();`
`if(entity != null) {`
  `if (checkDead && entity.checkEntityType(EntityTypes.ENEMY)) {`
    `Gdx.app.postRunnable(() -> {`
      `dropMaterial();`
      `dropWeapon();`
      `//entity.dispose();`
    `});`

    `if (entity.getComponent(AnimationRenderComponent.class) != null) {`
      `Gdx.app.postRunnable(() -> entity.getComponent(AnimationRenderComponent.class).stopAnimation()); //this is the magic line)`
    `}`
  `}`
  `if (isDead() && entity.checkEntityType(EntityTypes.PLAYER)) {`
    `entity.getEvents().trigger("death");`
  `}`
`}`

}

These were the main changes in the code which involved implementation of Damage Return as the code for Damage Reduction and the implementation for Dark Armour was already mostly in place and only involved calling the correct functions and some bug fixing