Skip to main content

Module combat

Module combat 

Source
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§

pub use view::Concealer;
pub use view::Vitality;

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§

CombatSnapshot
The current state of a combat as of log position seq.
CombatState
Where a combat stands: the result of applying its log, event by event.
CombatSummary
A combat in a list: GET /combats.
Combatant
Anyone in a combat: a character, a monster, or anyone else the DM adds.
CommandEnvelope
A command plus the metadata that makes it trackable. command_id is 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 in round, or at the start of round if 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).
LoggedEvent
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§

ClientMessage
Sent by a client over a combat’s WebSocket.
CombatCommand
What a participant wants to happen. Turned into events by decide.
CombatError
Why the rules refuse a command.
CombatEvent
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.
CombatStatus
Whether a combat is being set up, running, paused or over.
EffectEndReason
Why an effect ended.
ServerMessage
Sent by the server over a combat’s WebSocket.
SheetCost
What a command spends on a character’s sheet: a spell slot, or uses of a feature.
SpellSlot
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 count of monster to the combat, at their maximum hit points or, with roll, 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 count more 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, for super::decide to refuse.