summaryrefslogtreecommitdiff
path: root/src/rules
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2023-10-16 13:41:08 -0400
committerDavid Gay <eapoems@riseup.net>2023-10-16 13:41:08 -0400
commit686726b414dcb9d0fe66ec0d64436f51919a0fd1 (patch)
treed23fed79a62a8e9ddb02ff33a2433a5d7a860e75 /src/rules
parente7f14e4fcac1e82de0160661c7382db3e8ac6854 (diff)
Racial ability score min/max (male only)
Diffstat (limited to 'src/rules')
-rw-r--r--src/rules/npcs.rs11
-rw-r--r--src/rules/races.rs8
2 files changed, 17 insertions, 2 deletions
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<AbilityScore, i32>,
pub npc_ability_score_modifiers: HashMap<AbilityScore, i32>,
+ pub ability_score_ranges: HashMap<AbilityScore, AbilityScoreRange>,
+}
+
+// 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! {