mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 13:59:08 +00:00
44 lines
983 B
TypeScript
44 lines
983 B
TypeScript
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
|
|
|
export class EmbargoExecution implements Execution {
|
|
private active = true;
|
|
|
|
constructor(
|
|
private player: Player,
|
|
private targetID: PlayerID,
|
|
private readonly action: "start" | "stop",
|
|
) {}
|
|
|
|
init(mg: Game, _: number): void {
|
|
if (!mg.hasPlayer(this.player.id())) {
|
|
console.warn(`EmbargoExecution: sender ${this.player.id()} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (!mg.hasPlayer(this.targetID)) {
|
|
console.warn(`EmbargoExecution recipient ${this.targetID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
tick(_: number): void {
|
|
if (this.action == "start") this.player.addEmbargo(this.targetID);
|
|
else this.player.stopEmbargo(this.targetID);
|
|
|
|
this.active = false;
|
|
}
|
|
|
|
owner(): Player {
|
|
return null;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|