Skip to content

Commit

Permalink
Added repair capability to TowerUpgraderComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasdairS4698737 committed Sep 6, 2023
1 parent 705c3e2 commit 23d4e6e
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class TowerUpgraderComponent extends Component {
public enum UPGRADE {
ATTACK, MAXHP, FIRERATE
ATTACK, MAXHP, FIRERATE, REPAIR
}

@Override
Expand All @@ -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();}
}
}

Expand All @@ -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);
}
}

0 comments on commit 23d4e6e

Please sign in to comment.