fix(turn): preserve seizure NPC public messages

This commit is contained in:
2026-07-26 06:06:07 +00:00
parent 3b2b83addd
commit b7b1785b8c
6 changed files with 113 additions and 1 deletions
@@ -53,6 +53,7 @@ export interface TurnCommandEnv {
baseRice: number;
generalMinimumGold?: number;
generalMinimumRice?: number;
npcSeizureMessageProb?: number;
maxResourceActionAmount: number;
itemCatalog?: Record<string, TurnCommandItemCatalogEntry>;
generalActionModules?: Array<GeneralActionModule>;
@@ -15,7 +15,12 @@ import type {
GeneralActionOutcome,
GeneralActionResolveContext,
} from '@sammo-ts/logic/actions/engine.js';
import { createLogEffect, createNationPatchEffect, createGeneralPatchEffect } from '@sammo-ts/logic/actions/engine.js';
import {
createGeneralPatchEffect,
createLogEffect,
createMessageEffect,
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';
@@ -37,9 +42,40 @@ export interface SeizureResolveContext<
TriggerState extends GeneralTriggerState = GeneralTriggerState,
> extends GeneralActionResolveContext<TriggerState> {
destGeneral: General<TriggerState>;
messageTime: Date;
}
const ACTION_NAME = '몰수';
const NPC_SEIZURE_MESSAGE_PROB = 0.01;
const NPC_SEIZURE_MESSAGES = [
'몰수를 하다니... 이것이 윗사람이 할 짓이란 말입니까...',
'사유재산까지 몰수해가면서 이 나라가 잘 될거라 믿습니까? 정말 이해할 수가 없군요...',
'내 돈 내놔라! 내 돈! 몰수가 웬 말이냐!',
'몰수해간 내 자금... 언젠가 몰래 다시 빼내올 것이다...',
'몰수로 인한 사기 저하는 몰수로 얻은 물자보다 더 손해란걸 모른단 말인가!',
] as const;
type InclusiveRandomGenerator = GeneralActionResolveContext['rng'] & {
nextIntInclusive?: (maxInclusive: number) => number;
};
const pickLegacyNpcMessage = (rng: GeneralActionResolveContext['rng']): string => {
const inclusive = rng as InclusiveRandomGenerator;
const index = inclusive.nextIntInclusive
? inclusive.nextIntInclusive(NPC_SEIZURE_MESSAGES.length - 1)
: rng.nextInt(0, NPC_SEIZURE_MESSAGES.length);
return NPC_SEIZURE_MESSAGES[index]!;
};
const resolveGeneralIcon = (general: General): string => {
const runtimePicture = (general as General & { picture?: unknown }).picture;
const rawPicture = runtimePicture ?? general.meta.picture;
const picture =
(typeof rawPicture === 'string' && rawPicture !== '') || typeof rawPicture === 'number'
? String(rawPicture)
: 'default.jpg';
return `/image/icons/${picture}`;
};
export class ActionDefinition<
TriggerState extends GeneralTriggerState = GeneralTriggerState,
@@ -149,6 +185,30 @@ export class ActionDefinition<
}),
];
if (
destGeneral.npcState >= 2 &&
context.rng.nextBool(this.env.npcSeizureMessageProb ?? NPC_SEIZURE_MESSAGE_PROB)
) {
const target = {
generalId: destGeneral.id,
generalName: destGeneral.name,
nationId: nation.id,
nationName: nation.name,
color: nation.color,
icon: resolveGeneralIcon(destGeneral),
};
effects.push(
createMessageEffect({
msgType: 'public',
src: target,
dest: target,
text: pickLegacyNpcMessage(context.rng),
time: context.messageTime,
validUntil: new Date('9999-12-31T00:00:00.000Z'),
})
);
}
return { effects };
}
}
@@ -166,6 +226,7 @@ export const actionContextBuilder: ActionContextBuilder<SeizureArgs> = (base, op
return {
...base,
destGeneral,
messageTime: base.general.turnTime,
};
};