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/data/rules/races.yaml | 133 ++++++++++++++++++++++++++++++++++++++++++++++ src/rules/npcs.rs | 11 +++- src/rules/races.rs | 8 +++ 3 files changed, 150 insertions(+), 2 deletions(-) diff --git a/src/data/rules/races.yaml b/src/data/rules/races.yaml index 0a1ad25..23386e4 100644 --- a/src/data/rules/races.yaml +++ b/src/data/rules/races.yaml @@ -7,6 +7,25 @@ dwarf: Strength: 1 Constitution: 1 Charisma: -1 + ability_score_ranges: + Strength: + male: [8, 18] + female: [] + Intelligence: + male: [3, 18] + female: [] + Wisdom: + male: [3, 18] + female: [] + Dexterity: + male: [3, 17] + female: [] + Constitution: + male: [12, 19] + female: [] + Charisma: + male: [3, 16] + female: [] elf: name: "Elf" @@ -16,6 +35,25 @@ elf: npc_ability_score_modifiers: Intelligence: 1 Dexterity: 1 + ability_score_ranges: + Strength: + male: [3, 18] + female: [] + Intelligence: + male: [8, 18] + female: [] + Wisdom: + male: [3, 18] + female: [] + Dexterity: + male: [7, 19] + female: [] + Constitution: + male: [6, 18] + female: [] + Charisma: + male: [8, 18] + female: [] gnome: name: "Gnome" @@ -24,11 +62,49 @@ gnome: Wisdom: 1 Constitution: 1 Charisma: -1 + ability_score_ranges: + Strength: + male: [6, 18] + female: [] + Intelligence: + male: [7, 18] + female: [] + Wisdom: + male: [3, 18] + female: [] + Dexterity: + male: [3, 18] + female: [] + Constitution: + male: [8, 18] + female: [] + Charisma: + male: [3, 18] + female: [] half-elf: name: "Half-elf" ability_score_modifiers: npc_ability_score_modifiers: + ability_score_ranges: + Strength: + male: [3, 18] + female: [] + Intelligence: + male: [4, 18] + female: [] + Wisdom: + male: [3, 18] + female: [] + Dexterity: + male: [6, 18] + female: [] + Constitution: + male: [6, 18] + female: [] + Charisma: + male: [3, 18] + female: [] halfling: name: "Halfling" @@ -38,6 +114,25 @@ halfling: npc_ability_score_modifiers: Dexterity: 1 Constitution: 1 + ability_score_ranges: + Strength: + male: [6, 17] + female: [] + Intelligence: + male: [6, 18] + female: [] + Wisdom: + male: [3, 17] + female: [] + Dexterity: + male: [8, 18] + female: [] + Constitution: + male: [10, 19] + female: [] + Charisma: + male: [3, 18] + female: [] half-orc: name: "Half-orc" @@ -48,8 +143,46 @@ half-orc: npc_ability_score_modifiers: Dexterity: 1 Constitution: 1 + ability_score_ranges: + Strength: + male: [6, 18] + female: [] + Intelligence: + male: [3, 17] + female: [] + Wisdom: + male: [3, 14] + female: [] + Dexterity: + male: [3, 17] + female: [] + Constitution: + male: [13, 19] + female: [] + Charisma: + male: [3, 12] + female: [] human: name: "Human" ability_score_modifiers: npc_ability_score_modifiers: + ability_score_ranges: + Strength: + male: [3, 25] + female: [] + Intelligence: + male: [3, 25] + female: [] + Wisdom: + male: [3, 25] + female: [] + Dexterity: + male: [3, 25] + female: [] + Constitution: + male: [3, 25] + female: [] + Charisma: + male: [3, 25] + female: [] 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