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; } }