refactor(logic): replace arbitrary action hooks with typed events

This commit is contained in:
2026-07-30 03:31:31 +00:00
parent 96b41ef4b4
commit 7d3cb50a5b
168 changed files with 1554 additions and 631 deletions
@@ -22,6 +22,11 @@ export type ActionContextBase = {
worldView?: GeneralWorldView;
rng: ActionRandomSource;
uniqueLottery?: UniqueLotteryRunner;
time?: {
year: number;
month: number;
startYear: number;
};
};
export type ActionResolveContext = ActionContextBase & Record<string, unknown>;
@@ -1,7 +1,8 @@
import type { GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import type { GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { WarActionModule } from '@sammo-ts/logic/war/actions.js';
import type { UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
import type { NationTraitModule } from '@sammo-ts/logic/triggers/special/nation/index.js';
import type { NationTraitModule } from '@sammo-ts/logic/actionModules/traits/nation/index.js';
import type { RefOrderedActionStack } from '@sammo-ts/logic/actionModules/bundle.js';
export interface TurnCommandItemCatalogEntry {
slot: 'horse' | 'weapon' | 'book' | 'item';
@@ -56,7 +57,7 @@ export interface TurnCommandEnv {
npcSeizureMessageProb?: number;
maxResourceActionAmount: number;
itemCatalog?: Record<string, TurnCommandItemCatalogEntry>;
generalActionModules?: Array<GeneralActionModule>;
warActionModules?: Array<WarActionModule>;
generalActionModules?: RefOrderedActionStack<GeneralActionModule>;
warActionModules?: RefOrderedActionStack<WarActionModule>;
nationTraitModules?: Array<NationTraitModule>;
}
@@ -8,7 +8,7 @@ import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/action
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { setMetaNumber } from '@sammo-ts/logic/war/utils.js';
import { DOMESTIC_TRAIT_KEYS } from '@sammo-ts/logic/triggers/special/domestic/index.js';
import { DOMESTIC_TRAIT_KEYS } from '@sammo-ts/logic/actionModules/traits/domestic/index.js';
export interface ResetSpecialDomesticArgs {}
@@ -6,7 +6,7 @@ import {
} from './che_징병.js';
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import type { GeneralTurnCommandSpec } from './index.js';
import type { GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import type { GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
export class ActionDefinition<
TriggerState extends GeneralTriggerState = GeneralTriggerState,
@@ -14,7 +14,7 @@ export class ActionDefinition<
public override readonly key = 'che_모병';
public override readonly name = '모병';
constructor(modules: GeneralActionModule<TriggerState>[]) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState>>) {
super(modules, {
actionName: '모병',
costOffset: 2,
@@ -1,7 +1,7 @@
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
import { notBeNeutral, notWanderingNation, occupiedCity, suppliedCity } from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionOutcome,
@@ -31,7 +31,7 @@ export class ActionResolver<
readonly key = ACTION_KEY;
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>) {
this.pipeline = new GeneralActionPipeline(modules);
}
@@ -186,7 +186,7 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>) {
this.resolver = new ActionResolver(modules);
}
@@ -16,7 +16,7 @@ import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/action
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { clamp } from 'es-toolkit';
import { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
export interface BoostMoraleArgs {}
@@ -11,8 +11,8 @@ import {
reqGeneralRice,
suppliedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import type { TriggerDomesticActionType } from '@sammo-ts/logic/triggers/types.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { TriggerDomesticActionType } from '@sammo-ts/logic/actionModules/types.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionOutcome,
@@ -168,7 +168,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly config: InvestmentConfig;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: InvestmentEnvironment,
config: InvestmentConfig = DEFAULT_CONFIG
) {
@@ -324,7 +324,7 @@ export class ActionResolver<
private readonly config: InvestmentConfig;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: InvestmentEnvironment,
config: InvestmentConfig = DEFAULT_CONFIG
) {
@@ -398,7 +398,7 @@ export class ActionDefinition<
private readonly config: InvestmentConfig;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: InvestmentEnvironment,
config: InvestmentConfig = DEFAULT_CONFIG
) {
@@ -25,7 +25,7 @@ import type { ActionContextBase, ActionContextOptions } from '@sammo-ts/logic/ac
import type { GeneralTurnCommandSpec } from './index.js';
import { JosaUtil } from '@sammo-ts/common';
import { parseArgsWithSchema } from '../parseArgs.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
import { consumeSuccessfulStrategyItem } from './strategyItemConsumption.js';
import {
buildStrategyActionContext,
@@ -6,7 +6,7 @@ import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-t
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
export interface DisbandArgs {}
@@ -9,7 +9,7 @@ import type {
} from '@sammo-ts/logic/domain/entities.js';
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
import { reqGeneralGold, reqGeneralRice } from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionOutcome,
@@ -175,12 +175,11 @@ const legacyChoiceIndex = (rng: RandomGenerator, length: number): number => {
throw new Error('Empty items');
}
const inclusive = rng as InclusiveRandomGenerator;
return inclusive.nextIntInclusive
? inclusive.nextIntInclusive(length - 1)
: rng.nextInt(0, length);
return inclusive.nextIntInclusive ? inclusive.nextIntInclusive(length - 1) : rng.nextInt(0, length);
};
const legacyChoice = <T>(rng: RandomGenerator, values: readonly T[]): T => values[legacyChoiceIndex(rng, values.length)]!;
const legacyChoice = <T>(rng: RandomGenerator, values: readonly T[]): T =>
values[legacyChoiceIndex(rng, values.length)]!;
const resolveCandidate = (
context: TalentScoutResolveContext,
@@ -239,7 +238,10 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
private readonly env: TalentScoutEnvironment;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: TalentScoutEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: TalentScoutEnvironment
) {
this.pipeline = new GeneralActionPipeline(modules);
this.env = env;
}
@@ -269,7 +271,10 @@ export class ActionResolver<
private readonly env: TalentScoutEnvironment;
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: TalentScoutEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: TalentScoutEnvironment
) {
this.env = env;
this.command = new CommandResolver(modules, env);
}
@@ -353,20 +358,19 @@ export class ActionResolver<
let dex: [number, number, number, number, number];
if (pickType === '무') {
const distributions = [
[dexTotal * 5 / 8, dexTotal / 8, dexTotal / 8, dexTotal / 8],
[dexTotal / 8, dexTotal * 5 / 8, dexTotal / 8, dexTotal / 8],
[dexTotal / 8, dexTotal / 8, dexTotal * 5 / 8, dexTotal / 8],
[(dexTotal * 5) / 8, dexTotal / 8, dexTotal / 8, dexTotal / 8],
[dexTotal / 8, (dexTotal * 5) / 8, dexTotal / 8, dexTotal / 8],
[dexTotal / 8, dexTotal / 8, (dexTotal * 5) / 8, dexTotal / 8],
] as const;
const picked = legacyChoice(context.rng, distributions);
dex = [picked[0], picked[1], picked[2], picked[3], averageDex[4]];
} else if (pickType === '지') {
dex = [dexTotal / 8, dexTotal / 8, dexTotal / 8, dexTotal * 5 / 8, averageDex[4]];
dex = [dexTotal / 8, dexTotal / 8, dexTotal / 8, (dexTotal * 5) / 8, averageDex[4]];
} else {
dex = [dexTotal / 4, dexTotal / 4, dexTotal / 4, dexTotal / 4, averageDex[4]];
}
const personality =
resolvedCandidate.personality ??
legacyChoice(context.rng, this.env.availablePersonalities ?? ['che_안전']);
resolvedCandidate.personality ?? legacyChoice(context.rng, this.env.availablePersonalities ?? ['che_안전']);
const name = this.env.decorateName
? this.env.decorateName(resolvedCandidate.name, NPC_TYPE)
: `${resolvedCandidate.name}`;
@@ -374,10 +378,7 @@ export class ActionResolver<
const turnSecond = randomRangeInt(context.rng, 0, context.turnTermMinutes * 60 - 1);
const turnFraction = randomRangeInt(context.rng, 0, 999_999);
const killturn =
(deathYear - context.currentYear) * 12 +
randomRangeInt(context.rng, 0, 11) +
context.currentMonth -
1;
(deathYear - context.currentYear) * 12 + randomRangeInt(context.rng, 0, 11) + context.currentMonth - 1;
const meta: GeneralMeta = {
killturn,
npcType: NPC_TYPE,
@@ -461,7 +462,10 @@ export class ActionDefinition<
private readonly command: CommandResolver<TriggerState>;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: TalentScoutEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: TalentScoutEnvironment
) {
this.command = new CommandResolver(modules, env);
this.resolver = new ActionResolver(modules, env);
}
@@ -517,6 +521,5 @@ export const commandSpec: GeneralTurnCommandSpec = {
category: '인사',
reqArg: false,
createDefinition: (env: TurnCommandEnv) =>
new ActionDefinition(env.generalActionModules ?? [], env),
createDefinition: (env: TurnCommandEnv) => new ActionDefinition(env.generalActionModules ?? [], env),
};
@@ -8,8 +8,12 @@ import {
reqGeneralRice,
} from '@sammo-ts/logic/constraints/presets.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import { createGeneralPatchEffect } from '@sammo-ts/logic/actions/engine.js';
import type {
GeneralActionEffect,
GeneralActionOutcome,
GeneralActionResolveContext,
} from '@sammo-ts/logic/actions/engine.js';
import { createGeneralPatchEffect, createNationPatchEffect } from '@sammo-ts/logic/actions/engine.js';
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
import { JosaUtil } from '@sammo-ts/common';
import { z } from 'zod';
@@ -19,6 +23,8 @@ import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/action
import type { GeneralTurnCommandSpec } from './index.js';
import { parseArgsWithSchema } from '../parseArgs.js';
import { equipNewItem, removeEquippedItem } from '@sammo-ts/logic/items/inventory.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
import { createGeneralActionEvent } from '@sammo-ts/logic/actionModules/events.js';
const ACTION_NAME = '장비매매';
const ACTION_KEY = 'che_장비매매';
@@ -54,8 +60,11 @@ export class ActionDefinition<
> implements GeneralActionDefinition<TriggerState, TradeItemArgs> {
public readonly key = ACTION_KEY;
public readonly name = ACTION_NAME;
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(private readonly env: TurnCommandEnv) {}
constructor(private readonly env: TurnCommandEnv) {
this.pipeline = new GeneralActionPipeline(env.generalActionModules ?? []);
}
parseArgs(raw: unknown): TradeItemArgs | null {
const args = parseArgsWithSchema(ARGS_SCHEMA, raw);
@@ -144,6 +153,7 @@ export class ActionDefinition<
): GeneralActionOutcome<TriggerState> {
const general = context.general;
const nation = context.nation;
const nationResourcesBeforeEvent = nation ? { gold: nation.gold, rice: nation.rice } : null;
const itemType = args.itemType;
const requestedItemCode = args.itemCode;
@@ -162,14 +172,6 @@ export class ActionDefinition<
const josaUl = JosaUtil.pick(itemRawName, '을');
const nextGold = buying ? Math.max(0, general.gold - itemCost) : general.gold + Math.floor(itemCost / 2);
if (buying) {
equipNewItem(general, itemType, finalItemCode, {
...(item?.initialCharges === undefined ? {} : { charges: item.initialCharges }),
});
} else {
removeEquippedItem(general, itemType);
}
if (buying) {
context.addLog(`<C>${itemName}</>${josaUl} 구입했습니다.`, {
scope: LogScope.GENERAL,
@@ -184,6 +186,43 @@ export class ActionDefinition<
});
}
general.gold = nextGold;
if (buying) {
equipNewItem(general, itemType, finalItemCode, {
...(item?.initialCharges === undefined ? {} : { charges: item.initialCharges }),
});
}
const eventLog = {
push: (message: string) =>
context.addLog(message, {
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
format: LogFormat.MONTH,
}),
};
if (buying) {
this.pipeline.dispatch(
{ ...context, log: eventLog },
createGeneralActionEvent<TriggerState, 'item.purchased'>('item.purchased', {
itemKey: finalItemCode,
slot: itemType,
})
);
} else {
if (!context.time) {
throw new Error('장비 판매 이벤트에는 현재 연도와 시나리오 시작 연도가 필요합니다.');
}
this.pipeline.dispatch(
{ ...context, time: context.time, log: eventLog },
createGeneralActionEvent<TriggerState, 'item.sold'>('item.sold', {
itemKey: finalItemCode,
slot: itemType,
})
);
removeEquippedItem(general, itemType);
}
if (!buying && item && !item.buyable && nation) {
const josaYi = JosaUtil.pick(general.name, '이');
context.addLog(`<Y>${general.name}</>${josaYi} <C>${itemName}</>${josaUl} 판매했습니다!`, {
@@ -201,13 +240,31 @@ export class ActionDefinition<
tryApplyUniqueLottery(context, { acquireType: '아이템', reason: ACTION_NAME });
const effects: Array<GeneralActionEffect<TriggerState>> = [
createGeneralPatchEffect<TriggerState>({
gold: general.gold,
rice: general.rice,
experience: general.experience + 10,
}),
];
if (
nation &&
nationResourcesBeforeEvent &&
(nation.gold !== nationResourcesBeforeEvent.gold || nation.rice !== nationResourcesBeforeEvent.rice)
) {
effects.push(
createNationPatchEffect(
{
gold: nation.gold,
rice: nation.rice,
},
nation.id
)
);
}
return {
effects: [
createGeneralPatchEffect<TriggerState>({
gold: nextGold,
experience: general.experience + 10,
}),
],
effects,
};
}
}
@@ -8,7 +8,7 @@ import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/action
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
import type { GeneralTurnCommandSpec } from './index.js';
import { setMetaNumber } from '@sammo-ts/logic/war/utils.js';
import { WAR_TRAIT_KEYS } from '@sammo-ts/logic/triggers/special/war/index.js';
import { WAR_TRAIT_KEYS } from '@sammo-ts/logic/actionModules/traits/war/index.js';
export interface ResetSpecialWarArgs {}
@@ -9,7 +9,7 @@ import {
reqGeneralGold,
reqGeneralRice,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionOutcome,
@@ -217,7 +217,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
private readonly env: RecruitEnvironment;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
this.pipeline = new GeneralActionPipeline(modules);
this.env = env;
}
@@ -331,7 +331,7 @@ export class ActionResolver<
private readonly env: RecruitEnvironment;
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
this.env = env;
this.command = new CommandResolver(modules, env);
}
@@ -444,7 +444,7 @@ export class ActionDefinition<
private readonly resolver: ActionResolver<TriggerState>;
private readonly env: RecruitEnvironment;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
constructor(modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>, env: RecruitEnvironment) {
this.command = new CommandResolver(modules, env);
this.resolver = new ActionResolver(modules, env);
this.env = env;
@@ -31,7 +31,8 @@ import type { WarAftermathConfig, WarEngineConfig, WarTimeContext } from '@sammo
import { resolveWarAftermath } from '@sammo-ts/logic/war/aftermath.js';
import { resolveWarBattle } from '@sammo-ts/logic/war/engine.js';
import type { WarActionModule } from '@sammo-ts/logic/war/actions.js';
import type { NationTraitModule } from '@sammo-ts/logic/triggers/special/nation/index.js';
import type { NationTraitModule } from '@sammo-ts/logic/actionModules/traits/nation/index.js';
import type { GeneralActionModule } from '@sammo-ts/logic/actionModules/general.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';
@@ -163,9 +164,7 @@ const pickCandidateCity = (
const legacyCompatibleRng = rng as typeof rng & {
nextIntInclusive?: (maxInclusive: number) => number;
};
const index =
legacyCompatibleRng.nextIntInclusive?.(items.length - 1) ??
rng.nextInt(0, items.length);
const index = legacyCompatibleRng.nextIntInclusive?.(items.length - 1) ?? rng.nextInt(0, items.length);
return items[index]!;
};
const distances = Array.from(distanceList.keys()).sort((a, b) => a - b);
@@ -255,15 +254,18 @@ export class ActionDefinition<
getInheritanceActiveActionAmount(): number {
return 1;
}
private readonly warModules: Array<WarActionModule<TriggerState>>;
private readonly warModules: ReadonlyArray<WarActionModule<TriggerState>>;
private readonly nationTraitModules: Map<string, NationTraitModule>;
private readonly generalModules: ReadonlyArray<GeneralActionModule<TriggerState>>;
constructor(
modules: Array<WarActionModule<TriggerState> | null | undefined> = [],
nationTraitModules: NationTraitModule[] = []
modules: ReadonlyArray<WarActionModule<TriggerState> | null | undefined> = [],
nationTraitModules: NationTraitModule[] = [],
generalModules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined> = []
) {
this.warModules = modules.filter(Boolean) as Array<WarActionModule<TriggerState>>;
this.warModules = modules.filter(Boolean) as ReadonlyArray<WarActionModule<TriggerState>>;
this.nationTraitModules = new Map(nationTraitModules.map((module) => [module.key, module]));
this.generalModules = generalModules.filter(Boolean) as ReadonlyArray<GeneralActionModule<TriggerState>>;
}
parseArgs(raw: unknown): DispatchArgs | null {
@@ -474,15 +476,12 @@ export class ActionDefinition<
config: context.aftermathConfig,
time,
hiddenSeed: context.seedBase,
generalActionModules: this.generalModules,
calcNationTechGain: ({ nation, baseGain }) => {
const module = this.nationTraitModules.get(nation.typeCode);
return (
module?.onCalcDomestic?.(
{ general: context.general, nation },
'기술',
'score',
baseGain
) ?? baseGain
module?.onCalcDomestic?.({ general: context.general, nation }, '기술', 'score', baseGain) ??
baseGain
);
},
});
@@ -601,5 +600,5 @@ export const commandSpec: GeneralTurnCommandSpec = {
availabilityArgs: { destCityId: 0 },
argsSchema: ARGS_SCHEMA,
createDefinition: (env: TurnCommandEnv) =>
new ActionDefinition(env.warActionModules ?? [], env.nationTraitModules ?? []),
new ActionDefinition(env.warActionModules ?? [], env.nationTraitModules ?? [], env.generalActionModules ?? []),
};
@@ -25,7 +25,7 @@ import type { ActionContextBase, ActionContextOptions } from '@sammo-ts/logic/ac
import type { GeneralTurnCommandSpec } from './index.js';
import { JosaUtil } from '@sammo-ts/common';
import { parseArgsWithSchema } from '../parseArgs.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
import { consumeSuccessfulStrategyItem } from './strategyItemConsumption.js';
import {
buildStrategyActionContext,
@@ -25,7 +25,7 @@ import type { ActionContextBase, ActionContextOptions } from '@sammo-ts/logic/ac
import type { GeneralTurnCommandSpec } from './index.js';
import { JosaUtil } from '@sammo-ts/common';
import { parseArgsWithSchema } from '../parseArgs.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
import { consumeSuccessfulStrategyItem } from './strategyItemConsumption.js';
import {
buildStrategyActionContext,
@@ -12,7 +12,7 @@ import {
suppliedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import type { GeneralActionContext } from '@sammo-ts/logic/triggers/general.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -125,7 +125,10 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly env: FireAttackEnvironment;
private readonly statKey: 'leadership' | 'strength' | 'intelligence';
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: FireAttackEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: FireAttackEnvironment
) {
this.pipeline = new GeneralActionPipeline(modules);
this.env = env;
this.statKey = env.statKey ?? 'intelligence';
@@ -287,7 +290,10 @@ export class ActionResolver<
private readonly command: CommandResolver<TriggerState>;
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: FireAttackEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: FireAttackEnvironment
) {
this.command = new CommandResolver(modules, env);
this.pipeline = new GeneralActionPipeline(modules);
}
@@ -376,8 +382,7 @@ export class ActionResolver<
);
const itemCode = general.role.items.item;
const actionResult = consumeSuccessfulStrategyItem(this.pipeline, context);
const consumedItems = Array.isArray(actionResult?.['consumedItems']) ? actionResult['consumedItems'] : [];
const consumedItems = consumeSuccessfulStrategyItem(this.pipeline, context);
if (typeof itemCode === 'string' && consumedItems.includes(itemCode)) {
context.addLog(`<C>${itemCode}</>${JosaUtil.pick(itemCode, '을')} 사용!`, {
format: LogFormat.PLAIN,
@@ -405,7 +410,10 @@ export class ActionDefinition<
private readonly command: CommandResolver<TriggerState>;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, env: FireAttackEnvironment) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: FireAttackEnvironment
) {
this.command = new CommandResolver(modules, env);
this.resolver = new ActionResolver(modules, env);
}
@@ -15,7 +15,7 @@ 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 { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
const ACTION_NAME = '맹훈련';
const ACTION_KEY = 'cr_맹훈련';
@@ -1,4 +1,4 @@
import { NATION_TRAIT_KEYS } from '@sammo-ts/logic/triggers/special/nation/index.js';
import { NATION_TRAIT_KEYS } from '@sammo-ts/logic/actionModules/traits/nation/index.js';
import { getLegacyStringWidth } from '@sammo-ts/logic/troop/management.js';
import { z } from 'zod';
@@ -1,12 +1,15 @@
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
import type { GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
import type { GeneralActionPipeline } from '@sammo-ts/logic/triggers/general-action.js';
import type { GeneralActionPipeline } from '@sammo-ts/logic/actionModules/general.js';
import { createGeneralActionEvent } from '@sammo-ts/logic/actionModules/events.js';
export const consumeSuccessfulStrategyItem = <TriggerState extends GeneralTriggerState>(
pipeline: GeneralActionPipeline<TriggerState>,
context: GeneralActionResolveContext<TriggerState>
): Record<string, unknown> | null =>
pipeline.onArbitraryAction(context, 'GeneralCommand', null, {
command: '계략',
success: true,
});
): readonly string[] =>
pipeline.dispatch(
context,
createGeneralActionEvent<TriggerState, 'strategy.succeeded'>('strategy.succeeded', {
consumedItems: [],
})
).payload.consumedItems;
@@ -7,7 +7,7 @@ import {
existsDestNation,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -51,7 +51,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -75,7 +75,10 @@ export class ActionResolver<
readonly key = 'che_급습';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -177,7 +180,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -6,7 +6,7 @@ import {
occupiedCity,
occupiedDestCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -46,7 +46,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -70,7 +70,10 @@ export class ActionResolver<
readonly key = 'che_백성동원';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -154,7 +157,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -8,7 +8,7 @@ import {
notOccupiedDestCity,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -56,7 +56,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -86,7 +86,10 @@ export class ActionResolver<
readonly key = 'che_수몰';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -194,7 +197,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -14,7 +14,7 @@ import {
notOpeningPart,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -238,7 +238,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly env: VolunteerRecruitEnvironment;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: VolunteerRecruitEnvironment
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -272,7 +272,7 @@ export class ActionResolver<
private readonly command: CommandResolver<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: VolunteerRecruitEnvironment
) {
this.env = env;
@@ -461,7 +461,7 @@ export class ActionDefinition<
private readonly env: VolunteerRecruitEnvironment;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
env: VolunteerRecruitEnvironment
) {
this.env = env;
@@ -7,7 +7,7 @@ import {
existsDestNation,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -52,7 +52,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -76,7 +76,10 @@ export class ActionResolver<
readonly key = 'che_이호경식';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -184,7 +187,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -8,7 +8,7 @@ import {
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { allow, unknownOrDeny } from '@sammo-ts/logic/constraints/helpers.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -123,7 +123,7 @@ export class ActionResolver<
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined> = [],
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined> = [],
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -263,7 +263,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined> = [], initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined> = [],
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -6,7 +6,7 @@ import {
beChief,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -41,7 +41,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -65,7 +65,10 @@ export class ActionResolver<
readonly key = 'che_필사즉생';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -155,7 +158,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}
@@ -8,7 +8,7 @@ import {
notOccupiedDestCity,
occupiedCity,
} from '@sammo-ts/logic/constraints/presets.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
import { GeneralActionPipeline, type GeneralActionModule } from '@sammo-ts/logic/actionModules/general.js';
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
import type {
GeneralActionEffect,
@@ -72,7 +72,7 @@ export class CommandResolver<TriggerState extends GeneralTriggerState = GeneralT
private readonly pipeline: GeneralActionPipeline<TriggerState>;
constructor(
modules: Array<GeneralActionModule<TriggerState> | null | undefined>,
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
private readonly initialNationGenLimit = 10
) {
this.pipeline = new GeneralActionPipeline(modules);
@@ -96,7 +96,10 @@ export class ActionResolver<
readonly key = 'che_허보';
private readonly command: CommandResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.command = new CommandResolver(modules, initialNationGenLimit);
}
@@ -195,7 +198,10 @@ export class ActionDefinition<
public readonly name = ACTION_NAME;
private readonly resolver: ActionResolver<TriggerState>;
constructor(modules: Array<GeneralActionModule<TriggerState> | null | undefined>, initialNationGenLimit = 10) {
constructor(
modules: ReadonlyArray<GeneralActionModule<TriggerState> | null | undefined>,
initialNationGenLimit = 10
) {
this.resolver = new ActionResolver(modules, initialNationGenLimit);
}