feat: 토너먼트 관련 기능 추가 및 베팅 처리 로직 구현
This commit is contained in:
@@ -233,6 +233,29 @@ const normalizeCommand = (envelope: TurnDaemonCommandEnvelope): TurnDaemonComman
|
||||
refunds,
|
||||
};
|
||||
}
|
||||
case 'tournamentBettingPayout': {
|
||||
if (!Array.isArray(command.payouts)) {
|
||||
return null;
|
||||
}
|
||||
const payouts = command.payouts
|
||||
.filter((entry) =>
|
||||
entry && typeof entry.generalId === 'number' && typeof entry.amount === 'number'
|
||||
)
|
||||
.map((entry) => ({
|
||||
generalId: entry.generalId,
|
||||
amount: entry.amount,
|
||||
}));
|
||||
if (payouts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
type: 'tournamentBettingPayout',
|
||||
requestId: envelope.requestId,
|
||||
bettingId: typeof command.bettingId === 'number' ? command.bettingId : undefined,
|
||||
reason: typeof command.reason === 'string' ? command.reason : undefined,
|
||||
payouts,
|
||||
};
|
||||
}
|
||||
case 'getStatus': {
|
||||
const requestId = typeof command.requestId === 'string' ? command.requestId : envelope.requestId;
|
||||
return { type: 'getStatus', requestId };
|
||||
|
||||
@@ -499,6 +499,54 @@ async function handleTournamentRefund(
|
||||
};
|
||||
}
|
||||
|
||||
async function handleTournamentBettingPayout(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'tournamentBettingPayout' }>
|
||||
): Promise<TurnDaemonCommandResult> {
|
||||
const { world, hooks } = ctx;
|
||||
if (!command.payouts || command.payouts.length === 0) {
|
||||
return {
|
||||
type: 'tournamentBettingPayout',
|
||||
ok: false,
|
||||
bettingId: command.bettingId,
|
||||
reason: '정산 대상이 없습니다.',
|
||||
};
|
||||
}
|
||||
|
||||
let processed = 0;
|
||||
let missing = 0;
|
||||
let totalPayout = 0;
|
||||
|
||||
for (const payout of command.payouts) {
|
||||
if (!payout || typeof payout.generalId !== 'number' || typeof payout.amount !== 'number') {
|
||||
continue;
|
||||
}
|
||||
if (payout.amount <= 0) {
|
||||
continue;
|
||||
}
|
||||
const general = world.getGeneralById(payout.generalId);
|
||||
if (!general) {
|
||||
missing += 1;
|
||||
continue;
|
||||
}
|
||||
world.updateGeneral(payout.generalId, {
|
||||
gold: general.gold + payout.amount,
|
||||
});
|
||||
processed += 1;
|
||||
totalPayout += payout.amount;
|
||||
}
|
||||
|
||||
await flushWorld(world, hooks);
|
||||
return {
|
||||
type: 'tournamentBettingPayout',
|
||||
ok: true,
|
||||
bettingId: command.bettingId,
|
||||
processed,
|
||||
missing,
|
||||
totalPayout,
|
||||
};
|
||||
}
|
||||
|
||||
export const createTurnDaemonCommandHandler = (options: {
|
||||
world: InMemoryTurnWorld;
|
||||
hooks?: TurnDaemonHooks;
|
||||
@@ -535,6 +583,8 @@ export const createTurnDaemonCommandHandler = (options: {
|
||||
return handleAppoint(ctx, command);
|
||||
case 'tournamentRefund':
|
||||
return handleTournamentRefund(ctx, command);
|
||||
case 'tournamentBettingPayout':
|
||||
return handleTournamentBettingPayout(ctx, command);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user