mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 12:26:32 +00:00
9c7e0ce32f
## Description: Answering issue: #1017 [Cleanup] Pass Player into the execution constructor instead of PlayerID I have tested the changes running and playing a full game. I do not know other way to test the changes, please inform me ❤️ ## 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: Lele --------- Co-authored-by: lva <lva@rovsing.dk>
44 lines
880 B
TypeScript
44 lines
880 B
TypeScript
import { Execution, Game, Player } from "../game/Game";
|
|
|
|
const cancelDelay = 20;
|
|
|
|
export class RetreatExecution implements Execution {
|
|
private active = true;
|
|
private retreatOrdered = false;
|
|
private startTick: number;
|
|
private mg: Game;
|
|
constructor(
|
|
private player: Player,
|
|
private attackID: string,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
this.startTick = mg.ticks();
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (!this.retreatOrdered) {
|
|
this.player.orderRetreat(this.attackID);
|
|
this.retreatOrdered = true;
|
|
}
|
|
|
|
if (this.mg.ticks() >= this.startTick + cancelDelay) {
|
|
this.player.executeRetreat(this.attackID);
|
|
this.active = false;
|
|
}
|
|
}
|
|
|
|
owner(): Player {
|
|
return this.player;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|