diff --git a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java index 88e2d6446..91fecc471 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java @@ -221,7 +221,7 @@ private boolean isTargetVisible() { * @param newInterval The rate at which the tower should fire projectiles in shots per second. */ private void changeFireRateInterval(int newInterval) { - fireRateInterval = newInterval; + fireRateInterval = (float) newInterval / 5; } /** 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 937d52a6b..12c62ffc6 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 @@ -28,7 +28,7 @@ public void create() { public void upgradeTower(UPGRADE upgradeType, int value) { switch (upgradeType) { case ATTACK -> {upgradeTowerAttack(value);} - case MAXHP -> {upgradeTowerMaxHealth(value);} + case MAXHP -> {upgradeTowerMaxHealth( value);} case FIRERATE -> {getEntity().getEvents().trigger("addFireRate", value);} case REPAIR -> {repairTower();} } diff --git a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java index dfd61422b..f423368c4 100644 --- a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java +++ b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java @@ -193,8 +193,10 @@ public void clicked(InputEvent event, float x, float y) { value -= 10; ServiceLocator.getCurrencyService().getScrap().setAmount(value); ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats(); - turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, 5); - turretEntity.getComponent(UpgradableStatsComponent.class).setAttackRate(5); + float newFireRate = turretEntity.getComponent(UpgradableStatsComponent.class).getAttackRate() + 0.2f; + turretEntity.getComponent(UpgradableStatsComponent.class).setAttackRate(newFireRate); + turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, 1); + float fireRate = turretEntity.getComponent(UpgradableStatsComponent.class).getAttackRate(); fireRateLabel.setText(String.format("Fire Rate: %.2f", fireRate)); } diff --git a/source/core/src/test/com/csse3200/game/components/tower/TowerUpgraderComponentTest.java b/source/core/src/test/com/csse3200/game/components/tower/TowerUpgraderComponentTest.java index 703a1299b..9af62e404 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/TowerUpgraderComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/TowerUpgraderComponentTest.java @@ -60,7 +60,7 @@ void increaseFireRate() { entity.create(); entity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, 60); verify(towerUpgraderComponent).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, 60); - assertEquals(0.5, towerCombatTask.getFireRateInterval()); + assertEquals(12.0, towerCombatTask.getFireRateInterval()); } @Test @@ -74,8 +74,8 @@ void divideByZeroDefaultToIgnore() { entity.addComponent(aiTaskComponent); towerCombatTask.start(); entity.create(); - entity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, -60); - verify(towerUpgraderComponent).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, -60); - assertEquals(1., towerCombatTask.getFireRateInterval()); + entity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, 60); + verify(towerUpgraderComponent).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, 60); + assertEquals(12f, towerCombatTask.getFireRateInterval()); } }