Expand description
Combat encounters, modelled with event sourcing.
Clients send CombatCommands (intents). decide turns a command into
CombatEvents (facts), and CombatState::apply folds events into the
current state. The server is authoritative: it alone decides events and
fixes their order in the log. Because both functions live here, clients
run them too, showing the outcome of their own commands immediately and
reconciling when the server’s events arrive.
Re-exports§
Modules§
- undo
- Undoing a command.
- view
- What a player’s device sees of a combat. The party knows each other’s
hit points, but monsters’ (and anyone else the DM adds) stay behind the
DM’s screen: a player sees only how hurt one looks (
Vitality), and not its armor class.
Structs§
- Combat
Snapshot - The current state of a combat as of log position
seq. - Combat
State - Where a combat stands: the result of applying its log, event by event.
- Combat
Summary - A combat in a list:
GET /combats. - Combatant
- Anyone in a combat: a character, a monster, or anyone else the DM adds.
- Command
Envelope - A command plus the metadata that makes it trackable.
command_idis chosen by the client: the server tags the resulting events with it (so the client knows its prediction was confirmed) and ignores repeats (so resending after a dropped connection is safe). - Effect
- Anything in play with a duration or a target: spells, conditions, auras.
- Expiry
- When an effect ends: at the start of
at_turn_of’s turn inround, or at the start ofroundif there’s no such combatant (5e durations run from the caster’s turn; for an effect nobody cast, from the turn it was put down in). - Logged
Event - One entry in a combat’s permanent log.
- NewEffect
- An effect for a command to put into play.
- NoDice
- Dice that never roll: for predicting, where rolls wait for the server.
Enums§
- Client
Message - Sent by a client over a combat’s WebSocket.
- Combat
Command - What a participant wants to happen. Turned into events by
decide. - Combat
Error - Why the rules refuse a command.
- Combat
Event - Something that happened in a combat. Events are facts: they carry outcomes (the rolled number, the resulting HP) so replaying the log never needs to re-roll or re-decide anything.
- Combat
Status - Whether a combat is being set up, running, paused or over.
- Effect
EndReason - Why an effect ended.
- Server
Message - Sent by the server over a combat’s WebSocket.
- Sheet
Cost - What a command spends on a character’s sheet: a spell slot, or uses of a feature.
- Spell
Slot - The slot a spell was cast with: a regular slot of some level, or a Pact Magic slot (whose level is fixed).
Traits§
- Dice
- Source of d20 rolls. The server rolls real dice; clients predicting an
outcome use
NoDice, so anything needing a roll waits for the server.
Functions§
- add_
monsters - The events that add
countofmonsterto the combat, at their maximum hit points or, withroll, rolled. - decide
- Decides what events a command produces. Never returns an empty list: a command that would change nothing is an error, so every accepted command is visible in the log.
- monster_
names - Names for
countmore of a monster: just its name for the only one in the fight, otherwise numbered on from any already there (“Goblin 2”). - player_
may - Whether a player may send
command, given which combatants are their own. Combatants or effects the combat doesn’t have are let through, forsuper::decideto refuse.