2020-07-04 23:55:13 +00:00
|
|
|
use common::{
|
2020-12-06 02:29:46 +00:00
|
|
|
comp::{HealthSource, Object, PhysicsState, PoiseChange, PoiseSource, Pos, Vel},
|
2020-11-01 17:15:46 +00:00
|
|
|
effect::Effect,
|
2020-07-04 23:55:13 +00:00
|
|
|
event::{EventBus, ServerEvent},
|
2020-12-01 00:28:00 +00:00
|
|
|
resources::DeltaTime,
|
|
|
|
span, Damage, DamageSource, Explosion, RadiusEffect,
|
2020-07-04 23:55:13 +00:00
|
|
|
};
|
|
|
|
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>,
|
2020-08-11 11:52:15 +00:00
|
|
|
ReadStorage<'a, Vel>,
|
2020-07-04 23:55:13 +00:00
|
|
|
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,
|
2020-07-04 23:55:13 +00:00
|
|
|
) {
|
2020-09-07 04:59:16 +00:00
|
|
|
span!(_guard, "run", "object::Sys::run");
|
2020-07-04 23:55:13 +00:00
|
|
|
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()
|
2020-07-04 23:55:13 +00:00
|
|
|
{
|
|
|
|
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,
|
2020-10-15 00:43:53 +00:00
|
|
|
explosion: Explosion {
|
2020-10-30 20:41:21 +00:00
|
|
|
effects: vec![
|
2020-12-16 23:30:33 +00:00
|
|
|
RadiusEffect::Entity(
|
|
|
|
None,
|
2020-11-05 01:21:42 +00:00
|
|
|
Effect::Damage(Damage {
|
|
|
|
source: DamageSource::Explosion,
|
|
|
|
value: 500.0,
|
2020-11-02 00:26:01 +00:00
|
|
|
}),
|
2020-12-16 23:30:33 +00:00
|
|
|
),
|
|
|
|
RadiusEffect::Entity(
|
|
|
|
None,
|
|
|
|
Effect::PoiseChange(PoiseChange {
|
2020-12-06 02:29:46 +00:00
|
|
|
source: PoiseSource::Explosion,
|
2020-12-16 23:30:33 +00:00
|
|
|
amount: -100,
|
2020-12-06 02:29:46 +00:00
|
|
|
}),
|
2020-12-16 23:30:33 +00:00
|
|
|
),
|
2020-10-30 20:41:21 +00:00
|
|
|
RadiusEffect::TerrainDestruction(4.0),
|
|
|
|
],
|
2020-10-06 02:19:41 +00:00
|
|
|
radius: 12.0,
|
2020-10-08 00:32:30 +00:00
|
|
|
energy_regen: 0,
|
2020-10-06 02:19:41 +00:00
|
|
|
},
|
2020-07-04 23:55:13 +00:00
|
|
|
owner: *owner,
|
2020-08-11 14:05:34 +00:00
|
|
|
reagent: None,
|
2020-07-04 23:55:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
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,
|
2020-10-15 00:43:53 +00:00
|
|
|
explosion: Explosion {
|
2020-10-30 20:41:21 +00:00
|
|
|
effects: vec![
|
2020-12-16 23:30:33 +00:00
|
|
|
RadiusEffect::Entity(
|
|
|
|
None,
|
2020-11-05 01:21:42 +00:00
|
|
|
Effect::Damage(Damage {
|
|
|
|
source: DamageSource::Explosion,
|
|
|
|
value: 50.0,
|
2020-11-02 00:26:01 +00:00
|
|
|
}),
|
2020-12-16 23:30:33 +00:00
|
|
|
),
|
|
|
|
RadiusEffect::Entity(
|
|
|
|
None,
|
|
|
|
Effect::PoiseChange(PoiseChange {
|
2020-12-06 02:29:46 +00:00
|
|
|
source: PoiseSource::Explosion,
|
2020-12-16 23:30:33 +00:00
|
|
|
amount: -40,
|
2020-12-06 02:29:46 +00:00
|
|
|
}),
|
2020-12-16 23:30:33 +00:00
|
|
|
),
|
2020-10-30 20:41:21 +00:00
|
|
|
RadiusEffect::TerrainDestruction(4.0),
|
|
|
|
],
|
2020-10-06 02:19:41 +00:00
|
|
|
radius: 12.0,
|
2020-10-08 00:32:30 +00:00
|
|
|
energy_regen: 0,
|
2020-10-06 02:19:41 +00:00
|
|
|
},
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-07-04 23:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|