2020-07-04 23:55:13 +00:00
|
|
|
use common::{
|
|
|
|
comp::{HealthSource, Object, PhysicsState, Pos},
|
|
|
|
event::{EventBus, ServerEvent},
|
|
|
|
state::DeltaTime,
|
|
|
|
};
|
|
|
|
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
|
2020-07-04 23:55:13 +00:00
|
|
|
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>,
|
|
|
|
ReadStorage<'a, PhysicsState>,
|
|
|
|
WriteStorage<'a, Object>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&mut self,
|
2020-07-05 14:06:01 +00:00
|
|
|
(entities, _dt, server_bus, positions, physics_states, mut objects): Self::SystemData,
|
2020-07-04 23:55:13 +00:00
|
|
|
) {
|
|
|
|
let mut server_emitter = server_bus.emitter();
|
|
|
|
|
|
|
|
// Objects
|
2020-07-05 14:06:01 +00:00
|
|
|
for (entity, pos, physics, object) in
|
2020-07-04 23:55:13 +00:00
|
|
|
(&entities, &positions, &physics_states, &mut objects).join()
|
|
|
|
{
|
|
|
|
match object {
|
2020-07-05 14:06:01 +00:00
|
|
|
Object::Bomb { owner } => {
|
|
|
|
if physics.on_surface().is_some() {
|
2020-07-04 23:55:13 +00:00
|
|
|
server_emitter.emit(ServerEvent::Destroy {
|
|
|
|
entity,
|
|
|
|
cause: HealthSource::Suicide,
|
|
|
|
});
|
|
|
|
server_emitter.emit(ServerEvent::Explosion {
|
|
|
|
pos: pos.0,
|
|
|
|
power: 4.0,
|
|
|
|
owner: *owner,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|