diff --git a/src/data/events.rs b/src/data/events.rs index d8e97c8..eef19a1 100644 --- a/src/data/events.rs +++ b/src/data/events.rs @@ -10,13 +10,14 @@ pub enum EVENT { BROKE_DOOR(i32), LOOKED_FOR_HELP(i32), KILLED(String), + PLAYER_DIED(String), DISCOVERED(String), IDENTIFIED(String), } impl EVENT { pub const COUNT_TURN: &str = "turns"; - pub const COUNT_DEATH: &str = "deaths"; + pub const COUNT_KILLED: &str = "killed"; pub const COUNT_LEVEL: &str = "level"; pub const COUNT_CHANGED_FLOOR: &str = "changed_floor"; pub const COUNT_BROKE_DOOR: &str = "broke_door"; diff --git a/src/effects/damage.rs b/src/effects/damage.rs index 7230a3a..1c2c913 100644 --- a/src/effects/damage.rs +++ b/src/effects/damage.rs @@ -9,6 +9,7 @@ use crate::{ Map, Player, Pools, + Name, }; use crate::data::visuals::{ DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME }; use crate::data::messages::LEVELUP_PLAYER; @@ -139,12 +140,26 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { let mut xp_gain = 0; let mut pools = ecs.write_storage::(); let attributes = ecs.read_storage::(); + let names = ecs.read_storage::(); + let player = ecs.fetch::(); // If the target has a position, remove it from the SpatialMap. if let Some(pos) = targeting::entity_position(ecs, target) { crate::spatial::remove_entity(target, pos as usize); } // If the target was killed by a source, cont. if let Some(source) = effect.source { + // If the target was the player, game over, and record source of death. + if target == *player { + if let Some(src_name) = names.get(source) { + gamelog::record_event(EVENT::PLAYER_DIED(src_name.name.clone())); + } + return; + } else { + // If the player was the source, record the kill. + if let Some(tar_name) = names.get(target) { + gamelog::record_event(EVENT::KILLED(tar_name.name.clone())); + } + } // Calc XP value of target. if let Some(xp_value) = ecs.read_storage::().get(target) { xp_gain += xp_value.amount; diff --git a/src/gamelog/events.rs b/src/gamelog/events.rs index c2ffa30..6cf615e 100644 --- a/src/gamelog/events.rs +++ b/src/gamelog/events.rs @@ -7,7 +7,13 @@ lazy_static! { static ref EVENT_COUNTER: Mutex> = Mutex::new(HashMap::new()); // A record of events that happened on a given turn. i.e. "Advanced to level 2". pub static ref EVENTS: Mutex>> = Mutex::new(HashMap::new()); - static ref VISITED: Mutex> = Mutex::new(HashSet::new()); + // A record of floors visited, and monsters killed. Used to determine if an event is significant. + static ref VISITED: Mutex> = Mutex::new({ + let mut set = HashSet::new(); + set.insert(1); + set + }); + static ref KILLED: Mutex> = Mutex::new(HashSet::new()); } /// Makes a copy of event counts (FOR SERIALIZATION) @@ -70,9 +76,15 @@ pub fn record_event(event: EVENT) { modify_event_count(EVENT::COUNT_TURN, n); significant_event = false; } + // If de-levelling is ever implemented, this needs refactoring (along with a lot of stuff). EVENT::LEVEL(n) => { modify_event_count(EVENT::COUNT_LEVEL, n); - new_event = format!("Advanced to level {}", n); + let new_lvl = get_event_count(EVENT::COUNT_LEVEL); + if new_lvl == 1 { + new_event = format!("You embarked on your first adventure!"); + } else { + new_event = format!("Advanced to level {}", new_lvl); + } } EVENT::CHANGED_FLOOR(n) => { modify_event_count(EVENT::COUNT_CHANGED_FLOOR, 1); @@ -80,7 +92,7 @@ pub fn record_event(event: EVENT) { significant_event = false; } else { VISITED.lock().unwrap().insert(n); - new_event = format!("Visited level {} for the first time", n); + new_event = format!("Visited floor {} for the first time", n); } } EVENT::KICKED_SOMETHING(n) => { @@ -100,7 +112,13 @@ pub fn record_event(event: EVENT) { significant_event = false; } EVENT::KILLED(name) => { - new_event = format!("Killed {}", name); + modify_event_count(EVENT::COUNT_KILLED, 1); + if KILLED.lock().unwrap().contains(&name) { + significant_event = false; + } else { + KILLED.lock().unwrap().insert(name.clone()); + new_event = format!("Killed your first {}", name); + } } EVENT::DISCOVERED(name) => { new_event = format!("Discovered {}", name); @@ -108,6 +126,14 @@ pub fn record_event(event: EVENT) { EVENT::IDENTIFIED(name) => { new_event = format!("Identified {}", name); } + EVENT::PLAYER_DIED(name) => { + if name == "you" { + new_event = format!("You died! Killed by... yourself."); + } else { + // TODO: Use correct article here - or don't include article at all. + new_event = format!("You died, killed by {}", name); + } + } } if significant_event { diff --git a/src/gui/mod.rs b/src/gui/mod.rs index b470f7b..8270085 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1165,13 +1165,13 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { ); y += 1; } - if crate::gamelog::get_event_count(EVENT::COUNT_DEATH) > 0 { + if crate::gamelog::get_event_count(EVENT::COUNT_KILLED) > 0 { ctx.print_color( x + 1, y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - format!("- slew {} other creature(s)", crate::gamelog::get_event_count(EVENT::COUNT_DEATH)) + format!("- slew {} other creature(s)", crate::gamelog::get_event_count(EVENT::COUNT_KILLED)) ); y += 1; } diff --git a/src/morgue.rs b/src/morgue.rs index f3d2011..a097311 100644 --- a/src/morgue.rs +++ b/src/morgue.rs @@ -249,8 +249,12 @@ fn draw_events_list() -> String { for key in sorted_keys { if let Some(value) = lock.get(&key) { result.push_str(&format!("{:<4} | ", key)); - for event in value.iter() { - result.push_str(&format!("{}", event)); + for (i, event) in value.iter().enumerate() { + if i > 0 { + result.push_str(&format!("; {}", event.to_lowercase())); + } else { + result.push_str(&format!("{}", event)); + } } result.push_str("\n"); } diff --git a/src/particle_system.rs b/src/particle_system.rs index 249f232..3242988 100644 --- a/src/particle_system.rs +++ b/src/particle_system.rs @@ -35,7 +35,6 @@ fn create_delayed_particles(ecs: &mut World, ctx: &Rltk) { let mut particle_builder = ecs.write_resource::(); let mut handled_particles: Vec = Vec::new(); for delayed_particle in particle_builder.delayed_requests.iter_mut() { - rltk::console::log(delayed_particle.delay); delayed_particle.delay -= ctx.frame_time_ms; if delayed_particle.delay < 0.0 { handled_particles.push(ParticleRequest { diff --git a/wasm/rust-rl.js b/wasm/rust-rl.js index 4843977..7bba90b 100644 --- a/wasm/rust-rl.js +++ b/wasm/rust-rl.js @@ -801,15 +801,15 @@ function __wbg_get_imports() { const ret = wasm.memory; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper698 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 125, __wbg_adapter_20); + imports.wbg.__wbindgen_closure_wrapper699 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 124, __wbg_adapter_20); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper2738 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper2754 = function(arg0, arg1, arg2) { const ret = makeMutClosure(arg0, arg1, 522, __wbg_adapter_23); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper2740 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper2756 = function(arg0, arg1, arg2) { const ret = makeMutClosure(arg0, arg1, 522, __wbg_adapter_23); return addHeapObject(ret); }; diff --git a/wasm/rust-rl_bg.wasm b/wasm/rust-rl_bg.wasm index 6a8799c..961a9ca 100644 Binary files a/wasm/rust-rl_bg.wasm and b/wasm/rust-rl_bg.wasm differ