From c4a1883295cfacccee7b8ea422002b947672c7b8 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 21 Aug 2023 02:01:15 +0100 Subject: [PATCH] better char selection screen --- src/gamesystem.rs | 11 ++++--- src/gui/race_selection.rs | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/gamesystem.rs b/src/gamesystem.rs index f79432f..f9e42fa 100644 --- a/src/gamesystem.rs +++ b/src/gamesystem.rs @@ -1,6 +1,7 @@ use super::{Skill, Skills}; use crate::gui::Classes; use rltk::prelude::*; +use std::cmp::max; /// Returns the attribute bonus for a given attribute score, where every 2 points above /// or below 10 is an additional +1 or -1. @@ -10,7 +11,7 @@ pub fn attr_bonus(value: i32) -> i32 { /// Returns the number of HP gained per level for a given constitution score. pub fn hp_per_level(rng: &mut rltk::RandomNumberGenerator, constitution: i32) -> i32 { - return rng.roll_dice(1, 8) + attr_bonus(constitution); + return max(rng.roll_dice(1, 8) + attr_bonus(constitution), 1); } #[allow(dead_code)] @@ -37,7 +38,7 @@ pub fn npc_hp_at_level(rng: &mut rltk::RandomNumberGenerator, constitution: i32, /// Returns the number of mana gained per level for a given intelligence score. pub fn mana_per_level(rng: &mut rltk::RandomNumberGenerator, intelligence: i32) -> i32 { - return rng.roll_dice(1, 4) + attr_bonus(intelligence); + return max(rng.roll_dice(1, 4) + attr_bonus(intelligence), 1); } /// Returns the number of mana gained per level for a given intelligence score. @@ -78,15 +79,15 @@ pub fn roll_4d6(rng: &mut rltk::RandomNumberGenerator) -> i32 { pub fn get_attribute_rolls(rng: &mut RandomNumberGenerator, class: Classes) -> (i32, i32, i32, i32, i32, i32) { let (mut str, mut dex, mut con, mut int, mut wis, mut cha) = match class { Classes::Fighter => (10, 8, 10, 6, 6, 8), - Classes::Rogue => (8, 12, 8, 6, 8, 10), - Classes::Wizard => (6, 8, 6, 12, 10, 8), + Classes::Rogue => (8, 10, 8, 6, 8, 10), + Classes::Wizard => (6, 8, 6, 10, 10, 8), Classes::Villager => (6, 6, 6, 6, 6, 6), }; let remaining_points = 75 - (str + dex + con + int + wis + cha); let improve_chance: [i32; 6] = match class { Classes::Fighter => [30, 20, 30, 6, 7, 7], Classes::Rogue => [18, 30, 20, 9, 8, 15], - Classes::Wizard => [10, 20, 20, 30, 10, 10], + Classes::Wizard => [10, 15, 20, 30, 15, 10], Classes::Villager => [15, 15, 25, 15, 15, 15], }; let improve_table = crate::random_table::RandomTable::new() diff --git a/src/gui/race_selection.rs b/src/gui/race_selection.rs index 5ad3d47..da197a5 100644 --- a/src/gui/race_selection.rs +++ b/src/gui/race_selection.rs @@ -15,6 +15,52 @@ pub enum Races { Elf, } +lazy_static! { + static ref RACE_CLASS_DATA: HashMap> = { + let mut m = HashMap::new(); + // Races + m.insert( + "human".to_string(), + vec![ + "+nothing".to_string()]); + m.insert( + "dwarf".to_string(), + vec![ + "a natural bonus to defence".to_string()]); + m.insert( + "elf".to_string(), + vec![ + "minor telepathy".to_string(), + "a slightly increased speed".to_string()]); + // Classes + m.insert( + "fighter".to_string(), + vec![ + "a longsword and ring mail".to_string(), + "10 str, 8 dex, 10 con, 6 int, 6 wis, 8 cha".to_string(), + "and 27 random stat points".to_string()]); + m.insert( + "rogue".to_string(), + vec![ + "a rapier and leather armour".to_string(), + "8 str, 10 dex, 8 con, 6 int, 8 wis, 10 cha".to_string(), + "and 35 random stat points".to_string()]); + m.insert( + "wizard".to_string(), + vec![ + "a random assortment of scrolls and/or potions".to_string(), + "6 str, 8 dex, 6 con, 10 int, 10 wis, 8 cha".to_string(), + "and 17 random stat points".to_string()]);; + m.insert( + "villager".to_string(), + vec![ + "a random beginning".to_string(), + "6 str, 6 dex, 6 con, 6 int, 6 wis, 6 cha".to_string(), + "and 39 random stat points".to_string()]); + return m; + }; +} + #[derive(PartialEq, Copy, Clone)] pub enum Classes { Fighter, @@ -47,6 +93,10 @@ pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult { let bg = RGB::named(BLACK); // Races + ctx.print_color(x, y, bg, unselected_fg, "Ancestry"); + ctx.print_color(x + column_width, y, bg, unselected_fg, "Class"); + y += 1; + let mut race_str = "human"; if race == Races::Human { fg = selected_fg; } else { @@ -55,17 +105,20 @@ pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult { ctx.print_color(x, y, fg, bg, "h. Human"); if race == Races::Elf { fg = selected_fg; + race_str = "elf"; } else { fg = unselected_fg; } ctx.print_color(x, y + 1, fg, bg, "e. Elf"); if race == Races::Dwarf { fg = selected_fg; + race_str = "dwarf"; } else { fg = unselected_fg; } ctx.print_color(x, y + 2, fg, bg, "d. Dwarf"); // Classes + let mut class_str = "fighter"; x += column_width; if class == Classes::Fighter { fg = selected_fg; @@ -75,22 +128,38 @@ pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult { ctx.print_color(x, y, fg, bg, "f. Fighter"); if class == Classes::Rogue { fg = selected_fg; + class_str = "rogue"; } else { fg = unselected_fg; } ctx.print_color(x, y + 1, fg, bg, "r. Rogue"); if class == Classes::Wizard { fg = selected_fg; + class_str = "wizard"; } else { fg = unselected_fg; } ctx.print_color(x, y + 2, fg, bg, "w. Wizard"); if class == Classes::Villager { fg = selected_fg; + class_str = "villager"; } else { fg = unselected_fg; } ctx.print_color(x, y + 3, fg, bg, "v. Villager"); + // Selected race/class benefits + x += column_width; + ctx.print_color(x, y, selected_fg, bg, "Your ancestry grants..."); + for line in RACE_CLASS_DATA.get(race_str).unwrap().iter() { + y += 1; + ctx.print_color(x + 1, y, unselected_fg, bg, line); + } + y += 2; + ctx.print_color(x, y, selected_fg, bg, "Your class grants..."); + for line in RACE_CLASS_DATA.get(class_str).unwrap().iter() { + y += 1; + ctx.print_color(x + 1, y, unselected_fg, bg, line); + } match ctx.key { None => return CharCreateResult::NoSelection { race, class },