fix: 단일 잔존 국가 임관 금지를 연결한다

마지막 도시 점령으로 국가가 삭제되면 destroy_nation 시나리오 이벤트를 같은 턴 경계에서 실행한다. Ref와 같이 잔존국 scout를 금지로 바꾸고 일회성 이벤트를 삭제하되 정책 변경 잠금은 설정하지 않는다.
This commit is contained in:
2026-08-23 11:08:30 +00:00
parent 51ca5e9d70
commit 4d424d16c6
11 changed files with 209 additions and 6 deletions
@@ -1,6 +1,6 @@
import type { TurnCheckpoint, TurnProcessor, TurnRunBudget, TurnRunResult } from '../lifecycle/types.js';
import { getNextTickTime } from '../lifecycle/getNextTickTime.js';
import type { InMemoryTurnWorld } from './inMemoryWorld.js';
import type { InMemoryTurnWorld, TurnCalendarContext } from './inMemoryWorld.js';
import type { TurnGeneral } from './types.js';
import { asNumber, asRecord, calculateAccessRefreshLimit } from '@sammo-ts/common';
@@ -8,6 +8,7 @@ export interface InMemoryTurnProcessorOptions {
tickMinutes?: number;
beforeExecuteGeneral?: (general: TurnGeneral) => Promise<void>;
afterExecuteGeneral?: (general: TurnGeneral, result: TurnGeneralExecutionResult) => Promise<void>;
dispatchScenarioEvent?: (targetCode: string, context: TurnCalendarContext) => Promise<void>;
}
export type TurnGeneralExecutionResult = {
@@ -38,12 +39,14 @@ export class InMemoryTurnProcessor implements TurnProcessor {
private readonly tickMinutesOverride?: number;
private readonly beforeExecuteGeneral?: (general: TurnGeneral) => Promise<void>;
private readonly afterExecuteGeneral?: (general: TurnGeneral, result: TurnGeneralExecutionResult) => Promise<void>;
private readonly dispatchScenarioEvent?: (targetCode: string, context: TurnCalendarContext) => Promise<void>;
constructor(world: InMemoryTurnWorld, options: InMemoryTurnProcessorOptions = {}) {
this.world = world;
this.tickMinutesOverride = options.tickMinutes;
this.beforeExecuteGeneral = options.beforeExecuteGeneral;
this.afterExecuteGeneral = options.afterExecuteGeneral;
this.dispatchScenarioEvent = options.dispatchScenarioEvent;
}
async run(targetTime: Date, budget: TurnRunBudget, checkpoint?: TurnCheckpoint): Promise<TurnRunResult> {
@@ -99,7 +102,22 @@ export class InMemoryTurnProcessor implements TurnProcessor {
let nextTurnAt: Date | undefined;
let executionError: unknown;
try {
nextTurnAt = this.world.executeGeneralTurn(general);
const execution = this.world.executeGeneralTurn(general);
nextTurnAt = execution.nextTurnAt;
if (execution.destroyedNationIds.length > 0 && this.dispatchScenarioEvent) {
const state = this.world.getState();
const eventContext: TurnCalendarContext = {
previousYear: state.currentYear,
previousMonth: state.currentMonth,
currentYear: state.currentYear,
currentMonth: state.currentMonth,
turnTime: new Date(state.lastTurnTime.getTime()),
legacyTurnTime: new Date(state.lastTurnTime.getTime()),
};
for (const _nationId of execution.destroyedNationIds) {
await this.dispatchScenarioEvent('destroy_nation', eventContext);
}
}
} catch (error) {
executionError = error;
}
+12 -2
View File
@@ -67,9 +67,15 @@ export interface GeneralTurnResult {
general: boolean;
troopIds?: number[];
};
destroyedNationIds?: number[];
lifecycleEvent?: GeneralLifecycleEvent;
}
export interface GeneralTurnExecution {
nextTurnAt: Date;
destroyedNationIds: number[];
}
export interface GeneralLifecycleEvent {
generalId: number;
outcome: 'active' | 'detached' | 'deleted' | 'retired';
@@ -90,6 +96,7 @@ export interface TurnCalendarContext {
currentYear: number;
currentMonth: number;
turnTime: Date;
legacyTurnTime?: Date;
}
export interface TurnCalendarHandler {
@@ -1432,7 +1439,7 @@ export class InMemoryTurnWorld {
return due;
}
executeGeneralTurn(general: TurnGeneral): Date {
executeGeneralTurn(general: TurnGeneral): GeneralTurnExecution {
const currentGeneral = this.generals.get(general.id) ?? general;
const city = this.cities.get(currentGeneral.cityId);
const nation = currentGeneral.nationId > 0 ? (this.nations.get(currentGeneral.nationId) ?? null) : null;
@@ -1599,7 +1606,10 @@ export class InMemoryTurnWorld {
this.removeCollapsedNations();
return nextTurnAt;
return {
nextTurnAt,
destroyedNationIds: (result.destroyedNationIds ?? []).filter((nationId) => !this.nations.has(nationId)),
};
}
async advanceMonth(turnTime: Date): Promise<void> {
@@ -232,7 +232,9 @@ export const createMonthlyEventHandler = (options: {
// postUpdateMonthly step has completed. Event actions therefore see
// the previous monthly boundary even after turnDate() has advanced
// year/month. Generated general turn times depend on this distinction.
const legacyTurnTime = new Date(context.turnTime.getTime() - world.getState().tickSeconds * 1_000);
const legacyTurnTime =
context.legacyTurnTime ??
new Date(context.turnTime.getTime() - world.getState().tickSeconds * 1_000);
for (const event of world.listEvents(targetCode)) {
const environment: MonthlyEventEnvironment = {
@@ -916,6 +916,7 @@ export const createReservedTurnHandler = async (options: {
const createdGenerals: TurnGeneral[] = [];
const createdNations: Nation[] = [];
const commandDeletedTroopIds = new Set<number>();
const destroyedNationIds = new Set<number>();
let currentGeneral = context.general;
let currentCity = context.city;
@@ -1309,6 +1310,9 @@ export const createReservedTurnHandler = async (options: {
}
logs.push(...resolution.logs);
for (const nationId of resolution.destroyedNationIds ?? []) {
destroyedNationIds.add(nationId);
}
if (worldOverlay) {
worldOverlay.syncGeneral(currentGeneral);
if (currentCity) {
@@ -2166,6 +2170,7 @@ export const createReservedTurnHandler = async (options: {
},
}
: undefined),
...(destroyedNationIds.size > 0 ? { destroyedNationIds: [...destroyedNationIds] } : undefined),
lifecycleEvent: {
generalId: currentGeneral.id,
outcome: lifecycleOutcome,
+1
View File
@@ -778,6 +778,7 @@ const createTurnDaemonRuntimeWithLease = async (
const stateStore = new InMemoryTurnStateStore(world);
let fastForwardPreparedMonth = '';
const processor = new InMemoryTurnProcessor(world, {
dispatchScenarioEvent: (targetCode, context) => monthlyEventHandler.dispatchTarget(targetCode, context),
beforeExecuteGeneral: reservedTurnStoreHandle
? async (general) => {
if (options.exclusiveFastForward) {