atomising item use: damage and healing, and refactors

This commit is contained in:
Llywelwyn 2023-08-17 03:12:42 +01:00
parent 6677181a4e
commit 911873127d
12 changed files with 176 additions and 48 deletions

View file

@ -19,6 +19,7 @@ lazy_static! {
pub enum EffectType {
Damage { amount: i32 },
Healing { amount: i32 },
Bloodstain,
Particle { glyph: FontCharType, fg: RGB, bg: RGB, lifespan: f32, delay: f32 },
EntityDeath,
@ -95,6 +96,7 @@ fn affect_tile(ecs: &mut World, effect: &EffectSpawner, target: usize) {
fn tile_effect_hits_entities(effect: &EffectType) -> bool {
match effect {
EffectType::Damage { .. } => true,
EffectType::Healing { .. } => true,
EffectType::RestoreNutrition { .. } => true,
_ => false,
}
@ -104,6 +106,7 @@ fn tile_effect_hits_entities(effect: &EffectType) -> bool {
fn affect_entity(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
match &effect.effect_type {
EffectType::Damage { .. } => damage::inflict_damage(ecs, effect, target),
EffectType::Healing { .. } => damage::heal_damage(ecs, effect, target),
EffectType::Bloodstain { .. } => {
if let Some(pos) = targeting::entity_position(ecs, target) {
damage::bloodstain(ecs, pos)