랜덤 임관에서 이전 소속국을 제외하고 후보 소진 시 다시 순환한다
This commit is contained in:
1 parent
6a4f170fd9
commit
0ae14d5ee0
10 files changed
+221
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { General, Nation } from '../../../src/domain/entities.js';
|
||||
import type { General, GeneralMeta, Nation } from '../../../src/domain/entities.js';
|
||||
import type { GeneralActionResolveContext } from '../../../src/actions/engine.js';
|
||||
import { finalizeLogEntry } from '../../../src/logging/entries.js';
|
||||
import { LogCategory, type LogEntryDraft, LogFormat, LogScope } from '../../../src/logging/types.js';
|
||||
@@ -24,7 +24,7 @@ const actor = {
|
||||
specialWar: null,
|
||||
items: { horse: null, weapon: null, book: null, item: null },
|
||||
},
|
||||
meta: {},
|
||||
meta: { killturn: 70 },
|
||||
} as General;
|
||||
|
||||
const nation = {
|
||||
@@ -57,7 +57,7 @@ describe('appointment global summary log format', () => {
|
||||
const logs: LogEntryDraft[] = [];
|
||||
const action = new AppointmentAction({} as TurnCommandEnv);
|
||||
|
||||
action.resolve(
|
||||
const result = action.resolve(
|
||||
{
|
||||
general: actor,
|
||||
destNation: nation,
|
||||
@@ -69,6 +69,12 @@ describe('appointment global summary log format', () => {
|
||||
);
|
||||
|
||||
expectMonthlySummary(logs);
|
||||
expect(result.effects).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: 'general:patch',
|
||||
patch: expect.objectContaining({ meta: expect.objectContaining({ joinedNations: [2] }) }),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('adds the legacy month prefix to random appointment', () => {
|
||||
@@ -104,7 +110,7 @@ describe('appointment global summary log format', () => {
|
||||
const logs: LogEntryDraft[] = [];
|
||||
const action = new FollowAppointmentAction();
|
||||
|
||||
action.resolve(
|
||||
const result = action.resolve(
|
||||
{
|
||||
general: actor,
|
||||
destNation: nation,
|
||||
@@ -116,8 +122,74 @@ describe('appointment global summary log format', () => {
|
||||
);
|
||||
|
||||
expectMonthlySummary(logs);
|
||||
expect(result.effects).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: 'general:patch',
|
||||
patch: expect.objectContaining({ meta: expect.objectContaining({ joinedNations: [2] }) }),
|
||||
})
|
||||
);
|
||||
expect(
|
||||
logs.find((entry) => entry.scope === LogScope.GENERAL && entry.category === LogCategory.HISTORY)?.format
|
||||
).toBe(LogFormat.YEAR_MONTH);
|
||||
});
|
||||
});
|
||||
|
||||
describe('random appointment nation history', () => {
|
||||
const action = new RandomAppointmentAction({} as TurnCommandEnv);
|
||||
const resolve = (meta: GeneralMeta, eligibleIds: number[], historicalNpcAffinityMode = false) => {
|
||||
const rng = { nextFloat1: vi.fn(() => 0.42), nextInt: vi.fn(() => 0) };
|
||||
const candidateNations = eligibleIds.map((id) => ({
|
||||
nation: { ...nation, id },
|
||||
generals: [],
|
||||
generalCount: 1,
|
||||
monarchCityId: 2,
|
||||
monarchAffinity: 0,
|
||||
}));
|
||||
const result = action.resolve(
|
||||
{
|
||||
general: { ...actor, meta },
|
||||
rng,
|
||||
candidateNations,
|
||||
relYear: 4,
|
||||
initialNationGenLimit: 10,
|
||||
historicalNpcAffinityMode,
|
||||
} as unknown as Parameters<typeof action.resolve>[0],
|
||||
{}
|
||||
);
|
||||
return { ...result, rng, actorPatch: result.effects.find((effect) => effect.type === 'general:patch')?.patch };
|
||||
};
|
||||
|
||||
it.each([false, true])(
|
||||
'excludes visited nations and resets only when the eligible pool is exhausted (affinity: %s)',
|
||||
(affinity) => {
|
||||
const first = resolve(actor.meta, [2, 3], affinity);
|
||||
expect(first.actorPatch).toMatchObject({ nationId: 2, meta: { joinedNations: [2] } });
|
||||
expect(first.rng.nextFloat1).toHaveBeenCalledTimes(affinity ? 2 : 1);
|
||||
|
||||
const second = resolve(first.actorPatch!.meta!, [2, 3], affinity);
|
||||
expect(second.actorPatch).toMatchObject({ nationId: 3, meta: { joinedNations: [2, 3] } });
|
||||
expect(second.rng.nextFloat1).toHaveBeenCalledTimes(1);
|
||||
expect(second.rng.nextInt).toHaveBeenCalledTimes(1);
|
||||
|
||||
const third = resolve(second.actorPatch!.meta!, [2, 3], affinity);
|
||||
expect(third.actorPatch).toMatchObject({ nationId: 2, meta: { joinedNations: [2] } });
|
||||
expect(third.rng.nextFloat1).toHaveBeenCalledTimes(affinity ? 2 : 1);
|
||||
}
|
||||
);
|
||||
|
||||
it('reads legacy IDs, resets for one eligible visited nation, and retains history when the pool is empty', () => {
|
||||
const meta = { ...actor.meta, joinedNations: ['2', 4, 4, 0, 'invalid'] };
|
||||
const unvisited = resolve(meta, [2, 3]);
|
||||
expect(unvisited.actorPatch).toMatchObject({ nationId: 3, meta: { joinedNations: [2, 4, 3] } });
|
||||
|
||||
const restarted = resolve(meta, [2]);
|
||||
expect(restarted.actorPatch).toMatchObject({ nationId: 2, meta: { joinedNations: [2] } });
|
||||
expect(restarted.rng.nextFloat1).toHaveBeenCalledTimes(1);
|
||||
|
||||
const unavailable = resolve(meta, []);
|
||||
expect(unavailable.actorPatch).toBeUndefined();
|
||||
expect(unavailable.alternative).toEqual({ commandKey: 'che_인재탐색', args: {} });
|
||||
expect(unavailable.rng.nextFloat1).not.toHaveBeenCalled();
|
||||
expect(meta.joinedNations).toEqual(['2', 4, 4, 0, 'invalid']);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user