From 6061c97d781555d70cf39a4e74c20de9d59a6646 Mon Sep 17 00:00:00 2001 From: Abdallah Bahrawi <140177728+abdallahbahrawi1@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:59:06 +0300 Subject: [PATCH] Fix nations break alliance too ealry bug (#2123) ## Description: Betrayal was being considered too early (inside shouldAttack), causing alliances to break before calling attackChance. ## 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: abodcraft1 --- src/core/execution/FakeHumanExecution.ts | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index fae0be710..7326375f1 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -182,7 +182,6 @@ export class FakeHumanExecution implements Execution { this.player.breakAlliance(alliance); - // Successfully broken an alliance return true; } @@ -259,22 +258,25 @@ export class FakeHumanExecution implements Execution { return false; } + const shouldAttack = this.attackChance(other); + // Consider betrayal for allies - if (this.player.isAlliedWith(other)) { - const canProceed = this.maybeConsiderBetrayal(other); - return canProceed; + if (shouldAttack && this.player.isAlliedWith(other)) { + return this.maybeConsiderBetrayal(other); } - if (this.player.isFriendly(other)) { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(200); - } - return this.random.chance(50); + return shouldAttack; + } + + private attackChance(other: Player): boolean { + if (this.player === null) throw new Error("not initialized"); + + if (this.player.isAlliedWith(other)) { + return this.shouldDiscourageAttack(other) + ? this.random.chance(200) + : this.random.chance(50); } else { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(4); - } - return true; + return this.shouldDiscourageAttack(other) ? this.random.chance(4) : true; } }