경매 관련 진행 준비
This commit is contained in:
@@ -26,6 +26,7 @@ import { loadTurnCommandProfile } from './turnCommandProfile.js';
|
||||
import { loadTurnWorldFromDatabase } from './worldLoader.js';
|
||||
import { shouldUseAi } from './ai/generalAi.js';
|
||||
import { createUnificationHandler } from './unificationHandler.js';
|
||||
import { createAuctionFinalizer } from '../auction/finalizer.js';
|
||||
|
||||
export interface TurnDaemonRuntimeOptions {
|
||||
profile: string;
|
||||
@@ -170,6 +171,7 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
let hooks: TurnDaemonHooks | undefined;
|
||||
let publishRealtimeEvent: ((event: RealtimeEvent) => Promise<void>) | null = null;
|
||||
let close = async () => {};
|
||||
let auctionFinalizer: Awaited<ReturnType<typeof createAuctionFinalizer>> | null = null;
|
||||
let redisCommandStream: RedisTurnDaemonCommandStream | null = null;
|
||||
let redisConnector: ReturnType<typeof createRedisConnector> | null = null;
|
||||
let pauseGate: (() => Promise<boolean>) | undefined;
|
||||
@@ -189,6 +191,7 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
const dbHooks = await createDatabaseTurnHooks(options.databaseUrl, world, {
|
||||
reservedTurns: reservedTurnStoreHandle?.store,
|
||||
});
|
||||
auctionFinalizer = await createAuctionFinalizer(options.databaseUrl);
|
||||
hooks = {
|
||||
...dbHooks.hooks,
|
||||
onRunError: async (error) => {
|
||||
@@ -197,6 +200,9 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
},
|
||||
};
|
||||
close = async () => {
|
||||
if (auctionFinalizer) {
|
||||
await auctionFinalizer.close();
|
||||
}
|
||||
await dbHooks.close();
|
||||
if (reservedTurnStoreHandle) {
|
||||
await reservedTurnStoreHandle.close();
|
||||
@@ -281,6 +287,7 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
const commandHandler = createTurnDaemonCommandHandler({
|
||||
world,
|
||||
hooks,
|
||||
auctionFinalizer: auctionFinalizer ?? undefined,
|
||||
});
|
||||
|
||||
const defaultBudget: TurnRunBudget = options.defaultBudget ?? {
|
||||
|
||||
@@ -29,6 +29,11 @@ const flushWorld = async (world: InMemoryTurnWorld, hooks?: TurnDaemonHooks): Pr
|
||||
interface CommandHandlerContext {
|
||||
world: InMemoryTurnWorld;
|
||||
hooks?: TurnDaemonHooks;
|
||||
auctionFinalizer?: AuctionFinalizer;
|
||||
}
|
||||
|
||||
interface AuctionFinalizer {
|
||||
finalize(auctionId: number): Promise<TurnDaemonCommandResult>;
|
||||
}
|
||||
|
||||
async function handleTroopJoin(
|
||||
@@ -299,6 +304,21 @@ async function handleDropItem(
|
||||
return { type: 'dropItem', ok: true, generalId: command.generalId };
|
||||
}
|
||||
|
||||
async function handleAuctionFinalize(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'auctionFinalize' }>
|
||||
): Promise<TurnDaemonCommandResult> {
|
||||
if (!ctx.auctionFinalizer) {
|
||||
return {
|
||||
type: 'auctionFinalize',
|
||||
ok: false,
|
||||
auctionId: command.auctionId,
|
||||
reason: '경매 확정기가 준비되지 않았습니다.',
|
||||
};
|
||||
}
|
||||
return ctx.auctionFinalizer.finalize(command.auctionId);
|
||||
}
|
||||
|
||||
async function handleChangePermission(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'changePermission' }>
|
||||
@@ -434,8 +454,9 @@ async function handleAppoint(
|
||||
export const createTurnDaemonCommandHandler = (options: {
|
||||
world: InMemoryTurnWorld;
|
||||
hooks?: TurnDaemonHooks;
|
||||
auctionFinalizer?: AuctionFinalizer;
|
||||
}): TurnDaemonCommandHandler => {
|
||||
const ctx = { world: options.world, hooks: options.hooks };
|
||||
const ctx = { world: options.world, hooks: options.hooks, auctionFinalizer: options.auctionFinalizer };
|
||||
|
||||
return {
|
||||
handle: async (command): Promise<TurnDaemonCommandResult | null> => {
|
||||
@@ -456,6 +477,8 @@ export const createTurnDaemonCommandHandler = (options: {
|
||||
return handleSetMySetting(ctx, command);
|
||||
case 'dropItem':
|
||||
return handleDropItem(ctx, command);
|
||||
case 'auctionFinalize':
|
||||
return handleAuctionFinalize(ctx, command);
|
||||
case 'changePermission':
|
||||
return handleChangePermission(ctx, command);
|
||||
case 'kick':
|
||||
|
||||
Reference in New Issue
Block a user