feat: acquireType을 UniqueAcquireType으로 변경하고 관련 테스트 추가

This commit is contained in:
2026-02-03 18:37:11 +00:00
parent b0a8f768e9
commit a2bb667b57
2 changed files with 69 additions and 9 deletions
+8 -4
View File
@@ -4,6 +4,9 @@ import type { ItemModule } from '../items/types.js';
export type UniqueItemPool = Record<string, Record<string, number>>; export type UniqueItemPool = Record<string, Record<string, number>>;
export const UNIQUE_ACQUIRE_TYPES = ['아이템', '설문조사', '랜덤 임관', '건국'] as const;
export type UniqueAcquireType = typeof UNIQUE_ACQUIRE_TYPES[number];
export type UniqueLotteryConfig = { export type UniqueLotteryConfig = {
allItems: UniqueItemPool; allItems: UniqueItemPool;
maxUniqueItemLimit: Array<[number, number]>; maxUniqueItemLimit: Array<[number, number]>;
@@ -25,7 +28,7 @@ export type UniqueLotteryInput = {
startYear: number; startYear: number;
initYear: number; initYear: number;
initMonth: number; initMonth: number;
acquireType?: string; acquireType?: UniqueAcquireType;
inheritRandomUnique?: boolean; inheritRandomUnique?: boolean;
}; };
@@ -156,6 +159,7 @@ export const rollUniqueLottery = (input: UniqueLotteryInput): string | null => {
acquireType, acquireType,
inheritRandomUnique, inheritRandomUnique,
} = input; } = input;
const resolvedAcquireType = acquireType ?? '아이템';
if (userCount <= 0) { if (userCount <= 0) {
return null; return null;
@@ -215,9 +219,9 @@ export const rollUniqueLottery = (input: UniqueLotteryInput): string | null => {
prob = 1 / (userCount * itemTypeCnt); prob = 1 / (userCount * itemTypeCnt);
} }
if (acquireType === '설문조사') { if (resolvedAcquireType === '설문조사') {
prob = 1 / (userCount * itemTypeCnt * 0.7 / 3); prob = 1 / (userCount * itemTypeCnt * 0.7 / 3);
} else if (acquireType === '랜덤 임관') { } else if (resolvedAcquireType === '랜덤 임관') {
prob = 1 / (userCount * itemTypeCnt / 10 / 2); prob = 1 / (userCount * itemTypeCnt / 10 / 2);
} }
@@ -231,7 +235,7 @@ export const rollUniqueLottery = (input: UniqueLotteryInput): string | null => {
if (inheritRandomUnique && availableBuyUnique) { if (inheritRandomUnique && availableBuyUnique) {
prob = 1; prob = 1;
} else if (acquireType === '건국') { } else if (resolvedAcquireType === '건국') {
prob = 1; prob = 1;
} }
+61 -5
View File
@@ -4,6 +4,7 @@ import { LiteHashDRBG, RandUtil } from '@sammo-ts/common';
import type { GeneralItemSlots } from '../src/domain/entities.js'; import type { GeneralItemSlots } from '../src/domain/entities.js';
import type { ItemModule } from '../src/items/types.js'; import type { ItemModule } from '../src/items/types.js';
import { import {
type UniqueAcquireType,
buildVoteUniqueSeed, buildVoteUniqueSeed,
countOccupiedUniqueItems, countOccupiedUniqueItems,
resolveUniqueConfig, resolveUniqueConfig,
@@ -24,11 +25,11 @@ const buildItem = (key: string, slot: ItemModule['slot'], buyable = false): Item
}); });
describe('unique lottery', () => { describe('unique lottery', () => {
it('returns deterministic item for fixed seed', () => { const buildRegistry = (): Map<string, ItemModule> =>
const itemRegistry = new Map<string, ItemModule>([ new Map<string, ItemModule>([['itemB', buildItem('itemB', 'weapon', false)]]);
['itemB', buildItem('itemB', 'weapon', false)],
]); const buildConfig = (overrides?: Partial<ReturnType<typeof resolveUniqueConfig>>) =>
const config = resolveUniqueConfig({ resolveUniqueConfig({
allItems: { allItems: {
weapon: { weapon: {
itemB: 1, itemB: 1,
@@ -38,8 +39,13 @@ describe('unique lottery', () => {
uniqueTrialCoef: 10, uniqueTrialCoef: 10,
maxUniqueTrialProb: 10, maxUniqueTrialProb: 10,
minMonthToAllowInheritItem: 0, minMonthToAllowInheritItem: 0,
...(overrides ?? {}),
}); });
it('returns deterministic item for fixed seed', () => {
const itemRegistry = buildRegistry();
const config = buildConfig();
const rngSeed = buildVoteUniqueSeed('seed', 1, 1); const rngSeed = buildVoteUniqueSeed('seed', 1, 1);
const rng = new RandUtil(LiteHashDRBG.build(rngSeed)); const rng = new RandUtil(LiteHashDRBG.build(rngSeed));
const result = rollUniqueLottery({ const result = rollUniqueLottery({
@@ -61,6 +67,56 @@ describe('unique lottery', () => {
expect(result).toBe('itemB'); expect(result).toBe('itemB');
}); });
it('supports acquire types that can yield unique items', () => {
const itemRegistry = buildRegistry();
const config = buildConfig();
const acquireTypes: UniqueAcquireType[] = ['아이템', '설문조사', '랜덤 임관'];
for (const acquireType of acquireTypes) {
const rng = new RandUtil(LiteHashDRBG.build(buildVoteUniqueSeed('seed', 2, 2)));
const result = rollUniqueLottery({
rng,
config,
itemRegistry,
generalItems: { horse: null, weapon: null, book: null, item: null },
occupiedUniqueCounts: new Map(),
scenarioId: 200,
userCount: 1,
currentYear: 200,
currentMonth: 1,
startYear: 180,
initYear: 180,
initMonth: 1,
acquireType,
});
expect(result).toBe('itemB');
}
});
it('guarantees unique on founding acquire type', () => {
const itemRegistry = buildRegistry();
const config = buildConfig({ uniqueTrialCoef: 0, maxUniqueTrialProb: 0 });
const rng = new RandUtil(LiteHashDRBG.build(buildVoteUniqueSeed('seed', 3, 3)));
const result = rollUniqueLottery({
rng,
config,
itemRegistry,
generalItems: { horse: null, weapon: null, book: null, item: null },
occupiedUniqueCounts: new Map(),
scenarioId: 200,
userCount: 1,
currentYear: 200,
currentMonth: 1,
startYear: 180,
initYear: 180,
initMonth: 1,
acquireType: '건국',
});
expect(result).toBe('itemB');
});
it('counts only non-buyable equipped items', () => { it('counts only non-buyable equipped items', () => {
const itemRegistry = new Map<string, ItemModule>([ const itemRegistry = new Map<string, ItemModule>([
['uniqueItem', buildItem('uniqueItem', 'weapon', false)], ['uniqueItem', buildItem('uniqueItem', 'weapon', false)],