diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java index b98d7079d..4be3210de 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java @@ -18,6 +18,7 @@ public class WaveTask extends DefaultTask implements PriorityTask { private LevelWaves level; private WaveClass currentWave; private final GameTime globalTime; + private long nextWaveAt = 0; private int currentWaveIndex = 0; private boolean waveInProgress; private float startTime = 0; @@ -93,7 +94,7 @@ public void start() { @Override public void update() { if (ServiceLocator.getWaveService().getEnemyCount() == 0) { - currentWaveIndex++; +// currentWaveIndex++; long currentTime = ServiceLocator.getTimeSource().getTime(); // Setting the timestamp for when the next mobs will spawn. @@ -108,15 +109,28 @@ public void update() { } else { // Spawn the next wave - logger.info("No enemies remaining, begin next wave"); - this.waveEnd.play(); - this.waveInProgress = true; - this.level.setWaveIndex(currentWaveIndex); - // Set the service wave count to the current wave index. - ServiceLocator.getWaveService().setWaveCount(currentWaveIndex); - this.currentWave = this.level.getWave(currentWaveIndex); - ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize()); - //endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time +// logger.info("No enemies remaining, begin next wave"); + if (nextWaveAt == 0) { + logger.info("Next wave in 10 seconds"); + nextWaveAt = globalTime.getTime() + 10000; + ServiceLocator.getWaveService().setNextWaveTime(nextWaveAt); + } else { + if (globalTime.getTime() >= nextWaveAt || ServiceLocator.getWaveService().shouldSkip()) { + logger.info("Next wave starting"); + ServiceLocator.getWaveService().toggleDelay(); + currentWaveIndex++; + ServiceLocator.getWaveService().setNextWaveTime(0); + nextWaveAt = 0; + this.waveEnd.play(); + this.waveInProgress = true; + this.level.setWaveIndex(currentWaveIndex); + // Set the service wave count to the current wave index. + ServiceLocator.getWaveService().setWaveCount(currentWaveIndex); + this.currentWave = this.level.getWave(currentWaveIndex); + ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize()); + //endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time + } + } } } else { diff --git a/source/core/src/main/com/csse3200/game/services/WaveService.java b/source/core/src/main/com/csse3200/game/services/WaveService.java index c00693fbd..c7ddacdef 100644 --- a/source/core/src/main/com/csse3200/game/services/WaveService.java +++ b/source/core/src/main/com/csse3200/game/services/WaveService.java @@ -19,6 +19,8 @@ public class WaveService { private int spawnDelay; + private boolean skipDelay = false; + /** * Constructor for the Wave Service @@ -136,11 +138,26 @@ public void setNextWaveTime(long nextWaveTime) { public int getSpawnDelay() {return this.spawnDelay;} - /* Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed + /** + * Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed * for this instance of the display. * @return the updating instance of UIElementsDisplay */ public UIElementsDisplay getDisplay() { return this.display; } + + /** + * This will invert the value of the skipDelay boolean + * */ + public void toggleDelay() { + this.skipDelay = !this.skipDelay; + } + + /** + * retrieve the skipDelay condition + * */ + public boolean shouldSkip() { + return this.skipDelay; + } }