diff options
author | David Gay <eapoems@riseup.net> | 2024-01-31 02:05:14 -0500 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2024-01-31 02:05:14 -0500 |
commit | 4b4f725c74520c3a374849df99a1a6595e1e260a (patch) | |
tree | 89f11094dd47d538137d472e4a986a7c90548b74 /src/main.rs | |
parent | 7470832b07c458cddfae1bfa7c348b6dcc02d3c0 (diff) |
random npc command
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index bc9e200..44c162c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,38 @@ fn main() { Some(("random", sub_matches)) => { let random_command = sub_matches.subcommand().unwrap(); match random_command { + ("npc", npc_matches) => { + let class_name = npc_matches.get_one::<String>("class").unwrap_or_else(|| { + eprintln!("Error: Class is required."); + std::process::exit(1); + }); + let class_ref = CLASSES.get(&*class_name.to_lowercase()).unwrap_or_else(|| { + eprintln!("Class '{}' not found.", &*class_name); + std::process::exit(1); + }); + + let mut npc = Npc::new( + Some(RANDOM_TABLES.roll_table("npc_alignment")), + None, + Some(class_ref), + None, + None, + Vec::new(), + ); + + npc.add_random_magic_items(); + + println!( + "{} {}. {}", + npc.alignment.unwrap(), + npc.class.unwrap().name, + npc.magic_items + .iter() + .map(|item| item.name.clone()) + .collect::<Vec<String>>() + .join(", "), + ); + } ("henchman", henchman_matches) => { let class_name = RANDOM_TABLES.roll_table("henchman_class").to_string(); let race_name = RANDOM_TABLES.roll_table("henchman_race").to_string(); |