game.rules — the shared constants, state and rules of Spooky Spook Spook.
Every slice talks to every other slice through THIS module and nothing
else: the player, the enemies, the UI and the audio never require each
other. Read `R.state`, call the verbs below, and subscribe with `R.on`.
local R = require("game.rules")
R.on("enemyKilled", function(p) ... end)
R.emit("enemyKilled", { kind = "ghoul", pos = { x, y, z } })
Owned by the plan pass. A slice that needs a new event ADDS it to the
EVENTS list below and documents it there; it never changes an existing
signature.
groundHeight(x: number, z: number) → number
Height of the ground at world (x, z). The arena slice provides it as
"groundHeight"; until it does, the ground is flat at y = 0.
| arg | type | description |
|---|
| x | number | |
| z | number | |
boneName(bone: ?) → string
A procedural name for a bone from its seed, kind, rarity, affix and mutation.
rng(seed: number) → void
A tiny deterministic RNG so a seed reproduces a run.
| arg | type | description |
|---|
| seed | number | |
pickWeighted(rand: ?, list: ?) → void
| arg | type | description |
|---|
| rand | ? | |
| list | ? | |
rollBone(rand: (, wave: ?, kind: ?) → void
Roll a procedurally generated bone: kind, length, weight, rarity and affix.
| arg | type | description |
|---|
| rand | ( | A function returning 0..1 (M.rng(seed) or math.random). |
| wave | ? | The wave it dropped on; deeper waves roll rarer bones. |
| kind | ? | Optional fixed kind; random from BONE_ORDER when nil. |
computeStats(build: { any }) →
Derive the player's stats from the list of attached bones.
| arg | type | description |
|---|
| build | { any } | The attached bones, as stored in R.state.build. |
soft(v: ?, knee: ?, cap: ?) → void
soft caps: stacking keeps paying off, but a many-legged build stays controllable
| arg | type | description |
|---|
| v | ? | |
| knee | ? | |
| cap | ? | |
activeSynergies(stats: ?) → void
The archetypes a build has reached, as a list of SYNERGIES entries.
buildTitle(stats: ?) → string
A procedural epithet for the whole skeleton, from its dominant parts:
"the Many-Legged Hydra", "the Bone Lich", ... Used by the Ossuary and end screens.
openSockets(build: { any }) → void
The sockets left open on a build: start sockets plus every bone's `opens`, minus what is plugged.
| arg | type | description |
|---|
| build | { any } | |
canAttach(build: { any }, bone: ?) → boolean
| arg | type | description |
|---|
| build | { any } | |
| bone | ? | |
waveSpec(wave: number) → void
What a wave holds: a list of { kind, count }.
| arg | type | description |
|---|
| wave | number | |
on(name: string, fn: (any) → void
| arg | type | description |
|---|
| name | string | |
| fn | (any | |
emit(name: string, payload: any?) → void
| arg | type | description |
|---|
| name | string | |
| payload | any? | |
provide(name: string, fn: (...any) → void
| arg | type | description |
|---|
| name | string | |
| fn | (...any | |
call(name: string, ...: any) → void
| arg | type | description |
|---|
| name | string | |
| ... | any | |
setPhase(phase: string) → void
| arg | type | description |
|---|
| phase | string | |
newRun(seed: number?) → void
Start a fresh run: a lone skull, wave 1.
| arg | type | description |
|---|
| seed | number? | |
startNextWave( ) → void
Advance to the next wave and enter the fight phase.
clearWave( ) → void
Called by the WaveDirector when the last enemy of a wave dies.
hurtPlayer(amount: number) → void
| arg | type | description |
|---|
| amount | number | |
healPlayer(amount: number) → void
Knit HP back onto the skeleton, up to maxHp. Fractions accumulate.
| arg | type | description |
|---|
| amount | number | |
collectBone(bone: ?) → void
attachBone(boneId: string) → boolean
Move a bone from the inventory onto the skeleton, if a socket is open.
| arg | type | description |
|---|
| boneId | string | |
detachBone(boneId: string) → boolean
Pull the most recently attached bone of the build back into the inventory.
| arg | type | description |
|---|
| boneId | string | |
playerPos( ) → void
Where the player is right now, as { x, y, z }, or nil before the body exists.