Crate rpg_dice_roller

Source
Expand description

Roll dice with modifiers and apply expressions to them.

// Roll 3 d20, make the minimum value 5, keep the lowest 2 rolls.
let rolled = roll("3d20min5kl2")?;
println!("{rolled} = {}", rolled.value()); // [6, 5^, 17d] = 11

// Use a custom Rng that implements the rand::Rng trait
let mut rng = StdRng::seed_from_u64(1);
let rolled = roll_with("3d200", &mut rng)?;
println!("{rolled} = {}", rolled.value()); // [165, 195, 160] = 520

// Create Dice directly without parsing
let dice = Dice::new(5, DiceKind::Standard(8), &[Modifier::Min(5)]);
let rolled = dice.roll_all();
println!("{rolled} = {}", rolled.value()); // [8, 6, 5^, 8, 5] = 32

let rolled = dice.roll_once();
println!("{rolled} = {}", rolled.value()); // [8] = 8

Structs§

Dice

Enums§

ComparePoint
DiceKind
ExplodingKind
Expression
KeepKind
MathFn1
MathFn2
Modifier
Modifiers are special optional notations placed after a die or expression group.
RolledExpression

Functions§

parse
Parses the notation returning the parsed abstract syntax tree without rolling the dice.
roll
Parses the notation returning the result of rolling all the dice parsed.
roll_with
Same as roll() but allows you to choose the rng you prefer to use.