summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2023-10-15 01:36:37 -0400
committerDavid Gay <eapoems@riseup.net>2023-10-15 01:36:37 -0400
commit1591a38ea4d1c7dd5075773a8c7b5b321f8de8c7 (patch)
tree7e857cdec3c1ae86073eee9b413c71a250259208 /src
parent47ee997edcf7607c4dc1ed0ea8f6637ec1d66d42 (diff)
Hook up races
Diffstat (limited to 'src')
-rw-r--r--src/data/rules/races.yaml5
-rw-r--r--src/main.rs11
-rw-r--r--src/rules/npcs.rs5
3 files changed, 17 insertions, 4 deletions
diff --git a/src/data/rules/races.yaml b/src/data/rules/races.yaml
index 84d1150..8b54e78 100644
--- a/src/data/rules/races.yaml
+++ b/src/data/rules/races.yaml
@@ -19,6 +19,7 @@ elf:
gnome:
name: "Gnome"
+ ability_score_modifiers:
npc_ability_score_modifiers:
Wisdom: +1
Constitution: +1
@@ -26,6 +27,8 @@ gnome:
half-elf:
name: "Half-elf"
+ ability_score_modifiers:
+ npc_ability_score_modifiers:
halfling:
name: "Halfling"
@@ -48,3 +51,5 @@ half-orc:
human:
name: "Human"
+ ability_score_modifiers:
+ npc_ability_score_modifiers:
diff --git a/src/main.rs b/src/main.rs
index f97cf31..46fd094 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use dmn::random_tables::RandomTables;
use dmn::rules::ability_scores::AbilityScore;
use dmn::rules::classes::CLASSES;
use dmn::rules::npcs::Npc;
+use dmn::rules::races::RACES;
mod cli;
@@ -16,6 +17,7 @@ fn main() {
match random_command {
("henchman", _) => {
let class_name = random_tables.roll_table("henchman_class").to_string();
+ let race_name = random_tables.roll_table("henchman_race").to_string();
// HACK: Need a proper way to do lookups, shouldn't rely on
// downcasing the class name. This whole situation is really
// indicative of the need for an architectural improvement.
@@ -25,9 +27,14 @@ fn main() {
eprintln!("Class '{}' not found.", &*class_name);
std::process::exit(1);
});
+ let race_ref = RACES.get(&*race_name.to_lowercase()).unwrap_or_else(|| {
+ eprintln!("Race '{}' not found.", &*class_name);
+ std::process::exit(1);
+ });
+
let mut npc = Npc::new(
Some(random_tables.roll_table("npc_alignment")),
- Some(random_tables.roll_table("henchman_race")),
+ Some(race_ref),
Some(class_ref),
None,
);
@@ -36,7 +43,7 @@ fn main() {
println!(
"{} {} {}. STR {}, INT {}, WIS {}, CON {}, DEX {}, CHA {}",
npc.alignment.unwrap(),
- npc.race.unwrap(),
+ npc.race.unwrap().name,
npc.class.unwrap().name,
ability_scores.get_score(AbilityScore::Strength).unwrap(),
ability_scores
diff --git a/src/rules/npcs.rs b/src/rules/npcs.rs
index 22907cd..206151c 100644
--- a/src/rules/npcs.rs
+++ b/src/rules/npcs.rs
@@ -1,12 +1,13 @@
use crate::dice::roll_formula;
use crate::rules::ability_scores::{AbilityScore, AbilityScoreCollection};
use crate::rules::classes::Class;
+use crate::rules::races::Race;
use std::collections::HashMap;
// use std::fmt;
pub struct Npc {
pub alignment: Option<String>,
- pub race: Option<String>,
+ pub race: Option<&'static Race>,
pub class: Option<&'static Class>,
pub ability_scores: Option<AbilityScoreCollection>,
}
@@ -14,7 +15,7 @@ pub struct Npc {
impl Npc {
pub fn new(
alignment: Option<String>,
- race: Option<String>,
+ race: Option<&'static Race>,
class: Option<&'static Class>,
ability_scores: Option<AbilityScoreCollection>,
) -> Self {