feat(game): trait outcome effects — extra haul item + recruit chance (#43)
This commit is contained in:
+21
-4
@@ -3,7 +3,7 @@ import type { GameDb } from '@/lib/db/client'
|
||||
import { persist } from '@/lib/db/client'
|
||||
import * as schema from '@/lib/db/schema'
|
||||
import { generateStartingCrew, rollCrewMember, startingCrewRng, type CrewMember } from './crew'
|
||||
import { ACTION_SKILL, STARTING_LEVELS, XP_THRESHOLDS, type SkillName } from './crew-costs'
|
||||
import { ACTION_SKILL, RECRUIT_CHANCE_BASE, RECRUIT_CHANCE_TALKER, STARTING_LEVELS, XP_THRESHOLDS, type SkillName } from './crew-costs'
|
||||
import { BASE_CAPACITY, BASE_LEVEL, SHIP_TYPES } from './ship-costs'
|
||||
import { checkMissionCompletion, topUpMissionBoard } from './missions'
|
||||
import { resolveResearchTask, ResearchError } from './research'
|
||||
@@ -552,9 +552,26 @@ export async function resolveExploreTask(db: GameDb, task: Task): Promise<{ outc
|
||||
if (target.explored) throw new ExploreError(409, `${target.name} was already explored`)
|
||||
|
||||
const rng = explorationRng(save.seed, target.id)
|
||||
const outcome = rollExploration(rng) // resource/part haul first…
|
||||
const takenNames = new Set((await db.db.select().from(schema.crew)).map((c) => c.name))
|
||||
const foundMember = rollCrewMember(rng, takenNames) // …then the crew roll on the same stream
|
||||
let outcome = rollExploration(rng) // resource/part haul first…
|
||||
|
||||
// Trait outcome effects (#43): the assigned team (lead + helpers) can change how this
|
||||
// per-planet stream is drawn. Read their traits from the roster (a plain select — no rng draw).
|
||||
const assigned = new Set([task.leadCrewId, ...task.helpers].filter((id) => id > 0))
|
||||
const crewRows = await db.db.select().from(schema.crew)
|
||||
let hasFHT = false
|
||||
let hasTalker = false
|
||||
for (const c of crewRows) {
|
||||
if (!assigned.has(c.id)) continue
|
||||
if (c.traitGood === 'FINDS HIDDEN THINGS' || c.traitBad === 'FINDS HIDDEN THINGS') hasFHT = true
|
||||
if (c.traitGood === 'TALKS TO ANYONE' || c.traitBad === 'TALKS TO ANYONE') hasTalker = true
|
||||
}
|
||||
|
||||
// FINDS HIDDEN THINGS: one extra haul roll on the same seeded stream, appended (spec §5).
|
||||
if (hasFHT) outcome = [...outcome, ...rollExploration(rng)]
|
||||
|
||||
const takenNames = new Set(crewRows.map((c) => c.name))
|
||||
// TALKS TO ANYONE: recruit chance 30% instead of the base 18% (base === crew.ts CREW_CHANCE).
|
||||
const foundMember = rollCrewMember(rng, takenNames, hasTalker ? RECRUIT_CHANCE_TALKER : RECRUIT_CHANCE_BASE)
|
||||
|
||||
await db.db.update(schema.planets).set({ explored: true }).where(eq(schema.planets.id, target.id))
|
||||
for (const item of outcome) {
|
||||
|
||||
Reference in New Issue
Block a user