Crates.io | dnd_dice_roller |
lib.rs | dnd_dice_roller |
version | 0.5.1 |
source | src |
created_at | 2020-03-30 00:20:26.387459 |
updated_at | 2021-04-18 00:27:35.480124 |
description | A simple dice rolling library for dnd dice strings |
homepage | |
repository | https://github.com/arranf/dnd_dice_roller |
max_upload_size | |
id | 224243 |
size | 30,203 |
A simple Rust library for taking a DnD like dice string as an input and calculating a result.
Supports advantage and disadvantage.
use dice_roller::dice::{Dice, RollType};
use std::str::FromStr;
let dice = Dice::from_str("2d20 + 1")?;
// Roll dice uses thread RNG
let result = dice.roll_dice();
A single d20 with a plus five modifier and advantage
let second_dice = Dice::new(1, 20, Some(5), RollType::Advantage);
let results = second_dice.roll_dice();
d6
2d6
2d6 + 3
d20 advantage
d20 adv
d20 a
2d20 + 4 advantage
2d20 - 2 adv
1d6 - 1 disadvantage
1d6 dadv
d6 d