summaryrefslogtreecommitdiff
path: root/src/rules/npcs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rules/npcs.rs')
-rw-r--r--src/rules/npcs.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/rules/npcs.rs b/src/rules/npcs.rs
index ccf9936..ab111de 100644
--- a/src/rules/npcs.rs
+++ b/src/rules/npcs.rs
@@ -1,9 +1,11 @@
use crate::dice::roll_formula;
use crate::random_tables::RANDOM_TABLES;
use crate::rules::ability_scores::{AbilityScore, AbilityScoreCollection};
-use crate::rules::classes::Class;
+use crate::rules::classes::{Class, CLASSES};
+use crate::rules::magic_items::{MagicItem, MAGIC_ITEMS};
use crate::rules::races::Race;
use log::debug;
+use rand::Rng;
use std::collections::HashMap;
// use std::fmt;
@@ -13,6 +15,7 @@ pub struct Npc {
pub class: Option<&'static Class>,
pub ability_scores: Option<AbilityScoreCollection>,
pub persona: Option<String>,
+ pub magic_items: Vec<&'static MagicItem>,
}
impl Npc {
@@ -22,6 +25,7 @@ impl Npc {
class: Option<&'static Class>,
ability_scores: Option<AbilityScoreCollection>,
persona: Option<String>,
+ magic_items: Vec<&'static MagicItem>,
) -> Self {
Npc {
alignment,
@@ -29,6 +33,7 @@ impl Npc {
class,
ability_scores,
persona,
+ magic_items,
}
}
@@ -112,6 +117,44 @@ impl Npc {
self.persona = Some(components.join(", "));
}
+ // This uses the Appendix C method provided in the city/town section.
+ // I prefer it to the Monster Manual method and the NPC party method
+ // because it provides more variance.
+ // TODO: Support other levels than 1st.
+ pub fn add_random_magic_items(&mut self) {
+ let mut rng = rand::thread_rng();
+ let class_ref = self.class.unwrap();
+
+ // "Protection" isn't a real magic item kind, it's only used for this,
+ // which is why we don't just use MagicItemKind. Can improve this later.
+ let kind_strings_for_chances = [
+ "sword",
+ "potion",
+ "scroll",
+ "ring",
+ "rod_staff_wand",
+ "misc",
+ "armor_shield",
+ "protection",
+ ];
+
+ for &kind_string in kind_strings_for_chances.iter() {
+ if class_ref
+ .chances_for_magic
+ .get(kind_string)
+ .copied()
+ .unwrap_or(0)
+ <= rng.gen_range(1..=100)
+ {
+ self.magic_items.push(
+ MAGIC_ITEMS
+ .get(kind_string)
+ .expect("Failed to load magic item"),
+ );
+ }
+ }
+ }
+
// TODO: Probably break this out later like this.
// fn increase_prime_requisites(&mut self, roll_result: &mut RollResult) {
// let class_ref = self.class.unwrap();
@@ -159,6 +202,7 @@ mod tests {
class: Some(class_ref),
ability_scores: None,
persona: None,
+ magic_items: Vec::new(),
};
// Roll ability scores for the Npc.