Repository navigation
Combat Stat Component
Component used to store information related to combat such as health, attack, movementSpeed and attackSpeed. Any entities which engages it's combat should have an instance of this class registered. This class can be extended for more specific combat needs.
-
health: current health, minimum bound 0 -
maxHealth: the upper boud for health which can be set via construction or (via setMaxHealth) -
baseAttack: base attack damage -
movementSpeed: movement speed (in Sprint 1 only used by player using overloaded constructor) -
attackSpeed: attack Speed multiplier (for attack cooldown, currently related to player only)
-
CombatStatsComponent(int health, int baseAttack): used by enemies; movementSpeed/attackSpeed default to 0 -
CombatStatsComponent(int health, int baseAttack, float movementSpeed, float attackSpeed): used by the player
getter and setter methods for all fields. Additional methods:
-
isDead: return true if health = 0. -
setHealth(int health): clamps to [0, maxHealth]; triggers updateHealth, and entityDied if health transitions to 0 from some positive health - Add more health, movementSpeed and attackSpeed methods: can be used to increase current health by items/charms. E.g
addHealth(20)if player current health is 70, increases it to 90 -
takeDamage(int damage) / takeDamage(int damage, Entity attacker): reduces health and triggers a hit reaction -
hit(CombatStatComponent attacker): applies attacker's baseAttack as damage to the entity calling this event. E.genemyStat.hit(playerStat)reduces enemy's health by player's current base attack.
-
updateHealth,updateBaseAttack,updateMovementSpeed,updateMaxHealth,updateAttackSpeedevents are triggered when stat of the player changes and used by Player Stat Display. -
entityDiedthie event triggered when health field reaches zero.
// Enemy without movementSpeed/attackSpeed needed
Entity enemy = new Entity()
.addComponent(new CombatStatsComponent(50, 10));
// Player has now movementSpeed and attackSpeed
Entity player = new Entity()
.addComponent(new CombatStatsComponent(
stats.health, stats.baseAttack, stats.movementSpeed, stats.attackSpeed));
// Reading/modifying stats (e.g. a charm boosting movement speed)
CombatStatsComponent playerStats = player.getComponent(CombatStatsComponent.class);
playerStats.addMovementSpeed(1.5f); // e.g. speed charm buff
// Applying damage from an attacker
enemyStats.hit(playerStats); // reduces enemy health by player's baseAttackJunit : All of the methods develop by player team has their Junit tests in CombatStatComponentTest.java
Example:
shouldSetGetHealth: health clamps correctly at both bounds
shouldCheckIsDead: isDead() reflects health == 0
Manual Testing: Player health and Strength(attack speed) updates when player deal with enemies in game and base attack increases when player pick up the charm using E keys. This can be seen at the top left corner where player stats displays.
classDiagram
class Component {
<abstract>
}
class CombatStatsComponent {
-int health
-int maxHealth
-int baseAttack
-float movementSpeed
-float attackSpeed
+CombatStatsComponent(health, baseAttack)
+CombatStatsComponent(health, baseAttack, movementSpeed, attackSpeed)
+isDead() Boolean
+getHealth() int
+getMaxHealth() int
+setMaxHealth(health) void
+setHealth(health) void
+addHealth(health) void
+getBaseAttack() int
+setBaseAttack(attack) void
+addBaseAttack(attack) void
+getMovementSpeed() float
+setMovementSpeed(newSpeed) void
+addMovementSpeed(speed) void
+getAttackSpeed() float
+setAttackSpeed(newSpeed) void
+addAttackSpeed(speed) void
+takeDamage(damage) void
+takeDamage(damage, attacker) void
+hit(attacker) void
+applyHitReaction(attacker) void
}
Component <|-- CombatStatsComponent