fix tied conflict conquest order

This commit is contained in:
2026-07-26 23:14:27 +00:00
parent 5a9b85e821
commit fc019a786c
7 changed files with 128 additions and 20 deletions
+44
View File
@@ -304,4 +304,48 @@ describe('war aftermath', () => {
])
);
});
it('preserves the first contributor when conflict values are tied', () => {
const attackerNation = buildNation(1);
const defenderNation = buildNation(2);
defenderNation.capitalCityId = 5;
const laterNation = buildNation(3);
const firstNation = buildNation(4);
const attackerCity = buildCity(1, 1);
const defenderCity = buildCity(2, 2);
defenderCity.conflict = { 3: 100, 4: 100 };
defenderCity.meta.conflict_order = [4, 3];
const defenderCapital = buildCity(5, 2);
const attacker = buildGeneral(1, 1, 1);
const outcome = resolveWarAftermath({
battle: {
attacker,
defenders: [],
defenderCity,
logs: [],
conquered: true,
reports: [],
},
attackerNation,
defenderNation,
attackerCity,
defenderCity,
nations: [attackerNation, defenderNation, laterNation, firstNation],
cities: [attackerCity, defenderCity, defenderCapital],
generals: [attacker],
unitSet: buildUnitSet(),
config: buildConfig(),
time: {
year: 200,
month: 1,
startYear: 180,
},
});
expect(outcome.conquest?.conquerNationId).toBe(4);
expect(defenderCity.nationId).toBe(4);
expect(defenderCity.meta.conflict_order).toEqual([]);
expect(attacker.cityId).toBe(1);
});
});
+2
View File
@@ -301,6 +301,7 @@ describe('war triggers', () => {
cityUnit.setOppose(firstAttacker);
expect(cityUnit.addConflict()).toBe(false);
expect(city.conflict).toEqual({ 1: 1.05 });
expect(city.meta.conflict_order).toEqual([1]);
expect(city.meta.conflict).toBeUndefined();
const secondNation = { ...buildNation(), id: 2 };
@@ -319,6 +320,7 @@ describe('war triggers', () => {
cityUnit.setOppose(secondAttacker);
expect(cityUnit.addConflict()).toBe(true);
expect(city.conflict).toEqual({ 1: 1.05, 2: 1 });
expect(city.meta.conflict_order).toEqual([1, 2]);
});
});