미구현 커맨드 추가
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
|
||||
import {
|
||||
allowDiplomacyBetweenStatus,
|
||||
beChief,
|
||||
destGeneralInDestNation,
|
||||
existsDestGeneral,
|
||||
existsDestNation,
|
||||
notBeNeutral,
|
||||
} from '@sammo-ts/logic/constraints/presets.js';
|
||||
import { allow, unknownOrDeny } from '@sammo-ts/logic/constraints/helpers.js';
|
||||
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
|
||||
import type { GeneralActionOutcome, GeneralActionResolveContext } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { createDiplomacyPatchEffect, createLogEffect } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
|
||||
export interface StopWarAcceptArgs {
|
||||
destNationId: number;
|
||||
destGeneralId: number;
|
||||
}
|
||||
|
||||
const ACTION_NAME = '종전 수락';
|
||||
const DIPLOMACY_NEUTRAL = 2;
|
||||
|
||||
const parseNationId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
return raw > 0 ? Math.floor(raw) : null;
|
||||
};
|
||||
|
||||
const parseGeneralId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
return raw > 0 ? Math.floor(raw) : null;
|
||||
};
|
||||
|
||||
const notSameDestGeneral = (): Constraint => ({
|
||||
name: 'NotSameDestGeneral',
|
||||
requires: () => [{ kind: 'arg', key: 'destGeneralId' }],
|
||||
test: (ctx) => {
|
||||
const destGeneralId = ctx.args.destGeneralId;
|
||||
if (typeof destGeneralId !== 'number') {
|
||||
return unknownOrDeny(ctx, [{ kind: 'arg', key: 'destGeneralId' }], '장수 정보가 없습니다.');
|
||||
}
|
||||
if (destGeneralId === ctx.actorId) {
|
||||
return { kind: 'deny', reason: '대상이 올바르지 않습니다.' };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
// 종전 수락은 메시지와 연결되는 즉시 국가 커맨드로 사용한다.
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, StopWarAcceptArgs> {
|
||||
public readonly key = 'che_종전수락';
|
||||
public readonly name = ACTION_NAME;
|
||||
|
||||
parseArgs(raw: unknown): StopWarAcceptArgs | null {
|
||||
const data = raw as { destNationId?: unknown; destGeneralId?: unknown };
|
||||
const destNationId = parseNationId(data?.destNationId);
|
||||
const destGeneralId = parseGeneralId(data?.destGeneralId);
|
||||
if (destNationId === null || destGeneralId === null) {
|
||||
return null;
|
||||
}
|
||||
return { destNationId, destGeneralId };
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, _args: StopWarAcceptArgs): Constraint[] {
|
||||
return [
|
||||
beChief(),
|
||||
notBeNeutral(),
|
||||
existsDestNation(),
|
||||
existsDestGeneral(),
|
||||
destGeneralInDestNation(),
|
||||
notSameDestGeneral(),
|
||||
allowDiplomacyBetweenStatus([0, 1], '상대국과 선포, 전쟁중이지 않습니다.'),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(
|
||||
context: GeneralActionResolveContext<TriggerState>,
|
||||
args: StopWarAcceptArgs
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
const nationId = context.nation?.id;
|
||||
if (nationId === undefined || nationId <= 0) {
|
||||
return {
|
||||
effects: [
|
||||
createLogEffect(`${ACTION_NAME}을 준비했지만 국가 정보가 없습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const nationName = context.nation?.name ?? `국가${nationId}`;
|
||||
const destNationName =
|
||||
(context as { destNation?: { name?: string } }).destNation?.name ?? `국가${args.destNationId}`;
|
||||
const generalName = context.general.name;
|
||||
const josaYiGeneral = JosaUtil.pick(generalName, '이');
|
||||
const josaYiNation = JosaUtil.pick(nationName, '이');
|
||||
const josaWa = JosaUtil.pick(destNationName, '와');
|
||||
|
||||
return {
|
||||
effects: [
|
||||
createDiplomacyPatchEffect(nationId, args.destNationId, {
|
||||
state: DIPLOMACY_NEUTRAL,
|
||||
term: 0,
|
||||
}),
|
||||
createDiplomacyPatchEffect(args.destNationId, nationId, {
|
||||
state: DIPLOMACY_NEUTRAL,
|
||||
term: 0,
|
||||
}),
|
||||
createLogEffect(`<D><b>${destNationName}</b></>${josaWa} 종전에 합의했습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.PLAIN,
|
||||
}),
|
||||
createLogEffect(`<D><b>${destNationName}</b></>${josaWa} 종전 수락`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
createLogEffect(
|
||||
`<Y>${generalName}</>${josaYiGeneral} <D><b>${destNationName}</b></>${josaWa} <M>종전 합의</> 하였습니다.`,
|
||||
{
|
||||
scope: LogScope.SYSTEM,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.PLAIN,
|
||||
}
|
||||
),
|
||||
createLogEffect(
|
||||
`<Y><b>【종전】</b></><D><b>${nationName}</b></>${josaYiNation} <D><b>${destNationName}</b></>${josaWa} <M>종전 합의</> 하였습니다.`,
|
||||
{
|
||||
scope: LogScope.SYSTEM,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}
|
||||
),
|
||||
createLogEffect(`<D><b>${destNationName}</b></>${josaWa} 종전`, {
|
||||
scope: LogScope.NATION,
|
||||
nationId,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
createLogEffect(`<D><b>${nationName}</b></>${josaWa} 종전에 성공했습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
generalId: args.destGeneralId,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.PLAIN,
|
||||
}),
|
||||
createLogEffect(`<D><b>${nationName}</b></>${josaWa} 종전 성공`, {
|
||||
scope: LogScope.GENERAL,
|
||||
generalId: args.destGeneralId,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
createLogEffect(`<D><b>${nationName}</b></>${josaWa} 종전`, {
|
||||
scope: LogScope.NATION,
|
||||
nationId: args.destNationId,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,3 +7,7 @@ export {
|
||||
ActionDefinition as NonAggressionCancelAcceptActionDefinition,
|
||||
type NonAggressionCancelAcceptArgs,
|
||||
} from './che_불가침파기수락.js';
|
||||
export {
|
||||
ActionDefinition as StopWarAcceptActionDefinition,
|
||||
type StopWarAcceptArgs,
|
||||
} from './che_종전수락.js';
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
|
||||
import {
|
||||
allowDiplomacyBetweenStatus,
|
||||
beChief,
|
||||
existsDestNation,
|
||||
notBeNeutral,
|
||||
occupiedCity,
|
||||
suppliedCity,
|
||||
} 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 { createLogEffect } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } 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 type { NationTurnCommandSpec } from './index.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
|
||||
export interface StopWarProposalArgs {
|
||||
destNationId: number;
|
||||
}
|
||||
|
||||
const ACTION_NAME = '종전 제의';
|
||||
|
||||
const parseNationId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
return raw > 0 ? Math.floor(raw) : null;
|
||||
};
|
||||
|
||||
// 종전 제의를 처리하는 국가 커맨드.
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, StopWarProposalArgs> {
|
||||
public readonly key = 'che_종전제의';
|
||||
public readonly name = ACTION_NAME;
|
||||
|
||||
parseArgs(raw: unknown): StopWarProposalArgs | null {
|
||||
const data = raw as { destNationId?: unknown };
|
||||
const destNationId = parseNationId(data?.destNationId);
|
||||
if (destNationId === null) {
|
||||
return null;
|
||||
}
|
||||
return { destNationId };
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, _args: StopWarProposalArgs): Constraint[] {
|
||||
return [
|
||||
beChief(),
|
||||
notBeNeutral(),
|
||||
occupiedCity(),
|
||||
suppliedCity(),
|
||||
existsDestNation(),
|
||||
allowDiplomacyBetweenStatus([0, 1], '선포, 전쟁중인 상대국에게만 가능합니다.'),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(
|
||||
_context: GeneralActionResolveContext<TriggerState>,
|
||||
args: StopWarProposalArgs
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
const destNationName =
|
||||
(_context as { destNation?: { name?: string } }).destNation?.name ?? `국가${args.destNationId}`;
|
||||
const josaRo = JosaUtil.pick(destNationName, '로');
|
||||
return {
|
||||
effects: [
|
||||
createLogEffect(`<D><b>${destNationName}</b></>${josaRo} 종전 제의 서신을 보냈습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행은 기본 컨텍스트만 사용한다.
|
||||
export const actionContextBuilder = defaultActionContextBuilder;
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_종전제의',
|
||||
category: '외교',
|
||||
reqArg: true,
|
||||
args: { destNationId: 0 },
|
||||
createDefinition: (_env: TurnCommandEnv) => new ActionDefinition(),
|
||||
};
|
||||
@@ -0,0 +1,277 @@
|
||||
import type { City, GeneralTriggerState, Nation, TriggerValue } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext, StateView } from '@sammo-ts/logic/constraints/types.js';
|
||||
import {
|
||||
beChief,
|
||||
disallowDiplomacyBetweenStatus,
|
||||
occupiedCity,
|
||||
occupiedDestCity,
|
||||
suppliedCity,
|
||||
suppliedDestCity,
|
||||
} from '@sammo-ts/logic/constraints/presets.js';
|
||||
import { allow, unknownOrDeny } from '@sammo-ts/logic/constraints/helpers.js';
|
||||
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
|
||||
import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
} from '@sammo-ts/logic/actions/engine.js';
|
||||
import { createCityPatchEffect, createLogEffect, createNationPatchEffect } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
export interface ScorchedEarthArgs {
|
||||
destCityId: number;
|
||||
}
|
||||
|
||||
export interface ScorchedEarthResolveContext<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> extends GeneralActionResolveContext<TriggerState> {
|
||||
destCity: City;
|
||||
destNation: Nation | null;
|
||||
}
|
||||
|
||||
const ACTION_NAME = '초토화';
|
||||
const PRE_REQ_TURN = 2;
|
||||
const POST_REQ_TURN = 24;
|
||||
|
||||
const parseCityId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
const value = Math.floor(raw);
|
||||
return value > 0 ? value : null;
|
||||
};
|
||||
|
||||
const requireNoDiplomacyLimit = (): Constraint => ({
|
||||
name: 'requireNoDiplomacyLimit',
|
||||
requires: (ctx) => (ctx.nationId !== undefined ? [{ kind: 'nation', id: ctx.nationId }] : []),
|
||||
test: (ctx: ConstraintContext, view: StateView) => {
|
||||
const nationId = ctx.nationId;
|
||||
if (nationId === undefined) {
|
||||
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
|
||||
}
|
||||
const nation = view.get({ kind: 'nation', id: nationId }) as Nation | null;
|
||||
if (!nation) {
|
||||
return unknownOrDeny(ctx, [{ kind: 'nation', id: nationId }], '국가 정보가 없습니다.');
|
||||
}
|
||||
const surlimit = typeof nation.meta?.surlimit === 'number' ? Number(nation.meta.surlimit) : 0;
|
||||
if (surlimit > 0) {
|
||||
return { kind: 'deny', reason: '외교제한 턴이 남아있습니다.' };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
const notCapitalCity = (destCityId: number): Constraint => ({
|
||||
name: 'notCapitalCity',
|
||||
requires: (ctx) => (ctx.nationId !== undefined ? [{ kind: 'nation', id: ctx.nationId }] : []),
|
||||
test: (ctx: ConstraintContext, view: StateView) => {
|
||||
const nationId = ctx.nationId;
|
||||
if (nationId === undefined) {
|
||||
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
|
||||
}
|
||||
const nation = view.get({ kind: 'nation', id: nationId }) as Nation | null;
|
||||
if (!nation) {
|
||||
return unknownOrDeny(ctx, [{ kind: 'nation', id: nationId }], '국가 정보가 없습니다.');
|
||||
}
|
||||
if (nation.capitalCityId === destCityId) {
|
||||
return { kind: 'deny', reason: '수도입니다.' };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
const calcReturnAmount = (destCity: City): number => {
|
||||
let amount = destCity.population / 5;
|
||||
const resourcePairs: Array<[number, number]> = [
|
||||
[destCity.agriculture, destCity.agricultureMax],
|
||||
[destCity.commerce, destCity.commerceMax],
|
||||
[destCity.security, destCity.securityMax],
|
||||
];
|
||||
for (const [current, max] of resourcePairs) {
|
||||
if (max <= 0) {
|
||||
continue;
|
||||
}
|
||||
amount *= (current - max * 0.5) / max + 0.8;
|
||||
}
|
||||
return Math.max(0, Math.floor(amount));
|
||||
};
|
||||
|
||||
const calcReducedValue = (current: number, max: number, ratio: number): number => {
|
||||
if (max <= 0) {
|
||||
return Math.max(0, Math.floor(current * ratio));
|
||||
}
|
||||
return Math.max(Math.floor(max * 0.1), Math.floor(current * ratio));
|
||||
};
|
||||
|
||||
// 초토화 실행을 위한 정의/제약을 구성한다.
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, ScorchedEarthArgs, ScorchedEarthResolveContext<TriggerState>> {
|
||||
public readonly key = 'che_초토화';
|
||||
public readonly name = ACTION_NAME;
|
||||
|
||||
parseArgs(raw: unknown): ScorchedEarthArgs | null {
|
||||
const data = raw as { destCityId?: unknown };
|
||||
const destCityId = parseCityId(data?.destCityId);
|
||||
if (destCityId === null) {
|
||||
return null;
|
||||
}
|
||||
return { destCityId };
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, args: ScorchedEarthArgs): Constraint[] {
|
||||
void _ctx;
|
||||
return [
|
||||
occupiedCity(),
|
||||
occupiedDestCity(),
|
||||
beChief(),
|
||||
suppliedCity(),
|
||||
suppliedDestCity(),
|
||||
notCapitalCity(args.destCityId),
|
||||
requireNoDiplomacyLimit(),
|
||||
disallowDiplomacyBetweenStatus({
|
||||
0: '평시에만 가능합니다.',
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(
|
||||
context: ScorchedEarthResolveContext<TriggerState>,
|
||||
_args: ScorchedEarthArgs
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
void _args;
|
||||
const { general, nation, destCity } = context;
|
||||
if (!nation) {
|
||||
return { effects: [createLogEffect('국가 정보가 없습니다.', { scope: LogScope.GENERAL })] };
|
||||
}
|
||||
|
||||
const generalName = general.name;
|
||||
const nationName = nation.name;
|
||||
const destCityName = destCity.name;
|
||||
const josaUl = JosaUtil.pick(destCityName, '을');
|
||||
const josaYi = JosaUtil.pick(generalName, '이');
|
||||
const josaYiNation = JosaUtil.pick(nationName, '이');
|
||||
|
||||
const rewardAmount = calcReturnAmount(destCity);
|
||||
const nextSurlimit = Number(nation.meta.surlimit ?? 0) + POST_REQ_TURN;
|
||||
const nextAux: Record<string, TriggerValue> = {
|
||||
...nation.meta,
|
||||
surlimit: nextSurlimit,
|
||||
};
|
||||
|
||||
if (destCity.level >= 8) {
|
||||
const current = typeof nation.meta.did_특성초토화 === 'number' ? Number(nation.meta.did_특성초토화) : 0;
|
||||
nextAux.did_특성초토화 = current + 1;
|
||||
}
|
||||
|
||||
const reducedPopulation = calcReducedValue(destCity.population, destCity.populationMax, 0.2);
|
||||
const reducedAgri = calcReducedValue(destCity.agriculture, destCity.agricultureMax, 0.2);
|
||||
const reducedComm = calcReducedValue(destCity.commerce, destCity.commerceMax, 0.2);
|
||||
const reducedSecu = calcReducedValue(destCity.security, destCity.securityMax, 0.2);
|
||||
const reducedDef = calcReducedValue(destCity.defence, destCity.defenceMax, 0.2);
|
||||
const reducedWall = Math.max(Math.floor(destCity.wallMax * 0.1), Math.floor(destCity.wall * 0.5));
|
||||
const trust = typeof destCity.meta?.trust === 'number' ? Number(destCity.meta.trust) : 0;
|
||||
|
||||
const expGain = 5 * (PRE_REQ_TURN + 1);
|
||||
general.experience = Math.max(0, Math.floor(general.experience * 0.9)) + expGain;
|
||||
general.dedication += expGain;
|
||||
|
||||
const effects: Array<GeneralActionEffect<TriggerState>> = [
|
||||
createCityPatchEffect(
|
||||
{
|
||||
nationId: 0,
|
||||
frontState: 0,
|
||||
population: reducedPopulation,
|
||||
agriculture: reducedAgri,
|
||||
commerce: reducedComm,
|
||||
security: reducedSecu,
|
||||
defence: reducedDef,
|
||||
wall: reducedWall,
|
||||
meta: {
|
||||
...destCity.meta,
|
||||
trust: Math.max(50, trust),
|
||||
},
|
||||
},
|
||||
destCity.id
|
||||
),
|
||||
createNationPatchEffect(
|
||||
{
|
||||
gold: nation.gold + rewardAmount,
|
||||
rice: nation.rice + rewardAmount,
|
||||
meta: nextAux,
|
||||
},
|
||||
nation.id
|
||||
),
|
||||
createLogEffect(`<G><b>${destCityName}</b></>${josaUl} ${ACTION_NAME}했습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
createLogEffect(`<G><b>${destCityName}</b></>${josaUl} <M>${ACTION_NAME}</> 명령`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
createLogEffect(
|
||||
`<Y>${generalName}</>${josaYi} <G><b>${destCityName}</b></>${josaUl} <M>${ACTION_NAME}</> 명령`,
|
||||
{
|
||||
scope: LogScope.NATION,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}
|
||||
),
|
||||
createLogEffect(
|
||||
`<Y>${generalName}</>${josaYi} <G><b>${destCityName}</b></>${josaUl} <M>${ACTION_NAME}</>하였습니다.`,
|
||||
{
|
||||
scope: LogScope.SYSTEM,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.PLAIN,
|
||||
}
|
||||
),
|
||||
createLogEffect(
|
||||
`<S><b>【${ACTION_NAME}】</b></><D><b>${nationName}</b></>${josaYiNation} <G><b>${destCityName}</b></>${josaUl} <M>${ACTION_NAME}</>하였습니다.`,
|
||||
{
|
||||
scope: LogScope.SYSTEM,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}
|
||||
),
|
||||
];
|
||||
|
||||
return { effects };
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 대상 도시 정보를 구성한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const destCityId = options.actionArgs.destCityId;
|
||||
if (typeof destCityId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
const worldRef = options.worldRef;
|
||||
if (!worldRef) {
|
||||
return null;
|
||||
}
|
||||
const destCity = worldRef.getCityById(destCityId);
|
||||
if (!destCity) {
|
||||
return null;
|
||||
}
|
||||
const destNation = worldRef.getNationById(destCity.nationId);
|
||||
return {
|
||||
...base,
|
||||
destCity,
|
||||
destNation: destNation ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_초토화',
|
||||
category: '특수',
|
||||
reqArg: true,
|
||||
args: { destCityId: 0 },
|
||||
createDefinition: (_env: TurnCommandEnv) => new ActionDefinition(),
|
||||
};
|
||||
@@ -0,0 +1,270 @@
|
||||
import type { General, GeneralTriggerState, Nation } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
|
||||
import {
|
||||
allowDiplomacyBetweenStatus,
|
||||
availableStrategicCommand,
|
||||
beChief,
|
||||
existsDestNation,
|
||||
occupiedCity,
|
||||
} from '@sammo-ts/logic/constraints/presets.js';
|
||||
import { allow, unknownOrDeny } from '@sammo-ts/logic/constraints/helpers.js';
|
||||
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
|
||||
import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '@sammo-ts/logic/actions/engine.js';
|
||||
import { createLogEffect } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
|
||||
export interface CounterStrategyArgs {
|
||||
destNationId: number;
|
||||
commandType: string;
|
||||
}
|
||||
|
||||
export interface CounterStrategyResolveContext<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> extends GeneralActionResolveContext<TriggerState> {
|
||||
destNation: Nation;
|
||||
friendlyGenerals: Array<General<TriggerState>>;
|
||||
destNationGenerals: Array<General<TriggerState>>;
|
||||
}
|
||||
|
||||
const ACTION_NAME = '피장파장';
|
||||
const DEFAULT_GLOBAL_DELAY = 8;
|
||||
const PRE_REQ_TURN = 1;
|
||||
const EXP_DED_GAIN = 5 * (PRE_REQ_TURN + 1);
|
||||
|
||||
const STRATEGIC_COMMANDS: Record<string, string> = {
|
||||
che_필사즉생: '필사즉생',
|
||||
che_백성동원: '백성동원',
|
||||
che_수몰: '수몰',
|
||||
che_허보: '허보',
|
||||
che_의병모집: '의병모집',
|
||||
che_이호경식: '이호경식',
|
||||
che_급습: '급습',
|
||||
che_피장파장: '피장파장',
|
||||
};
|
||||
|
||||
const parseNationId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
const value = Math.floor(raw);
|
||||
return value > 0 ? value : null;
|
||||
};
|
||||
|
||||
const parseCommandType = (raw: unknown): string | null => {
|
||||
if (typeof raw !== 'string') {
|
||||
return null;
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(STRATEGIC_COMMANDS, raw)) {
|
||||
return null;
|
||||
}
|
||||
if (raw === 'che_피장파장') {
|
||||
return null;
|
||||
}
|
||||
return raw;
|
||||
};
|
||||
|
||||
const requireCommandType = (): Constraint => ({
|
||||
name: 'requireStrategicCommandType',
|
||||
requires: () => [{ kind: 'arg', key: 'commandType' }],
|
||||
test: (ctx) => {
|
||||
const commandType = ctx.args.commandType;
|
||||
if (typeof commandType !== 'string') {
|
||||
return unknownOrDeny(ctx, [{ kind: 'arg', key: 'commandType' }], '전략 정보가 없습니다.');
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(STRATEGIC_COMMANDS, commandType)) {
|
||||
return { kind: 'deny', reason: '전략 정보가 올바르지 않습니다.' };
|
||||
}
|
||||
if (commandType === 'che_피장파장') {
|
||||
return { kind: 'deny', reason: '같은 전략은 선택할 수 없습니다.' };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
// 피장파장 실행 결과를 계산한다.
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionResolver<TriggerState, CounterStrategyArgs> {
|
||||
readonly key = 'che_피장파장';
|
||||
|
||||
resolve(
|
||||
context: CounterStrategyResolveContext<TriggerState>,
|
||||
args: CounterStrategyArgs
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
const { general, nation, destNation } = context;
|
||||
const generalName = general.name;
|
||||
const generalJosa = JosaUtil.pick(generalName, '이');
|
||||
const nationName = nation?.name ?? '아국';
|
||||
const destNationName = destNation.name;
|
||||
const targetCommandName = STRATEGIC_COMMANDS[args.commandType] ?? args.commandType;
|
||||
const actionJosa = JosaUtil.pick(ACTION_NAME, '을');
|
||||
|
||||
general.experience += EXP_DED_GAIN;
|
||||
general.dedication += EXP_DED_GAIN;
|
||||
|
||||
context.addLog(`<G><b>${targetCommandName}</b></> 전략의 ${ACTION_NAME} 발동!`, {
|
||||
format: LogFormat.MONTH,
|
||||
});
|
||||
context.addLog(
|
||||
`<D><b>${destNationName}</b></>에 <G><b>${targetCommandName}</b></> <M>${ACTION_NAME}</>${actionJosa} 발동`,
|
||||
{
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}
|
||||
);
|
||||
|
||||
const effects: Array<GeneralActionEffect<TriggerState>> = [];
|
||||
const broadcastMessage = `<Y>${generalName}</>${generalJosa} <G><b>${destNationName}</b></>에 <G><b>${targetCommandName}</b></> 전략의 <M>${ACTION_NAME}</>${actionJosa} 발동하였습니다.`;
|
||||
const destBroadcastMessage = `아국에 <G><b>${targetCommandName}</b></> 전략의 <M>${ACTION_NAME}</>${JosaUtil.pick(
|
||||
ACTION_NAME,
|
||||
'이'
|
||||
)} 발동되었습니다.`;
|
||||
|
||||
for (const target of context.friendlyGenerals) {
|
||||
if (target.id === general.id) {
|
||||
continue;
|
||||
}
|
||||
effects.push(
|
||||
createLogEffect(broadcastMessage, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
generalId: target.id,
|
||||
format: LogFormat.PLAIN,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
for (const target of context.destNationGenerals) {
|
||||
effects.push(
|
||||
createLogEffect(destBroadcastMessage, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
generalId: target.id,
|
||||
format: LogFormat.PLAIN,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (nation) {
|
||||
const globalDelay = DEFAULT_GLOBAL_DELAY;
|
||||
nation.meta = {
|
||||
...(nation.meta as object),
|
||||
strategic_cmd_limit: globalDelay,
|
||||
};
|
||||
effects.push(
|
||||
createLogEffect(broadcastMessage, {
|
||||
scope: LogScope.NATION,
|
||||
category: LogCategory.HISTORY,
|
||||
nationId: nation.id,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
effects.push(
|
||||
createLogEffect(
|
||||
`<D><b>${nationName}</b></>의 <Y>${generalName}</>${generalJosa} 아국에 <G><b>${targetCommandName}</b></> <M>${ACTION_NAME}</>${actionJosa} 발동`,
|
||||
{
|
||||
scope: LogScope.NATION,
|
||||
category: LogCategory.HISTORY,
|
||||
nationId: destNation.id,
|
||||
format: LogFormat.PLAIN,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if (nation?.id !== undefined) {
|
||||
effects.push(
|
||||
createLogEffect(
|
||||
`<Y>${generalName}</>${generalJosa} <D><b>${destNationName}</b></>에 <G><b>${targetCommandName}</b></> <M>${ACTION_NAME}</>${actionJosa} 발동`,
|
||||
{
|
||||
scope: LogScope.NATION,
|
||||
category: LogCategory.HISTORY,
|
||||
nationId: nation.id,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return { effects };
|
||||
}
|
||||
}
|
||||
|
||||
// 피장파장 실행을 위한 정의/제약을 구성한다.
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, CounterStrategyArgs, CounterStrategyResolveContext<TriggerState>> {
|
||||
public readonly key = 'che_피장파장';
|
||||
public readonly name = ACTION_NAME;
|
||||
private readonly resolver = new ActionResolver<TriggerState>();
|
||||
|
||||
parseArgs(raw: unknown): CounterStrategyArgs | null {
|
||||
const data = raw as { destNationId?: unknown; commandType?: unknown };
|
||||
const destNationId = parseNationId(data?.destNationId);
|
||||
const commandType = parseCommandType(data?.commandType);
|
||||
if (destNationId === null || commandType === null) {
|
||||
return null;
|
||||
}
|
||||
return { destNationId, commandType };
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, _args: CounterStrategyArgs): Constraint[] {
|
||||
void _ctx;
|
||||
void _args;
|
||||
return [
|
||||
occupiedCity(),
|
||||
beChief(),
|
||||
existsDestNation(),
|
||||
allowDiplomacyBetweenStatus([0, 1], '선포, 전쟁중인 상대국에게만 가능합니다.'),
|
||||
availableStrategicCommand(),
|
||||
requireCommandType(),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(context: CounterStrategyResolveContext<TriggerState>, args: CounterStrategyArgs): GeneralActionOutcome<TriggerState> {
|
||||
return this.resolver.resolve(context, args);
|
||||
}
|
||||
}
|
||||
|
||||
// 예약 턴 실행에 필요한 대상 국가/장수 정보를 구성한다.
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const destNationId = options.actionArgs.destNationId;
|
||||
if (typeof destNationId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
const worldRef = options.worldRef;
|
||||
if (!worldRef) {
|
||||
return null;
|
||||
}
|
||||
const destNation = worldRef.getNationById(destNationId);
|
||||
if (!destNation) {
|
||||
return null;
|
||||
}
|
||||
const generals = worldRef.listGenerals();
|
||||
const friendlyGenerals = generals.filter((general) => general.nationId === base.general.nationId);
|
||||
const destNationGenerals = generals.filter((general) => general.nationId === destNationId);
|
||||
return {
|
||||
...base,
|
||||
destNation,
|
||||
friendlyGenerals,
|
||||
destNationGenerals,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'che_피장파장',
|
||||
category: '전략',
|
||||
reqArg: true,
|
||||
args: { destNationId: 0, commandType: '' },
|
||||
createDefinition: (_env: TurnCommandEnv) => new ActionDefinition(),
|
||||
};
|
||||
@@ -0,0 +1,189 @@
|
||||
import type { City, GeneralTriggerState, Nation } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext } from '@sammo-ts/logic/constraints/types.js';
|
||||
import {
|
||||
beChief,
|
||||
nearCity,
|
||||
notSameDestCity,
|
||||
occupiedCity,
|
||||
occupiedDestCity,
|
||||
reqCityCapacity,
|
||||
reqNationGold,
|
||||
reqNationRice,
|
||||
suppliedCity,
|
||||
suppliedDestCity,
|
||||
} from '@sammo-ts/logic/constraints/presets.js';
|
||||
import type { GeneralActionDefinition } from '@sammo-ts/logic/actions/definition.js';
|
||||
import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
} from '@sammo-ts/logic/actions/engine.js';
|
||||
import { createCityPatchEffect, createLogEffect, 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 type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface PopulationMoveArgs {
|
||||
destCityId: number;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export interface PopulationMoveResolveContext<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> extends GeneralActionResolveContext<TriggerState> {
|
||||
destCity: City;
|
||||
destNation: Nation | null;
|
||||
}
|
||||
|
||||
const ACTION_NAME = '인구이동';
|
||||
const AMOUNT_LIMIT = 100000;
|
||||
const MIN_AVAILABLE_RECRUIT_POP = 30000;
|
||||
|
||||
const parseCityId = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
const value = Math.floor(raw);
|
||||
return value > 0 ? value : null;
|
||||
};
|
||||
|
||||
const parseAmount = (raw: unknown): number | null => {
|
||||
if (typeof raw !== 'number' || !Number.isFinite(raw)) {
|
||||
return null;
|
||||
}
|
||||
const value = Math.floor(raw);
|
||||
if (value < 0) {
|
||||
return null;
|
||||
}
|
||||
return clamp(value, 0, AMOUNT_LIMIT);
|
||||
};
|
||||
|
||||
const calcCost = (develCost: number, amount: number): number => Math.round((develCost * amount) / 10000);
|
||||
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, PopulationMoveArgs, PopulationMoveResolveContext<TriggerState>> {
|
||||
public readonly key = 'cr_인구이동';
|
||||
public readonly name = ACTION_NAME;
|
||||
|
||||
constructor(private readonly env: TurnCommandEnv) {}
|
||||
|
||||
parseArgs(raw: unknown): PopulationMoveArgs | null {
|
||||
const data = raw as { destCityId?: unknown; amount?: unknown };
|
||||
const destCityId = parseCityId(data?.destCityId);
|
||||
const amount = parseAmount(data?.amount);
|
||||
if (destCityId === null || amount === null) {
|
||||
return null;
|
||||
}
|
||||
return { destCityId, amount };
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, args: PopulationMoveArgs): Constraint[] {
|
||||
const cost = calcCost(this.env.develCost, args.amount);
|
||||
return [
|
||||
notSameDestCity(),
|
||||
occupiedCity(),
|
||||
reqCityCapacity('population', '주민', MIN_AVAILABLE_RECRUIT_POP + 100),
|
||||
occupiedDestCity(),
|
||||
nearCity(1),
|
||||
beChief(),
|
||||
suppliedCity(),
|
||||
suppliedDestCity(),
|
||||
reqNationGold(() => this.env.baseGold + cost),
|
||||
reqNationRice(() => this.env.baseRice + cost),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(
|
||||
context: PopulationMoveResolveContext<TriggerState>,
|
||||
args: PopulationMoveArgs
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
const { general, nation, city, destCity } = context;
|
||||
if (!nation || !city) {
|
||||
return { effects: [createLogEffect('국가 정보가 없습니다.', { scope: LogScope.GENERAL })] };
|
||||
}
|
||||
|
||||
const available = Math.max(0, city.population - MIN_AVAILABLE_RECRUIT_POP);
|
||||
const amount = clamp(args.amount, 0, available);
|
||||
if (amount <= 0) {
|
||||
return {
|
||||
effects: [
|
||||
createLogEffect('이동할 인구가 부족합니다.', {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const cost = calcCost(this.env.develCost, amount);
|
||||
const amountText = amount.toLocaleString();
|
||||
const destCityName = destCity.name;
|
||||
const josaRo = JosaUtil.pick(destCityName, '로');
|
||||
|
||||
general.experience += 5;
|
||||
general.dedication += 5;
|
||||
|
||||
const effects: Array<GeneralActionEffect<TriggerState>> = [
|
||||
createCityPatchEffect(
|
||||
{
|
||||
population: destCity.population + amount,
|
||||
},
|
||||
destCity.id
|
||||
),
|
||||
createCityPatchEffect(
|
||||
{
|
||||
population: city.population - amount,
|
||||
},
|
||||
city.id
|
||||
),
|
||||
createNationPatchEffect(
|
||||
{
|
||||
gold: nation.gold - cost,
|
||||
rice: nation.rice - cost,
|
||||
},
|
||||
nation.id
|
||||
),
|
||||
createLogEffect(`<G><b>${destCityName}</b></>${josaRo} 인구 <C>${amountText}</>명을 옮겼습니다.`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
];
|
||||
|
||||
return { effects };
|
||||
}
|
||||
}
|
||||
|
||||
export const actionContextBuilder: ActionContextBuilder = (base, options) => {
|
||||
const destCityId = options.actionArgs.destCityId;
|
||||
if (typeof destCityId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
const worldRef = options.worldRef;
|
||||
if (!worldRef) {
|
||||
return null;
|
||||
}
|
||||
const destCity = worldRef.getCityById(destCityId);
|
||||
if (!destCity) {
|
||||
return null;
|
||||
}
|
||||
const destNation = worldRef.getNationById(destCity.nationId);
|
||||
return {
|
||||
...base,
|
||||
destCity,
|
||||
destNation: destNation ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
export const commandSpec: NationTurnCommandSpec = {
|
||||
key: 'cr_인구이동',
|
||||
category: '특수',
|
||||
reqArg: true,
|
||||
args: { destCityId: 0, amount: 0 },
|
||||
createDefinition: (env: TurnCommandEnv) => new ActionDefinition(env),
|
||||
};
|
||||
@@ -0,0 +1,154 @@
|
||||
import type { GeneralTriggerState, Nation } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { Constraint, ConstraintContext, StateView } from '@sammo-ts/logic/constraints/types.js';
|
||||
import { allow, unknownOrDeny } from '@sammo-ts/logic/constraints/helpers.js';
|
||||
import { beChief, occupiedCity, reqNationGold, reqNationRice } 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 { createLogEffect, createNationPatchEffect } from '@sammo-ts/logic/actions/engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
|
||||
export interface EventResearchConfig {
|
||||
key: string;
|
||||
name: string;
|
||||
auxKey: string;
|
||||
preReqTurn: number;
|
||||
cost: number;
|
||||
category?: string;
|
||||
}
|
||||
|
||||
const requireNationAux = (auxKey: string, actionName: string): Constraint => ({
|
||||
name: 'requireNationAux',
|
||||
requires: (ctx) => (ctx.nationId !== undefined ? [{ kind: 'nation', id: ctx.nationId }] : []),
|
||||
test: (ctx: ConstraintContext, view: StateView) => {
|
||||
if (ctx.nationId === undefined) {
|
||||
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
|
||||
}
|
||||
const nation = view.get({ kind: 'nation', id: ctx.nationId }) as Nation | null;
|
||||
if (!nation) {
|
||||
return unknownOrDeny(ctx, [{ kind: 'nation', id: ctx.nationId }], '국가 정보가 없습니다.');
|
||||
}
|
||||
const current = typeof nation.meta?.[auxKey] === 'number' ? Number(nation.meta?.[auxKey]) : 0;
|
||||
if (current >= 1) {
|
||||
return { kind: 'deny', reason: `${actionName}가 이미 완료되었습니다.` };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
export const createEventResearchCommand = (config: EventResearchConfig): {
|
||||
ActionDefinition: new <TriggerState extends GeneralTriggerState = GeneralTriggerState>(
|
||||
env: TurnCommandEnv
|
||||
) => GeneralActionDefinition<TriggerState, Record<string, never>>;
|
||||
commandSpec: NationTurnCommandSpec;
|
||||
actionContextBuilder: ActionContextBuilder;
|
||||
} => {
|
||||
const ACTION_NAME = config.name;
|
||||
const COST = config.cost;
|
||||
const PRE_REQ_TURN = config.preReqTurn;
|
||||
const EXP_DED_GAIN = 5 * (PRE_REQ_TURN + 1);
|
||||
const CATEGORY = config.category ?? '특수';
|
||||
|
||||
class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState,
|
||||
> implements GeneralActionDefinition<TriggerState, Record<string, never>> {
|
||||
public readonly key = config.key;
|
||||
public readonly name = ACTION_NAME;
|
||||
|
||||
constructor(private readonly env: TurnCommandEnv) {}
|
||||
|
||||
parseArgs(_raw: unknown): Record<string, never> | null {
|
||||
void _raw;
|
||||
return {};
|
||||
}
|
||||
|
||||
buildConstraints(_ctx: ConstraintContext, _args: Record<string, never>): Constraint[] {
|
||||
void _ctx;
|
||||
void _args;
|
||||
return [
|
||||
occupiedCity(),
|
||||
beChief(),
|
||||
requireNationAux(config.auxKey, ACTION_NAME),
|
||||
reqNationGold(() => this.env.baseGold + COST),
|
||||
reqNationRice(() => this.env.baseRice + COST),
|
||||
];
|
||||
}
|
||||
|
||||
resolve(
|
||||
context: GeneralActionResolveContext<TriggerState>,
|
||||
_args: Record<string, never>
|
||||
): GeneralActionOutcome<TriggerState> {
|
||||
void _args;
|
||||
const { general, nation } = context;
|
||||
if (!nation) {
|
||||
return {
|
||||
effects: [
|
||||
createLogEffect('국가 정보가 없습니다.', {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
general.experience += EXP_DED_GAIN;
|
||||
general.dedication += EXP_DED_GAIN;
|
||||
|
||||
const generalName = general.name;
|
||||
const josaYi = JosaUtil.pick(generalName, '이');
|
||||
|
||||
return {
|
||||
effects: [
|
||||
createNationPatchEffect(
|
||||
{
|
||||
gold: nation.gold - COST,
|
||||
rice: nation.rice - COST,
|
||||
meta: {
|
||||
...nation.meta,
|
||||
[config.auxKey]: 1,
|
||||
},
|
||||
},
|
||||
nation.id
|
||||
),
|
||||
createLogEffect(`<M>${ACTION_NAME}</> 완료`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.ACTION,
|
||||
format: LogFormat.MONTH,
|
||||
}),
|
||||
createLogEffect(`<M>${ACTION_NAME}</> 완료`, {
|
||||
scope: LogScope.GENERAL,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
createLogEffect(`<Y>${generalName}</>${josaYi} <M>${ACTION_NAME}</> 완료`, {
|
||||
scope: LogScope.NATION,
|
||||
category: LogCategory.HISTORY,
|
||||
format: LogFormat.YEAR_MONTH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const commandSpec: NationTurnCommandSpec = {
|
||||
key: config.key as NationTurnCommandSpec['key'],
|
||||
category: CATEGORY,
|
||||
reqArg: false,
|
||||
args: {},
|
||||
createDefinition: (env: TurnCommandEnv) => new ActionDefinition(env),
|
||||
};
|
||||
|
||||
return {
|
||||
ActionDefinition,
|
||||
commandSpec,
|
||||
actionContextBuilder: defaultActionContextBuilder,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_극병연구',
|
||||
name: '극병 연구',
|
||||
auxKey: 'can_극병사용',
|
||||
preReqTurn: 23,
|
||||
cost: 100000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_대검병연구',
|
||||
name: '대검병 연구',
|
||||
auxKey: 'can_대검병사용',
|
||||
preReqTurn: 11,
|
||||
cost: 50000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_무희연구',
|
||||
name: '무희 연구',
|
||||
auxKey: 'can_무희사용',
|
||||
preReqTurn: 23,
|
||||
cost: 100000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_산저병연구',
|
||||
name: '산저병 연구',
|
||||
auxKey: 'can_산저병사용',
|
||||
preReqTurn: 11,
|
||||
cost: 50000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_상병연구',
|
||||
name: '상병 연구',
|
||||
auxKey: 'can_상병사용',
|
||||
preReqTurn: 23,
|
||||
cost: 100000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_원융노병연구',
|
||||
name: '원융노병 연구',
|
||||
auxKey: 'can_원융노병사용',
|
||||
preReqTurn: 23,
|
||||
cost: 100000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_음귀병연구',
|
||||
name: '음귀병 연구',
|
||||
auxKey: 'can_음귀병사용',
|
||||
preReqTurn: 11,
|
||||
cost: 50000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_화륜차연구',
|
||||
name: '화륜차 연구',
|
||||
auxKey: 'can_화륜차사용',
|
||||
preReqTurn: 23,
|
||||
cost: 100000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createEventResearchCommand } from './eventResearch.js';
|
||||
|
||||
const { ActionDefinition, commandSpec, actionContextBuilder } = createEventResearchCommand({
|
||||
key: 'event_화시병연구',
|
||||
name: '화시병 연구',
|
||||
auxKey: 'can_화시병사용',
|
||||
preReqTurn: 11,
|
||||
cost: 50000,
|
||||
});
|
||||
|
||||
export { ActionDefinition, commandSpec, actionContextBuilder };
|
||||
@@ -6,6 +6,7 @@ export const NATION_TURN_COMMAND_KEYS = [
|
||||
'che_부대탈퇴지시',
|
||||
'che_발령',
|
||||
'che_선전포고',
|
||||
'che_종전제의',
|
||||
'che_불가침제의',
|
||||
'che_불가침파기제의',
|
||||
'che_의병모집',
|
||||
@@ -15,14 +16,26 @@ export const NATION_TURN_COMMAND_KEYS = [
|
||||
'che_이호경식',
|
||||
'che_수몰',
|
||||
'che_급습',
|
||||
'che_피장파장',
|
||||
'che_초토화',
|
||||
'che_천도',
|
||||
'che_국호변경',
|
||||
'che_무작위수도이전',
|
||||
'che_국기변경',
|
||||
'che_증축',
|
||||
'che_감축',
|
||||
'cr_인구이동',
|
||||
'che_몰수',
|
||||
'che_물자원조',
|
||||
'event_원융노병연구',
|
||||
'event_화시병연구',
|
||||
'event_음귀병연구',
|
||||
'event_대검병연구',
|
||||
'event_화륜차연구',
|
||||
'event_산저병연구',
|
||||
'event_극병연구',
|
||||
'event_상병연구',
|
||||
'event_무희연구',
|
||||
] as const;
|
||||
|
||||
export type NationTurnCommandKey = (typeof NATION_TURN_COMMAND_KEYS)[number];
|
||||
@@ -39,6 +52,7 @@ const defaultImporters: Record<NationTurnCommandKey, NationTurnCommandImporter>
|
||||
che_부대탈퇴지시: async () => import('./che_부대탈퇴지시.js'),
|
||||
che_발령: async () => import('./che_발령.js'),
|
||||
che_선전포고: async () => import('./che_선전포고.js'),
|
||||
che_종전제의: async () => import('./che_종전제의.js'),
|
||||
che_불가침제의: async () => import('./che_불가침제의.js'),
|
||||
che_불가침파기제의: async () => import('./che_불가침파기제의.js'),
|
||||
che_의병모집: async () => import('./che_의병모집.js'),
|
||||
@@ -48,14 +62,26 @@ const defaultImporters: Record<NationTurnCommandKey, NationTurnCommandImporter>
|
||||
che_이호경식: async () => import('./che_이호경식.js'),
|
||||
che_수몰: async () => import('./che_수몰.js'),
|
||||
che_급습: async () => import('./che_급습.js'),
|
||||
che_피장파장: async () => import('./che_피장파장.js'),
|
||||
che_초토화: async () => import('./che_초토화.js'),
|
||||
che_천도: async () => import('./che_천도.js'),
|
||||
che_국호변경: async () => import('./che_국호변경.js'),
|
||||
che_무작위수도이전: async () => import('./che_무작위수도이전.js'),
|
||||
che_국기변경: async () => import('./che_국기변경.js'),
|
||||
che_증축: async () => import('./che_증축.js'),
|
||||
che_감축: async () => import('./che_감축.js'),
|
||||
cr_인구이동: async () => import('./cr_인구이동.js'),
|
||||
che_몰수: async () => import('./che_몰수.js'),
|
||||
che_물자원조: async () => import('./che_물자원조.js'),
|
||||
event_원융노병연구: async () => import('./event_원융노병연구.js'),
|
||||
event_화시병연구: async () => import('./event_화시병연구.js'),
|
||||
event_음귀병연구: async () => import('./event_음귀병연구.js'),
|
||||
event_대검병연구: async () => import('./event_대검병연구.js'),
|
||||
event_화륜차연구: async () => import('./event_화륜차연구.js'),
|
||||
event_산저병연구: async () => import('./event_산저병연구.js'),
|
||||
event_극병연구: async () => import('./event_극병연구.js'),
|
||||
event_상병연구: async () => import('./event_상병연구.js'),
|
||||
event_무희연구: async () => import('./event_무희연구.js'),
|
||||
};
|
||||
|
||||
export const isNationTurnCommandKey = (value: string): value is NationTurnCommandKey =>
|
||||
|
||||
Reference in New Issue
Block a user