From 686726b414dcb9d0fe66ec0d64436f51919a0fd1 Mon Sep 17 00:00:00 2001 From: David Gay Date: Mon, 16 Oct 2023 13:41:08 -0400 Subject: Racial ability score min/max (male only) --- src/rules/npcs.rs | 11 +++++++++-- src/rules/races.rs | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/rules') diff --git a/src/rules/npcs.rs b/src/rules/npcs.rs index fae1c69..d9fdc0f 100644 --- a/src/rules/npcs.rs +++ b/src/rules/npcs.rs @@ -73,6 +73,12 @@ impl Npc { .unwrap_or(0) as u32; debug!("After adding racial modifiers, now at {}", total); + // Ensure racial ability score limits are imposed. + // TODO: Use u8 for all of these, so no conversion from u32 will be needed. + let [min_score, max_score] = race_ref.ability_score_ranges.get(&ability).unwrap().male; + total = total.max(min_score as u32); + total = total.min(max_score as u32); + ability_score_rolls.insert(ability, total); } @@ -84,7 +90,6 @@ impl Npc { self.ability_scores = Some(score_collection); - // TODO: Apply racial minimums and maximums. // TODO: Verify legality of class based on alignment. // TODO: Verify legality of class based on race. // TODO: Verify legality of class based on ability scores. @@ -123,15 +128,17 @@ impl Npc { mod tests { use super::*; use crate::rules::classes::CLASSES; + use crate::rules::races::RACES; #[test] #[ignore] #[should_panic(expected = "Ability score generation isn't testable yet.")] fn test_roll_henchman_ability_scores() { let class_ref = CLASSES.get("fighter").unwrap(); + let race_ref = RACES.get("dwarf").unwrap(); let mut npc = Npc { alignment: Some(String::from("Lawful Good")), - race: Some(String::from("Dwarf")), + race: Some(race_ref), class: Some(class_ref), ability_scores: None, }; diff --git a/src/rules/races.rs b/src/rules/races.rs index 700c7ea..6c9b00f 100644 --- a/src/rules/races.rs +++ b/src/rules/races.rs @@ -10,6 +10,14 @@ pub struct Race { pub name: String, pub ability_score_modifiers: HashMap, pub npc_ability_score_modifiers: HashMap, + pub ability_score_ranges: HashMap, +} + +// TODO: Allow configuration of whether to use female ranges or not. +#[derive(Deserialize)] +pub struct AbilityScoreRange { + pub male: [u8; 2], + // pub female: [u8; 2], // TODO: Enable female ranges. } lazy_static! { -- cgit v1.2.3