feat(game): skill XP on task completion + power bands in duration (#45)
CI / build + unit + e2e (pull_request) Successful in 2m48s
CI / build + unit + e2e (pull_request) Successful in 2m48s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { checkExploreTarget, ExploreError, getSystemState, queueStateFromSave, saveTaskRow } from '@/lib/game/save'
|
||||
import { checkExploreTarget, ExploreError, getSystemState, makePowerOfFor, queueStateFromSave, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Scan one body of the current system: assign the crew team (lead + helpers) and queue the
|
||||
@@ -29,7 +30,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
await checkExploreTarget(db, planetId) // existing pre-checks: 404 unknown body · 409 already scanned
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task } = queueTask(state, { type: 'EXPLORE', payload: { planetId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task } = queueTask(state, { type: 'EXPLORE', payload: { planetId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'EXPLORE'))
|
||||
await saveTaskRow(db, task) // inventory is unchanged until the scan resolves — no hold write
|
||||
return Response.json({ ...(await getSystemState(db)), outcome: [], crewFound: null })
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { checkJumpTarget, getWorldState, JumpError, queueStateFromSave, saveTaskRow } from '@/lib/game/save'
|
||||
import { checkJumpTarget, getWorldState, JumpError, makePowerOfFor, queueStateFromSave, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Jump to a system within range: assign the crew team (lead + helpers) and queue the JUMP
|
||||
@@ -28,7 +29,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
const hops = await checkJumpTarget(db, systemId) // existing pre-checks: 404 unknown · 409 already there / out of range
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task } = queueTask(state, { type: 'JUMP', payload: { systemId, hops }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task } = queueTask(state, { type: 'JUMP', payload: { systemId, hops }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'JUMP'))
|
||||
await saveTaskRow(db, task) // inventory is unchanged for a JUMP — no hold write
|
||||
return Response.json(await getWorldState(db))
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { getTechState, checkResearchPreconditions, ResearchError } from '@/lib/game/research'
|
||||
import { queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { makePowerOfFor, queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Research one tech: assign the crew team (lead + helpers) and queue the RESEARCH task — the
|
||||
@@ -30,7 +31,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
await checkResearchPreconditions(db, techId) // existing pre-checks: 404 unknown · 409 already researched / missing prereq
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task, inventory } = queueTask(state, { type: 'RESEARCH', payload: { techId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task, inventory } = queueTask(state, { type: 'RESEARCH', payload: { techId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'RESEARCH'))
|
||||
await saveTaskRow(db, task)
|
||||
await saveInventory(db, inventory) // the cost was deducted at queue time
|
||||
return Response.json(await getTechState(db))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { checkBuildPreconditions, getShipState, ShipError } from '@/lib/game/ship'
|
||||
import { queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { makePowerOfFor, queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Build an unbuilt ship system type at base values: assign the crew team (lead + helpers)
|
||||
@@ -30,7 +31,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
await checkBuildPreconditions(db, type) // existing pre-checks: 404 unknown type · 409 already built / build gate
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_BUILD', payload: { type }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_BUILD', payload: { type }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'SHIP_BUILD'))
|
||||
await saveTaskRow(db, task)
|
||||
await saveInventory(db, inventory) // the cost was deducted at queue time
|
||||
return Response.json(await getShipState(db))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { checkExpandPreconditions, getShipState, ShipError } from '@/lib/game/ship'
|
||||
import { queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { makePowerOfFor, queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Raise a built ship system's capacity by one (capped at max capacity): assign the crew team
|
||||
@@ -30,7 +31,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
await checkExpandPreconditions(db, systemId) // existing pre-checks: 404 unknown · 409 not built / max capacity
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_EXPAND', payload: { systemId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_EXPAND', payload: { systemId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'SHIP_EXPAND'))
|
||||
await saveTaskRow(db, task)
|
||||
await saveInventory(db, inventory) // the cost was deducted at queue time
|
||||
return Response.json(await getShipState(db))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { parseCrewTeam } from '@/app/api/crew-team'
|
||||
import { checkUpgradePreconditions, getShipState, ShipError } from '@/lib/game/ship'
|
||||
import { queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { makePowerOfFor, queueStateFromSave, saveInventory, saveTaskRow } from '@/lib/game/save'
|
||||
import { queueTask, TaskError } from '@/lib/game/tasks'
|
||||
|
||||
// Level up a built ship system by one (capped at max level): assign the crew team (lead +
|
||||
@@ -30,7 +31,8 @@ export async function POST(req: Request) {
|
||||
const db = await getGameDb()
|
||||
await checkUpgradePreconditions(db, systemId) // existing pre-checks: 404 unknown · 409 not built / max level
|
||||
const state = await queueStateFromSave(db)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_UPGRADE', payload: { systemId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds })
|
||||
const [save] = await db.db.select().from(schema.saves).limit(1)
|
||||
const { task, inventory } = queueTask(state, { type: 'SHIP_UPGRADE', payload: { systemId }, leadCrewId: team.leadCrewId, helperCrewIds: team.helperCrewIds }, await makePowerOfFor(db, save, 'SHIP_UPGRADE'))
|
||||
await saveTaskRow(db, task)
|
||||
await saveInventory(db, inventory) // the cost was deducted at queue time
|
||||
return Response.json(await getShipState(db))
|
||||
|
||||
Reference in New Issue
Block a user