added gameover, added class/ancestry defaults

This commit is contained in:
Llywelwyn 2023-09-25 22:04:49 +01:00
parent 65ec5c1b15
commit 2c4b4ca143
8 changed files with 60 additions and 98 deletions

View file

@ -85,6 +85,7 @@ pub fn get_attribute_rolls(
ancestry: Ancestry ancestry: Ancestry
) -> (i32, i32, i32, i32, i32, i32) { ) -> (i32, i32, i32, i32, i32, i32) {
let (mut str, mut dex, mut con, mut int, mut wis, mut cha) = match class { let (mut str, mut dex, mut con, mut int, mut wis, mut cha) = match class {
Class::Unset => VILLAGER_MIN_ATTR,
Class::Fighter => FIGHTER_MIN_ATTR, Class::Fighter => FIGHTER_MIN_ATTR,
Class::Rogue => ROGUE_MIN_ATTR, Class::Rogue => ROGUE_MIN_ATTR,
Class::Wizard => WIZARD_MIN_ATTR, Class::Wizard => WIZARD_MIN_ATTR,
@ -92,6 +93,7 @@ pub fn get_attribute_rolls(
}; };
let mut remaining_points = TOTAL_ATTRIBUTE_POINTS_MAXIMUM - (str + dex + con + int + wis + cha); let mut remaining_points = TOTAL_ATTRIBUTE_POINTS_MAXIMUM - (str + dex + con + int + wis + cha);
let improve_chance: [i32; 6] = match class { let improve_chance: [i32; 6] = match class {
Class::Unset => VILLAGER_IMPR_CHANCE,
Class::Fighter => FIGHTER_IMPR_CHANCE, Class::Fighter => FIGHTER_IMPR_CHANCE,
Class::Rogue => ROGUE_IMPR_CHANCE, Class::Rogue => ROGUE_IMPR_CHANCE,
Class::Wizard => WIZARD_IMPR_CHANCE, Class::Wizard => WIZARD_IMPR_CHANCE,

View file

@ -32,7 +32,7 @@ use crate::consts::prelude::*;
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
pub enum Ancestry { pub enum Ancestry {
NULL, Unset,
Human, Human,
Dwarf, Dwarf,
Gnome, Gnome,
@ -42,6 +42,7 @@ pub enum Ancestry {
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
pub enum Class { pub enum Class {
Unset,
Fighter, Fighter,
Rogue, Rogue,
Wizard, Wizard,
@ -212,7 +213,7 @@ pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
Some(key) => Some(key) =>
match key { match key {
VirtualKeyCode::Escape => { VirtualKeyCode::Escape => {
return CharCreateResult::Selected { ancestry: Ancestry::NULL, class }; return CharCreateResult::Selected { ancestry: Ancestry::Unset, class };
} }
VirtualKeyCode::Return => { VirtualKeyCode::Return => {
return CharCreateResult::Selected { ancestry, class }; return CharCreateResult::Selected { ancestry, class };
@ -413,6 +414,9 @@ fn get_starting_inventory(
let mut carried: Vec<String> = Vec::new(); let mut carried: Vec<String> = Vec::new();
let starting_food: &str; let starting_food: &str;
match class { match class {
Class::Unset => {
starting_food = VILLAGER_STARTING_FOOD;
}
Class::Fighter => { Class::Fighter => {
starting_food = FIGHTER_STARTING_FOOD; starting_food = FIGHTER_STARTING_FOOD;
equipped = vec![ equipped = vec![

View file

@ -1641,94 +1641,19 @@ pub enum YesNoResult {
No, No,
} }
pub fn game_over(ctx: &mut BTerm) -> YesNoResult { pub fn game_over(ctx: &mut App) -> YesNoResult {
let mut x = 3; for keycode in &ctx.keyboard.pressed {
let mut y = 12; match *keycode {
let width = 45; KeyCode::N => {
let height = 20; return YesNoResult::No;
ctx.draw_box(x, y, width, height, RGB::named(WHITE), RGB::named(BLACK));
ctx.print_color(x + 3, y, RGB::named(YELLOW), RGB::named(BLACK), "You died!");
ctx.print_color(
x + 3,
y + height,
RGB::named(YELLOW),
RGB::named(BLACK),
" Write a morgue file? [y/n] "
);
x += 2;
y += 2;
ctx.print_color(
x,
y,
RGB::named(GREEN),
RGB::named(BLACK),
format!("You survived for {} turns.", crate::gamelog::get_event_count(EVENT::COUNT_TURN))
);
y += 2;
ctx.print_color(x, y, RGB::named(GREEN), RGB::named(BLACK), format!("And in the process, you"));
y += 1;
if crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR) > 0 {
ctx.print_color(
x + 1,
y,
RGB::named(WHITE),
RGB::named(BLACK),
format!(
"- changed floor {} times",
crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR)
)
);
y += 1;
}
if crate::gamelog::get_event_count(EVENT::COUNT_KICK) > 0 {
ctx.print_color(
x + 1,
y,
RGB::named(WHITE),
RGB::named(BLACK),
format!(
"- kicked {} time(s), breaking {} object(s)",
crate::gamelog::get_event_count(EVENT::COUNT_KICK),
crate::gamelog::get_event_count(EVENT::COUNT_BROKE_DOOR)
)
);
y += 1;
}
if crate::gamelog::get_event_count(EVENT::COUNT_KILLED) > 0 {
ctx.print_color(
x + 1,
y,
RGB::named(WHITE),
RGB::named(BLACK),
format!(
"- slew {} other creature(s)",
crate::gamelog::get_event_count(EVENT::COUNT_KILLED)
)
);
y += 1;
}
if crate::gamelog::get_event_count(EVENT::COUNT_LOOKED_FOR_HELP) > 0 {
ctx.print_color(
x + 1,
y,
RGB::named(WHITE),
RGB::named(BLACK),
format!(
"- forgot the controls {} time(s)",
crate::gamelog::get_event_count(EVENT::COUNT_LOOKED_FOR_HELP)
)
);
}
match ctx.key {
None => YesNoResult::NoSelection,
Some(key) =>
match key {
VirtualKeyCode::N => YesNoResult::No,
VirtualKeyCode::Y => YesNoResult::Yes,
_ => YesNoResult::NoSelection,
} }
KeyCode::Y => {
return YesNoResult::Yes;
}
_ => {}
}
} }
YesNoResult::NoSelection
} }
pub fn with_article(name: &String) -> String { pub fn with_article(name: &String) -> String {

View file

@ -473,10 +473,10 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
gui::draw_cheat_menu(&mut draw, &gs.atlas, &gs.font); gui::draw_cheat_menu(&mut draw, &gs.atlas, &gs.font);
} }
RunState::ActionWithDirection { .. } => { RunState::ActionWithDirection { .. } => {
let offset = crate::camera::get_offset(); corner_text("In what direction? [0-9]/[YUHJKLBN]", &mut draw, &gs.font);
draw.text(&gs.font, "In what direction? [0-9]/[YUHJKLBN]") }
.position(((offset.x + 1) as f32) * TILESIZE, ((offset.y + 1) as f32) * TILESIZE) RunState::GameOver => {
.size(TILESIZE); corner_text("Create morgue file? [Y/N]", &mut draw, &gs.font);
} }
_ => {} _ => {}
} }
@ -487,3 +487,10 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
fn update(ctx: &mut App, state: &mut State) { fn update(ctx: &mut App, state: &mut State) {
state.update(ctx); state.update(ctx);
} }
fn corner_text(text: &str, draw: &mut Draw, font: &notan::draw::Font) {
let offset = crate::camera::get_offset();
draw.text(&font, &text)
.position(((offset.x + 1) as f32) * TILESIZE, ((offset.y + 1) as f32) * TILESIZE)
.size(FONTSIZE);
}

View file

@ -36,6 +36,7 @@ fn create_file_name(ecs: &World, morgue_dir: &str) -> String {
let pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
let pool = pools.get(*e).unwrap(); let pool = pools.get(*e).unwrap();
let class = match ecs.read_storage::<HasClass>().get(*e).unwrap().name { let class = match ecs.read_storage::<HasClass>().get(*e).unwrap().name {
Class::Unset => "classless",
Class::Fighter => "fighter", Class::Fighter => "fighter",
Class::Wizard => "wizard", Class::Wizard => "wizard",
Class::Rogue => "rogue", Class::Rogue => "rogue",
@ -47,7 +48,7 @@ fn create_file_name(ecs: &World, morgue_dir: &str) -> String {
Ancestry::Dwarf => "dwarf", Ancestry::Dwarf => "dwarf",
Ancestry::Gnome => "gnome", Ancestry::Gnome => "gnome",
Ancestry::Catfolk => "catfolk", Ancestry::Catfolk => "catfolk",
Ancestry::NULL => "NULL", Ancestry::Unset => "NULL",
}; };
return format!( return format!(
"{}/lv{}-{}-{}-{}.txt", "{}/lv{}-{}-{}-{}.txt",
@ -64,6 +65,7 @@ fn create_morgue_string(ecs: &World) -> String {
let mut morgue_info: String = Default::default(); let mut morgue_info: String = Default::default();
let e = ecs.fetch::<Entity>(); let e = ecs.fetch::<Entity>();
let class = match ecs.read_storage::<HasClass>().get(*e).unwrap().name { let class = match ecs.read_storage::<HasClass>().get(*e).unwrap().name {
Class::Unset => "classless",
Class::Fighter => "fighter", Class::Fighter => "fighter",
Class::Wizard => "wizard", Class::Wizard => "wizard",
Class::Rogue => "rogue", Class::Rogue => "rogue",
@ -75,7 +77,7 @@ fn create_morgue_string(ecs: &World) -> String {
Ancestry::Dwarf => "dwarf", Ancestry::Dwarf => "dwarf",
Ancestry::Gnome => "gnome", Ancestry::Gnome => "gnome",
Ancestry::Catfolk => "catfolk", Ancestry::Catfolk => "catfolk",
Ancestry::NULL => "NULL", Ancestry::Unset => "NULL",
}; };
let pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
let pool = pools.get(*e).unwrap(); let pool = pools.get(*e).unwrap();

View file

@ -1022,7 +1022,7 @@ fn get_ancestry_string(ancestry: Ancestry) -> &'static str {
Ancestry::Gnome => { Ancestry::Gnome => {
return "gnome"; return "gnome";
} }
Ancestry::NULL => { Ancestry::Unset => {
return "NULL"; return "NULL";
} }
} }

View file

@ -27,7 +27,10 @@ use super::{
Bleeds, Bleeds,
HasDamageModifiers, HasDamageModifiers,
Intrinsics, Intrinsics,
HasAncestry,
HasClass,
}; };
use crate::gui::{ Ancestry, Class };
use crate::consts::entity; use crate::consts::entity;
use crate::consts::visuals::BLOODSTAIN_COLOUR; use crate::consts::visuals::BLOODSTAIN_COLOUR;
use crate::gamesystem::*; use crate::gamesystem::*;
@ -63,6 +66,8 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
.with(Player {}) .with(Player {})
.with(Mind {}) .with(Mind {})
.with(Faction { name: "player".to_string() }) .with(Faction { name: "player".to_string() })
.with(HasAncestry { name: Ancestry::Unset })
.with(HasClass { name: Class::Unset })
.with(Viewshed { .with(Viewshed {
visible_tiles: Vec::new(), visible_tiles: Vec::new(),
range: entity::DEFAULT_VIEWSHED_STANDARD, range: entity::DEFAULT_VIEWSHED_STANDARD,

View file

@ -290,7 +290,24 @@ impl State {
menu_selection: gui::MainMenuSelection::LoadGame, menu_selection: gui::MainMenuSelection::LoadGame,
}; };
} }
//RunState::GameOver RunState::GameOver => {
let result = gui::game_over(ctx);
let write_to_morgue: Option<bool> = match result {
gui::YesNoResult::NoSelection => None,
gui::YesNoResult::No => Some(false),
gui::YesNoResult::Yes => Some(true),
};
if let Some(response) = write_to_morgue {
if response {
morgue::create_morgue_file(&self.ecs);
}
self.game_over_cleanup();
new_runstate = RunState::MapGeneration;
self.mapgen_next_state = Some(RunState::MainMenu {
menu_selection: gui::MainMenuSelection::NewGame,
});
}
}
RunState::GoToLevel(id, dest_tile) => { RunState::GoToLevel(id, dest_tile) => {
self.goto_id(id, dest_tile); self.goto_id(id, dest_tile);
self.mapgen_next_state = Some(RunState::PreRun); self.mapgen_next_state = Some(RunState::PreRun);
@ -680,7 +697,7 @@ impl State {
new_runstate = RunState::CharacterCreation { ancestry, class }; new_runstate = RunState::CharacterCreation { ancestry, class };
} }
gui::CharCreateResult::Selected { ancestry, class } => { gui::CharCreateResult::Selected { ancestry, class } => {
if ancestry == gui::Ancestry::NULL { if ancestry == gui::Ancestry::Unset {
new_runstate = RunState::MainMenu { new_runstate = RunState::MainMenu {
menu_selection: gui::MainMenuSelection::NewGame, menu_selection: gui::MainMenuSelection::NewGame,
}; };
@ -699,7 +716,7 @@ impl State {
}; };
} }
RunState::GameOver => { RunState::GameOver => {
let result = gui::game_over(ctx); let result = gui::YesNoResult::No; //gui::game_over(ctx);
let write_to_morgue: Option<bool> = match result { let write_to_morgue: Option<bool> = match result {
gui::YesNoResult::NoSelection => None, gui::YesNoResult::NoSelection => None,
gui::YesNoResult::No => Some(false), gui::YesNoResult::No => Some(false),