character creation starting inventories

This commit is contained in:
Llywelwyn 2023-08-21 09:01:58 +01:00
parent c4a1883295
commit c7fcd301e2
7 changed files with 50 additions and 56 deletions

View file

@ -60,6 +60,7 @@ pub fn skill_bonus(skill: Skill, skills: &Skills) -> i32 {
} }
/// Roll 4d6 and drop the lowest, for rolling d20-style stats /// Roll 4d6 and drop the lowest, for rolling d20-style stats
#[allow(unused)]
pub fn roll_4d6(rng: &mut rltk::RandomNumberGenerator) -> i32 { pub fn roll_4d6(rng: &mut rltk::RandomNumberGenerator) -> i32 {
let mut rolls: Vec<i32> = Vec::new(); let mut rolls: Vec<i32> = Vec::new();
for _i in 0..4 { for _i in 0..4 {

View file

@ -287,39 +287,45 @@ pub fn setup_player_class(ecs: &mut World, class: Classes) {
fn get_starting_inventory(class: Classes, rng: &mut RandomNumberGenerator) -> (Vec<String>, Vec<String>) { fn get_starting_inventory(class: Classes, rng: &mut RandomNumberGenerator) -> (Vec<String>, Vec<String>) {
let mut equipped: Vec<String> = Vec::new(); let mut equipped: Vec<String> = Vec::new();
let mut carried: Vec<String> = Vec::new(); let mut carried: Vec<String> = Vec::new();
let mut starting_food: &str = "1";
match class { match class {
Classes::Fighter => { Classes::Fighter => {
starting_food = "1d2+1";
equipped = vec![ equipped = vec![
"equip_shortsword".to_string(), "equip_shortsword".to_string(),
"equip_body_ringmail".to_string(), "equip_body_ringmail".to_string(),
"equip_mediumshield".to_string(), "equip_mediumshield".to_string(),
]; ];
carried = vec!["food_rations".to_string()];
} }
Classes::Rogue => { Classes::Rogue => {
starting_food = "1d2+2";
equipped = vec!["equip_rapier".to_string(), "equip_body_weakleather".to_string()]; equipped = vec!["equip_rapier".to_string(), "equip_body_weakleather".to_string()];
carried = vec![ carried = vec!["equip_dagger".to_string(), "equip_dagger".to_string()];
"equip_dagger".to_string(),
"equip_dagger".to_string(),
"food_rations".to_string(),
"food_apple".to_string(),
];
} }
Classes::Wizard => { Classes::Wizard => {
starting_food = "1d2+1";
equipped = vec!["equip_dagger".to_string(), "equip_back_protection".to_string()]; equipped = vec!["equip_dagger".to_string(), "equip_back_protection".to_string()];
carried = vec!["food_rations".to_string()]; pick_random_table_item(rng, &mut carried, "scrolls", "1d3", Some(3));
for _i in 0..rng.roll_dice(1, 3) { pick_random_table_item(rng, &mut carried, "potions", "1d3-1", Some(3));
carried.push(scroll_table(3).roll(rng));
}
for _i in 0..rng.roll_dice(1, 2) - 1 {
carried.push(potion_table(3).roll(rng));
}
} }
Classes::Villager => { Classes::Villager => {
let rolled_weapon = raws::table_by_name(&raws::RAWS.lock().unwrap(), "villager_equipment", 1).roll(rng); starting_food = "1d3+2";
equipped.push(rolled_weapon); pick_random_table_item(rng, &mut equipped, "villager_equipment", "1", None);
carried = vec!["food_rations".to_string(), "food_apple".to_string(), "food_apple".to_string()];
} }
} }
pick_random_table_item(rng, &mut carried, "food", starting_food, None);
return (equipped, carried); return (equipped, carried);
} }
fn pick_random_table_item(
rng: &mut RandomNumberGenerator,
push_to: &mut Vec<String>,
table: &'static str,
dice: &'static str,
difficulty: Option<i32>,
) {
let (n, d, m) = raws::parse_dice_string(dice);
for _i in 0..rng.roll_dice(n, d) + m {
push_to.push(raws::table_by_name(&raws::RAWS.lock().unwrap(), table, difficulty).roll(rng));
}
}

View file

@ -43,7 +43,7 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) {
} }
let mut spawn_locations: Vec<(i32, i32)> = Vec::new(); let mut spawn_locations: Vec<(i32, i32)> = Vec::new();
let mut rng = ecs.write_resource::<RandomNumberGenerator>(); let mut rng = ecs.write_resource::<RandomNumberGenerator>();
let key = spawner::mob_table(difficulty).roll(&mut rng); let key = spawner::mob_table(Some(difficulty)).roll(&mut rng);
let spawn_type = raws::get_mob_spawn_type(&raws::RAWS.lock().unwrap(), &key); let spawn_type = raws::get_mob_spawn_type(&raws::RAWS.lock().unwrap(), &key);
let roll = raws::get_mob_spawn_amount(&mut rng, &spawn_type, player_level); let roll = raws::get_mob_spawn_amount(&mut rng, &spawn_type, player_level);
for _i in 0..roll { for _i in 0..roll {

View file

@ -103,23 +103,23 @@ impl PrefabBuilder {
} }
'%' => { '%' => {
build_data.map.tiles[idx] = TileType::Floor; build_data.map.tiles[idx] = TileType::Floor;
build_data.spawn_list.push((idx, spawner::food_table(difficulty).roll(rng))); build_data.spawn_list.push((idx, spawner::food_table(Some(difficulty)).roll(rng)));
} }
'!' => { '!' => {
build_data.map.tiles[idx] = TileType::Floor; build_data.map.tiles[idx] = TileType::Floor;
build_data.spawn_list.push((idx, spawner::potion_table(difficulty).roll(rng))); build_data.spawn_list.push((idx, spawner::potion_table(Some(difficulty)).roll(rng)));
} }
'/' => { '/' => {
build_data.map.tiles[idx] = TileType::Floor; build_data.map.tiles[idx] = TileType::Floor;
build_data.spawn_list.push((idx, spawner::wand_table(difficulty).roll(rng))); build_data.spawn_list.push((idx, spawner::wand_table(Some(difficulty)).roll(rng)));
} }
'?' => { '?' => {
build_data.map.tiles[idx] = TileType::Floor; build_data.map.tiles[idx] = TileType::Floor;
build_data.spawn_list.push((idx, spawner::scroll_table(difficulty).roll(rng))); build_data.spawn_list.push((idx, spawner::scroll_table(Some(difficulty)).roll(rng)));
} }
')' => { ')' => {
build_data.map.tiles[idx] = TileType::Floor; build_data.map.tiles[idx] = TileType::Floor;
build_data.spawn_list.push((idx, spawner::equipment_table(difficulty).roll(rng))); build_data.spawn_list.push((idx, spawner::equipment_table(Some(difficulty)).roll(rng)));
} }
_ => { _ => {
rltk::console::log(format!("Unknown glyph '{}' when loading prefab", (ch as u8) as char)); rltk::console::log(format!("Unknown glyph '{}' when loading prefab", (ch as u8) as char));

View file

@ -139,17 +139,6 @@ impl ParticleBuilder {
); );
} }
pub fn trap_triggered(&mut self, x: i32, y: i32) {
self.request(
x,
y,
rltk::RGB::named(rltk::RED),
rltk::RGB::named(rltk::RED),
rltk::to_cp437('‼'),
DEFAULT_PARTICLE_LIFETIME,
);
}
pub fn kick(&mut self, x: i32, y: i32) { pub fn kick(&mut self, x: i32, y: i32) {
self.request( self.request(
x, x,

View file

@ -593,9 +593,15 @@ fn get_renderable_component(renderable: &super::item_structs::Renderable) -> cra
} }
} }
pub fn table_by_name(raws: &RawMaster, key: &str, difficulty: i32) -> RandomTable { pub fn table_by_name(raws: &RawMaster, key: &str, optional_difficulty: Option<i32>) -> RandomTable {
let upper_bound = difficulty; let (difficulty, upper_bound, lower_bound);
let lower_bound = if key != "mobs" { 0 } else { difficulty / 6 }; if optional_difficulty.is_some() {
difficulty = optional_difficulty.unwrap();
upper_bound = difficulty;
lower_bound = if key != "mobs" { 0 } else { difficulty / 6 };
} else {
difficulty = -1;
}
if raws.table_index.contains_key(key) { if raws.table_index.contains_key(key) {
let spawn_table = &raws.raws.spawn_tables[raws.table_index[key]]; let spawn_table = &raws.raws.spawn_tables[raws.table_index[key]];

View file

@ -53,14 +53,6 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
.marked::<SimpleMarker<SerializeMe>>() .marked::<SimpleMarker<SerializeMe>>()
.build(); .build();
raws::spawn_named_entity(
&raws::RAWS.lock().unwrap(),
ecs,
"food_rations",
raws::SpawnType::Carried { by: player },
0,
);
return player; return player;
} }
@ -118,7 +110,7 @@ pub fn spawn_region(
}; };
// Roll on each table, getting an entity + spawn point // Roll on each table, getting an entity + spawn point
if spawn_mob { if spawn_mob {
let key = mob_table(difficulty).roll(rng); let key = mob_table(Some(difficulty)).roll(rng);
let spawn_type = raws::get_mob_spawn_type(&raws::RAWS.lock().unwrap(), &key); let spawn_type = raws::get_mob_spawn_type(&raws::RAWS.lock().unwrap(), &key);
let roll = raws::get_mob_spawn_amount(rng, &spawn_type, player_level); let roll = raws::get_mob_spawn_amount(rng, &spawn_type, player_level);
for _i in 0..roll { for _i in 0..roll {
@ -126,13 +118,13 @@ pub fn spawn_region(
} }
} }
for _i in 0..num_traps { for _i in 0..num_traps {
let key = trap_table(difficulty).roll(rng); let key = trap_table(Some(difficulty)).roll(rng);
entity_to_spawn_list(rng, &mut areas, key, &mut spawn_points); entity_to_spawn_list(rng, &mut areas, key, &mut spawn_points);
} }
for _i in 0..num_items { for _i in 0..num_items {
// Player level isn't taken into account for item spawning, to encourage // Player level isn't taken into account for item spawning, to encourage
// delving deeper to gear up more quickly. // delving deeper to gear up more quickly.
let key = get_random_item_category(rng, map.difficulty).roll(rng); let key = get_random_item_category(rng, Some(map.difficulty)).roll(rng);
entity_to_spawn_list(rng, &mut areas, key, &mut spawn_points); entity_to_spawn_list(rng, &mut areas, key, &mut spawn_points);
} }
// Push entities and their spawn points to map's spawn list // Push entities and their spawn points to map's spawn list
@ -189,7 +181,7 @@ fn debug_table() -> RandomTable {
return RandomTable::new().add("debug", 1); return RandomTable::new().add("debug", 1);
} }
fn get_random_item_category(rng: &mut RandomNumberGenerator, difficulty: i32) -> RandomTable { fn get_random_item_category(rng: &mut RandomNumberGenerator, difficulty: Option<i32>) -> RandomTable {
let item_category = item_category_table().roll(rng); let item_category = item_category_table().roll(rng);
match item_category.as_ref() { match item_category.as_ref() {
"equipment" => return equipment_table(difficulty), "equipment" => return equipment_table(difficulty),
@ -201,31 +193,31 @@ fn get_random_item_category(rng: &mut RandomNumberGenerator, difficulty: i32) ->
}; };
} }
pub fn equipment_table(difficulty: i32) -> RandomTable { pub fn equipment_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "equipment", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "equipment", difficulty)
} }
pub fn potion_table(difficulty: i32) -> RandomTable { pub fn potion_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "potions", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "potions", difficulty)
} }
pub fn scroll_table(difficulty: i32) -> RandomTable { pub fn scroll_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "scrolls", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "scrolls", difficulty)
} }
pub fn wand_table(difficulty: i32) -> RandomTable { pub fn wand_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "wands", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "wands", difficulty)
} }
pub fn food_table(difficulty: i32) -> RandomTable { pub fn food_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "food", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "food", difficulty)
} }
/// Locks RAWS, and provides access to master list of all mobs. /// Locks RAWS, and provides access to master list of all mobs.
pub fn mob_table(difficulty: i32) -> RandomTable { pub fn mob_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "mobs", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "mobs", difficulty)
} }
pub fn trap_table(difficulty: i32) -> RandomTable { pub fn trap_table(difficulty: Option<i32>) -> RandomTable {
raws::table_by_name(&raws::RAWS.lock().unwrap(), "traps", difficulty) raws::table_by_name(&raws::RAWS.lock().unwrap(), "traps", difficulty)
} }