Fix: Nations reject alliance requests during spawn phase (#3312)

## Description:

This PR fixes an exploit that allows the player to request alliances to
Nations, mostly in impossible mode, during spawn phase, with high
chances for it to be accepted due to troop count parity.

Nations now reject alliance requests during the spawn phase.

## 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:

deshack_82603
This commit is contained in:
Mattia Migliorini
2026-03-01 12:20:19 +01:00
committed by GitHub
parent 8754f5291f
commit a9c89e4f15
2 changed files with 19 additions and 0 deletions
@@ -76,6 +76,11 @@ export class NationAllianceBehavior {
otherPlayer: Player,
isResponse: boolean,
): boolean {
// Reject alliance requests during the spawn phase
if (this.game.inSpawnPhase()) {
return false;
}
// Easy (dumb) nations sometimes get confused and accept/reject randomly (Just like dumb humans do)
if (this.isConfused()) {
return this.random.chance(2);
+14
View File
@@ -51,6 +51,10 @@ describe("AllianceBehavior.handleAllianceRequests", () => {
player,
new NationEmojiBehavior(random, game, player),
);
while (game.inSpawnPhase()) {
game.executeNextTick();
}
});
function setupAllianceRequest({
@@ -92,6 +96,16 @@ describe("AllianceBehavior.handleAllianceRequests", () => {
return mockRequest;
}
test("should reject alliance during spawn phase", () => {
vi.spyOn(game, "inSpawnPhase").mockReturnValue(true);
const request = setupAllianceRequest({});
allianceBehavior.handleAllianceRequests();
expect(request.accept).not.toHaveBeenCalled();
expect(request.reject).toHaveBeenCalled();
});
test("should accept alliance when all conditions are met", () => {
const request = setupAllianceRequest({});