feat: integrate unique lottery system into general actions

- Added `tryApplyUniqueLottery` function to various action definitions to apply unique item rewards based on specific actions.
- Enhanced the `uniqueLottery.ts` module to handle unique item acquisition and logging.
- Created unit tests for the unique lottery feature to ensure proper functionality during general commands.
- Updated action definitions to include unique item acquisition for actions such as training, technology research, and item procurement.
This commit is contained in:
2026-02-04 12:03:47 +00:00
parent a2bb667b57
commit 568084927c
30 changed files with 461 additions and 2 deletions
@@ -1,4 +1,5 @@
import type { City, General, Nation, Troop } from '@sammo-ts/logic/domain/entities.js';
import type { UniqueLotteryRunner } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { ScenarioConfig } from '@sammo-ts/logic/scenario/types.js';
import type { ScenarioMeta } from '@sammo-ts/logic/world/types.js';
import type { MapDefinition, UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
@@ -18,6 +19,7 @@ export type ActionContextBase = {
city?: City;
nation?: Nation | null;
rng: ActionRandomSource;
uniqueLottery?: UniqueLotteryRunner;
};
export type ActionResolveContext = ActionContextBase & Record<string, unknown>;
@@ -19,6 +19,7 @@ import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import { JosaUtil } from '@sammo-ts/common';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { MapDefinition } from '@sammo-ts/logic/world/types.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
@@ -101,6 +102,8 @@ export class ActionResolver<
const nextLeadershipExp =
(typeof general.meta.leadership_exp === 'number' ? general.meta.leadership_exp : 0) + 1;
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
effects.push(
createGeneralPatchEffect(
{
@@ -10,6 +10,7 @@ import {
import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { ActionContextBuilder, ActionContextBase } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface UprisingArgs { }
@@ -115,6 +116,8 @@ export class ActionDefinition<
format: LogFormat.PLAIN,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
const effects = [
createNationAddEffect(newNation),
createGeneralPatchEffect<TriggerState>({
@@ -20,6 +20,7 @@ import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -131,6 +132,8 @@ export class ActionDefinition<
format: LogFormat.PLAIN,
});
tryApplyUniqueLottery(context, { acquireType: '건국', reason: ACTION_NAME });
const effects = [
createNationPatchEffect(
{
@@ -4,6 +4,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { increaseMetaNumber } from '@sammo-ts/logic/war/utils.js';
@@ -218,6 +219,7 @@ export class ActionDefinition<
general.experience += exp;
context.addLog(message);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -7,6 +7,7 @@ import { LogFormat } from '@sammo-ts/logic/logging/types.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -112,6 +113,8 @@ export class ActionDefinition<
general.experience += 30;
general.dedication += 50;
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
}
@@ -20,6 +20,7 @@ import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import { JosaUtil } from '@sammo-ts/common';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface ReturnArgs {}
@@ -115,6 +116,8 @@ export class ActionResolver<
const exp = 70;
const ded = 100;
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
effects.push(
createGeneralPatchEffect(
{
@@ -11,6 +11,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface TechResearchArgs {}
@@ -79,6 +80,7 @@ export class ActionDefinition<
general.gold = Math.max(0, general.gold - costGold);
context.addLog(`${ACTION_NAME}로 기술이 ${applied} 상승했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -6,6 +6,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
import { JosaUtil } from '@sammo-ts/common';
@@ -156,6 +157,7 @@ export class ActionDefinition<
general.rice = Math.max(0, general.rice - cost);
context.addLog(logText);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -19,6 +19,7 @@ import { LogCategory, LogScope } from '@sammo-ts/logic/logging/types.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { ActionContextBase, ActionContextOptions } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -99,6 +100,8 @@ export class ActionResolver<
const effects: GeneralActionEffect<TriggerState>[] = [];
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
effects.push(
createGeneralPatchEffect(
{
@@ -11,6 +11,7 @@ import type {
} from '@sammo-ts/logic/actions/engine.js';
import { createGeneralPatchEffect, createLogEffect } from '@sammo-ts/logic/actions/engine.js';
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { resolveStartYear } from '@sammo-ts/logic/actions/turn/actionContextHelpers.js';
@@ -226,6 +227,8 @@ export class ActionDefinition<
)
);
tryApplyUniqueLottery(context, { acquireType: '랜덤 임관', reason: ACTION_NAME });
return { effects };
}
}
@@ -12,6 +12,7 @@ import { createGeneralPatchEffect, createNationPatchEffect } from '@sammo-ts/log
import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface ProcureArgs {}
@@ -131,6 +132,8 @@ export class ActionResolver<
});
}
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return {
effects: [
createGeneralPatchEffect(
@@ -11,6 +11,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { clamp } from 'es-toolkit';
@@ -70,6 +71,7 @@ export class ActionDefinition<
general.gold = Math.max(0, general.gold - costGold);
context.addLog(`${ACTION_NAME}로 사기가 ${applied} 증가했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -20,6 +20,7 @@ import type {
} from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { clamp } from 'es-toolkit';
@@ -255,6 +256,7 @@ export class ActionResolver<
const pickLabel = result.pick === 'success' ? '성공' : result.pick === 'fail' ? '실패' : '완료';
const logMessage = `${ACTION_NAME} ${pickLabel}: +${Math.round(result.score)}`;
context.addLog(logMessage);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -5,6 +5,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
import { JosaUtil } from '@sammo-ts/common';
@@ -80,6 +81,7 @@ export class ActionDefinition<
increaseMetaNumber(general.meta, 'leadership_exp', 2);
context.addLog(`${srcName} 숙련 ${cutDex}${cutJosa} ${destName} 숙련 ${addDex}${addJosa} 전환했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -12,6 +12,7 @@ import { createGeneralPatchEffect } from '@sammo-ts/logic/actions/engine.js';
import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface RetireArgs {}
@@ -73,6 +74,8 @@ export class ActionResolver<
const effects: GeneralActionEffect<TriggerState>[] = [];
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
effects.push(
createGeneralPatchEffect(
{
@@ -20,6 +20,7 @@ import { JosaUtil } from '@sammo-ts/common';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { MapDefinition } from '@sammo-ts/logic/world/types.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -106,6 +107,8 @@ export class ActionResolver<
format: LogFormat.MONTH,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
for (const target of moveTargets) {
const isSelf = target.id === general.id;
@@ -23,6 +23,7 @@ import { JosaUtil } from '@sammo-ts/common';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { buildWorldSummary } from '@sammo-ts/logic/actions/turn/actionContextHelpers.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
export interface TalentScoutArgs {}
@@ -292,6 +293,7 @@ export class ActionResolver<
category: LogCategory.ACTION,
format: LogFormat.MONTH,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -369,6 +371,8 @@ export class ActionResolver<
format: LogFormat.YEAR_MONTH,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return {
effects: [createGeneralAddEffect(newGeneral)],
};
@@ -8,6 +8,7 @@ import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -59,6 +60,8 @@ export class ActionDefinition<
format: LogFormat.MONTH,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
const effects = [
createGeneralPatchEffect<TriggerState>({
nationId: args.destNationId,
@@ -5,6 +5,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { setMetaNumber } from '@sammo-ts/logic/war/utils.js';
@@ -54,6 +55,7 @@ export class ActionDefinition<
general.role.specialWar = null;
setMetaNumber(general.meta, 'specAge2', general.age + 1);
context.addLog('새로운 전투 특기를 가질 준비가 되었습니다.');
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
}
@@ -12,6 +12,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import { clamp } from 'es-toolkit';
import type { GeneralTurnCommandSpec } from './index.js';
@@ -68,6 +69,7 @@ export class ActionDefinition<
general.rice = Math.max(0, general.rice - costRice);
context.addLog(`인구가 ${nextValue - current} 증가했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: '정착 장려' });
return { effects: [] };
}
@@ -14,6 +14,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { clamp } from 'es-toolkit';
@@ -165,6 +166,7 @@ export class ActionDefinition<
general.meta = { ...addMetaNumber(general.meta, STAT_EXP_KEY, 1), max_domestic_critical: 0 };
context.addLog(`민심이 ${result.trustDelta.toFixed(1)} 상승했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
}
@@ -16,6 +16,7 @@ import type {
import { createGeneralPatchEffect, createLogEffect } from '@sammo-ts/logic/actions/engine.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
import { JosaUtil } from '@sammo-ts/common';
@@ -78,6 +79,7 @@ export class ActionDefinition<
general.experience += 70;
general.dedication += 100;
increaseMetaNumber(general.meta, 'leadership_exp', 1);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects };
}
@@ -19,6 +19,7 @@ import type {
import type { MapDefinition, UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { resolveStartYear } from '@sammo-ts/logic/actions/turn/actionContextHelpers.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { GeneralTurnCommandSpec } from './index.js';
@@ -392,6 +393,7 @@ export class ActionResolver<
general.meta = addMetaNumber(general.meta, 'leadership_exp', 1);
context.addLog(logMessage);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
@@ -36,6 +36,7 @@ import type { WarActionModule } from '@sammo-ts/logic/war/actions.js';
import { increaseMetaNumber, simpleSerialize } from '@sammo-ts/logic/war/utils.js';
import type { MapDefinition, UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import {
buildWarAftermathConfig,
buildWarConfig,
@@ -509,6 +510,8 @@ export class ActionDefinition<
);
}
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects };
}
}
@@ -19,6 +19,7 @@ import { LogCategory, LogFormat } from '@sammo-ts/logic/logging/types.js';
import { z } from 'zod';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
@@ -60,6 +61,8 @@ export class ActionResolver<
format: LogFormat.MONTH,
});
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return {
effects: [
createGeneralPatchEffect(
@@ -5,6 +5,7 @@ import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { clamp } from 'es-toolkit';
@@ -64,6 +65,7 @@ export class ActionDefinition<
general.gold = Math.max(0, general.gold - costGold);
context.addLog(`${ACTION_NAME}을 통해 훈련도가 ${applied} 증가했습니다.`);
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
return { effects: [] };
}
+80 -2
View File
@@ -1,5 +1,7 @@
import { asRecord, parseJson, type RandUtil } from '@sammo-ts/common';
import type { GeneralItemSlots } from '../domain/entities.js';
import { asRecord, JosaUtil, parseJson, type RandUtil } from '@sammo-ts/common';
import type { General, GeneralItemSlots, GeneralTriggerState } from '../domain/entities.js';
import type { GeneralActionResolveContext } from '../actions/engine.js';
import { LogCategory, LogFormat, LogScope } from '../logging/types.js';
import type { ItemModule } from '../items/types.js';
export type UniqueItemPool = Record<string, Record<string, number>>;
@@ -7,6 +9,15 @@ 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 UniqueLotteryRequest = {
acquireType: UniqueAcquireType;
reason: string;
};
export type UniqueLotteryRunner = <TriggerState extends GeneralTriggerState = GeneralTriggerState>(
request: UniqueLotteryRequest & { general: General<TriggerState> }
) => ItemModule | null;
export type UniqueLotteryConfig = {
allItems: UniqueItemPool;
maxUniqueItemLimit: Array<[number, number]>;
@@ -139,6 +150,17 @@ const serializeSeed = (...values: Array<string | number>): string =>
.map((value) => (typeof value === 'string' ? `str(${value.length},${value})` : `int(${Math.floor(value)})`))
.join('|');
export const buildGenericUniqueSeed = (
hiddenSeed: string | number,
year: number,
month: number,
generalId: number,
reason?: string
): string =>
reason !== undefined
? serializeSeed(hiddenSeed, 'unique', year, month, generalId, reason)
: serializeSeed(hiddenSeed, 'unique', year, month, generalId);
export const buildVoteUniqueSeed = (hiddenSeed: string | number, voteId: number, generalId: number): string =>
serializeSeed(hiddenSeed, 'voteUnique', voteId, generalId);
@@ -280,3 +302,59 @@ export const rollUniqueLottery = (input: UniqueLotteryInput): string | null => {
return rng.choiceUsingWeightPair(availableUnique);
};
export const applyUniqueItemGain = <TriggerState extends GeneralTriggerState = GeneralTriggerState>(
context: GeneralActionResolveContext<TriggerState>,
itemModule: ItemModule,
acquireType: UniqueAcquireType
): void => {
const general = context.general;
const nationName = context.nation?.name ?? '재야';
const generalName = general.name;
const itemName = itemModule.name;
const itemRawName = itemModule.rawName;
const josaYi = JosaUtil.pick(generalName, '이');
const josaUl = JosaUtil.pick(itemRawName, '을');
general.role.items[itemModule.slot] = itemModule.key;
context.addLog(`<C>${itemName}</>${josaUl} 습득했습니다!`, {
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
format: LogFormat.MONTH,
});
context.addLog(`<C>${itemName}</>${josaUl} 습득`, {
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
format: LogFormat.YEAR_MONTH,
});
context.addLog(`<Y>${generalName}</>${josaYi} <C>${itemName}</>${josaUl} 습득했습니다!`, {
scope: LogScope.SYSTEM,
category: LogCategory.SUMMARY,
format: LogFormat.MONTH,
});
context.addLog(
`<C><b>【${acquireType}】</b></><D><b>${nationName}</b></>의 <Y>${generalName}</>${josaYi} <C>${itemName}</>${josaUl} 습득했습니다!`,
{
scope: LogScope.SYSTEM,
category: LogCategory.HISTORY,
format: LogFormat.YEAR_MONTH,
}
);
};
export const tryApplyUniqueLottery = <TriggerState extends GeneralTriggerState = GeneralTriggerState>(
context: GeneralActionResolveContext<TriggerState> & { uniqueLottery?: UniqueLotteryRunner },
request: UniqueLotteryRequest
): boolean => {
const runner = context.uniqueLottery;
if (!runner) {
return false;
}
const itemModule = runner({ ...request, general: context.general });
if (!itemModule) {
return false;
}
applyUniqueItemGain(context, itemModule, request.acquireType);
return true;
};