fix inheritance accounting for unowned generals
This commit is contained in:
@@ -1123,7 +1123,9 @@ export const createReservedTurnHandler = async (options: {
|
||||
kind === 'nation' &&
|
||||
!usedFallback &&
|
||||
resolution.completed &&
|
||||
definition.countsAsInheritanceActiveAction
|
||||
definition.countsAsInheritanceActiveAction &&
|
||||
Boolean(currentGeneral.userId) &&
|
||||
currentGeneral.npcState < 2
|
||||
) {
|
||||
const meta = { ...currentGeneral.meta };
|
||||
const active = typeof meta.inherit_active_action === 'number' ? meta.inherit_active_action : 0;
|
||||
@@ -1135,7 +1137,9 @@ export const createReservedTurnHandler = async (options: {
|
||||
kind === 'general' &&
|
||||
!usedFallback &&
|
||||
resolution.completed &&
|
||||
executionDefinition.getInheritanceActiveActionAmount
|
||||
executionDefinition.getInheritanceActiveActionAmount &&
|
||||
Boolean(currentGeneral.userId) &&
|
||||
currentGeneral.npcState < 2
|
||||
) {
|
||||
const amount = executionDefinition.getInheritanceActiveActionAmount(actionContext, actionArgs);
|
||||
if (Number.isFinite(amount) && amount !== 0) {
|
||||
|
||||
@@ -7,8 +7,9 @@ import { createTurnTestHarness } from './helpers/turnTestHarness.js';
|
||||
|
||||
const mockDate = new Date('0189-01-01T00:00:00Z');
|
||||
|
||||
const createChief = (): TurnGeneral => ({
|
||||
const createChief = (userId: string | null): TurnGeneral => ({
|
||||
id: 1,
|
||||
userId,
|
||||
name: '군주',
|
||||
nationId: 1,
|
||||
cityId: 1,
|
||||
@@ -38,13 +39,18 @@ const createChief = (): TurnGeneral => ({
|
||||
});
|
||||
|
||||
describe('레거시 사령부 턴 실행 호환성', () => {
|
||||
it('화시병 연구는 선행 11턴을 누적한 뒤 12번째 턴에만 완료한다', async () => {
|
||||
it.each([
|
||||
{ ownerLabel: '소유 장수', userId: 'test-user', expectedActiveAction: 1 },
|
||||
{ ownerLabel: '무소유 장수', userId: null, expectedActiveAction: undefined },
|
||||
])(
|
||||
'화시병 연구는 $ownerLabel에서 12번째 턴에 완료하고 소유자에게만 능동 행동을 준다',
|
||||
async ({ userId, expectedActiveAction }) => {
|
||||
const cities = buildLargeTestCities();
|
||||
for (const city of cities) {
|
||||
city.nationId = city.id === 1 ? 1 : city.id === 2 ? 2 : 0;
|
||||
}
|
||||
const snapshot: TurnWorldSnapshot = {
|
||||
generals: [createChief()],
|
||||
generals: [createChief(userId)],
|
||||
cities,
|
||||
nations: [
|
||||
{
|
||||
@@ -141,7 +147,7 @@ describe('레거시 사령부 턴 실행 호환성', () => {
|
||||
command: '화시병 연구',
|
||||
term: 0,
|
||||
});
|
||||
expect(world.getGeneralById(1)!.meta.inherit_active_action).toBe(1);
|
||||
expect(world.getGeneralById(1)!.meta.inherit_active_action).toBe(expectedActiveAction);
|
||||
expect(world.getGeneralById(1)!.experience).toBe(60);
|
||||
expect(world.getGeneralById(1)!.dedication).toBe(60);
|
||||
|
||||
@@ -162,7 +168,8 @@ describe('레거시 사령부 턴 실행 호환성', () => {
|
||||
option: { action: 'stopWar', deletable: false },
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it('MONTH action 전에 전략·외교 제한, 임시 세율, 첩보 기간을 갱신한다', async () => {
|
||||
const updates: Array<{ id: number; patch: Record<string, unknown> }> = [];
|
||||
|
||||
@@ -145,6 +145,7 @@ export const projectCoreDatabaseSnapshot = (rows: {
|
||||
atmos: row.atmos,
|
||||
age: row.age,
|
||||
npcState: row.npcState,
|
||||
hasOwner: typeof row.userId === 'string' && row.userId.length > 0,
|
||||
turnTime: row.turnTime instanceof Date ? serializeDate(row.turnTime) : row.turnTime,
|
||||
recentWarTime: row.recentWarTime instanceof Date ? serializeDate(row.recentWarTime) : row.recentWarTime,
|
||||
lastTurn: row.lastTurn,
|
||||
|
||||
@@ -249,6 +249,7 @@ const buildGeneral = (row: Record<string, unknown>, fallbackTurnTime: Date): Tur
|
||||
atmos: readNumber(row, 'atmos'),
|
||||
age: readNumber(row, 'age', 30),
|
||||
npcState: readNumber(row, 'npcState'),
|
||||
userId: row.hasOwner === true ? 'turn-differential-owner' : null,
|
||||
penalty: row.penalty,
|
||||
triggerState: { flags: {}, counters: {}, modifiers: {}, meta: {} },
|
||||
meta: {
|
||||
@@ -585,6 +586,7 @@ const projectWorld = (
|
||||
atmos: toDatabaseInt(general.atmos),
|
||||
age: general.age,
|
||||
npcState: general.npcState,
|
||||
hasOwner: Boolean(general.userId),
|
||||
turnTime: general.turnTime.toISOString(),
|
||||
recentWarTime: general.recentWarTime?.toISOString() ?? null,
|
||||
lastTurn: general.lastTurn ?? null,
|
||||
|
||||
Reference in New Issue
Block a user