Log inGet started
Package

missionRunner.module

README.md

missionRunner

Runs authored work from data: steps with goals, fails, limits and

checkpoints, a twist, CHOICES that branch what follows, bonus objectives, and the rewards all of that adds up to.

One runner runs story missions; a second runs activities (the same data shape, see content.missions and
content.activities). It evaluates conditions against facts the game supplies each tick and events the game
reports as they happen. It applies nothing itself: every moment goes out on the hub with the step's or twist's
`stage` directions for the host to act on, and the finished job's rewards for the game to pay.

  local Runner = require("metropolisGame.logic.missionRunner")
  local r = Runner.new(Missions.list, hub, { name = "mission" })      -- name prefixes the hub events
  r:available({ done = {...}, rank = 1, colour = { old_quay = 12 }, upgrades = {}, painted = 0, flags = {}, trust = {} })
  r:start("proper_piece")
  r:event("bought", { tins = 6 })
  r:choose("bargain")                       -- answers a `choose` step (false when no such option is on offer)
  local status = r:tick(dt, facts)          -- "idle" | "running" | "done" | "failed"
  r:retry()                                 -- back to the last checkpoint step (after "failed")
  r:abandon()
  r:view()    -- { id, step, count, limit = { left, duration }?, twisted, failed, options = { id }?, chosen = {} } or nil
  r:serialise()   r:restore(data)           -- the active job, its checkpoint and choices, and what is done
  r.done      -- { [id] = true }            r.chosen -- { [id] = { choice, ... } } what was chosen in finished jobs

A step: { goal, fail?, limit?, checkpoint?, stage?, teach?, vars?, when = { chose = "x" }?, choose = { "x", "y" }? }
  when.chose   the step only exists on the branch where that option was chosen (otherwise it is skipped)
  choose       the step is a decision: it completes when `r:choose(option)` is called (goal is ignored)
A job: { id, steps, twist?, requires?, rewards?, rewardsBy = { [choice] = rewards }?,
         bonus = { { id, goal, rewards } }? (checked every tick; each can be earned once),
         failRewards? (applied when an activity fails: consequences are part of the design) }

Hub events ("<name>" = the runner's name): "<name>Started" { id }, "<name>Step" { id, step, stage, teach, vars,
options }, "<name>Twist" { id, stage, teach }, "<name>StepDone" { id, step }, "<name>Chose" { id, step, choice },
"<name>Bonus" { id, bonus }, "<name>Done" { id, rewards = { rewards, ... }, choices, bonuses },
"<name>Failed" { id, step, why, rewards }.
Runner.test(cond, facts, events, time) is the condition evaluator (see content.missions for the vocabulary).

The interface is documented in the header of init.luau; this file repeats it for the asset browser.