import { routes } from "@deadhead/schema"; import type { FastifyInstance } from "fastify"; import { buyShip, leaseBay } from "../game/fleet"; import { assignPilot, hirePilot, spendSkillPoint, unassignPilot } from "../game/pilots"; import { registerRoute } from "../http/route"; import type { AppContext } from "./context"; import { withPlayer } from "./with-player"; /** Ships, bays and pilots. */ export function registerFleetRoutes(app: FastifyInstance, ctx: AppContext): void { registerRoute(app, routes.buyShip, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ ship: await buyShip(tx, playerId, input, now), })), ); registerRoute(app, routes.leaseBay, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ bay: await leaseBay(tx, playerId, input.locationId, now), })), ); registerRoute(app, routes.hirePilot, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ pilot: await hirePilot(tx, playerId, input.locationId, now), })), ); registerRoute(app, routes.assignPilot, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ pilot: await assignPilot(tx, playerId, input.pilotId, input.shipId, now), })), ); registerRoute(app, routes.unassignPilot, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ pilot: await unassignPilot(tx, playerId, input.pilotId, now), })), ); registerRoute(app, routes.spendSkillPoint, ctx.options, async (input, { playerId }) => withPlayer(ctx, playerId, async (tx, now) => ({ pilot: await spendSkillPoint(tx, playerId, input.pilotId, input.skillId, now), })), ); }