1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use specs::{
WriteStorage,
Read,
System,
Join
};
use crate::{
components::{Health, Healing},
resources::TimeStamp
};
pub struct Heal;
impl <'a> System<'a> for Heal {
type SystemData = (
WriteStorage<'a, Health>,
WriteStorage<'a, Healing>,
Read<'a, TimeStamp>
);
fn run(&mut self, (mut healths, mut healing, timestamp): Self::SystemData) {
for (health, mut heal) in (&mut healths, &mut healing).join() {
if let Some(next_heal) = heal.next_heal {
if next_heal <= timestamp.time {
health.heal(heal.health);
heal.next_heal = None
}
}
if health.health < health.maxhealth && heal.next_heal == None {
heal.next_heal = Some(timestamp.time + heal.delay)
}
}
}
}
|