fix: Ref 게임 로직과 시나리오 풀 호환을 보정
월 경계, 전투 기술 상한, 연감과 베팅·설문·경매 정산 순서를 Ref 계약에 맞춘다.\n\n시나리오 일반 풀을 ENGINE mutation과 logical tick 기반으로 직렬화하고 914·915 catalog 및 조건부 100기 pool 실행 경계를 추가한다.\n\n경매 worker는 세대별 durable event만 만들고 ENGINE이 row lock 후 상태 전이와 정산을 단일 transaction으로 소유한다.
This commit is contained in:
@@ -5,9 +5,31 @@ import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { loadScenarioDefinitionById, resolveScenarioDefaultsPath } from '../src/scenario/scenarioLoader.js';
|
||||
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
||||
import { hasRefSourceRoot, resolveRefSourceRoot } from './refSourceRoot.js';
|
||||
|
||||
type LoadedScenario = Awaited<ReturnType<typeof loadScenarioDefinitionById>>;
|
||||
|
||||
interface ReferenceScenario914 {
|
||||
title: string;
|
||||
startYear: number;
|
||||
map: Record<string, unknown>;
|
||||
history: string[];
|
||||
const: {
|
||||
allItems: Record<string, Record<string, number>>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
events: unknown[];
|
||||
}
|
||||
|
||||
interface ReferenceScenario915 {
|
||||
title: string;
|
||||
startYear: number;
|
||||
map: Record<string, unknown>;
|
||||
history: string[];
|
||||
const: Record<string, unknown>;
|
||||
events: unknown[];
|
||||
}
|
||||
|
||||
const readItemSlot = (scenario: LoadedScenario, slot: string): Record<string, number> => {
|
||||
const allItems = scenario.config.const.allItems as Record<string, Record<string, number>> | undefined;
|
||||
return allItems?.[slot] ?? {};
|
||||
@@ -16,6 +38,8 @@ const readItemSlot = (scenario: LoadedScenario, slot: string): Record<string, nu
|
||||
const readAvailableSpecialWar = (scenario: LoadedScenario): string[] =>
|
||||
(scenario.config.const.availableSpecialWar as string[] | undefined) ?? [];
|
||||
|
||||
const refSourceIt = hasRefSourceRoot() ? it : it.skip;
|
||||
|
||||
describe('tracked scenario resources', () => {
|
||||
it('loads every scenario through its composed resource graph', async () => {
|
||||
const scenarioRoot = path.dirname(resolveScenarioDefaultsPath());
|
||||
@@ -26,11 +50,88 @@ describe('tracked scenario resources', () => {
|
||||
.map((match) => Number(match[1]))
|
||||
.sort((left, right) => left - right);
|
||||
|
||||
expect(scenarioIds).toHaveLength(80);
|
||||
expect(scenarioIds).toContain(914);
|
||||
expect(scenarioIds).toContain(915);
|
||||
const scenarios = await Promise.all(scenarioIds.map((scenarioId) => loadScenarioDefinitionById(scenarioId)));
|
||||
expect(scenarios.every((scenario) => scenario.title.length > 0)).toBe(true);
|
||||
});
|
||||
|
||||
refSourceIt('preserves the Ref scenario 915 S100 pool and event order exactly', async () => {
|
||||
const referencePath = path.join(resolveRefSourceRoot(), 'hwe', 'scenario', 'scenario_915.json');
|
||||
const [scenario, referenceSource] = await Promise.all([
|
||||
loadScenarioDefinitionById(915),
|
||||
fs.readFile(referencePath, 'utf8').then((raw) => JSON.parse(raw) as ReferenceScenario915),
|
||||
]);
|
||||
|
||||
expect(scenario.title).toBe(referenceSource.title);
|
||||
expect(scenario.startYear).toBe(referenceSource.startYear);
|
||||
expect(scenario.config.map).toEqual(referenceSource.map);
|
||||
expect(scenario.history).toEqual(referenceSource.history);
|
||||
expect(scenario.config.const).toEqual(referenceSource.const);
|
||||
expect(scenario.events).toEqual(referenceSource.events);
|
||||
expect(
|
||||
scenario.events
|
||||
.filter((entry): entry is unknown[] => Array.isArray(entry) && entry[0] === 'month')
|
||||
.map((entry) => ({ priority: entry[1], condition: entry[2], actions: entry.slice(3) }))
|
||||
).toEqual([
|
||||
{ priority: 8_000, condition: true, actions: [['AdvanceCentennialAllStar']] },
|
||||
{
|
||||
priority: 1_000,
|
||||
condition: ['Date', '==', null, 12],
|
||||
actions: [['CreateManyNPC', 100, 0], ['DeleteEvent']],
|
||||
},
|
||||
{
|
||||
priority: 1_000,
|
||||
condition: ['Date', '==', 181, 1],
|
||||
actions: [['RaiseNPCNation'], ['DeleteEvent']],
|
||||
},
|
||||
{
|
||||
priority: 999,
|
||||
condition: ['Date', '==', 181, 1],
|
||||
actions: [['OpenNationBetting', 4, 5_000], ['OpenNationBetting', 1, 2_000], ['DeleteEvent']],
|
||||
},
|
||||
{
|
||||
priority: 999,
|
||||
condition: ['and', ['Date', '>=', 183, 1], ['RemainNation', '<=', 8]],
|
||||
actions: [['OpenNationBetting', 1, 1_000], ['DeleteEvent']],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
refSourceIt('preserves the Ref scenario 914 item pool, monthly action order, and deletion markers', async () => {
|
||||
const referencePath = path.join(resolveRefSourceRoot(), 'hwe', 'scenario', 'scenario_914.json');
|
||||
const [scenario, referenceSource] = await Promise.all([
|
||||
loadScenarioDefinitionById(914),
|
||||
fs.readFile(referencePath, 'utf8').then((raw) => JSON.parse(raw) as ReferenceScenario914),
|
||||
]);
|
||||
|
||||
expect(scenario.title).toBe(referenceSource.title);
|
||||
expect(scenario.startYear).toBe(referenceSource.startYear);
|
||||
expect(scenario.config.map).toEqual(referenceSource.map);
|
||||
expect(scenario.history).toEqual(referenceSource.history);
|
||||
expect(scenario.config.const).toEqual(referenceSource.const);
|
||||
expect(scenario.config.const.allItems).toEqual(referenceSource.const.allItems);
|
||||
for (const [slot, items] of Object.entries(referenceSource.const.allItems)) {
|
||||
expect(Object.keys(readItemSlot(scenario, slot))).toEqual(Object.keys(items));
|
||||
}
|
||||
expect(scenario.events).toEqual(referenceSource.events);
|
||||
|
||||
const monthlyActionNames = scenario.events
|
||||
.filter((event): event is unknown[] => Array.isArray(event) && event[0] === 'month')
|
||||
.map((event) =>
|
||||
event
|
||||
.slice(3)
|
||||
.map((action) => (Array.isArray(action) && typeof action[0] === 'string' ? action[0] : null))
|
||||
);
|
||||
expect(monthlyActionNames).toEqual([
|
||||
['CreateManyNPC', 'DeleteEvent'],
|
||||
['RaiseNPCNation', 'DeleteEvent'],
|
||||
['OpenNationBetting', 'OpenNationBetting', 'DeleteEvent'],
|
||||
['ChangeCity'],
|
||||
['ChangeCity'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('opens nation betting in the first playable year of every scenario 29 variant', async () => {
|
||||
const scenarioIds = [2900, 2901, 2903, 2904];
|
||||
const scenarios = await Promise.all(scenarioIds.map((scenarioId) => loadScenarioDefinitionById(scenarioId)));
|
||||
|
||||
Reference in New Issue
Block a user