2019-05-17 20:47:58 +00:00
|
|
|
// Library
|
|
|
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
// Crate
|
|
|
|
use crate::{
|
|
|
|
comp::{Control, Dying, Stats},
|
|
|
|
state::DeltaTime,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Basic ECS AI agent system
|
|
|
|
pub struct Sys;
|
|
|
|
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
|
|
type SystemData = (
|
|
|
|
Entities<'a>,
|
2019-05-19 20:14:18 +00:00
|
|
|
Read<'a, DeltaTime>,
|
|
|
|
WriteStorage<'a, Stats>,
|
2019-05-17 20:47:58 +00:00
|
|
|
WriteStorage<'a, Dying>,
|
|
|
|
);
|
|
|
|
|
2019-05-19 20:14:18 +00:00
|
|
|
fn run(&mut self, (entities, dt, mut stats, mut dyings): Self::SystemData) {
|
|
|
|
for (entity, mut stat) in (&entities, &mut stats).join() {
|
2019-05-17 20:47:58 +00:00
|
|
|
if stat.hp.current == 0 {
|
|
|
|
dyings.insert(entity, Dying);
|
|
|
|
}
|
2019-05-19 20:14:18 +00:00
|
|
|
if let Some(change) = &mut stat.hp.last_change {
|
|
|
|
change.1 += dt.0 as f64;
|
|
|
|
}
|
2019-05-17 20:47:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|