건국 커맨드 구현 및 테스트 추가
This commit is contained in:
@@ -133,6 +133,8 @@ describe('Blank Start Scenario', () => {
|
||||
if (req.kind === 'env') {
|
||||
if (req.key === 'world') return { currentYear: year };
|
||||
if (req.key === 'openingPartYear') return systemEnv.openingPartYear;
|
||||
if (req.key === 'relYear') return year - 189;
|
||||
if (req.key === 'year') return year;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -181,33 +183,13 @@ describe('Blank Start Scenario', () => {
|
||||
]);
|
||||
|
||||
const gen0AfterUprising = world.getGeneral(gen0.id)!;
|
||||
expect(gen0AfterUprising.meta.uprising).toBe(true);
|
||||
expect(gen0AfterUprising.nationId).toBeGreaterThan(0);
|
||||
expect(gen0AfterUprising.officerLevel).toBe(12);
|
||||
|
||||
// Simulate Uprising Daemon
|
||||
const newNationId = 1;
|
||||
const newNation: Nation = {
|
||||
id: newNationId,
|
||||
name: 'Gen0Nation',
|
||||
color: '#FF0000',
|
||||
capitalCityId: gen0AfterUprising.cityId,
|
||||
chiefGeneralId: gen0AfterUprising.id,
|
||||
gold: 10000,
|
||||
rice: 10000,
|
||||
power: 0,
|
||||
level: 0, // Wandering Nation
|
||||
typeCode: 'che_def',
|
||||
meta: {},
|
||||
};
|
||||
world.snapshot.nations.push(newNation);
|
||||
const cityIdx = world.snapshot.cities.findIndex((c) => c.id === gen0AfterUprising.cityId);
|
||||
world.snapshot.cities[cityIdx] = { ...world.snapshot.cities[cityIdx], nationId: newNationId, level: 5 } as City; // level 5 (소)
|
||||
const gen0Idx = world.snapshot.generals.findIndex((g) => g.id === gen0AfterUprising.id);
|
||||
world.snapshot.generals[gen0Idx] = {
|
||||
...world.snapshot.generals[gen0Idx],
|
||||
nationId: newNationId,
|
||||
officerLevel: 12, // Monarch
|
||||
meta: { ...gen0AfterUprising.meta, uprising: false },
|
||||
} as General;
|
||||
const newNationId = gen0AfterUprising.nationId;
|
||||
const newNation = world.getNation(newNationId)!;
|
||||
expect(newNation.chiefGeneralId).toBe(gen0.id);
|
||||
expect(newNation.level).toBe(0); // Wandering Nation
|
||||
|
||||
// --- Step 2: Gen 1 performs Appointment ---
|
||||
// Before appointment, Gen 0 should FAIL Founding because general count = 1
|
||||
@@ -280,8 +262,10 @@ describe('Blank Start Scenario', () => {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(world.getGeneral(gen0.id)?.meta.founding).toBe(true);
|
||||
expect(world.getGeneral(gen0.id)?.meta.foundingArgs).toEqual(FOUNDING_ARGS);
|
||||
const nationAfterFounding = world.getNation(newNationId)!;
|
||||
expect(nationAfterFounding.level).toBe(1);
|
||||
expect(nationAfterFounding.name).toBe(FOUNDING_ARGS.nationName);
|
||||
expect(nationAfterFounding.capitalCityId).toBe(gen0.cityId);
|
||||
});
|
||||
|
||||
it('should fail founding if city is not level 5 or 6', async () => {
|
||||
|
||||
@@ -84,8 +84,13 @@ export class InMemoryWorld {
|
||||
this.updateNation(resolution.nation);
|
||||
}
|
||||
|
||||
if (resolution.created && resolution.created.generals) {
|
||||
this.snapshot.generals.push(...resolution.created.generals);
|
||||
if (resolution.created) {
|
||||
if (resolution.created.generals) {
|
||||
this.snapshot.generals.push(...resolution.created.generals);
|
||||
}
|
||||
if (resolution.created.nations) {
|
||||
this.snapshot.nations.push(...resolution.created.nations);
|
||||
}
|
||||
}
|
||||
|
||||
if (resolution.effects) {
|
||||
@@ -177,6 +182,9 @@ export class TestGameRunner {
|
||||
this.currentDate = new Date(startYear, startMonth - 1);
|
||||
}
|
||||
|
||||
nextGeneralId = 1;
|
||||
nextNationId = 1;
|
||||
|
||||
async runTurn(commands: TestCommand[]) {
|
||||
const schedule: TurnSchedule = {
|
||||
entries: [{ startMinute: 0, tickMinutes: 60 }],
|
||||
@@ -212,6 +220,21 @@ export class TestGameRunner {
|
||||
map: this.world.snapshot.map,
|
||||
unitSet: this.world.snapshot.unitSet,
|
||||
cities: this.world.snapshot.cities,
|
||||
nations: this.world.snapshot.nations,
|
||||
createGeneralId: () => {
|
||||
if (this.nextGeneralId === 1) {
|
||||
const ids = this.world.getAllGenerals().map((g) => g.id);
|
||||
this.nextGeneralId = ids.length > 0 ? Math.max(...ids) + 1 : 1;
|
||||
}
|
||||
return this.nextGeneralId++;
|
||||
},
|
||||
createNationId: () => {
|
||||
if (this.nextNationId === 1) {
|
||||
const ids = this.world.getAllNations().map((n) => n.id);
|
||||
this.nextNationId = ids.length > 0 ? Math.max(...ids) + 1 : 1;
|
||||
}
|
||||
return this.nextNationId++;
|
||||
},
|
||||
...cmd.context,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user