From 23d4e6e588f65be742a7989bc54e80b257dba204 Mon Sep 17 00:00:00 2001 From: MajorDzaster Date: Wed, 6 Sep 2023 15:01:19 +1000 Subject: [PATCH] Added repair capability to TowerUpgraderComponent --- .../components/tower/TowerUpgraderComponent.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java index 789f31d39..07ead7edc 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java +++ b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java @@ -10,7 +10,7 @@ */ public class TowerUpgraderComponent extends Component { public enum UPGRADE { - ATTACK, MAXHP, FIRERATE + ATTACK, MAXHP, FIRERATE, REPAIR } @Override @@ -24,13 +24,14 @@ public void create() { * Note: The fire rate upgrade is in shots per minute. * * @param upgradeType An enum indicating the type of upgrade to do - * @param value How much the upgrade should change the tower's stats + * @param value How much the upgrade should change the tower's stats, if applicable */ void upgradeTower(UPGRADE upgradeType, int value) { switch (upgradeType) { case ATTACK -> {upgradeTowerAttack(value);} case MAXHP -> {upgradeTowerMaxHealth(value);} case FIRERATE -> {getEntity().getEvents().trigger("addFireRate", value);} + case REPAIR -> {repairTower();} } } @@ -54,4 +55,12 @@ void upgradeTowerMaxHealth(int increase) { getEntity().getComponent(CombatStatsComponent.class).setMaxHealth(oldMaxHealth + increase); getEntity().getComponent(CombatStatsComponent.class).setHealth(oldMaxHealth + increase); } + + /** + * Restores the tower's health to its maximum health. + */ + void repairTower() { + int maxHealth = getEntity().getComponent(CombatStatsComponent.class).getMaxHealth(); + getEntity().getComponent(CombatStatsComponent.class).setHealth(maxHealth); + } }