From 649e4d2ed7d60b8f004a82e52974c604b65a6ba5 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 9 Oct 2025 22:21:05 -0400 Subject: [PATCH] fix(PlayerExecution): remove alarming DefensePost destruction messages on capture (#2163) ## Description: Patches issue flagged from https://github.com/openfrontio/OpenFrontIO/pull/1957#issuecomment-3386398998. Right now for every single defense post capture, attackers receive two messages: - "Your Defense Post was destroyed" and "Captured Defense Post from ..." By downgrading before captures, behavior will now be: - defender receives "Your Defense Post was destroyed" - attacker receives no message unless capturing a lv2+ defense post (downgraded to lv 1), in which case they receive "Captured Defense Post from ..." ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: `seekerreturns` --------- Co-authored-by: evanpelle --- src/core/execution/PlayerExecution.ts | 39 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 32935eabb..fed23323d 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -27,23 +27,30 @@ export class PlayerExecution implements Execution { tick(ticks: number) { this.player.decayRelations(); - this.player.units().forEach((u) => { - const tileOwner = this.mg!.owner(u.tile()); - if (u.info().territoryBound) { - if (tileOwner?.isPlayer()) { - if (tileOwner !== this.player) { - if (u.type() === UnitType.DefensePost) { - this.mg!.player(tileOwner.id()).captureUnit(u); - u.decreaseLevel(this.mg!.player(tileOwner.id())); - } else { - this.mg!.player(tileOwner.id()).captureUnit(u); - } - } - } else { - u.delete(); - } + for (const u of this.player.units()) { + if (!u.info().territoryBound) { + continue; } - }); + + const owner = this.mg!.owner(u.tile()); + if (!owner?.isPlayer()) { + u.delete(); + continue; + } + if (owner === this.player) { + continue; + } + + const captor = this.mg!.player(owner.id()); + if (u.type() === UnitType.DefensePost) { + u.decreaseLevel(captor); + if (u.isActive()) { + captor.captureUnit(u); + } + } else { + captor.captureUnit(u); + } + } if (!this.player.isAlive()) { // Player has no tiles, delete any remaining units and gold