import { GdRoot } from "../../GameData/index.js";
import { ISimCommand, SimLevel } from "../index.js";

export class SimCommandStartNextWave implements ISimCommand {
    private _simLevel: SimLevel;
    private _gdRoot: GdRoot;

    constructor(gdRoot: GdRoot, level: SimLevel) {
        this._gdRoot = gdRoot;
        this._simLevel = level;
    }

    execute() {
        const level = this._simLevel;
        const data = level.gdLevel;
        level.currentWave += 1;
        if (!data.waves[level.currentWave]) {
            level.paused = true;
            return;
        }
        level.nextWaveStep = level.currentStep + this._gdRoot.simulation.waveDuration * this._gdRoot.simulation.stepsPerSecond - 1;
        level.lastEnemySpawnStep = level.currentStep;
        level.enemiesLeftToSpawn = data.waves[level.currentWave].amount;
    }
}
