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
This commit is contained in:
Abdallah Bahrawi
2025-10-02 21:59:06 +03:00
committed by evanpelle
parent d42fd9b5fc
commit b03f9778db
+23 -9
View File
@@ -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) {