diff options
| author | troido <troido@protonmail.com> | 2020-02-24 12:38:23 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-24 12:38:23 +0100 |
| commit | 715c9106dbff4524f3fdf5d23f762e5e6518e0cb (patch) | |
| tree | cf5dc0c5d30fc9ba7e38bdff40907fe4a96261a2 /src/systems/heal.rs | |
| parent | 4718cfdc7c2bf67d2389ca18ab035fe5a0887ff0 (diff) | |
healing works now too, the first time based system
Diffstat (limited to 'src/systems/heal.rs')
| -rw-r--r-- | src/systems/heal.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/systems/heal.rs b/src/systems/heal.rs new file mode 100644 index 0000000..458bc17 --- /dev/null +++ b/src/systems/heal.rs @@ -0,0 +1,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) + } + } + } +} + |
