test(game-engine): cover NPC actions through month boundary
This commit is contained in:
@@ -5,6 +5,7 @@ import type { City } from '@sammo-ts/logic';
|
|||||||
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
||||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||||
import { createCreateManyNpcHandler } from '../src/turn/monthlyCreateManyNpcAction.js';
|
import { createCreateManyNpcHandler } from '../src/turn/monthlyCreateManyNpcAction.js';
|
||||||
|
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
|
||||||
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
||||||
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
||||||
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||||
@@ -119,7 +120,7 @@ integration('CreateManyNPC database persistence', () => {
|
|||||||
data: {
|
data: {
|
||||||
scenarioCode: 'monthly-create-many-npc-persistence',
|
scenarioCode: 'monthly-create-many-npc-persistence',
|
||||||
currentYear: 193,
|
currentYear: 193,
|
||||||
currentMonth: 5,
|
currentMonth: 4,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
config: {},
|
config: {},
|
||||||
meta: { hiddenSeed: 'create-many-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
meta: { hiddenSeed: 'create-many-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
||||||
@@ -128,9 +129,9 @@ integration('CreateManyNPC database persistence', () => {
|
|||||||
const state: TurnWorldState = {
|
const state: TurnWorldState = {
|
||||||
id: stateRow.id,
|
id: stateRow.id,
|
||||||
currentYear: 193,
|
currentYear: 193,
|
||||||
currentMonth: 5,
|
currentMonth: 4,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
lastTurnTime: new Date('0193-05-01T00:00:00.000Z'),
|
lastTurnTime: new Date('0193-04-01T00:00:00.000Z'),
|
||||||
meta: { hiddenSeed: 'create-many-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
meta: { hiddenSeed: 'create-many-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
||||||
};
|
};
|
||||||
const snapshot: TurnWorldSnapshot = {
|
const snapshot: TurnWorldSnapshot = {
|
||||||
@@ -160,29 +161,25 @@ integration('CreateManyNPC database persistence', () => {
|
|||||||
events: [event],
|
events: [event],
|
||||||
initialEvents: [],
|
initialEvents: [],
|
||||||
};
|
};
|
||||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
|
||||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
|
||||||
});
|
|
||||||
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
||||||
|
let world: InMemoryTurnWorld | null = null;
|
||||||
const handler = createCreateManyNpcHandler({
|
const handler = createCreateManyNpcHandler({
|
||||||
getWorld: () => world,
|
getWorld: () => world,
|
||||||
reservedTurns,
|
reservedTurns,
|
||||||
env: buildCommandEnv(snapshot.scenarioConfig),
|
env: buildCommandEnv(snapshot.scenarioConfig),
|
||||||
});
|
});
|
||||||
|
world = new InMemoryTurnWorld(state, snapshot, {
|
||||||
|
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||||
|
calendarHandler: createMonthlyEventHandler({
|
||||||
|
getWorld: () => world,
|
||||||
|
startYear: 190,
|
||||||
|
actions: new Map([['CreateManyNPC', handler]]),
|
||||||
|
}),
|
||||||
|
});
|
||||||
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await handler(
|
await world.advanceMonth(new Date('0193-05-01T00:00:00.000Z'));
|
||||||
[1, 0],
|
|
||||||
{
|
|
||||||
year: 193,
|
|
||||||
month: 5,
|
|
||||||
startyear: 190,
|
|
||||||
currentEventID: 1,
|
|
||||||
turnTime: state.lastTurnTime,
|
|
||||||
},
|
|
||||||
event
|
|
||||||
);
|
|
||||||
await dbHooks.hooks.flushChanges?.({
|
await dbHooks.hooks.flushChanges?.({
|
||||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||||
processedGenerals: 0,
|
processedGenerals: 0,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
|||||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||||
import { createChangeCityHandler } from '../src/turn/monthlyChangeCityAction.js';
|
import { createChangeCityHandler } from '../src/turn/monthlyChangeCityAction.js';
|
||||||
import { createProvideNpcTroopLeaderHandler } from '../src/turn/monthlyProvideNpcTroopLeaderAction.js';
|
import { createProvideNpcTroopLeaderHandler } from '../src/turn/monthlyProvideNpcTroopLeaderAction.js';
|
||||||
|
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
|
||||||
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
||||||
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
||||||
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||||
@@ -58,7 +59,7 @@ const event: TurnEvent = {
|
|||||||
targetCode: 'month',
|
targetCode: 'month',
|
||||||
priority: 1_000,
|
priority: 1_000,
|
||||||
condition: true,
|
condition: true,
|
||||||
action: [['ProvideNPCTroopLeader']],
|
action: [['ProvideNPCTroopLeader'], ['ChangeCity', 'all', { pop_max: '+100', pop: '50%', trust: 80, trade: 105 }]],
|
||||||
meta: {},
|
meta: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,8 +136,8 @@ integration('monthly NPC support database persistence', () => {
|
|||||||
const stateRow = await db.worldState.create({
|
const stateRow = await db.worldState.create({
|
||||||
data: {
|
data: {
|
||||||
scenarioCode: 'monthly-npc-support-persistence',
|
scenarioCode: 'monthly-npc-support-persistence',
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
config: {},
|
config: {},
|
||||||
meta: {
|
meta: {
|
||||||
@@ -148,10 +149,10 @@ integration('monthly NPC support database persistence', () => {
|
|||||||
});
|
});
|
||||||
const state: TurnWorldState = {
|
const state: TurnWorldState = {
|
||||||
id: stateRow.id,
|
id: stateRow.id,
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
lastTurnTime: new Date('0200-01-01T00:00:00.000Z'),
|
lastTurnTime: new Date('0199-12-01T00:00:00.000Z'),
|
||||||
meta: {
|
meta: {
|
||||||
hiddenSeed: 'monthly-npc-support-persistence',
|
hiddenSeed: 'monthly-npc-support-persistence',
|
||||||
lastGeneralId: generalId - 1,
|
lastGeneralId: generalId - 1,
|
||||||
@@ -175,31 +176,32 @@ integration('monthly NPC support database persistence', () => {
|
|||||||
events: [event],
|
events: [event],
|
||||||
initialEvents: [],
|
initialEvents: [],
|
||||||
};
|
};
|
||||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
|
||||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
|
||||||
});
|
|
||||||
const reservedTurns = new InMemoryReservedTurnStore(db, {
|
const reservedTurns = new InMemoryReservedTurnStore(db, {
|
||||||
maxGeneralTurns: 30,
|
maxGeneralTurns: 30,
|
||||||
maxNationTurns: 12,
|
maxNationTurns: 12,
|
||||||
});
|
});
|
||||||
|
let world: InMemoryTurnWorld | null = null;
|
||||||
const provide = createProvideNpcTroopLeaderHandler({
|
const provide = createProvideNpcTroopLeaderHandler({
|
||||||
getWorld: () => world,
|
getWorld: () => world,
|
||||||
reservedTurns,
|
reservedTurns,
|
||||||
env: buildCommandEnv(snapshot.scenarioConfig),
|
env: buildCommandEnv(snapshot.scenarioConfig),
|
||||||
});
|
});
|
||||||
const changeCity = createChangeCityHandler({ getWorld: () => world });
|
const changeCity = createChangeCityHandler({ getWorld: () => world });
|
||||||
|
world = new InMemoryTurnWorld(state, snapshot, {
|
||||||
|
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||||
|
calendarHandler: createMonthlyEventHandler({
|
||||||
|
getWorld: () => world,
|
||||||
|
startYear: 190,
|
||||||
|
actions: new Map([
|
||||||
|
['ProvideNPCTroopLeader', provide],
|
||||||
|
['ChangeCity', changeCity],
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
});
|
||||||
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const environment = {
|
await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
|
||||||
year: 200,
|
|
||||||
month: 1,
|
|
||||||
startyear: 190,
|
|
||||||
currentEventID: 1,
|
|
||||||
turnTime: state.lastTurnTime,
|
|
||||||
};
|
|
||||||
await provide([], environment, event);
|
|
||||||
await changeCity(['all', { pop_max: '+100', pop: '50%', trust: 80, trade: 105 }], environment, event);
|
|
||||||
await dbHooks.hooks.flushChanges?.({
|
await dbHooks.hooks.flushChanges?.({
|
||||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||||
processedGenerals: 0,
|
processedGenerals: 0,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { City, MapDefinition, Nation } from '@sammo-ts/logic';
|
|||||||
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
||||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||||
import { createRaiseNpcNationHandler } from '../src/turn/monthlyRaiseNpcNationAction.js';
|
import { createRaiseNpcNationHandler } from '../src/turn/monthlyRaiseNpcNationAction.js';
|
||||||
|
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
|
||||||
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
||||||
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
||||||
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||||
@@ -182,8 +183,8 @@ integration('RaiseNPCNation database persistence', () => {
|
|||||||
const stateRow = await db.worldState.create({
|
const stateRow = await db.worldState.create({
|
||||||
data: {
|
data: {
|
||||||
scenarioCode: 'monthly-raise-npc-nation-persistence',
|
scenarioCode: 'monthly-raise-npc-nation-persistence',
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
config: {},
|
config: {},
|
||||||
meta: {
|
meta: {
|
||||||
@@ -196,10 +197,10 @@ integration('RaiseNPCNation database persistence', () => {
|
|||||||
});
|
});
|
||||||
const state: TurnWorldState = {
|
const state: TurnWorldState = {
|
||||||
id: stateRow.id,
|
id: stateRow.id,
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
lastTurnTime: new Date('0200-01-01T00:00:00.000Z'),
|
lastTurnTime: new Date('0199-12-01T00:00:00.000Z'),
|
||||||
meta: {
|
meta: {
|
||||||
hiddenSeed: 'raise-npc-nation-persistence',
|
hiddenSeed: 'raise-npc-nation-persistence',
|
||||||
lastGeneralId: createdGeneralId - 1,
|
lastGeneralId: createdGeneralId - 1,
|
||||||
@@ -230,10 +231,8 @@ integration('RaiseNPCNation database persistence', () => {
|
|||||||
events: [event],
|
events: [event],
|
||||||
initialEvents: [],
|
initialEvents: [],
|
||||||
};
|
};
|
||||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
|
||||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
|
||||||
});
|
|
||||||
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
||||||
|
let world: InMemoryTurnWorld | null = null;
|
||||||
const handler = createRaiseNpcNationHandler({
|
const handler = createRaiseNpcNationHandler({
|
||||||
getWorld: () => world,
|
getWorld: () => world,
|
||||||
reservedTurns,
|
reservedTurns,
|
||||||
@@ -241,20 +240,18 @@ integration('RaiseNPCNation database persistence', () => {
|
|||||||
map,
|
map,
|
||||||
loadArchivedNationMaxId: async () => 0,
|
loadArchivedNationMaxId: async () => 0,
|
||||||
});
|
});
|
||||||
|
world = new InMemoryTurnWorld(state, snapshot, {
|
||||||
|
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||||
|
calendarHandler: createMonthlyEventHandler({
|
||||||
|
getWorld: () => world,
|
||||||
|
startYear: 190,
|
||||||
|
actions: new Map([['RaiseNPCNation', handler]]),
|
||||||
|
}),
|
||||||
|
});
|
||||||
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await handler(
|
await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
|
||||||
[],
|
|
||||||
{
|
|
||||||
year: 200,
|
|
||||||
month: 1,
|
|
||||||
startyear: 190,
|
|
||||||
currentEventID: 1,
|
|
||||||
turnTime: state.lastTurnTime,
|
|
||||||
},
|
|
||||||
event
|
|
||||||
);
|
|
||||||
await dbHooks.hooks.flushChanges?.({
|
await dbHooks.hooks.flushChanges?.({
|
||||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||||
processedGenerals: 0,
|
processedGenerals: 0,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { City } from '@sammo-ts/logic';
|
|||||||
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
||||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||||
import { createRegisterNpcHandler } from '../src/turn/monthlyRegisterNpcAction.js';
|
import { createRegisterNpcHandler } from '../src/turn/monthlyRegisterNpcAction.js';
|
||||||
|
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
|
||||||
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
|
||||||
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
|
||||||
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
import type { TurnEvent, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||||
@@ -13,6 +14,7 @@ const databaseUrl = process.env.INPUT_EVENT_DATABASE_URL;
|
|||||||
const integration = describe.skipIf(!databaseUrl);
|
const integration = describe.skipIf(!databaseUrl);
|
||||||
const cityId = 990_082;
|
const cityId = 990_082;
|
||||||
const createdGeneralId = 990_082;
|
const createdGeneralId = 990_082;
|
||||||
|
const createdNeutralGeneralId = 990_083;
|
||||||
|
|
||||||
const city: City = {
|
const city: City = {
|
||||||
id: cityId,
|
id: cityId,
|
||||||
@@ -42,7 +44,10 @@ const event: TurnEvent = {
|
|||||||
targetCode: 'month',
|
targetCode: 'month',
|
||||||
priority: 1_000,
|
priority: 1_000,
|
||||||
condition: true,
|
condition: true,
|
||||||
action: [['RegNPC']],
|
action: [
|
||||||
|
['RegNPC', 77, '저장장수', 1001, 0, cityId, 60, 50, 40, 7, 186, 240, '유지', '인덕', '대사'],
|
||||||
|
['RegNeutralNPC', 88, '저장재야', 1002, 0, cityId, 45, 55, 65, 186, 241, '안전', '무쌍', '재야대사'],
|
||||||
|
],
|
||||||
meta: {},
|
meta: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,12 +58,16 @@ integration('RegNPC database persistence', () => {
|
|||||||
const clean = async () => {
|
const clean = async () => {
|
||||||
await db.logEntry.deleteMany({
|
await db.logEntry.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [{ generalId: createdGeneralId }, { year: 200, month: 1, text: { contains: 'ⓝ저장장수' } }],
|
OR: [
|
||||||
|
{ generalId: { in: [createdGeneralId, createdNeutralGeneralId] } },
|
||||||
|
{ year: 200, month: 1, text: { contains: '저장장수' } },
|
||||||
|
{ year: 200, month: 1, text: { contains: '저장재야' } },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await db.generalTurn.deleteMany({ where: { generalId: createdGeneralId } });
|
await db.generalTurn.deleteMany({ where: { generalId: { in: [createdGeneralId, createdNeutralGeneralId] } } });
|
||||||
await db.rankData.deleteMany({ where: { generalId: createdGeneralId } });
|
await db.rankData.deleteMany({ where: { generalId: { in: [createdGeneralId, createdNeutralGeneralId] } } });
|
||||||
await db.general.deleteMany({ where: { id: createdGeneralId } });
|
await db.general.deleteMany({ where: { id: { in: [createdGeneralId, createdNeutralGeneralId] } } });
|
||||||
await db.city.deleteMany({ where: { id: cityId } });
|
await db.city.deleteMany({ where: { id: cityId } });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,8 +115,8 @@ integration('RegNPC database persistence', () => {
|
|||||||
const stateRow = await db.worldState.create({
|
const stateRow = await db.worldState.create({
|
||||||
data: {
|
data: {
|
||||||
scenarioCode: 'monthly-register-npc-persistence',
|
scenarioCode: 'monthly-register-npc-persistence',
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
config: {},
|
config: {},
|
||||||
meta: { hiddenSeed: 'register-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
meta: { hiddenSeed: 'register-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
||||||
@@ -115,10 +124,10 @@ integration('RegNPC database persistence', () => {
|
|||||||
});
|
});
|
||||||
const state: TurnWorldState = {
|
const state: TurnWorldState = {
|
||||||
id: stateRow.id,
|
id: stateRow.id,
|
||||||
currentYear: 200,
|
currentYear: 199,
|
||||||
currentMonth: 1,
|
currentMonth: 12,
|
||||||
tickSeconds: 600,
|
tickSeconds: 600,
|
||||||
lastTurnTime: new Date('0200-01-01T00:00:00.000Z'),
|
lastTurnTime: new Date('0199-12-01T00:00:00.000Z'),
|
||||||
meta: { hiddenSeed: 'register-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
meta: { hiddenSeed: 'register-npc-persistence', lastGeneralId: createdGeneralId - 1 },
|
||||||
};
|
};
|
||||||
const snapshot: TurnWorldSnapshot = {
|
const snapshot: TurnWorldSnapshot = {
|
||||||
@@ -152,10 +161,8 @@ integration('RegNPC database persistence', () => {
|
|||||||
events: [event],
|
events: [event],
|
||||||
initialEvents: [],
|
initialEvents: [],
|
||||||
};
|
};
|
||||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
|
||||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
|
||||||
});
|
|
||||||
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
|
||||||
|
let world: InMemoryTurnWorld | null = null;
|
||||||
const handler = createRegisterNpcHandler({
|
const handler = createRegisterNpcHandler({
|
||||||
actionName: 'RegNPC',
|
actionName: 'RegNPC',
|
||||||
getWorld: () => world,
|
getWorld: () => world,
|
||||||
@@ -163,20 +170,28 @@ integration('RegNPC database persistence', () => {
|
|||||||
env: buildCommandEnv(snapshot.scenarioConfig),
|
env: buildCommandEnv(snapshot.scenarioConfig),
|
||||||
worldConfig: snapshot.worldConfig,
|
worldConfig: snapshot.worldConfig,
|
||||||
});
|
});
|
||||||
|
const neutralHandler = createRegisterNpcHandler({
|
||||||
|
actionName: 'RegNeutralNPC',
|
||||||
|
getWorld: () => world,
|
||||||
|
reservedTurns,
|
||||||
|
env: buildCommandEnv(snapshot.scenarioConfig),
|
||||||
|
worldConfig: snapshot.worldConfig,
|
||||||
|
});
|
||||||
|
world = new InMemoryTurnWorld(state, snapshot, {
|
||||||
|
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||||
|
calendarHandler: createMonthlyEventHandler({
|
||||||
|
getWorld: () => world,
|
||||||
|
startYear: 190,
|
||||||
|
actions: new Map([
|
||||||
|
['RegNPC', handler],
|
||||||
|
['RegNeutralNPC', neutralHandler],
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
});
|
||||||
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await handler(
|
await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
|
||||||
[77, '저장장수', 1001, 0, cityId, 60, 50, 40, 7, 186, 240, '유지', '인덕', '대사'],
|
|
||||||
{
|
|
||||||
year: 200,
|
|
||||||
month: 1,
|
|
||||||
startyear: 190,
|
|
||||||
currentEventID: 1,
|
|
||||||
turnTime: state.lastTurnTime,
|
|
||||||
},
|
|
||||||
event
|
|
||||||
);
|
|
||||||
await dbHooks.hooks.flushChanges?.({
|
await dbHooks.hooks.flushChanges?.({
|
||||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||||
processedGenerals: 0,
|
processedGenerals: 0,
|
||||||
@@ -214,6 +229,30 @@ integration('RegNPC database persistence', () => {
|
|||||||
category: 'ACTION',
|
category: 'ACTION',
|
||||||
text: expect.stringContaining('성인이 되어'),
|
text: expect.stringContaining('성인이 되어'),
|
||||||
});
|
});
|
||||||
|
expect(await db.general.findUniqueOrThrow({ where: { id: createdNeutralGeneralId } })).toMatchObject({
|
||||||
|
name: 'ⓤ저장재야',
|
||||||
|
nationId: 0,
|
||||||
|
cityId,
|
||||||
|
officerLevel: 0,
|
||||||
|
npcState: 6,
|
||||||
|
affinity: 88,
|
||||||
|
bornYear: 186,
|
||||||
|
deadYear: 241,
|
||||||
|
picture: '1002.jpg',
|
||||||
|
personalCode: 'che_안전',
|
||||||
|
specialCode: 'None',
|
||||||
|
special2Code: 'che_무쌍',
|
||||||
|
});
|
||||||
|
expect(await db.generalTurn.count({ where: { generalId: createdNeutralGeneralId } })).toBe(30);
|
||||||
|
expect(await db.rankData.count({ where: { generalId: createdNeutralGeneralId } })).toBe(44);
|
||||||
|
expect(
|
||||||
|
await db.logEntry.findFirst({
|
||||||
|
where: { year: 200, month: 1, text: { contains: 'ⓤ저장재야' } },
|
||||||
|
})
|
||||||
|
).toMatchObject({
|
||||||
|
category: 'ACTION',
|
||||||
|
text: expect.stringContaining('성인이 되어'),
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await dbHooks.close();
|
await dbHooks.close();
|
||||||
await db.worldState.delete({ where: { id: stateRow.id } });
|
await db.worldState.delete({ where: { id: stateRow.id } });
|
||||||
|
|||||||
Reference in New Issue
Block a user