Files
OpenFrontIO/src/core/execution/SetTargetTroopRatioExecution.ts
T
2025-02-18 16:26:49 -08:00

46 lines
1.0 KiB
TypeScript

import { consolex } from "../Consolex";
import { Execution, Game, Player, PlayerID } from "../game/Game";
export class SetTargetTroopRatioExecution implements Execution {
private player: Player;
private active = true;
constructor(
private playerID: PlayerID,
private targetTroopsRatio: number,
) {}
init(mg: Game, ticks: number): void {
if (!mg.hasPlayer(this.playerID)) {
console.warn(
`SetTargetTRoopRatioExecution: player ${this.playerID} not found`,
);
}
this.player = mg.player(this.playerID);
}
tick(ticks: number): void {
if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) {
consolex.warn(
`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`,
);
} else {
this.player.setTargetTroopRatio(this.targetTroopsRatio);
}
this.active = false;
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}