From b03f9778dbcada54e0f47232af4cd511a8629980 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) Betrayal was being considered too early (inside shouldAttack), causing alliances to break before calling attackChance. - [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 regression is found: abodcraft1 --- src/core/execution/utils/BotBehavior.ts | 32 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/core/execution/utils/BotBehavior.ts b/src/core/execution/utils/BotBehavior.ts index 3cff57227..2fd64cc71 100644 --- a/src/core/execution/utils/BotBehavior.ts +++ b/src/core/execution/utils/BotBehavior.ts @@ -83,17 +83,31 @@ export class BotBehavior { if (this.player.isOnSameTeam(other)) { return false; } - if (this.player.isFriendly(other)) { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(200); - } - return this.random.chance(50); - } else { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(4); - } + const shouldAttack = this.attackChance(other); + if (shouldAttack && this.player.isAlliedWith(other)) { + this.betray(other); return true; } + return shouldAttack; + } + + private betray(target: Player): void { + if (this.player === null) throw new Error("not initialized"); + const alliance = this.player.allianceWith(target); + if (!alliance) return; + this.player.breakAlliance(alliance); + } + + 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 { + return this.shouldDiscourageAttack(other) ? this.random.chance(4) : true; + } } private shouldDiscourageAttack(other: Player) {