Fixed bug with healing above 5.0 and preparing for options

This commit is contained in:
socksonme 2022-02-04 21:02:53 +02:00 committed by Socksonme
parent db16e6147c
commit 64f0f05608
3 changed files with 83 additions and 164 deletions

View File

@ -2,7 +2,6 @@ use crate::DamageSource;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use crate::{comp, consts::HP_PER_LEVEL}; use crate::{comp, consts::HP_PER_LEVEL};
use hashbrown::HashMap; use hashbrown::HashMap;
use rand;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -71,13 +71,6 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
if let Some(mut health) = ecs.write_storage::<Health>().get_mut(entity) { if let Some(mut health) = ecs.write_storage::<Health>().get_mut(entity) {
changed = health.change_by(change); changed = health.change_by(change);
} }
// This if statement filters out anything under 5 damage, for DOT ticks
// TODO: Find a better way to separate direct damage from DOT here
let damage = -change.amount;
if damage > -5.0 {
if let Some(agent) = ecs.write_storage::<Agent>().get_mut(entity) {
agent.inbox.push_front(AgentEvent::Hurt);
}
if let (Some(pos), Some(uid)) = ( if let (Some(pos), Some(uid)) = (
ecs.read_storage::<Pos>().get(entity), ecs.read_storage::<Pos>().get(entity),
ecs.read_storage::<Uid>().get(entity), ecs.read_storage::<Uid>().get(entity),
@ -97,6 +90,13 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
}); });
} }
} }
// This if statement filters out anything under 5 damage, for DOT ticks
// TODO: Find a better way to separate direct damage from DOT here
let damage = -change.amount;
if damage > -5.0 {
if let Some(agent) = ecs.write_storage::<Agent>().get_mut(entity) {
agent.inbox.push_front(AgentEvent::Hurt);
}
} }
} }

View File

@ -1575,8 +1575,7 @@ impl Hud {
((crate::ecs::sys::floater::MY_HP_SHOWTIME - floater.timer) * 0.25) ((crate::ecs::sys::floater::MY_HP_SHOWTIME - floater.timer) * 0.25)
+ 0.2 + 0.2
}; };
// TODO: Add options for these as well // TODO: Add options for floating/non-floating
if floater.info.amount.abs() > 1.0 {
Text::new(&format!("{:.1}", floater.info.amount.abs())) Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size) .font_size(font_size)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
@ -1598,29 +1597,6 @@ impl Hud {
}) })
.x_y(x, y) .x_y(x, y)
.set(player_sct_id, ui_widgets); .set(player_sct_id, ui_widgets);
} else {
Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(Color::Rgba(0.0, 0.0, 0.0, hp_fade))
.x_y(x, y - 3.0)
.set(player_sct_bg_id, ui_widgets);
Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(if floater.info.amount < 0.0 {
// TODO: example
if crit {
Color::Rgba(1.0, 0.9, 0.1, hp_fade)
} else {
Color::Rgba(1.0, 0.1, 0.0, hp_fade)
}
} else {
Color::Rgba(0.1, 1.0, 0.1, hp_fade)
})
.x_y(x, y)
.set(player_sct_id, ui_widgets);
}
} }
} }
// EXP Numbers // EXP Numbers
@ -2348,9 +2324,7 @@ impl Hud {
// Timer sets text transparency // Timer sets text transparency
let fade = let fade =
((crate::ecs::sys::floater::HP_SHOWTIME - timer) * 0.25) + 0.2; ((crate::ecs::sys::floater::HP_SHOWTIME - timer) * 0.25) + 0.2;
// TODO: Can the Healing variant even be reached as healing is ignored? // TODO: Add options for floating/non-floating
if hp_damage.abs() < 1.0 {
// Damage and heal below 10/10 are shown as decimals
Text::new(&format!("{}", hp_damage.abs())) Text::new(&format!("{}", hp_damage.abs()))
.font_size(font_size) .font_size(font_size)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
@ -2369,28 +2343,6 @@ impl Hud {
}) })
.position_ingame(ingame_pos) .position_ingame(ingame_pos)
.set(sct_id, ui_widgets); .set(sct_id, ui_widgets);
} else {
// Damage and heal above 10/10 are shown rounded
Text::new(&format!("{}", hp_dmg_rounded_abs))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(Color::Rgba(0.0, 0.0, 0.0, fade))
.x_y(0.0, y - 3.0)
.position_ingame(ingame_pos)
.set(sct_bg_id, ui_widgets);
Text::new(&format!("{}", hp_dmg_rounded_abs))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.x_y(0.0, y)
.color(if hp_damage < 0.0 {
Color::Rgba(font_col.r, font_col.g, font_col.b, fade)
} else {
Color::Rgba(0.1, 1.0, 0.1, fade)
})
.position_ingame(ingame_pos)
.set(sct_id, ui_widgets);
};
} }
} else { } else {
for floater in floaters { for floater in floaters {
@ -2452,10 +2404,7 @@ impl Hud {
((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25) ((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25)
+ 0.2 + 0.2
}; };
if floater.info.amount.abs() < 1.0 { // TODO: Add options for floating/non-floating
// Damage and heal below 10/10 are shown as decimals
// TODO: this is not true right now, but we might want to add an
// option for this
Text::new(&format!("{:.1}", floater.info.amount.abs())) Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size) .font_size(font_size)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
@ -2478,33 +2427,6 @@ impl Hud {
}) })
.position_ingame(ingame_pos) .position_ingame(ingame_pos)
.set(sct_id, ui_widgets); .set(sct_id, ui_widgets);
} else {
// Damage and heal above 10/10 are shown rounded
// TODO: this is not true right now, but we might want to add an
// option for this
Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(if floater.info.amount < 0.0 {
Color::Rgba(0.0, 0.0, 0.0, fade)
} else {
Color::Rgba(0.0, 0.0, 0.0, 1.0)
})
.x_y(x, y - 3.0)
.position_ingame(ingame_pos)
.set(sct_bg_id, ui_widgets);
Text::new(&format!("{:.1}", floater.info.amount.abs()))
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.x_y(x, y)
.color(if floater.info.amount < 0.0 {
Color::Rgba(font_col.r, font_col.g, font_col.b, fade)
} else {
Color::Rgba(0.1, 1.0, 0.1, 1.0)
})
.position_ingame(ingame_pos)
.set(sct_id, ui_widgets);
}
} }
} }
} }
@ -4648,7 +4570,7 @@ impl Hud {
None => hit_me, None => hit_me,
} { } {
// Group up damage from the same tick, with the same instance number and // Group up damage from the same tick, with the same instance number and
// has the same crit value // crit value
for floater in floater_list.floaters.iter_mut().rev() { for floater in floater_list.floaters.iter_mut().rev() {
if floater.timer > 0.0 { if floater.timer > 0.0 {
break; break;
@ -4663,7 +4585,6 @@ impl Hud {
} else { } else {
floater.info.crit_mult floater.info.crit_mult
}; };
dbg!(&floater.info.crit_mult);
return; return;
} }
} }
@ -4681,7 +4602,6 @@ impl Hud {
&& info.crit_mult.is_some() == f.info.crit_mult.is_some() && info.crit_mult.is_some() == f.info.crit_mult.is_some()
}) })
}; };
dbg!(&last_floater);
match last_floater { match last_floater {
Some(f) Some(f)