feat: 토너먼트 보상 처리 기능 추가 및 관련 타입 정의
This commit is contained in:
@@ -27,6 +27,7 @@ import { loadTurnWorldFromDatabase } from './worldLoader.js';
|
||||
import { shouldUseAi } from './ai/generalAi.js';
|
||||
import { createUnificationHandler } from './unificationHandler.js';
|
||||
import { createAuctionFinalizer } from '../auction/finalizer.js';
|
||||
import { createTournamentRewardFinalizer } from '../tournament/finalizer.js';
|
||||
|
||||
export interface TurnDaemonRuntimeOptions {
|
||||
profile: string;
|
||||
@@ -172,6 +173,7 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
let publishRealtimeEvent: ((event: RealtimeEvent) => Promise<void>) | null = null;
|
||||
let close = async () => {};
|
||||
let auctionFinalizer: Awaited<ReturnType<typeof createAuctionFinalizer>> | null = null;
|
||||
let tournamentRewardFinalizer: Awaited<ReturnType<typeof createTournamentRewardFinalizer>> | null = null;
|
||||
let redisCommandStream: RedisTurnDaemonCommandStream | null = null;
|
||||
let redisConnector: ReturnType<typeof createRedisConnector> | null = null;
|
||||
let pauseGate: (() => Promise<boolean>) | undefined;
|
||||
@@ -196,6 +198,11 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
world,
|
||||
hooks: dbHooks.hooks,
|
||||
});
|
||||
tournamentRewardFinalizer = await createTournamentRewardFinalizer({
|
||||
databaseUrl: options.databaseUrl,
|
||||
world,
|
||||
hooks: dbHooks.hooks,
|
||||
});
|
||||
hooks = {
|
||||
...dbHooks.hooks,
|
||||
onRunError: async (error) => {
|
||||
@@ -207,6 +214,9 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
if (auctionFinalizer) {
|
||||
await auctionFinalizer.close();
|
||||
}
|
||||
if (tournamentRewardFinalizer) {
|
||||
await tournamentRewardFinalizer.close();
|
||||
}
|
||||
await dbHooks.close();
|
||||
if (reservedTurnStoreHandle) {
|
||||
await reservedTurnStoreHandle.close();
|
||||
@@ -292,6 +302,7 @@ export const createTurnDaemonRuntime = async (options: TurnDaemonRuntimeOptions)
|
||||
world,
|
||||
hooks,
|
||||
auctionFinalizer: auctionFinalizer ?? undefined,
|
||||
tournamentRewardFinalizer: tournamentRewardFinalizer ?? undefined,
|
||||
});
|
||||
|
||||
const defaultBudget: TurnRunBudget = options.defaultBudget ?? {
|
||||
|
||||
@@ -30,12 +30,17 @@ interface CommandHandlerContext {
|
||||
world: InMemoryTurnWorld;
|
||||
hooks?: TurnDaemonHooks;
|
||||
auctionFinalizer?: AuctionFinalizer;
|
||||
tournamentRewardFinalizer?: TournamentRewardFinalizer;
|
||||
}
|
||||
|
||||
interface AuctionFinalizer {
|
||||
finalize(auctionId: number): Promise<TurnDaemonCommandResult>;
|
||||
}
|
||||
|
||||
interface TournamentRewardFinalizer {
|
||||
finalize(command: Extract<TurnDaemonCommand, { type: 'tournamentReward' }>): Promise<TurnDaemonCommandResult>;
|
||||
}
|
||||
|
||||
async function handleTroopJoin(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'troopJoin' }>
|
||||
@@ -547,12 +552,34 @@ async function handleTournamentBettingPayout(
|
||||
};
|
||||
}
|
||||
|
||||
async function handleTournamentReward(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'tournamentReward' }>
|
||||
): Promise<TurnDaemonCommandResult> {
|
||||
if (!ctx.tournamentRewardFinalizer) {
|
||||
return {
|
||||
type: 'tournamentReward',
|
||||
ok: false,
|
||||
winnerId: command.winnerId,
|
||||
runnerUpId: command.runnerUpId,
|
||||
reason: '보상 처리기가 준비되지 않았습니다.',
|
||||
};
|
||||
}
|
||||
return ctx.tournamentRewardFinalizer.finalize(command);
|
||||
}
|
||||
|
||||
export const createTurnDaemonCommandHandler = (options: {
|
||||
world: InMemoryTurnWorld;
|
||||
hooks?: TurnDaemonHooks;
|
||||
auctionFinalizer?: AuctionFinalizer;
|
||||
tournamentRewardFinalizer?: TournamentRewardFinalizer;
|
||||
}): TurnDaemonCommandHandler => {
|
||||
const ctx = { world: options.world, hooks: options.hooks, auctionFinalizer: options.auctionFinalizer };
|
||||
const ctx = {
|
||||
world: options.world,
|
||||
hooks: options.hooks,
|
||||
auctionFinalizer: options.auctionFinalizer,
|
||||
tournamentRewardFinalizer: options.tournamentRewardFinalizer,
|
||||
};
|
||||
|
||||
return {
|
||||
handle: async (command): Promise<TurnDaemonCommandResult | null> => {
|
||||
@@ -585,6 +612,8 @@ export const createTurnDaemonCommandHandler = (options: {
|
||||
return handleTournamentRefund(ctx, command);
|
||||
case 'tournamentBettingPayout':
|
||||
return handleTournamentBettingPayout(ctx, command);
|
||||
case 'tournamentReward':
|
||||
return handleTournamentReward(ctx, command);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user