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
This commit is contained in:
Abdallah Bahrawi
2025-10-02 21:59:06 +03:00
committed by GitHub
parent 2c67d2b7bf
commit 6061c97d78
+15 -13
View File
@@ -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;
}
}