fix faction disband state and log parity

This commit is contained in:
2026-07-26 20:13:10 +00:00
parent 0f9fa69e1f
commit a7de5778ed
10 changed files with 198 additions and 13 deletions
@@ -98,6 +98,8 @@ export class ActionResolver<
// 2. Recruiter Rewards
const recruiterExperience = destGeneral.experience + 100;
const recruiterDedication = destGeneral.dedication + 100;
const belong = readMetaNumberFromUnknown(general.meta, 'belong') ?? 0;
const maxBelong = readMetaNumberFromUnknown(general.meta, 'max_belong') ?? 0;
const recruiterExpLevel = Math.max(
0,
Math.min(
@@ -242,6 +244,7 @@ export class ActionResolver<
...(general.npcState < 2
? {
killturn: context.worldKillturn ?? general.meta.killturn,
max_belong: Math.max(belong, maxBelong),
}
: {}),
},
@@ -10,6 +10,7 @@ import type {
import {
createCityPatchEffect,
createGeneralPatchEffect,
createLogEffect,
createNationPatchEffect,
} from '@sammo-ts/logic/actions/engine.js';
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.js';
@@ -22,6 +23,9 @@ import type { GeneralTurnCommandSpec } from './index.js';
const ACTION_NAME = '해산';
const ACTION_KEY = 'che_해산';
const readMetaNumber = (value: unknown): number =>
typeof value === 'number' && Number.isFinite(value) ? value : 0;
export interface DisbandFactionArgs {}
export interface DisbandFactionResolveContext<
@@ -76,6 +80,8 @@ export class ActionDefinition<
const nationGenerals = context.nationGenerals ?? [];
for (const targetGeneral of nationGenerals) {
const isActor = targetGeneral.id === general.id;
const belong = readMetaNumber(targetGeneral.meta.belong);
const maxBelong = readMetaNumber(targetGeneral.meta.max_belong);
effects.push(
createGeneralPatchEffect(
{
@@ -92,6 +98,8 @@ export class ActionDefinition<
belong: 0,
officer_city: 0,
officerCity: 0,
permission: 'normal',
...(targetGeneral.npcState < 2 ? { max_belong: Math.max(belong, maxBelong) } : {}),
...(isActor ? { makelimit: 12 } : {}),
},
},
@@ -135,13 +143,39 @@ export class ActionDefinition<
});
context.addLog(`<Y>${general.name}</>${josaYi} 세력을 해산했습니다.`, {
scope: LogScope.SYSTEM,
category: LogCategory.ACTION,
category: LogCategory.SUMMARY,
});
context.addLog(`<D><b>${nation.name}</b></>${josaUl} 해산`, {
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
});
const josaUn = JosaUtil.pick(nation.name, '은');
const josaNationYi = JosaUtil.pick(nation.name, '이');
effects.push(
createLogEffect(`<R><b>【멸망】</b></><D><b>${nation.name}</b></>${josaUn} <R>멸망</>했습니다.`, {
scope: LogScope.SYSTEM,
category: LogCategory.HISTORY,
format: LogFormat.YEAR_MONTH,
})
);
for (const targetGeneral of nationGenerals) {
effects.push(
createLogEffect(`<D><b>${nation.name}</b></>${josaNationYi} <R>멸망</>했습니다.`, {
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
format: LogFormat.PLAIN,
generalId: targetGeneral.id,
}),
createLogEffect(`<D><b>${nation.name}</b></>${josaNationYi} <R>멸망</>`, {
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
format: LogFormat.YEAR_MONTH,
generalId: targetGeneral.id,
})
);
}
return { effects };
}
}
@@ -172,7 +172,7 @@ describe('che_등용수락', () => {
age: 20,
npcState: 0,
triggerState: { flags: {}, counters: {}, modifiers: {}, meta: {} },
meta: { killturn: 24 },
meta: { killturn: 24, belong: 10, max_belong: 2 },
};
const recruiterGen: General = {
@@ -244,6 +244,11 @@ describe('che_등용수락', () => {
expect(updatedSelf?.cityId).toBe(102); // Capital of Nation2
expect(updatedSelf?.experience).toBe(100);
expect(updatedSelf?.dedication).toBe(100);
expect(updatedSelf?.meta).toMatchObject({
belong: 1,
max_belong: 10,
permission: 'normal',
});
expect(updatedRecruiter?.experience).toBe(100);
expect(updatedRecruiter?.dedication).toBe(100);
@@ -253,8 +253,26 @@ describe('migrated general commands', () => {
});
it('che_해산: 방랑군 해산 시 세력과 소속을 정리한다', async () => {
const lord = makeGeneral({ id: 1, nationId: 1, cityId: 1, name: '군주', officerLevel: 12, gold: 1500, rice: 1800 });
const member = makeGeneral({ id: 2, nationId: 1, cityId: 2, name: '부하', officerLevel: 1, gold: 2500, rice: 500 });
const lord = makeGeneral({
id: 1,
nationId: 1,
cityId: 1,
name: '군주',
officerLevel: 12,
gold: 1500,
rice: 1800,
meta: { belong: 5, max_belong: 2, permission: 'ambassador' },
});
const member = makeGeneral({
id: 2,
nationId: 1,
cityId: 2,
name: '부하',
officerLevel: 1,
gold: 2500,
rice: 500,
meta: { belong: 7, max_belong: 3, permission: 'auditor' },
});
const nation = makeNation({
id: 1,
name: '방랑군',
@@ -294,6 +312,8 @@ describe('migrated general commands', () => {
expect(updatedLord.meta.makelimit).toBe(12);
expect(updatedLord.gold).toBe(1000);
expect(updatedMember.gold).toBe(1000);
expect(updatedLord.meta).toMatchObject({ belong: 0, max_belong: 5, permission: 'normal' });
expect(updatedMember.meta).toMatchObject({ belong: 0, max_belong: 7, permission: 'normal' });
expect(world.getCity(1)!.nationId).toBe(0);
expect(world.getCity(2)!.nationId).toBe(0);
expect(world.getNation(1)!.meta.collapsed).toBe(true);