mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-17 05:34:37 +00:00
feat: cancel attack
Canceling attack takes time and incurs a malus (loose some troops). Also prettier fixed a file HostLobbyModal.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
||||
|
||||
const cancelDelay = 2;
|
||||
|
||||
export class RetreatExecution implements Execution {
|
||||
private active = true;
|
||||
private retreatOrdered = false;
|
||||
private player: Player;
|
||||
private executionDateInSecs = new Date().getTime() / 1000 + cancelDelay;
|
||||
|
||||
constructor(
|
||||
private playerID: PlayerID,
|
||||
private attackID: string,
|
||||
) {}
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
if (!mg.hasPlayer(this.playerID)) {
|
||||
console.warn(`RetreatExecution: player ${this.player.id()} not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.player = mg.player(this.playerID);
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
const nowInSecs = new Date().getTime() / 1000;
|
||||
|
||||
if (!this.retreatOrdered) {
|
||||
this.player.orderRetreat(this.attackID);
|
||||
this.retreatOrdered = true;
|
||||
}
|
||||
|
||||
if (nowInSecs >= this.executionDateInSecs) {
|
||||
this.player.executeRetreat(this.attackID);
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
owner(): Player {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user