Skip to content

Commit c67b403

Browse files
committed
adding different shift schedules for Staff vs Patron NPCs
1 parent 6778104 commit c67b403

File tree

5 files changed

+76
-62
lines changed

5 files changed

+76
-62
lines changed

src/narrative_time_manager/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ pub mod ntm {
3838
#[derive(Clone, Copy, Debug, PartialEq)]
3939
pub enum SlotNames {
4040
Twilight,
41-
Sunrise,
42-
EarlyMorning,
43-
MidMorning,
44-
LateMorning,
45-
Midday,
46-
EarlyAfternoon,
47-
MidAfternoon,
48-
LateAfternoon,
49-
Dusk,
50-
Sunset,
51-
LateEvening,
52-
EarlyEvening,
53-
MidEvening,
54-
Night,
55-
Midnight,
56-
LateNight,
41+
Sunrise, // 1 *
42+
EarlyMorning, // 2 *
43+
MidMorning, // 3 *
44+
LateMorning, // 4 * *
45+
Midday, // 5 * *
46+
EarlyAfternoon, // 6 *
47+
MidAfternoon, // 7 *
48+
LateAfternoon, // 8 * *
49+
Dusk, // 9 * *
50+
Sunset, // 10 *
51+
LateEvening, // 11 *
52+
EarlyEvening, // 12 * *
53+
MidEvening, // 13 * *
54+
Night, // 14 *
55+
Midnight, // 15 *
56+
LateNight, // 16 *
5757
LongDark,
5858
}
5959

src/npc/impls.rs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,49 @@ impl Profile {
5353
let all_slots: Vec<TimeSlot> = crate::narrative_time_manager::ntm::load();
5454
let mut encounter_chance_timeslots: Vec<TimeSlot> = vec![];
5555

56-
let center_slot_name: SlotNames = rand::random();
57-
let mut middle_index: usize = 0;
58-
for this_slot in all_slots.iter() {
59-
if this_slot.name == center_slot_name {
60-
// check if night before
61-
let mut early_index = (middle_index as i8) - 1;
62-
if early_index <= 0 && all_slots.get(early_index as usize).is_none() {
63-
early_index = all_slots.iter().count() as i8 - 1;
64-
};
65-
66-
// check if runs into next morning
67-
let mut late_index: usize = middle_index + 1;
68-
if all_slots.get(late_index).is_none() {
69-
late_index = 0
70-
};
71-
72-
let early_slot = all_slots[early_index as usize];
73-
let normal_slot = all_slots[middle_index];
74-
let late_slot = all_slots[late_index];
75-
76-
encounter_chance_timeslots = vec![early_slot, normal_slot, late_slot];
56+
if self.npc_type == NpcTypeCode::Staff {
57+
let request: &str = "1d4";
58+
let resulting_roll = <DiceResult as RollDice>::from_string(request);
59+
60+
let mut slot_list: Vec<i8> = vec![];
61+
match resulting_roll.get_total() {
62+
1 => slot_list = [1, 2, 3, 4, 5].to_vec(),
63+
2 => slot_list = [4, 5, 6, 7, 8, 9].to_vec(),
64+
3 => slot_list = [8, 9, 10, 11, 12, 13].to_vec(),
65+
4 => slot_list = [12, 13, 14, 15, 16].to_vec(),
66+
_ => slot_list = [3, 4, 5, 6, 7, 8].to_vec(),
67+
}
68+
69+
for this_slot in slot_list.iter() {
70+
encounter_chance_timeslots.push(all_slots[*this_slot as usize]);
71+
}
72+
}
73+
74+
if self.npc_type == NpcTypeCode::Patron {
75+
let center_slot_name: SlotNames = rand::random();
76+
let mut middle_index: usize = 0;
77+
for this_slot in all_slots.iter() {
78+
if this_slot.name == center_slot_name {
79+
// check if night before
80+
let mut early_index = (middle_index as i8) - 1;
81+
if early_index <= 0 && all_slots.get(early_index as usize).is_none() {
82+
early_index = all_slots.iter().count() as i8 - 1;
83+
};
84+
85+
// check if runs into next morning
86+
let mut late_index: usize = middle_index + 1;
87+
if all_slots.get(late_index).is_none() {
88+
late_index = 0
89+
};
90+
91+
let early_slot = all_slots[early_index as usize];
92+
let normal_slot = all_slots[middle_index];
93+
let late_slot = all_slots[late_index];
94+
95+
encounter_chance_timeslots = vec![early_slot, normal_slot, late_slot];
96+
}
97+
middle_index += 1;
7798
}
78-
middle_index += 1;
7999
}
80100

81101
self.encounter_slots = encounter_chance_timeslots;

src/npc/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,14 @@ mod suite {
299299
assert!(!ects[1].name.to_string().is_empty());
300300
assert!(!ects[2].name.to_string().is_empty());
301301
}
302+
303+
#[test]
304+
fn set_rect_for_staff() {
305+
let mut new_npc: Profile = Profile::new();
306+
new_npc.npc_type = NpcTypeCode::Staff;
307+
new_npc.set_random_encounter_chance_timeslots();
308+
309+
assert_eq!(5, new_npc.encounter_slots.iter().count())
310+
}
302311
} // mod suite
303312
// ---- end of file ----

src/tavern/implementations.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub mod list {
1919
};
2020
use crate::tavern::structs::list::{App, PBHouse};
2121
use crate::tavern::traits::list::{AppFn, ToCapitalized};
22-
use crate::text_postproc::tpp::{enum_string_to_phrase, is_a_an, l1_heading, l2_heading, l3_heading, tidy, trim_whitespace};
22+
use crate::text_postproc::tpp::{
23+
enum_string_to_phrase, is_a_an, l1_heading, l2_heading, l3_heading, tidy, trim_whitespace,
24+
};
2325

2426
impl Distribution<HouseDishWhatSide> for StandardUniform {
2527
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> HouseDishWhatSide {
@@ -498,42 +500,26 @@ pub mod list {
498500
}
499501

500502
impl fmt::Display for PBHouse {
501-
502503
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
503-
writeln!(
504-
f,
505-
"{}", l1_heading("Narrative Information".to_string())
506-
)?;
504+
writeln!(f, "{}", l1_heading("Narrative Information".to_string()))?;
507505
writeln!(f, " ")?;
508506

509-
writeln!(
510-
f,
511-
"{}", l2_heading("For the Characters".to_string())
512-
)?;
507+
writeln!(f, "{}", l2_heading("For the Characters".to_string()))?;
513508
writeln!(f, " ")?;
514509
for line in &self.general_info() {
515-
write!(f, "{}", line)?;
510+
write!(f, "{}", line)?;
516511
}
517512

518-
writeln!(
519-
f,
520-
"{}", l2_heading("GM Notes".to_string())
521-
)?;
513+
writeln!(f, "{}", l2_heading("GM Notes".to_string()))?;
522514
writeln!(f, " ")?;
523-
writeln!(
524-
f,
525-
"{}", l3_heading("Establishment History".to_string())
526-
)?;
515+
writeln!(f, "{}", l3_heading("Establishment History".to_string()))?;
527516
writeln!(f, " ")?;
528517
for line in &self.establishment_history_notes {
529518
writeln!(f, "{}", line)?;
530519
}
531520
writeln!(f, " ")?;
532521

533-
writeln!(
534-
f,
535-
"{}", l3_heading("Redlight Services".to_string())
536-
)?;
522+
writeln!(f, "{}", l3_heading("Redlight Services".to_string()))?;
537523
for line in &self.redlight_services {
538524
writeln!(f, "{}", line)?;
539525
}

src/text_postproc/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub mod tpp {
4545
format!("\n==={}===\n", s).trim().to_string()
4646
}
4747

48-
4948
pub fn is_a_an(test: &str) -> String {
5049
use ::is_vowel::IsRomanceVowel;
5150
if test

0 commit comments

Comments
 (0)