mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 12:02:42 +00:00
77f57207be
## Description: Changed from consolex to console ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: @qqkedsi
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { Execution, Game, Player, PlayerID, UnitType } from "../game/Game";
|
|
|
|
export class BoatRetreatExecution implements Execution {
|
|
private active = true;
|
|
private player: Player | undefined;
|
|
constructor(
|
|
private playerID: PlayerID,
|
|
private unitID: number,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.hasPlayer(this.playerID)) {
|
|
console.warn(`BoatRetreatExecution: Player ${this.playerID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
this.player = mg.player(this.playerID);
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (!this.player) {
|
|
console.warn(`BoatRetreatExecution: Player ${this.playerID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
const unit = this.player
|
|
.units()
|
|
.find(
|
|
(unit) =>
|
|
unit.id() === this.unitID && unit.type() === UnitType.TransportShip,
|
|
);
|
|
|
|
if (!unit) {
|
|
console.warn(`Didn't find outgoing boat with id ${this.unitID}`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
unit.orderBoatRetreat();
|
|
this.active = false;
|
|
}
|
|
|
|
owner(): Player {
|
|
if (this.player === undefined) {
|
|
throw new Error("Not initialized");
|
|
}
|
|
return this.player;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|