improves morgue file significant event logging, bumps wasm build
This commit is contained in:
parent
738484436b
commit
9ac2adc5d6
8 changed files with 59 additions and 14 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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::<Pools>();
|
||||
let attributes = ecs.read_storage::<Attributes>();
|
||||
let names = ecs.read_storage::<Name>();
|
||||
let player = ecs.fetch::<Entity>();
|
||||
// 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::<GrantsXP>().get(target) {
|
||||
xp_gain += xp_value.amount;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ lazy_static! {
|
|||
static ref EVENT_COUNTER: Mutex<HashMap<String, i32>> = 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<HashMap<u32, Vec<String>>> = Mutex::new(HashMap::new());
|
||||
static ref VISITED: Mutex<HashSet<i32>> = Mutex::new(HashSet::new());
|
||||
// A record of floors visited, and monsters killed. Used to determine if an event is significant.
|
||||
static ref VISITED: Mutex<HashSet<i32>> = Mutex::new({
|
||||
let mut set = HashSet::new();
|
||||
set.insert(1);
|
||||
set
|
||||
});
|
||||
static ref KILLED: Mutex<HashSet<String>> = 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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,9 +249,13 @@ 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() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ fn create_delayed_particles(ecs: &mut World, ctx: &Rltk) {
|
|||
let mut particle_builder = ecs.write_resource::<ParticleBuilder>();
|
||||
let mut handled_particles: Vec<ParticleRequest> = 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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue