summaryrefslogtreecommitdiff
path: root/src/rules/npcs.rs
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2024-01-31 03:14:53 -0500
committerDavid Gay <eapoems@riseup.net>2024-01-31 03:14:53 -0500
commite63dbbde68f81f8a65b48608d41ef6bf6be799e6 (patch)
treeb6c9a200278974d6bc70ccdb9e3960b9e871344f /src/rules/npcs.rs
parent05a13c4c3232f10ade9a2cc75de84e93278d22c6 (diff)
`random npc` accepts level argumentHEADmaster
Diffstat (limited to 'src/rules/npcs.rs')
-rw-r--r--src/rules/npcs.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/rules/npcs.rs b/src/rules/npcs.rs
index fe87e76..5477306 100644
--- a/src/rules/npcs.rs
+++ b/src/rules/npcs.rs
@@ -13,6 +13,7 @@ pub struct Npc {
pub alignment: Option<String>,
pub race: Option<&'static Race>,
pub class: Option<&'static Class>,
+ pub level: i32,
pub ability_scores: Option<AbilityScoreCollection>,
pub persona: Option<String>,
pub magic_items: Vec<&'static MagicItem>,
@@ -23,6 +24,7 @@ impl Npc {
alignment: Option<String>,
race: Option<&'static Race>,
class: Option<&'static Class>,
+ level: i32, // TODO: Multiclass and dualclass.
ability_scores: Option<AbilityScoreCollection>,
persona: Option<String>,
magic_items: Vec<&'static MagicItem>,
@@ -31,6 +33,7 @@ impl Npc {
alignment,
race,
class,
+ level,
ability_scores,
persona,
magic_items,
@@ -120,7 +123,6 @@ impl Npc {
// 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();
@@ -139,13 +141,13 @@ impl Npc {
];
for &kind_string in kind_strings_for_chances.iter() {
- if class_ref
+ let chance_per_level = class_ref
.chances_for_magic
.get(kind_string)
.copied()
- .unwrap_or(0)
- >= rng.gen_range(1..=100)
- {
+ .unwrap_or(0);
+ let chance = chance_per_level * self.level;
+ if chance >= rng.gen_range(1..=100) {
// For now, just get a dummy item named after the item type.
// Later, we'll add the actual magic items.
self.magic_items.push(
@@ -202,6 +204,7 @@ mod tests {
alignment: Some(String::from("Lawful Good")),
race: Some(race_ref),
class: Some(class_ref),
+ level: 1,
ability_scores: None,
persona: None,
magic_items: Vec::new(),