Outcomes now correctly read if an attack had any healing components.

This commit is contained in:
Sam 2021-01-31 12:15:28 -05:00
parent 5eec915c2e
commit 17d1432be0
4 changed files with 19 additions and 17 deletions

View File

@ -66,6 +66,8 @@ impl Attack {
self
}
pub fn effects(&self) -> impl Iterator<Item = &EffectComponent> { self.effects.iter() }
#[allow(clippy::too_many_arguments)]
pub fn apply_attack(
&self,
@ -303,6 +305,8 @@ impl EffectComponent {
self.requirement = Some(requirement);
self
}
pub fn effect(&self) -> &AttackEffect { &self.effect }
}
#[derive(Clone, Debug, Serialize, Deserialize)]

View File

@ -9,9 +9,6 @@ pub struct Properties {
pub attack: Attack,
pub angle: f32,
pub speed: f32,
//pub lifesteal_eff: f32,
//pub energy_regen: u32,
//pub energy_cost: u32,
pub duration: Duration,
pub owner: Option<Uid>,
}

View File

@ -1,6 +1,7 @@
use crate::{sys, Server, StateExt};
use common::{
character::CharacterId,
combat,
comp::{
self,
aura::{Aura, AuraKind, AuraTarget},
@ -170,7 +171,10 @@ pub fn handle_beam(server: &mut Server, properties: beam::Properties, pos: Pos,
let ecs = state.ecs();
ecs.write_resource::<Vec<Outcome>>().push(Outcome::Beam {
pos: pos.0,
heal: false, //properties.lifesteal_eff > 0.0, // Fix before merging
heal: properties
.attack
.effects()
.any(|e| matches!(e.effect(), combat::AttackEffect::Heal(h) if *h > 0.0)),
});
state.create_beam(properties, pos, ori).build();
}

View File

@ -577,24 +577,21 @@ pub fn handle_explosion(
// Add an outcome
// Uses radius as outcome power, makes negative if explosion has healing effect
let outcome_power = explosion.radius;
//
// * if explosion.effects.iter().any(|e| { matches!( e, RadiusEffect::Entity( _,
// Effect::Damage(Damage { source: DamageSource::Healing, .. }) ) )
// }) {
// -1.0
// } else {
// 1.0
// };
let outcome_power = explosion.radius
* if explosion.effects.iter().any(|e| matches!(e, RadiusEffect::Attack(a) if a.effects().any(|e| matches!(e.effect(), combat::AttackEffect::Heal(h) if *h > 0.0)))) {
-1.0
} else {
1.0
};
ecs.write_resource::<Vec<Outcome>>()
.push(Outcome::Explosion {
pos,
power: outcome_power,
radius: explosion.radius,
is_attack: false, /*explosion
.effects
.iter()
.any(|e| matches!(e, RadiusEffect::Entity(_, Effect::Damage(_))))*/
is_attack: explosion
.effects
.iter()
.any(|e| matches!(e, RadiusEffect::Attack(_))),
reagent,
});
let owner_entity = owner.and_then(|uid| {