diff options
| author | troido <troido@protonmail.com> | 2020-02-24 14:39:04 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-24 14:39:04 +0100 |
| commit | 481e03e04b055cebaf230b3a3cdce3446418c68c (patch) | |
| tree | 565a2d8afc2fba8d73e310cd1a32b6a94b84039f /src/systems/attacking.rs | |
| parent | f6a037faa2b675cd7318d6dd8ccee5133c89845d (diff) | |
added volatile wounds
Diffstat (limited to 'src/systems/attacking.rs')
| -rw-r--r-- | src/systems/attacking.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index 1f518cb..4b47f11 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -1,13 +1,17 @@ use specs::{ + ReadStorage, WriteStorage, + Write, System, Entities, Join }; use crate::{ - components::{Health, Attacked, Dying, Removed}, + components::{Health, Attacked, Dying, Removed, Position}, + resources::NewEntities, + Template, util }; @@ -19,18 +23,29 @@ impl <'a> System<'a> for Attacking { WriteStorage<'a, Attacked>, WriteStorage<'a, Health>, WriteStorage<'a, Dying>, - WriteStorage<'a, Removed> + WriteStorage<'a, Removed>, + ReadStorage<'a, Position>, + Write<'a, NewEntities> ); - fn run(&mut self, (entities, mut victims, mut healths, mut deads, mut removals): Self::SystemData) { + fn run(&mut self, (entities, mut victims, mut healths, mut deads, mut removals, positions, mut new): Self::SystemData) { for (ent, health, attacked) in (&entities, &mut healths, &mut victims).join() { + let mut wounded = false; for attack in attacked.attacks.drain(..) { health.health -= attack.damage; + if attack.damage > 0 { + wounded = true; + } } health.health = util::clamp(health.health, 0, health.maxhealth); if health.health == 0 { deads.insert(ent, Dying).unwrap(); removals.insert(ent, Removed).unwrap(); } + if let Some(position) = positions.get(ent){ + if wounded { + new.create(position.pos, Template::empty("wound")).unwrap(); + } + } } victims.clear(); } |
