Files
OpenFrontIO/src/core/game/AttackImpl.ts
T
ilan schemoul 9a1f916f4d feat: cancel attack
Canceling attack takes time and incurs a malus (loose some troops).
Also prettier fixed a file HostLobbyModal.
2025-03-03 22:06:35 +01:00

73 lines
1.4 KiB
TypeScript

import { Attack, Player, TerraNullius } from "./Game";
import { TileRef } from "./GameMap";
import { PlayerImpl } from "./PlayerImpl";
export class AttackImpl implements Attack {
private _isActive = true;
public _retreating = false;
public _retreated = false;
constructor(
private _id: string,
private _target: Player | TerraNullius,
private _attacker: Player,
private _troops: number,
private _sourceTile: TileRef | null,
) {}
sourceTile(): TileRef | null {
return this._sourceTile;
}
target(): Player | TerraNullius {
return this._target;
}
attacker(): Player {
return this._attacker;
}
troops(): number {
return this._troops;
}
setTroops(troops: number) {
this._troops = troops;
}
isActive() {
return this._isActive;
}
id() {
return this._id;
}
delete() {
if (this._target.isPlayer()) {
(this._target as PlayerImpl)._incomingAttacks = (
this._target as PlayerImpl
)._incomingAttacks.filter((a) => a != this);
}
(this._attacker as PlayerImpl)._outgoingAttacks = (
this._attacker as PlayerImpl
)._outgoingAttacks.filter((a) => a != this);
this._isActive = false;
}
orderRetreat() {
this._retreating = true;
}
executeRetreat() {
this._retreated = true;
}
retreating(): boolean {
return this._retreating;
}
retreated(): boolean {
return this._retreated;
}
}