Expand description
Evaluation and rolling of D&D 5e die roll expressions.
The RollExpression
trait provides methods for dealing with the
various kinds of rolls. Roll
provides the simplest text-in,
text-out interface for rolling expressions an printing the result
regardless of the type of roll.
use critfail::{RollExpression, Roll};
let check = Roll::new("r-3").unwrap();
let check_outcome = check.roll();
print!("{}", check_outcome); // eg. "11"
print!("{:?}", check_outcome); // eg. "(14)-3"
let damage = Roll::new("2d8+6").unwrap();
let damage_outcome = damage.roll();
print!("{}", damage_outcome); // eg. "13"
print!("{:?}", damage_outcome); // eg. "[2+5]+6"
let attack = Roll::new("r+1?2d6+4").unwrap();
let attack_outcome = attack.roll();
print!("{}", attack_outcome); // eg. "10 ? 16"
print!("{:?}", attack_outcome); // eg. "(9)+1 ? [6+6]+4"
In order to handle the outcome of a Roll
programatically, roll
expressions are split into Check
rolls, Damage
rolls, and
Attack
rolls, each with their own outcome type which provides
methods for determining the score and makeup of the results for
each.
§Features
wasm-bindgen
: Enable this when compiling for wasm32 targets, or random number generation won’t work.
Structs§
- Attack
- An attack roll consisting of a check and a damage roll.
- Attack
Outcome - The outcome of an attack roll.
- Attack
Outcome Builder - This is used to create a ‘fudged’
AttackOutcome
without actually randomly generating anything. - Check
- An ability check - roll a d20, potentially with modifiers or advantage.
- Check
Outcome - The outcome of a check roll.
- Check
Outcome Builder - This is used to create a ‘fudged’
CheckOutcome
without actually randomly generating anything. - Damage
- A list of dice to roll and modifiers to add, usually used for damage.
- Damage
Outcome - The outcome of a check roll.
- Damage
Outcome Builder - This is used to create a ‘fudged’
DamageOutcome
without actually randomly generating anything. - Parse
Error - Represents an error parsing a roll expression.
Enums§
- AdvState
- The advantage state of an ability check.
- Crit
Score - The score of a roll that could be a critical hit/failure
- Outcome
Part - Enum representing the different kinds of values that can be returned for damage or the modifier on a check.
- Roll
- Any kind of roll—either a check, damage, or attack roll.
- Roll
Outcome - The outcome of rolling a check, damage, or attack roll.
Traits§
- Roll
Expression - Used for structs defining a set of dice that can be rolled.