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"))]
use crate::{comp, consts::HP_PER_LEVEL};
use hashbrown::HashMap;
use rand;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

View File

@ -71,6 +71,25 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
if let Some(mut health) = ecs.write_storage::<Health>().get_mut(entity) {
changed = health.change_by(change);
}
if let (Some(pos), Some(uid)) = (
ecs.read_storage::<Pos>().get(entity),
ecs.read_storage::<Uid>().get(entity),
) {
// If the absolute health change amount was greater than the health epsilon,
// push a new Damage outcome
if changed {
outcomes.push(Outcome::Damage {
pos: pos.0,
info: DamageInfo {
amount: change.amount,
by: change.by,
target: *uid,
crit_mult: change.crit_mult,
instance: change.instance,
},
});
}
}
// 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;
@ -78,25 +97,6 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
if let Some(agent) = ecs.write_storage::<Agent>().get_mut(entity) {
agent.inbox.push_front(AgentEvent::Hurt);
}
if let (Some(pos), Some(uid)) = (
ecs.read_storage::<Pos>().get(entity),
ecs.read_storage::<Uid>().get(entity),
) {
// If the absolute health change amount was greater than the health epsilon,
// push a new Damage outcome
if changed {
outcomes.push(Outcome::Damage {
pos: pos.0,
info: DamageInfo {
amount: change.amount,
by: change.by,
target: *uid,
crit_mult: change.crit_mult,
instance: change.instance,
},
});
}
}
}
}

View File

@ -1575,52 +1575,28 @@ impl Hud {
((crate::ecs::sys::floater::MY_HP_SHOWTIME - floater.timer) * 0.25)
+ 0.2
};
// TODO: Add options for these as well
if floater.info.amount.abs() > 1.0 {
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)
}
// TODO: Add options for floating/non-floating
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(0.1, 1.0, 0.1, hp_fade)
})
.x_y(x, y)
.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);
}
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
@ -2348,49 +2324,25 @@ impl Hud {
// Timer sets text transparency
let fade =
((crate::ecs::sys::floater::HP_SHOWTIME - timer) * 0.25) + 0.2;
// TODO: Can the Healing variant even be reached as healing is ignored?
if hp_damage.abs() < 1.0 {
// Damage and heal below 10/10 are shown as decimals
Text::new(&format!("{}", hp_damage.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_damage.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 {
// 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);
};
// TODO: Add options for floating/non-floating
Text::new(&format!("{}", hp_damage.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_damage.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 {
for floater in floaters {
@ -2452,59 +2404,29 @@ impl Hud {
((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25)
+ 0.2
};
if floater.info.amount.abs() < 1.0 {
// 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()))
.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);
} 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);
}
// TODO: Add options for floating/non-floating
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,
} {
// 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() {
if floater.timer > 0.0 {
break;
@ -4663,7 +4585,6 @@ impl Hud {
} else {
floater.info.crit_mult
};
dbg!(&floater.info.crit_mult);
return;
}
}
@ -4681,7 +4602,6 @@ impl Hud {
&& info.crit_mult.is_some() == f.info.crit_mult.is_some()
})
};
dbg!(&last_floater);
match last_floater {
Some(f)