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 <evanpelle@gmail.com>
This commit is contained in:
Jeff
2025-10-09 22:21:05 -04:00
committed by GitHub
parent cc49dc986e
commit 649e4d2ed7
+23 -16
View File
@@ -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