Expand description
A library to assist in creating and managing D&D 5e characters.
The main feature of this crate is the Character struct. Most of the other datastructures in this crate (found in the rules2014 module) are centered around it, building the foundations for a complete D&D character.
#[tokio::main]
async fn main() {
use rand::Rng;
use dnd_lib::prelude::*;
let mut rng = rand::thread_rng();
// first, we construct the api getter.
let provider = Dnd5eapigetter::new();
// then, we get all the things we need to create a character.
let rogue = provider.get_class("rogue").await.unwrap();
let human = provider.get_race("human").await.unwrap();
let acolyte = provider.get_background("acolyte").await.unwrap();
// this is john. John is a human rogue.
let mut john = CharacterBuilder::new("John")
.race(&human)
.background(&acolyte)
.class(&rogue)
.stats(Stats::default())
.build().unwrap();
// john sees an upcoming fight, and equips his dagger.
john.items[3].equip();
// Uh-Oh! John is about to get hit! What's his AC?
let ac = john.ac();
// looks like it was too small. John gets hit with 3 damage.
john.damage(3);
// Now it's John's turn. He readies his dagger.
let dagger_attack = &john.weapon_actions()[0];
// John tries to attack...
let attack_roll = rng.random_range(1..=20) as isize + dagger_attack.attack_bonus;
// And it hits!
let damage_roll = dagger_attack.damage_roll;
// It does enough damage to kill the monster immediately!
// With the xp from that fight, john levels up.
john.level_up(&rogue);
// Afterwards, john is smited from reality for the sin of existance.
drop(john);
}This crate stores different choices for a character as different structs. For example, a
rules2014::class::Class would be a Wizard, or a Figter, or a Monk. If you wanted to store every D&D class a
character could take, you’d need a Vec<Class>. These rules must be parsed from an api and constructed.
This is what get::Dnd5eapigetter is for. You first get the required rules (class, background, race) from the api, then you build a character with that.
§Feature flags
integrationSpecifically for testing. Enables all tests.dnd5eapi- (enabled by default) Enables retrieving through the dnd5eapi.co api.item_list- (enabled by default) Enables the constant array of item names retrievable through the dnd5eapi.co api, seen at get::ITEM_NAMES. This is delegated to a features, as it is ~2.5 kb of data by itself.
Re-exports§
pub use rules2014::player_character::Character;pub use rules2014::player_character::CharacterBuilder;
Modules§
- get
- Gets data from dnd5eapi.co
- prelude
- rules2014
- A module that contains the needed rules and etc factors to make a character in 5e 2014 D&D.
- save
- A simple helper to save other data to a file.
Enums§
- Character
Data Error - Errors that can occur when retrieving or parsing character data
Traits§
- Data
Provider - A trait representing a source capable of retrieving D&D data, e.g. from an api.