diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 8d62debb5..8f6c5ac5e 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -256,6 +256,8 @@ export class AttackExecution implements Execution { ); numTilesPerTick -= tilesPerTickUsed; this.attack.setTroops(this.attack.troops() - attackerTroopLoss); + this.attack.applyLosses(attackerTroopLoss); + if (this.target.isPlayer()) { this.target.removeTroops(defenderTroopLoss); } diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 8795e349f..1f17abb8c 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -182,6 +182,7 @@ export class NukeExecution implements Execution { .config() .nukeDeathFactor(attack.troops(), owner.numTilesOwned()); attack.setTroops(attack.troops() - deaths); + attack.applyLosses(deaths); }); owner.units(UnitType.TransportShip).forEach((attack) => { const deaths = this.mg diff --git a/src/core/game/AttackImpl.ts b/src/core/game/AttackImpl.ts index d2f91bff2..8d65ac96b 100644 --- a/src/core/game/AttackImpl.ts +++ b/src/core/game/AttackImpl.ts @@ -7,13 +7,17 @@ export class AttackImpl implements Attack { public _retreating = false; public _retreated = false; + private _remainingTroops: number; + constructor( private _id: string, private _target: Player | TerraNullius, private _attacker: Player, private _troops: number, private _sourceTile: TileRef | null, - ) {} + ) { + this._remainingTroops = _troops; // Start with full strength + } sourceTile(): TileRef | null { return this._sourceTile; @@ -31,6 +35,13 @@ export class AttackImpl implements Attack { setTroops(troops: number) { this._troops = troops; } + remainingTroops(): number { + return this._remainingTroops; + } + + applyLosses(losses: number): void { + this._remainingTroops = Math.max(0, this._remainingTroops - losses); + } isActive() { return this._isActive; diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index ebf4857bd..7dd3d7270 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -214,6 +214,8 @@ export interface Attack { attacker(): Player; troops(): number; setTroops(troops: number): void; + applyLosses(losses: number): void; + remainingTroops(): number; isActive(): boolean; delete(): void; // The tile the attack originated from, mostly used for boat attacks. diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index d3fe768bd..52cbb6545 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -645,8 +645,13 @@ export class PlayerImpl implements Player { private attackingTroops(): number { return this._outgoingAttacks .filter((a) => a.isActive()) - .reduce((sum, a) => sum + a.troops(), 0); + .reduce( + (sum, a) => + sum + (a instanceof AttackImpl ? a.remainingTroops() : a.troops()), + 0, + ); } + private boatTroops(): number { return this.units(UnitType.TransportShip) .map((u) => u.troops())