mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 19:46:43 +00:00
46 lines
1.0 KiB
TypeScript
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;
|
|
}
|
|
}
|