From 4375797d92964993c03f02a870cbdbc8d4201769 Mon Sep 17 00:00:00 2001 From: Ilan Schemoul Date: Mon, 10 Mar 2025 21:30:07 +0100 Subject: [PATCH] feat: show a message when attack is canceled (with number of deaths) (#193) --- src/core/execution/AttackExecution.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index bec66a445..8e8a9cf20 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -12,7 +12,7 @@ import { } from "../game/Game"; import { PseudoRandom } from "../PseudoRandom"; import { MessageType } from "../game/Game"; -import { renderNumber } from "../../client/Utils"; +import { renderNumber, renderTroops } from "../../client/Utils"; import { TileRef } from "../game/GameMap"; const malusForRetreat = 25; @@ -165,7 +165,15 @@ export class AttackExecution implements Execution { } private retreat(malusPercent = 0) { - this._owner.addTroops(this.attack.troops() * (1 - malusPercent / 100)); + const deaths = this.attack.troops() * (malusPercent / 100); + if (deaths) { + this.mg.displayMessage( + `Attack cancelled, ${renderTroops(deaths)} soldiers killed during retreat.`, + MessageType.SUCCESS, + this._owner.id(), + ); + } + this._owner.addTroops(this.attack.troops() - deaths); this.attack.delete(); this.active = false; }