mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 22:31:55 +00:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
|
|
|
export class TargetPlayerExecution implements Execution {
|
|
private requestor: Player;
|
|
private target: Player;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private requestorID: PlayerID,
|
|
private targetID: PlayerID,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.hasPlayer(this.requestorID)) {
|
|
console.warn(
|
|
`TargetPlayerExecution: requestor ${this.requestorID} not found`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (!mg.hasPlayer(this.targetID)) {
|
|
console.warn(`TargetPlayerExecution: target ${this.targetID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.requestor = mg.player(this.requestorID);
|
|
this.target = mg.player(this.targetID);
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.requestor.canTarget(this.target)) {
|
|
this.requestor.target(this.target);
|
|
this.target.updateRelation(this.requestor, -40);
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
owner(): Player {
|
|
return null;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|