veloren/server/src/sys/object.rs

106 lines
4.1 KiB
Rust
Raw Normal View History

use common::{
comp::{HealthSource, Object, PhysicsState, Pos, Vel},
event::{EventBus, ServerEvent},
2020-08-29 06:39:16 +00:00
span,
state::DeltaTime,
Damage, DamageSource, Damages, Explosion, RadiusEffect,
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
2020-07-05 12:39:28 +00:00
/// This system is responsible for handling misc object behaviours
pub struct Sys;
impl<'a> System<'a> for Sys {
#[allow(clippy::type_complexity)]
type SystemData = (
Entities<'a>,
Read<'a, DeltaTime>,
Read<'a, EventBus<ServerEvent>>,
ReadStorage<'a, Pos>,
2020-08-11 11:52:15 +00:00
ReadStorage<'a, Vel>,
ReadStorage<'a, PhysicsState>,
WriteStorage<'a, Object>,
);
fn run(
&mut self,
2020-08-11 11:52:15 +00:00
(entities, _dt, server_bus, positions, velocities, physics_states, mut objects): Self::SystemData,
) {
span!(_guard, "run", "object::Sys::run");
let mut server_emitter = server_bus.emitter();
// Objects
2020-08-11 14:05:34 +00:00
for (entity, pos, vel, physics, object) in (
&entities,
&positions,
&velocities,
&physics_states,
&mut objects,
)
.join()
{
match object {
2020-07-05 14:06:01 +00:00
Object::Bomb { owner } => {
if physics.on_surface().is_some() {
server_emitter.emit(ServerEvent::Destroy {
entity,
cause: HealthSource::Suicide,
});
server_emitter.emit(ServerEvent::Explosion {
pos: pos.0,
explosion: Explosion {
effects: vec![
RadiusEffect::Damages(Damages::new(
Some(Damage {
source: DamageSource::Explosion,
value: 500.0,
}),
Some(Damage {
source: DamageSource::Explosion,
value: 500.0,
}),
)),
RadiusEffect::TerrainDestruction(4.0),
],
radius: 12.0,
energy_regen: 0,
},
owner: *owner,
2020-08-11 14:05:34 +00:00
reagent: None,
});
}
},
2020-08-11 14:05:34 +00:00
Object::Firework { owner, reagent } => {
if vel.0.z < 0.0 {
2020-08-11 11:52:15 +00:00
server_emitter.emit(ServerEvent::Destroy {
entity,
cause: HealthSource::Suicide,
});
server_emitter.emit(ServerEvent::Explosion {
pos: pos.0,
explosion: Explosion {
effects: vec![
RadiusEffect::Damages(Damages::new(
Some(Damage {
source: DamageSource::Explosion,
value: 50.0,
}),
Some(Damage {
source: DamageSource::Explosion,
value: 50.0,
}),
)),
RadiusEffect::TerrainDestruction(4.0),
],
radius: 12.0,
energy_regen: 0,
},
2020-08-11 11:52:15 +00:00
owner: *owner,
2020-08-11 14:05:34 +00:00
reagent: Some(*reagent),
2020-08-11 11:52:15 +00:00
});
}
},
}
}
}
}