From 2b11ae6569fd8c3591d34acec6daee61a9103554 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 30 Jan 2021 00:03:23 -0500 Subject: [PATCH] Attacks can now heal. --- common/src/combat.rs | 26 +++++++++++++++++++++++++- common/src/states/basic_beam.rs | 13 ++++++++----- server/src/events/entity_creation.rs | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index d2d59948e0..2ef0a1f0fc 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -148,6 +148,18 @@ impl Attack { kb_dir: *dir, }); }, + AttackEffect::Heal(h) => { + let change = HealthChange { + amount: *h as i32, + cause: HealthSource::Heal { + by: Some(attacker_uid), + }, + }; + server_events.push(ServerEvent::Damage { + entity: target_entity, + change, + }); + }, } } } @@ -211,6 +223,18 @@ impl Attack { kb_dir: *dir, }); }, + AttackEffect::Heal(h) => { + let change = HealthChange { + amount: h as i32, + cause: HealthSource::Heal { + by: Some(attacker_uid), + }, + }; + server_events.push(ServerEvent::Damage { + entity: target_entity, + change, + }); + }, } } } @@ -264,7 +288,7 @@ impl EffectComponent { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum AttackEffect { - //Heal(f32), + Heal(f32), Buff(CombatBuff), Knockback(Knockback), EnergyReward(u32), diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 5c367e38d1..b4de42bf78 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -126,10 +126,8 @@ impl CharacterBehavior for Data { source: DamageSource::Energy, value: self.static_data.base_dps as f32 / self.static_data.tick_rate, }; - let heal = Damage { - source: DamageSource::Healing, - value: self.static_data.base_hps as f32 / self.static_data.tick_rate, - }; + let heal = self.static_data.base_hps as f32 / self.static_data.tick_rate; + let heal = AttackEffect::Heal(heal); let speed = self.static_data.range / self.static_data.beam_duration.as_secs_f32(); @@ -139,7 +137,12 @@ impl CharacterBehavior for Data { let lifesteal = AttackEffect::Lifesteal(self.static_data.lifesteal_eff); let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup)) .with_effect(lifesteal); - let attack = Attack::default().with_damage(damage).with_effect(energy); + let heal = EffectComponent::new(Some(GroupTarget::InGroup), heal) + /*.with_requirement(CombatRequirement::SufficientEnergy(self.static_data.energy_cost))*/; + let attack = Attack::default() + .with_damage(damage) + .with_effect(energy) + .with_effect(heal); let properties = beam::Properties { attack, diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index ca4930eb95..1464a420c8 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -170,7 +170,7 @@ pub fn handle_beam(server: &mut Server, properties: beam::Properties, pos: Pos, let ecs = state.ecs(); ecs.write_resource::>().push(Outcome::Beam { pos: pos.0, - heal: false, //properties.lifesteal_eff > 0.0, + heal: false, //properties.lifesteal_eff > 0.0, // Fix before merging }); state.create_beam(properties, pos, ori).build(); }