diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index 27ced5f27b..ce7d6e936d 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -106,6 +106,7 @@ impl ToolData { cause: HealthSource::Projectile { owner: None }, }), projectile::Effect::Knockback(10.0), + projectile::Effect::RewardEnergy(100), projectile::Effect::Vanish, ], time_left: Duration::from_secs(15), @@ -146,6 +147,7 @@ impl ToolData { amount: -1, cause: HealthSource::Projectile { owner: None }, }), + projectile::Effect::RewardEnergy(100), projectile::Effect::Vanish, ], time_left: Duration::from_secs(20), diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index a4dda1ac7c..8ff384a87a 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -7,6 +7,7 @@ use std::time::Duration; pub enum Effect { Damage(comp::HealthChange), Knockback(f32), + RewardEnergy(u32), Explode { power: f32 }, Vanish, Stick, diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index 3f0ee14a04..bf0fc1064d 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -1,5 +1,7 @@ use crate::{ - comp::{projectile, HealthSource, Ori, PhysicsState, Pos, Projectile, Vel}, + comp::{ + projectile, Energy, EnergySource, HealthSource, Ori, PhysicsState, Pos, Projectile, Vel, + }, event::{EventBus, LocalEvent, ServerEvent}, state::DeltaTime, sync::UidAllocator, @@ -22,6 +24,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Vel>, WriteStorage<'a, Ori>, WriteStorage<'a, Projectile>, + WriteStorage<'a, Energy>, ); fn run( @@ -37,6 +40,7 @@ impl<'a> System<'a> for Sys { velocities, mut orientations, mut projectiles, + mut energies, ): Self::SystemData, ) { let mut local_emitter = local_bus.emitter(); @@ -108,6 +112,15 @@ impl<'a> System<'a> for Sys { }); } }, + projectile::Effect::RewardEnergy(energy) => { + if let Some(energy_mut) = projectile + .owner + .and_then(|o| uid_allocator.retrieve_entity_internal(o.into())) + .and_then(|o| energies.get_mut(o)) + { + energy_mut.change_by(energy as i32, EnergySource::HitEnemy); + } + }, projectile::Effect::Explode { power } => { server_emitter.emit(ServerEvent::Explosion { pos: pos.0,