summaryrefslogtreecommitdiff
path: root/src/systems/heal.rs
blob: 34e67f4aa57fca3b36018f89f4b00c02f2f71899 (plain)
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::Time
};


pub struct Heal;
impl <'a> System<'a> for Heal {
	type SystemData = (
		WriteStorage<'a, Health>,
		WriteStorage<'a, Healing>,
		Read<'a, Time>
	);
	fn run(&mut self, (mut healths, mut healing, time): Self::SystemData) {
		for (health, mut heal) in (&mut healths, &mut healing).join() {
			
			if let Some(next_heal) = heal.next_heal {
				if next_heal <= time.time {
					health.heal(heal.health);
					heal.next_heal = None
				}
			}
			if health.health < health.maxhealth && heal.next_heal == None {
				heal.next_heal = Some(time.time + heal.delay)
			}
		}
	}
}