feat: Introduce action context builders for various turn actions
- Added `actionContextBuilder` to multiple turn action files to utilize the default action context builder. - Implemented specific context builders for actions requiring additional context, such as war configurations, world summaries, and general statistics. - Created new `actionContext.ts` and `actionContextHelpers.ts` files to define interfaces and helper functions for managing action contexts. - Enhanced context handling for nation and general actions, ensuring proper data injection for turn execution.
This commit is contained in:
@@ -29,6 +29,8 @@ import type {
|
||||
import { createGeneralPatchEffect, createLogEffect } from '../../engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { ActionContextBuilder } from '../actionContext.js';
|
||||
import { resolveTurnTermMinutes } from '../actionContextHelpers.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
@@ -211,6 +213,30 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 대상 장수/도시 컨텍스트를 구성한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const destGeneralId = options.actionArgs.destGeneralId;
|
||||
const destCityId = options.actionArgs.destCityId;
|
||||
if (typeof destGeneralId !== 'number' || typeof destCityId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
const destGeneral = options.worldRef?.getGeneralById(destGeneralId);
|
||||
const destCity = options.worldRef?.getCityById(destCityId);
|
||||
if (!destGeneral || !destCity) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
destGeneral,
|
||||
destCity,
|
||||
currentYear: options.world.currentYear,
|
||||
currentMonth: options.world.currentMonth,
|
||||
turnTermMinutes: resolveTurnTermMinutes(options.world),
|
||||
generalTurnTime: base.general.turnTime,
|
||||
destGeneralTurnTime: destGeneral.turnTime,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_발령',
|
||||
category: '인사',
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
} from '../../engine.js';
|
||||
import { createLogEffect } from '../../engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import type { ActionContextBuilder } from '../actionContext.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
@@ -161,6 +162,13 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 날짜 정보를 제공한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => ({
|
||||
...base,
|
||||
currentYear: options.world.currentYear,
|
||||
currentMonth: options.world.currentMonth,
|
||||
});
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_불가침제의',
|
||||
category: '외교',
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
import { createLogEffect } from '../../engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '../actionContext.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
export interface NonAggressionCancelProposalArgs {
|
||||
@@ -86,6 +87,9 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행은 기본 컨텍스트만 사용한다.
|
||||
export const actionContextBuilder = defaultActionContextBuilder;
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_불가침파기제의',
|
||||
category: '외교',
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
import { createDiplomacyPatchEffect, createLogEffect } from '../../engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '../actionContext.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
export interface DeclareWarArgs {
|
||||
@@ -106,6 +107,9 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행은 기본 컨텍스트만 사용한다.
|
||||
export const actionContextBuilder = defaultActionContextBuilder;
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_선전포고',
|
||||
category: '외교',
|
||||
|
||||
@@ -32,6 +32,12 @@ import {
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import { buildRecruitmentGeneral } from '../general/recruitment.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { ActionContextBuilder } from '../actionContext.js';
|
||||
import {
|
||||
buildAverageNationGeneralCount,
|
||||
buildNationSummary,
|
||||
resolveStartYear,
|
||||
} from '../actionContextHelpers.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
@@ -419,6 +425,26 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 국가 평균 정보를 구성한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const nationSummary = buildNationSummary(
|
||||
options.worldRef,
|
||||
base.general.nationId
|
||||
);
|
||||
return {
|
||||
...base,
|
||||
currentYear: options.world.currentYear,
|
||||
startYear: resolveStartYear(options.world, options.scenarioMeta),
|
||||
averageNationGeneralCount: buildAverageNationGeneralCount(
|
||||
options.worldRef
|
||||
),
|
||||
nationAverageStats: nationSummary.averageStats,
|
||||
nationAverageExperience: nationSummary.averageExperience,
|
||||
nationAverageDedication: nationSummary.averageDedication,
|
||||
createGeneralId: options.createGeneralId,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_의병모집',
|
||||
category: '전략',
|
||||
|
||||
@@ -36,6 +36,7 @@ import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { ActionContextBuilder } from '../actionContext.js';
|
||||
|
||||
export interface AwardArgs {
|
||||
isGold: boolean;
|
||||
@@ -271,6 +272,22 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 대상 장수를 주입한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const destGeneralId = options.actionArgs.destGeneralId;
|
||||
if (typeof destGeneralId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
const destGeneral = options.worldRef?.getGeneralById(destGeneralId);
|
||||
if (!destGeneral) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
destGeneral,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_포상',
|
||||
category: '인사',
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '../actionContext.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
export interface NationRestArgs {}
|
||||
@@ -62,6 +63,9 @@ export class ActionDefinition<
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행은 기본 컨텍스트만 사용한다.
|
||||
export const actionContextBuilder = defaultActionContextBuilder;
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: '휴식',
|
||||
category: '휴식',
|
||||
|
||||
Reference in New Issue
Block a user