feat: complete legacy-compatible auction system
This commit is contained in:
@@ -36,6 +36,17 @@ const zAuctionFinalize = z.object({
|
||||
auctionId: zFiniteNumber,
|
||||
});
|
||||
|
||||
const zAuctionOpen = z.object({
|
||||
type: z.literal('auctionOpen'),
|
||||
generalId: zFiniteNumber,
|
||||
auctionType: z.enum(['BUY_RICE', 'SELL_RICE', 'UNIQUE_ITEM']),
|
||||
amount: zFiniteNumber,
|
||||
closeTurnCnt: zFiniteNumber.optional(),
|
||||
startBidAmount: zFiniteNumber.optional(),
|
||||
finishBidAmount: zFiniteNumber.optional(),
|
||||
itemKey: z.string().optional(),
|
||||
});
|
||||
|
||||
const zAuctionBid = z.object({
|
||||
type: z.literal('auctionBid'),
|
||||
auctionId: zFiniteNumber,
|
||||
@@ -246,6 +257,14 @@ const normalizeAuctionFinalize: CommandNormalizer<'auctionFinalize'> = (envelope
|
||||
return { ...command, requestId: envelope.requestId };
|
||||
};
|
||||
|
||||
const normalizeAuctionOpen: CommandNormalizer<'auctionOpen'> = (envelope) => {
|
||||
const command = parseWith(zAuctionOpen, envelope.command);
|
||||
if (!command) {
|
||||
return null;
|
||||
}
|
||||
return { ...command, requestId: envelope.requestId };
|
||||
};
|
||||
|
||||
const normalizeAuctionBid: CommandNormalizer<'auctionBid'> = (envelope) => {
|
||||
const command = parseWith(zAuctionBid, envelope.command);
|
||||
if (!command) {
|
||||
@@ -444,6 +463,7 @@ const normalizeShutdown: CommandNormalizer<'shutdown'> = (envelope) => {
|
||||
|
||||
const normalizers: CommandNormalizerMap = {
|
||||
auctionFinalize: normalizeAuctionFinalize,
|
||||
auctionOpen: normalizeAuctionOpen,
|
||||
auctionBid: normalizeAuctionBid,
|
||||
troopJoin: normalizeTroopJoin,
|
||||
troopExit: normalizeTroopExit,
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
} from '@sammo-ts/logic/items/index.js';
|
||||
import type { InMemoryTurnWorld } from './inMemoryWorld.js';
|
||||
import type { TurnGeneral } from './types.js';
|
||||
import { openAuction } from '../auction/opener.js';
|
||||
|
||||
let itemRegistryPromise: Promise<Map<string, ItemModule>> | null = null;
|
||||
|
||||
@@ -663,6 +664,13 @@ async function handleAuctionFinalize(
|
||||
return ctx.auctionFinalizer.finalize(command.auctionId, ctx.commandDb);
|
||||
}
|
||||
|
||||
async function handleAuctionOpen(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'auctionOpen' }>
|
||||
): Promise<TurnDaemonCommandResult> {
|
||||
return openAuction(command, ctx.world, ctx.commandDb);
|
||||
}
|
||||
|
||||
async function handleAuctionBid(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'auctionBid' }>
|
||||
@@ -1168,6 +1176,8 @@ export const createTurnDaemonCommandHandler = (options: {
|
||||
dropItem: (command) => handleDropItem(ctx, command as Extract<TurnDaemonCommand, { type: 'dropItem' }>),
|
||||
auctionFinalize: (command) =>
|
||||
handleAuctionFinalize(ctx, command as Extract<TurnDaemonCommand, { type: 'auctionFinalize' }>),
|
||||
auctionOpen: (command) =>
|
||||
handleAuctionOpen(ctx, command as Extract<TurnDaemonCommand, { type: 'auctionOpen' }>),
|
||||
auctionBid: (command) => handleAuctionBid(ctx, command as Extract<TurnDaemonCommand, { type: 'auctionBid' }>),
|
||||
changePermission: (command) =>
|
||||
handleChangePermission(ctx, command as Extract<TurnDaemonCommand, { type: 'changePermission' }>),
|
||||
|
||||
Reference in New Issue
Block a user