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:
@@ -0,0 +1,129 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
buildScenarioGeneralPoolClaimMeta,
|
||||
getScenarioGeneralPoolCandidateWeight,
|
||||
parseScenarioGeneralPoolCandidate,
|
||||
pickUniqueScenarioGeneralPoolCandidates,
|
||||
readScenarioGeneralPoolClaim,
|
||||
resolveLegacyNpcStatTypeFromFixedStats,
|
||||
type ScenarioGeneralPoolCandidate,
|
||||
} from '../../../src/actions/turn/generalPool.js';
|
||||
|
||||
const candidate = (poolEntryId: number, name: string, weight: number): ScenarioGeneralPoolCandidate => ({
|
||||
poolEntryId,
|
||||
uniqueName: name,
|
||||
name,
|
||||
dex: [weight, 0, 0, 0, 0],
|
||||
sourceInfo: {},
|
||||
});
|
||||
|
||||
describe('scenario general pool', () => {
|
||||
it('keeps the Ref weighted array and consumes duplicate draws before selecting a new row', () => {
|
||||
const draws = [0, 0, 0.75];
|
||||
let drawCount = 0;
|
||||
const rng = {
|
||||
nextFloat1: () => {
|
||||
const value = draws[drawCount];
|
||||
drawCount += 1;
|
||||
return value ?? 0;
|
||||
},
|
||||
nextBool: () => false,
|
||||
nextInt: () => 0,
|
||||
};
|
||||
|
||||
expect(pickUniqueScenarioGeneralPoolCandidates(rng, [candidate(1, '갑', 1), candidate(2, '을', 1)], 2)).toEqual(
|
||||
[expect.objectContaining({ poolEntryId: 1 }), expect.objectContaining({ poolEntryId: 2 })]
|
||||
);
|
||||
expect(drawCount).toBe(3);
|
||||
});
|
||||
|
||||
it('fails with the Ref pool-shortage message instead of using a random-name fallback', () => {
|
||||
const rng = { nextFloat1: () => 0, nextBool: () => false, nextInt: () => 0 };
|
||||
expect(() => pickUniqueScenarioGeneralPoolCandidates(rng, [candidate(1, '갑', 1)], 2)).toThrow('pool 부족');
|
||||
});
|
||||
|
||||
it('keeps zero-dex centennial NPC candidates selectable with the Ref minimum weight', () => {
|
||||
const centennial = {
|
||||
...candidate(3, '성장후보', 0),
|
||||
sourceInfo: { event100Growth: true },
|
||||
};
|
||||
let draws = 0;
|
||||
const rng = {
|
||||
nextFloat1: () => {
|
||||
draws += 1;
|
||||
return 0;
|
||||
},
|
||||
nextBool: () => false,
|
||||
nextInt: () => 0,
|
||||
};
|
||||
|
||||
expect(getScenarioGeneralPoolCandidateWeight(centennial)).toBe(100_000);
|
||||
expect(pickUniqueScenarioGeneralPoolCandidates(rng, [centennial], 1)).toEqual([centennial]);
|
||||
expect(draws).toBe(1);
|
||||
});
|
||||
|
||||
it('parses the U30 builder fields and round-trips the persisted claim marker', () => {
|
||||
const parsed = parseScenarioGeneralPoolCandidate({
|
||||
id: 17,
|
||||
uniqueName: '풀장수',
|
||||
info: {
|
||||
generalName: '풀장수',
|
||||
leadership: 69,
|
||||
strength: 12,
|
||||
intel: 80,
|
||||
specialDomestic: 'che_event_징병',
|
||||
dex: [1, 2, 3, 4, 5],
|
||||
imgsvr: 1,
|
||||
picture: 'pool.gif',
|
||||
},
|
||||
});
|
||||
const claimedAt = new Date('0200-05-01T00:00:00.000Z');
|
||||
const meta = { killturn: 1, ...buildScenarioGeneralPoolClaimMeta(parsed, claimedAt) };
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
poolEntryId: 17,
|
||||
uniqueName: '풀장수',
|
||||
name: '풀장수',
|
||||
stats: { leadership: 69, strength: 12, intelligence: 80 },
|
||||
dex: [1, 2, 3, 4, 5],
|
||||
specialDomestic: 'che_event_징병',
|
||||
imageServer: 1,
|
||||
picture: 'pool.gif',
|
||||
});
|
||||
expect(readScenarioGeneralPoolClaim(meta)).toEqual({
|
||||
poolEntryId: 17,
|
||||
uniqueName: '풀장수',
|
||||
claimedAt: claimedAt.toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
it('only consumes a stat-type draw for an ambiguous fixed-stat candidate', () => {
|
||||
let draws = 0;
|
||||
const rng = {
|
||||
nextFloat1: () => {
|
||||
draws += 1;
|
||||
return 0;
|
||||
},
|
||||
nextBool: () => false,
|
||||
nextInt: () => 0,
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveLegacyNpcStatTypeFromFixedStats(rng, {
|
||||
leadership: 70,
|
||||
strength: 80,
|
||||
intelligence: 10,
|
||||
})
|
||||
).toBe('무');
|
||||
expect(draws).toBe(0);
|
||||
expect(
|
||||
resolveLegacyNpcStatTypeFromFixedStats(rng, {
|
||||
leadership: 70,
|
||||
strength: 50,
|
||||
intelligence: 50,
|
||||
})
|
||||
).toBe('무');
|
||||
expect(draws).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { ConstantRNG, RandUtil } from '@sammo-ts/common';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { General, Nation } from '../../../src/domain/entities.js';
|
||||
import { parseScenarioGeneralPoolCandidate } from '../../../src/actions/turn/generalPool.js';
|
||||
import {
|
||||
ActionResolver,
|
||||
type VolunteerRecruitEnvironment,
|
||||
@@ -80,10 +81,19 @@ describe('nation volunteer recruitment lifespan', () => {
|
||||
currentYear: 190,
|
||||
currentMonth: 1,
|
||||
startYear: 180,
|
||||
centennialRules: {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: null,
|
||||
dexLimit: 1_000_000,
|
||||
},
|
||||
centennialNpcDexTargetRatio: 0.4,
|
||||
averageNationGeneralCount: 0,
|
||||
nationAverageStats: { leadership: 50, strength: 50, intelligence: 50 },
|
||||
nationAverageExperience: 1_000,
|
||||
nationAverageDedication: 1_000,
|
||||
nationAverageExperience: 0,
|
||||
nationAverageDedication: 0,
|
||||
nationAverageDex: [100, 100, 100, 100, 100],
|
||||
friendlyGenerals: [general],
|
||||
createGeneralId: () => 2,
|
||||
@@ -104,10 +114,161 @@ describe('nation volunteer recruitment lifespan', () => {
|
||||
name: 'ⓖ장수',
|
||||
bornYear: 170,
|
||||
deadYear: 200,
|
||||
experience: 2_000,
|
||||
dedication: 2_000,
|
||||
meta: {
|
||||
birthYear: 170,
|
||||
deathYear: 200,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('uses a U30 candidate batch while keeping the Ref volunteer overrides', () => {
|
||||
const resolver = new ActionResolver([], environment);
|
||||
const turnTimeBase = new Date('0190-01-01T00:00:00.000Z');
|
||||
const poolCandidate = parseScenarioGeneralPoolCandidate({
|
||||
id: 17,
|
||||
uniqueName: '의병후보',
|
||||
info: {
|
||||
generalName: '의병후보',
|
||||
leadership: 70,
|
||||
strength: 80,
|
||||
intel: 10,
|
||||
specialDomestic: 'che_event_징병',
|
||||
dex: [11, 22, 33, 44, 55],
|
||||
imgsvr: 1,
|
||||
picture: 'volunteer.gif',
|
||||
},
|
||||
});
|
||||
const context = {
|
||||
general: structuredClone(general),
|
||||
nation: structuredClone(nation),
|
||||
rng: new RandUtil(new ConstantRNG(0)),
|
||||
addLog: () => undefined,
|
||||
currentYear: 190,
|
||||
currentMonth: 1,
|
||||
startYear: 180,
|
||||
centennialRules: {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: null,
|
||||
dexLimit: 1_000_000,
|
||||
},
|
||||
centennialNpcDexTargetRatio: 0.4,
|
||||
averageNationGeneralCount: 0,
|
||||
nationAverageStats: { leadership: 50, strength: 50, intelligence: 50 },
|
||||
nationAverageExperience: 1_000,
|
||||
nationAverageDedication: 1_000,
|
||||
nationAverageDex: [100, 100, 100, 100, 100],
|
||||
friendlyGenerals: [general],
|
||||
generalPool: [poolCandidate],
|
||||
existingGeneralNames: ['군주'],
|
||||
createGeneralId: () => 2,
|
||||
turnTermSeconds: 60,
|
||||
turnTimeBase,
|
||||
ticksPerSecond: 1,
|
||||
} as VolunteerRecruitResolveContext;
|
||||
|
||||
const outcome = resolver.resolve(context, {});
|
||||
const createdEffect = outcome.effects.find((effect) => effect.type === 'general:add');
|
||||
expect(createdEffect?.type).toBe('general:add');
|
||||
if (!createdEffect || createdEffect.type !== 'general:add') {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(createdEffect.general).toMatchObject({
|
||||
name: 'ⓖ의병후보',
|
||||
stats: { leadership: 70, strength: 80, intelligence: 10 },
|
||||
picture: 'volunteer.gif',
|
||||
imageServer: 1,
|
||||
role: { specialDomestic: null, specialWar: null },
|
||||
meta: {
|
||||
dex1: 11,
|
||||
dex2: 22,
|
||||
dex3: 33,
|
||||
dex4: 44,
|
||||
dex5: 55,
|
||||
scenarioGeneralPoolClaim: {
|
||||
poolEntryId: 17,
|
||||
uniqueName: '의병후보',
|
||||
claimedAt: turnTimeBase.toISOString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('generates ordinary volunteer stats and dex before applying the S100 .9/.4 target', () => {
|
||||
const resolver = new ActionResolver([], environment);
|
||||
const turnTimeBase = new Date('0195-01-01T00:00:00.000Z');
|
||||
const poolCandidate = parseScenarioGeneralPoolCandidate({
|
||||
id: 101,
|
||||
uniqueName: 'A1000101',
|
||||
info: {
|
||||
uniqueName: 'A1000101',
|
||||
generalName: '100기의병',
|
||||
leadership: 100,
|
||||
strength: 80,
|
||||
intel: 10,
|
||||
specialDomestic: 'che_event_징병',
|
||||
dex: [900_000, 800_000, 700_000, 600_000, 500_000],
|
||||
imgsvr: 1,
|
||||
picture: 'centennial-volunteer.gif',
|
||||
event100Growth: true,
|
||||
},
|
||||
});
|
||||
const context = {
|
||||
general: structuredClone(general),
|
||||
nation: structuredClone(nation),
|
||||
rng: new RandUtil(new ConstantRNG(0)),
|
||||
addLog: () => undefined,
|
||||
currentYear: 195,
|
||||
currentMonth: 1,
|
||||
startYear: 180,
|
||||
centennialRules: {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: null,
|
||||
dexLimit: 1_000_000,
|
||||
},
|
||||
centennialNpcDexTargetRatio: 0.4,
|
||||
averageNationGeneralCount: 0,
|
||||
nationAverageStats: { leadership: 50, strength: 50, intelligence: 50 },
|
||||
nationAverageExperience: 1_000,
|
||||
nationAverageDedication: 1_000,
|
||||
nationAverageDex: [100, 100, 100, 100, 100],
|
||||
friendlyGenerals: [general],
|
||||
generalPool: [poolCandidate],
|
||||
existingGeneralNames: ['군주'],
|
||||
createGeneralId: () => 2,
|
||||
turnTermSeconds: 60,
|
||||
turnTimeBase,
|
||||
ticksPerSecond: 1,
|
||||
} as VolunteerRecruitResolveContext;
|
||||
|
||||
const outcome = resolver.resolve(context, {});
|
||||
const createdEffect = outcome.effects.find((effect) => effect.type === 'general:add');
|
||||
expect(createdEffect?.type).toBe('general:add');
|
||||
if (!createdEffect || createdEffect.type !== 'general:add') {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(createdEffect.general).toMatchObject({
|
||||
name: 'ⓖ100기의병',
|
||||
stats: { leadership: 91, strength: 73, intelligence: 10 },
|
||||
role: { specialDomestic: 'che_event_징병' },
|
||||
meta: {
|
||||
dex1: 360_000,
|
||||
dex2: 320_000,
|
||||
dex3: 280_000,
|
||||
dex4: 240_000,
|
||||
dex5: 200_000,
|
||||
scenarioGeneralPoolClaim: { poolEntryId: 101, uniqueName: 'A1000101' },
|
||||
event100_allstar: { targetId: 'A1000101', milestone: 4, dexTargetRatio: 0.4 },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
import { ConstantRNG, RandUtil } from '@sammo-ts/common';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { ActionResolver, type TalentScoutResolveContext } from '../../../src/actions/turn/general/che_인재탐색.js';
|
||||
import { parseScenarioGeneralPoolCandidate } from '../../../src/actions/turn/generalPool.js';
|
||||
import type { City, General } from '../../../src/domain/entities.js';
|
||||
|
||||
const general: General = {
|
||||
id: 1,
|
||||
name: '탐색자',
|
||||
nationId: 1,
|
||||
cityId: 3,
|
||||
troopId: 0,
|
||||
stats: { leadership: 70, strength: 70, intelligence: 70 },
|
||||
experience: 1_000,
|
||||
dedication: 1_000,
|
||||
officerLevel: 1,
|
||||
role: {
|
||||
personality: null,
|
||||
specialDomestic: null,
|
||||
specialWar: null,
|
||||
items: { horse: null, weapon: null, book: null, item: null },
|
||||
},
|
||||
injury: 0,
|
||||
gold: 1_000,
|
||||
rice: 1_000,
|
||||
crew: 0,
|
||||
crewTypeId: 0,
|
||||
train: 0,
|
||||
atmos: 0,
|
||||
age: 30,
|
||||
npcState: 0,
|
||||
triggerState: { flags: {}, counters: {}, modifiers: {}, meta: {} },
|
||||
meta: { killturn: 24 },
|
||||
};
|
||||
|
||||
const city: City = {
|
||||
id: 3,
|
||||
name: '탐색도시',
|
||||
nationId: 1,
|
||||
level: 4,
|
||||
state: 0,
|
||||
population: 10_000,
|
||||
populationMax: 20_000,
|
||||
agriculture: 1_000,
|
||||
agricultureMax: 2_000,
|
||||
commerce: 1_000,
|
||||
commerceMax: 2_000,
|
||||
security: 1_000,
|
||||
securityMax: 2_000,
|
||||
supplyState: 1,
|
||||
frontState: 0,
|
||||
defence: 1_000,
|
||||
defenceMax: 2_000,
|
||||
wall: 1_000,
|
||||
wallMax: 2_000,
|
||||
meta: {},
|
||||
};
|
||||
|
||||
describe('talent scout scenario general pool', () => {
|
||||
it('keeps the U30 fixed stats and dex while applying the Ref scout overrides', () => {
|
||||
const resolver = new ActionResolver([], {
|
||||
develCost: 100,
|
||||
maxGeneral: 100,
|
||||
defaultNpcGold: 1_000,
|
||||
defaultNpcRice: 1_000,
|
||||
defaultCrewTypeId: 0,
|
||||
defaultSpecialDomestic: null,
|
||||
defaultSpecialWar: null,
|
||||
availablePersonalities: ['che_안전'],
|
||||
});
|
||||
const turnTimeBase = new Date('0190-01-01T00:00:00.000Z');
|
||||
const poolCandidate = parseScenarioGeneralPoolCandidate({
|
||||
id: 23,
|
||||
uniqueName: '탐색후보',
|
||||
info: {
|
||||
generalName: '탐색후보',
|
||||
leadership: 70,
|
||||
strength: 80,
|
||||
intel: 10,
|
||||
specialDomestic: 'che_event_징병',
|
||||
dex: [12, 24, 36, 48, 60],
|
||||
imgsvr: 1,
|
||||
picture: 'scout.gif',
|
||||
},
|
||||
});
|
||||
const context = {
|
||||
general: structuredClone(general),
|
||||
rng: new RandUtil(new ConstantRNG(0)),
|
||||
addLog: () => undefined,
|
||||
currentYear: 190,
|
||||
currentMonth: 1,
|
||||
startYear: 180,
|
||||
retirementYear: 80,
|
||||
centennialRules: {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: null,
|
||||
dexLimit: 1_000_000,
|
||||
},
|
||||
centennialNpcDexTargetRatio: 0.4,
|
||||
worldSummary: {
|
||||
totalGeneralCount: 0,
|
||||
totalNpcCount: 0,
|
||||
averageStats: { leadership: 50, strength: 50, intelligence: 50 },
|
||||
averageDex: [100, 100, 100, 100, 100],
|
||||
},
|
||||
generalPool: [poolCandidate],
|
||||
cityPool: [city],
|
||||
existingGeneralNames: ['탐색자'],
|
||||
createGeneralId: () => 2,
|
||||
turnTermMinutes: 10,
|
||||
turnTimeBase,
|
||||
ticksPerSecond: 1,
|
||||
} as TalentScoutResolveContext;
|
||||
|
||||
const outcome = resolver.resolve(context, {});
|
||||
const createdEffect = outcome.effects.find((effect) => effect.type === 'general:add');
|
||||
expect(createdEffect?.type).toBe('general:add');
|
||||
if (!createdEffect || createdEffect.type !== 'general:add') {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(createdEffect.general).toMatchObject({
|
||||
name: 'ⓜ탐색후보',
|
||||
stats: { leadership: 70, strength: 80, intelligence: 10 },
|
||||
picture: 'scout.gif',
|
||||
imageServer: 1,
|
||||
role: { specialDomestic: null, specialWar: null },
|
||||
meta: {
|
||||
dex1: 12,
|
||||
dex2: 24,
|
||||
dex3: 36,
|
||||
dex4: 48,
|
||||
dex5: 60,
|
||||
scenarioGeneralPoolClaim: {
|
||||
poolEntryId: 23,
|
||||
uniqueName: '탐색후보',
|
||||
claimedAt: turnTimeBase.toISOString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('generates ordinary stats and dex before applying the S100 .9/.4 target', () => {
|
||||
const resolver = new ActionResolver([], {
|
||||
develCost: 100,
|
||||
maxGeneral: 100,
|
||||
defaultNpcGold: 1_000,
|
||||
defaultNpcRice: 1_000,
|
||||
defaultCrewTypeId: 0,
|
||||
defaultSpecialDomestic: null,
|
||||
defaultSpecialWar: null,
|
||||
availablePersonalities: ['che_안전'],
|
||||
});
|
||||
const turnTimeBase = new Date('0195-01-01T00:00:00.000Z');
|
||||
const poolCandidate = parseScenarioGeneralPoolCandidate({
|
||||
id: 100,
|
||||
uniqueName: 'A1000100',
|
||||
info: {
|
||||
uniqueName: 'A1000100',
|
||||
generalName: '100기탐색',
|
||||
leadership: 100,
|
||||
strength: 80,
|
||||
intel: 10,
|
||||
specialDomestic: 'che_event_징병',
|
||||
dex: [900_000, 800_000, 700_000, 600_000, 500_000],
|
||||
imgsvr: 1,
|
||||
picture: 'centennial-scout.gif',
|
||||
event100Growth: true,
|
||||
},
|
||||
});
|
||||
const context = {
|
||||
general: structuredClone(general),
|
||||
rng: new RandUtil(new ConstantRNG(0)),
|
||||
addLog: () => undefined,
|
||||
currentYear: 195,
|
||||
currentMonth: 1,
|
||||
startYear: 180,
|
||||
retirementYear: 80,
|
||||
centennialRules: {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: null,
|
||||
dexLimit: 1_000_000,
|
||||
},
|
||||
centennialNpcDexTargetRatio: 0.4,
|
||||
worldSummary: {
|
||||
totalGeneralCount: 0,
|
||||
totalNpcCount: 0,
|
||||
averageStats: { leadership: 50, strength: 50, intelligence: 50 },
|
||||
averageDex: [100, 100, 100, 100, 100],
|
||||
},
|
||||
generalPool: [poolCandidate],
|
||||
cityPool: [city],
|
||||
existingGeneralNames: ['탐색자'],
|
||||
createGeneralId: () => 2,
|
||||
turnTermMinutes: 10,
|
||||
turnTimeBase,
|
||||
ticksPerSecond: 1,
|
||||
} as TalentScoutResolveContext;
|
||||
|
||||
const outcome = resolver.resolve(context, {});
|
||||
const createdEffect = outcome.effects.find((effect) => effect.type === 'general:add');
|
||||
expect(createdEffect?.type).toBe('general:add');
|
||||
if (!createdEffect || createdEffect.type !== 'general:add') {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(createdEffect.general).toMatchObject({
|
||||
name: 'ⓜ100기탐색',
|
||||
stats: { leadership: 91, strength: 73, intelligence: 10 },
|
||||
role: { specialDomestic: 'che_event_징병' },
|
||||
meta: {
|
||||
dex1: 360_000,
|
||||
dex2: 320_000,
|
||||
dex3: 280_000,
|
||||
dex4: 240_000,
|
||||
dex5: 200_000,
|
||||
scenarioGeneralPoolClaim: { poolEntryId: 100, uniqueName: 'A1000100' },
|
||||
event100_allstar: { targetId: 'A1000100', milestone: 4, dexTargetRatio: 0.4 },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,229 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { General } from '../src/domain/entities.js';
|
||||
import {
|
||||
CENTENNIAL_ALL_STAR_AUX_KEY,
|
||||
applyCentennialAllStarTarget,
|
||||
calculateCentennialGeneratedNpcInitialStats,
|
||||
calculateCentennialLegacyUserGrant,
|
||||
calculateCentennialProgress,
|
||||
calculateCentennialUserInitialStats,
|
||||
initialCentennialAllStarAux,
|
||||
prepareCentennialLegacyUserReselection,
|
||||
readCentennialAllStarPoolTarget,
|
||||
readCentennialAllStarAux,
|
||||
reconcileCentennialDexConversion,
|
||||
type CentennialAllStarRules,
|
||||
type CentennialAllStarTarget,
|
||||
} from '../src/scenario/centennialAllStar.js';
|
||||
|
||||
const rules: CentennialAllStarRules = {
|
||||
defaultStatMin: 15,
|
||||
defaultStatMax: 80,
|
||||
defaultStatTotal: 165,
|
||||
maxStatLevel: 255,
|
||||
defaultSpecialDomestic: 'None',
|
||||
dexLimit: 1_000_000,
|
||||
};
|
||||
|
||||
const target = (overrides: Partial<CentennialAllStarTarget> = {}): CentennialAllStarTarget => ({
|
||||
uniqueName: 'A1000001',
|
||||
generalName: '1·조민',
|
||||
leadership: 100,
|
||||
strength: 80,
|
||||
intel: 10,
|
||||
dex: [900_000, 800_000, 700_000, 600_000, 500_000],
|
||||
specialDomestic: 'che_event_무쌍',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const general = (overrides: Partial<General> = {}): General => ({
|
||||
id: 1,
|
||||
name: '장수',
|
||||
nationId: 0,
|
||||
cityId: 1,
|
||||
troopId: 0,
|
||||
stats: { leadership: 15, strength: 15, intelligence: 10 },
|
||||
experience: 0,
|
||||
dedication: 0,
|
||||
officerLevel: 0,
|
||||
role: {
|
||||
personality: 'che_안전',
|
||||
specialDomestic: 'None',
|
||||
specialWar: 'None',
|
||||
items: { horse: null, weapon: null, book: null, item: null },
|
||||
},
|
||||
injury: 0,
|
||||
gold: 1_000,
|
||||
rice: 1_000,
|
||||
crew: 0,
|
||||
crewTypeId: 1100,
|
||||
train: 0,
|
||||
atmos: 0,
|
||||
age: 20,
|
||||
npcState: 0,
|
||||
triggerState: { flags: {}, counters: {}, modifiers: {}, meta: {} },
|
||||
meta: { killturn: 5, dex1: 0, dex2: 0, dex3: 0, dex4: 0, dex5: 0 },
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const metaWithAux = (aux: ReturnType<typeof initialCentennialAllStarAux>, killturn = 5): General['meta'] => {
|
||||
const meta: General['meta'] = { killturn, dex1: 0, dex2: 0, dex3: 0, dex4: 0, dex5: 0 };
|
||||
const mutable: Record<string, unknown> = meta;
|
||||
mutable[CENTENNIAL_ALL_STAR_AUX_KEY] = aux;
|
||||
return meta;
|
||||
};
|
||||
|
||||
describe('100기 올스타 성장 계약', () => {
|
||||
it('uses the Ref 15-year linear milestones and shaped user allocation', () => {
|
||||
expect(calculateCentennialProgress({ startYear: 180, year: 180, month: 1 })).toBe(0);
|
||||
expect(calculateCentennialProgress({ startYear: 180, year: 183, month: 1 })).toBeCloseTo(0.2);
|
||||
expect(calculateCentennialProgress({ startYear: 180, year: 186, month: 1 })).toBeCloseTo(0.4);
|
||||
expect(calculateCentennialProgress({ startYear: 180, year: 195, month: 1 })).toBe(1);
|
||||
expect(calculateCentennialProgress({ startYear: 180, year: 220, month: 1 }, 0.9)).toBe(0.9);
|
||||
expect(calculateCentennialUserInitialStats(target({ leadership: 80, strength: 70, intel: 50 }), rules)).toEqual(
|
||||
{ leadership: 65, strength: 58, intel: 42 }
|
||||
);
|
||||
});
|
||||
|
||||
it('recognizes only the S100 source marker as a Centennial pool target', () => {
|
||||
expect(
|
||||
readCentennialAllStarPoolTarget({
|
||||
uniqueName: target().uniqueName,
|
||||
name: target().generalName!,
|
||||
sourceInfo: { ...target(), event100Growth: true },
|
||||
})
|
||||
).toMatchObject(target());
|
||||
expect(
|
||||
readCentennialAllStarPoolTarget({
|
||||
uniqueName: 'legacy',
|
||||
name: 'legacy',
|
||||
sourceInfo: { ...target(), event100Growth: false },
|
||||
})
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('marks the legacy creation range as replaceable before first reselection', () => {
|
||||
expect(calculateCentennialLegacyUserGrant(90, 10, rules)).toBe(75);
|
||||
const legacyMeta = metaWithAux({
|
||||
...initialCentennialAllStarAux(target(), rules),
|
||||
granted: {
|
||||
...initialCentennialAllStarAux(target(), rules).granted,
|
||||
leadership: 10,
|
||||
},
|
||||
userInitialStats: null,
|
||||
});
|
||||
const prepared = prepareCentennialLegacyUserReselection(
|
||||
general({
|
||||
stats: { leadership: 90, strength: 50, intelligence: 10 },
|
||||
meta: legacyMeta,
|
||||
}),
|
||||
rules
|
||||
);
|
||||
const aux = readCentennialAllStarAux(prepared)!;
|
||||
|
||||
expect(aux.granted.leadership).toBe(75);
|
||||
expect(aux.granted.strength).toBe(35);
|
||||
expect(aux.granted.intel).toBe(0);
|
||||
expect(aux.userInitialStats).toEqual({ leadership: 80, strength: 50, intel: 10 });
|
||||
});
|
||||
|
||||
it('keeps generated NPC stat RNG output while mapping its strong axes to the target', () => {
|
||||
expect(
|
||||
calculateCentennialGeneratedNpcInitialStats(target(), {
|
||||
leadership: 72,
|
||||
strength: 66,
|
||||
intelligence: 12,
|
||||
})
|
||||
).toEqual({ leadership: 72, strength: 66, intelligence: 12 });
|
||||
|
||||
const npc = general({
|
||||
npcState: 3,
|
||||
stats: { leadership: 72, strength: 66, intelligence: 12 },
|
||||
meta: metaWithAux(initialCentennialAllStarAux(target(), rules), 120),
|
||||
});
|
||||
const result = applyCentennialAllStarTarget(
|
||||
npc,
|
||||
target(),
|
||||
{ startYear: 180, year: 195, month: 1 },
|
||||
rules,
|
||||
0.9,
|
||||
0.4
|
||||
);
|
||||
expect(result.stats).toEqual({ leadership: 91, strength: 73, intelligence: 12 });
|
||||
expect([result.meta.dex1, result.meta.dex2, result.meta.dex3, result.meta.dex4, result.meta.dex5]).toEqual([
|
||||
360_000, 320_000, 280_000, 240_000, 200_000,
|
||||
]);
|
||||
expect(result.milestone).toBe(4);
|
||||
});
|
||||
|
||||
it('unlocks the historical trait at 40% and preserves organic growth on reselection', () => {
|
||||
const firstTarget = target();
|
||||
const initial = calculateCentennialUserInitialStats(firstTarget, rules);
|
||||
const first = general({
|
||||
stats: {
|
||||
leadership: initial.leadership,
|
||||
strength: initial.strength,
|
||||
intelligence: initial.intel,
|
||||
},
|
||||
meta: metaWithAux(initialCentennialAllStarAux(firstTarget, rules, initial)),
|
||||
});
|
||||
const grown = applyCentennialAllStarTarget(first, firstTarget, { startYear: 180, year: 186, month: 1 }, rules);
|
||||
expect(grown.role.specialDomestic).toBe('che_event_무쌍');
|
||||
expect(grown.milestone).toBe(2);
|
||||
|
||||
const oldGranted = readCentennialAllStarAux(grown.meta)!.granted.leadership;
|
||||
const organicLeadership = grown.stats.leadership + 100;
|
||||
const changed = applyCentennialAllStarTarget(
|
||||
{
|
||||
...first,
|
||||
stats: { ...grown.stats, leadership: organicLeadership },
|
||||
role: grown.role,
|
||||
meta: grown.meta,
|
||||
},
|
||||
target({
|
||||
uniqueName: 'A1000002',
|
||||
leadership: 70,
|
||||
strength: 60,
|
||||
intel: 50,
|
||||
specialDomestic: 'che_event_견고',
|
||||
}),
|
||||
{ startYear: 180, year: 186, month: 1 },
|
||||
rules
|
||||
);
|
||||
expect(changed.stats.leadership).toBe(organicLeadership - oldGranted);
|
||||
expect(changed.role.specialDomestic).toBe('che_event_견고');
|
||||
expect(changed.targetChanged).toBe(true);
|
||||
});
|
||||
|
||||
it('does not refill an event-backed dex floor after 숙련전환 consumes it', () => {
|
||||
const dexTarget = target({ dex: [1_000_000, 0, 0, 0, 0] });
|
||||
const base = general({
|
||||
meta: metaWithAux(initialCentennialAllStarAux(dexTarget, rules)),
|
||||
});
|
||||
const full = applyCentennialAllStarTarget(base, dexTarget, { startYear: 180, year: 195, month: 1 }, rules);
|
||||
const convertedMeta = {
|
||||
...full.meta,
|
||||
dex1: 600_000,
|
||||
dex2: 360_000,
|
||||
};
|
||||
const reconciled = reconcileCentennialDexConversion(
|
||||
convertedMeta,
|
||||
'dex1',
|
||||
'dex2',
|
||||
1_000_000,
|
||||
600_000,
|
||||
0,
|
||||
360_000,
|
||||
0.9
|
||||
);
|
||||
const afterMonth = applyCentennialAllStarTarget(
|
||||
{ ...base, stats: full.stats, role: full.role, meta: reconciled },
|
||||
dexTarget,
|
||||
{ startYear: 180, year: 195, month: 2 },
|
||||
rules
|
||||
);
|
||||
expect(afterMonth.meta.dex1).toBe(600_000);
|
||||
expect(afterMonth.meta.dex2).toBe(360_000);
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,13 @@ import { computeBattleOrder, resolveWarBattle } from '../src/war/engine.js';
|
||||
import { createWarTriggerEnv, WarTriggerCaller } from '../src/war/triggers.js';
|
||||
import type { WarEngineConfig } from '../src/war/types.js';
|
||||
import { WarUnitCity, WarUnitGeneral, type WarUnit } from '../src/war/units.js';
|
||||
import { getCrewTypePickScore, parseUnitSetDefinition } from '../src/world/unitSet.js';
|
||||
import {
|
||||
getCrewTypePickScore,
|
||||
getTechAbility,
|
||||
getTechCost,
|
||||
getTechLevel,
|
||||
parseUnitSetDefinition,
|
||||
} from '../src/world/unitSet.js';
|
||||
import type { CrewTypeDefinition, UnitSetDefinition } from '../src/world/types.js';
|
||||
|
||||
const config: WarEngineConfig = {
|
||||
@@ -393,6 +399,20 @@ describe('crew type war triggers', () => {
|
||||
});
|
||||
|
||||
describe('crew type numeric policy', () => {
|
||||
it('uses the scenario 913 maximum tech level for ability and cost', () => {
|
||||
expect(getTechLevel(13_000, 15)).toBe(13);
|
||||
expect(getTechAbility(13_000, 15)).toBe(325);
|
||||
expect(getTechCost(13_000, 15)).toBe(2.95);
|
||||
|
||||
expect(getTechLevel(15_000, 15)).toBe(15);
|
||||
expect(getTechAbility(15_000, 15)).toBe(375);
|
||||
expect(getTechCost(15_000, 15)).toBe(3.25);
|
||||
|
||||
expect(getTechLevel(15_000)).toBe(12);
|
||||
expect(getTechAbility(15_000)).toBe(300);
|
||||
expect(getTechCost(15_000)).toBe(2.8);
|
||||
});
|
||||
|
||||
it('matches the legacy pickScore formula including magicCoef', () => {
|
||||
const wizard = crewType(1400, 4, '귀병', {
|
||||
attack: 80,
|
||||
@@ -404,4 +424,17 @@ describe('crew type numeric policy', () => {
|
||||
const expected = ((500 + 80 + 80 + 75 * 2) * (1 + 7 / 2) * (1 + 0.5 / 2)) / (1 - 0.05);
|
||||
expect(getCrewTypePickScore(wizard, 3000, 500)).toBeCloseTo(expected);
|
||||
});
|
||||
|
||||
it('uses the scenario maximum tech level in the crew pick score', () => {
|
||||
const wizard = crewType(1400, 4, '귀병', {
|
||||
attack: 80,
|
||||
defence: 80,
|
||||
speed: 7,
|
||||
avoid: 5,
|
||||
magicCoef: 0.5,
|
||||
});
|
||||
const expected = ((500 + 80 + 80 + 375 * 2) * (1 + 7 / 2) * (1 + 0.5 / 2)) / (1 - 0.05);
|
||||
|
||||
expect(getCrewTypePickScore(wizard, 15_000, 500, 15)).toBeCloseTo(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,9 @@ import { createItemActionModules, createItemModuleRegistry } from '../src/items/
|
||||
import { getEquippedItemInstance } from '../src/items/inventory.js';
|
||||
import { itemModule as dogiModule } from '../src/items/che_보물_도기.js';
|
||||
import { itemModule as strategyItemModule } from '../src/items/che_계략_이추.js';
|
||||
import { itemModule as leadershipWineModule } from '../src/items/che_능력치_통솔_보령압주.js';
|
||||
import { itemModule as strengthWineModule } from '../src/items/che_능력치_무력_두강주.js';
|
||||
import { itemModule as intelligenceWineModule } from '../src/items/che_능력치_지력_이강주.js';
|
||||
import { LogFormat } from '../src/logging/types.js';
|
||||
|
||||
const BASE_ENV: TurnCommandEnv = {
|
||||
@@ -109,6 +112,31 @@ const dogiCatalog: Record<string, TurnCommandItemCatalogEntry> = {
|
||||
},
|
||||
};
|
||||
|
||||
const scalingStatItems = [
|
||||
{ module: leadershipWineModule, statName: 'leadership' as const },
|
||||
{ module: strengthWineModule, statName: 'strength' as const },
|
||||
{ module: intelligenceWineModule, statName: 'intelligence' as const },
|
||||
];
|
||||
|
||||
describe('year-scaling stat items', () => {
|
||||
it.each([
|
||||
{ year: 180, startYear: 180, maxTechLevel: 12, expected: 75 },
|
||||
{ year: 200, startYear: 180, maxTechLevel: 12, expected: 80 },
|
||||
{ year: 260, startYear: 180, maxTechLevel: 12, expected: 87 },
|
||||
{ year: 260, startYear: 180, maxTechLevel: 15, expected: 90 },
|
||||
])('applies +5, four-year growth, and the $maxTechLevel cap', ({ year, startYear, maxTechLevel, expected }) => {
|
||||
const context = {
|
||||
general: makeGeneral(null),
|
||||
time: { year, month: 1, startYear },
|
||||
maxTechLevel,
|
||||
};
|
||||
|
||||
for (const { module, statName } of scalingStatItems) {
|
||||
expect(module.onCalcStat?.(context, statName, 70)).toBe(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const createItemOnlyStack = (items: ReturnType<typeof createItemActionModules>['general']) => {
|
||||
const noOp = {};
|
||||
return createRefOrderedActionStack({
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { UnitSetDefinition } from '../src/world/types.js';
|
||||
import { resolveWarAftermath } from '../src/war/aftermath.js';
|
||||
import type { WarAftermathConfig } from '../src/war/types.js';
|
||||
import { LogFormat } from '../src/logging/types.js';
|
||||
import { buildWarAftermathConfig } from '../src/actions/turn/actionContextHelpers.js';
|
||||
import { buildWarAftermathConfig, buildWarConfig } from '../src/actions/turn/actionContextHelpers.js';
|
||||
import type { ScenarioConfig } from '../src/scenario/types.js';
|
||||
|
||||
const buildUnitSet = (): UnitSetDefinition => ({
|
||||
@@ -137,6 +137,62 @@ describe('war aftermath', () => {
|
||||
expect(config.maxTechLevel).toBe(12);
|
||||
});
|
||||
|
||||
it('propagates the scenario maximum tech level to battle and aftermath configs', () => {
|
||||
const scenarioConfig: ScenarioConfig = {
|
||||
stat: { total: 0, min: 0, max: 0, npcTotal: 0, npcMax: 0, npcMin: 0, chiefMin: 0 },
|
||||
iconPath: '',
|
||||
map: {},
|
||||
const: { maxTechLevel: 15 },
|
||||
environment: { mapName: 'test', unitSet: 'test' },
|
||||
};
|
||||
|
||||
expect(buildWarConfig(scenarioConfig, buildUnitSet()).maxTechLevel).toBe(15);
|
||||
expect(buildWarAftermathConfig(scenarioConfig, 999).maxTechLevel).toBe(15);
|
||||
});
|
||||
|
||||
it('uses the scenario maximum tech level for supply-city rice consumption', () => {
|
||||
const attackerNation = buildNation(1);
|
||||
const defenderNation = buildNation(2);
|
||||
defenderNation.meta.tech = 15_000;
|
||||
const attackerCity = buildCity(1, 1);
|
||||
const defenderCity = buildCity(2, 2);
|
||||
defenderCity.meta.supply = 1;
|
||||
const attacker = buildGeneral(1, 1, 1);
|
||||
|
||||
resolveWarAftermath({
|
||||
battle: {
|
||||
attacker,
|
||||
defenders: [],
|
||||
defenderCity,
|
||||
logs: [],
|
||||
conquered: false,
|
||||
reports: [
|
||||
{
|
||||
id: defenderCity.id,
|
||||
type: 'city',
|
||||
name: defenderCity.name,
|
||||
isAttacker: false,
|
||||
killed: 100,
|
||||
dead: 0,
|
||||
phase: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
attackerNation,
|
||||
defenderNation,
|
||||
attackerCity,
|
||||
defenderCity,
|
||||
nations: [attackerNation, defenderNation],
|
||||
cities: [attackerCity, defenderCity],
|
||||
generals: [attacker],
|
||||
unitSet: buildUnitSet(),
|
||||
config: { ...buildConfig(), maxTechLevel: 15 },
|
||||
time: { year: 200, month: 1, startYear: 180 },
|
||||
});
|
||||
|
||||
expect(defenderNation.rice).toBe(985);
|
||||
});
|
||||
|
||||
it('updates tech and diplomacy deltas', () => {
|
||||
const attackerNation = buildNation(1);
|
||||
const defenderNation = buildNation(2);
|
||||
|
||||
@@ -166,6 +166,45 @@ const buildGeneral = (strength: number): General => ({
|
||||
});
|
||||
|
||||
describe('war triggers', () => {
|
||||
it('passes battle time and maximum tech level to year-scaling stat items', async () => {
|
||||
const general = buildGeneral(80);
|
||||
const [leadershipWine] = await loadItemModules(['che_능력치_통솔_보령압주']);
|
||||
expect(leadershipWine).toBeDefined();
|
||||
const unit = new WarUnitGeneral(
|
||||
new RandUtil(new ConstantRNG(0)),
|
||||
{ ...buildConfig(), maxTechLevel: 15 },
|
||||
general,
|
||||
buildCity(),
|
||||
buildNation(),
|
||||
true,
|
||||
new WarCrewType(buildUnitSet().crewTypes![0]!),
|
||||
new ActionLogger({ generalId: 1, nationId: 1 }),
|
||||
new WarActionPipeline([leadershipWine!]),
|
||||
{ year: 260, month: 1, startYear: 180 }
|
||||
);
|
||||
|
||||
expect(unit.getComputedStat('leadership', general.stats.leadership, { withInjury: false })).toBe(90);
|
||||
});
|
||||
|
||||
it('uses the battle config maximum tech level for combat ability', () => {
|
||||
const nation = buildNation();
|
||||
nation.meta.tech = 15_000;
|
||||
const unit = new WarUnitGeneral(
|
||||
new RandUtil(new ConstantRNG(0)),
|
||||
{ ...buildConfig(), maxTechLevel: 15 },
|
||||
buildGeneral(80),
|
||||
buildCity(),
|
||||
nation,
|
||||
true,
|
||||
new WarCrewType(buildUnitSet().crewTypes![0]!),
|
||||
new ActionLogger({ generalId: 1, nationId: 1 }),
|
||||
new WarActionPipeline([]),
|
||||
{ year: 200, month: 1, startYear: 180 }
|
||||
);
|
||||
|
||||
expect(unit.getComputedAttack()).toBeCloseTo(608, 12);
|
||||
});
|
||||
|
||||
it('normalizes accumulated dexterity to the PHP SQL float precision', () => {
|
||||
const general = buildGeneral(80);
|
||||
general.meta.dex4 = 14_677.199999999997;
|
||||
|
||||
Reference in New Issue
Block a user