2019-11-24 20:12:03 +00:00
|
|
|
use crate::{comp, sync::Uid};
|
2019-09-26 16:48:37 +00:00
|
|
|
use specs::{Component, FlaggedStorage};
|
2019-09-17 12:43:19 +00:00
|
|
|
use specs_idvs::IDVStorage;
|
2019-10-06 17:30:06 +00:00
|
|
|
use std::time::Duration;
|
2019-09-17 12:43:19 +00:00
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2019-09-17 12:43:19 +00:00
|
|
|
pub enum Effect {
|
2019-10-17 20:59:36 +00:00
|
|
|
Damage(comp::HealthChange),
|
2020-03-22 19:39:50 +00:00
|
|
|
Explode { power: f32 },
|
2019-09-17 12:43:19 +00:00
|
|
|
Vanish,
|
2019-09-28 19:35:28 +00:00
|
|
|
Stick,
|
2019-10-11 23:30:05 +00:00
|
|
|
Possess,
|
2019-09-17 12:43:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2019-09-17 12:43:19 +00:00
|
|
|
pub struct Projectile {
|
2019-11-04 00:57:36 +00:00
|
|
|
// TODO: use SmallVec for these effects
|
2019-09-17 12:43:19 +00:00
|
|
|
pub hit_ground: Vec<Effect>,
|
2019-09-29 08:37:07 +00:00
|
|
|
pub hit_wall: Vec<Effect>,
|
2019-09-17 12:43:19 +00:00
|
|
|
pub hit_entity: Vec<Effect>,
|
2019-10-06 17:30:06 +00:00
|
|
|
/// Time left until the projectile will despawn
|
|
|
|
pub time_left: Duration,
|
2020-03-16 11:32:57 +00:00
|
|
|
pub owner: Option<Uid>,
|
2019-09-17 12:43:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 13:26:18 +00:00
|
|
|
impl Projectile {
|
|
|
|
pub fn set_owner(&mut self, new_owner: Uid) {
|
|
|
|
self.owner = Some(new_owner);
|
|
|
|
for e in self
|
|
|
|
.hit_ground
|
|
|
|
.iter_mut()
|
|
|
|
.chain(self.hit_wall.iter_mut())
|
|
|
|
.chain(self.hit_entity.iter_mut())
|
|
|
|
{
|
|
|
|
if let Effect::Damage(comp::HealthChange {
|
|
|
|
cause: comp::HealthSource::Projectile { owner, .. },
|
|
|
|
..
|
|
|
|
}) = e
|
|
|
|
{
|
|
|
|
*owner = Some(new_owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 12:43:19 +00:00
|
|
|
impl Component for Projectile {
|
|
|
|
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
|
|
|
}
|