2019-09-17 12:43:19 +00:00
|
|
|
use crate::{
|
|
|
|
comp::{
|
|
|
|
projectile, ActionState::*, CharacterState, Controller, ForceUpdate, HealthSource, Ori,
|
|
|
|
PhysicsState, Pos, Projectile, Stats, Vel,
|
|
|
|
},
|
|
|
|
event::{EventBus, ServerEvent},
|
|
|
|
state::{DeltaTime, Uid},
|
|
|
|
};
|
|
|
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
|
|
|
use std::time::Duration;
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
/// This system is responsible for handling projectile effect triggers
|
|
|
|
pub struct Sys;
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
|
|
type SystemData = (
|
|
|
|
Entities<'a>,
|
|
|
|
ReadStorage<'a, Uid>,
|
|
|
|
Read<'a, DeltaTime>,
|
|
|
|
Read<'a, EventBus<ServerEvent>>,
|
|
|
|
ReadStorage<'a, Pos>,
|
|
|
|
ReadStorage<'a, Vel>,
|
|
|
|
ReadStorage<'a, PhysicsState>,
|
2019-09-21 12:43:24 +00:00
|
|
|
WriteStorage<'a, Ori>,
|
2019-09-17 12:43:19 +00:00
|
|
|
WriteStorage<'a, Projectile>,
|
|
|
|
WriteStorage<'a, Stats>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
(
|
|
|
|
entities,
|
|
|
|
uids,
|
|
|
|
dt,
|
|
|
|
server_bus,
|
|
|
|
positions,
|
|
|
|
velocities,
|
|
|
|
physics_states,
|
2019-09-21 12:43:24 +00:00
|
|
|
mut orientations,
|
2019-09-17 12:43:19 +00:00
|
|
|
mut projectiles,
|
|
|
|
mut stats,
|
|
|
|
): Self::SystemData,
|
|
|
|
) {
|
|
|
|
let mut server_emitter = server_bus.emitter();
|
|
|
|
|
|
|
|
// Attacks
|
2019-09-21 12:43:24 +00:00
|
|
|
for (entity, uid, pos, vel, physics, ori, projectile) in (
|
2019-09-17 12:43:19 +00:00
|
|
|
&entities,
|
|
|
|
&uids,
|
|
|
|
&positions,
|
|
|
|
&velocities,
|
|
|
|
&physics_states,
|
2019-09-21 12:43:24 +00:00
|
|
|
&mut orientations,
|
2019-09-17 12:43:19 +00:00
|
|
|
&mut projectiles,
|
|
|
|
)
|
|
|
|
.join()
|
|
|
|
{
|
2019-09-21 12:43:24 +00:00
|
|
|
ori.0 = vel.0.normalized();
|
|
|
|
|
2019-09-17 12:43:19 +00:00
|
|
|
// Hit ground
|
|
|
|
if physics.on_ground {
|
|
|
|
for effect in projectile.hit_ground.drain(..) {
|
|
|
|
match effect {
|
|
|
|
projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy {
|
|
|
|
entity,
|
|
|
|
cause: HealthSource::World,
|
|
|
|
}),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-21 12:43:24 +00:00
|
|
|
// Hit entity
|
|
|
|
if let Some(other) = physics.touch_entity {
|
2019-09-17 12:43:19 +00:00
|
|
|
for effect in projectile.hit_entity.drain(..) {
|
|
|
|
match effect {
|
2019-09-21 12:43:24 +00:00
|
|
|
projectile::Effect::Damage(power) => {
|
|
|
|
server_emitter.emit(ServerEvent::Damage {
|
|
|
|
uid: other,
|
2019-09-25 21:31:25 +00:00
|
|
|
dmg: power,
|
2019-09-21 12:43:24 +00:00
|
|
|
cause: HealthSource::Projectile,
|
|
|
|
})
|
|
|
|
}
|
2019-09-17 12:43:19 +00:00
|
|
|
projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy {
|
|
|
|
entity,
|
|
|
|
cause: HealthSource::World,
|
|
|
|
}),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|