From 481e03e04b055cebaf230b3a3cdce3446418c68c Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 24 Feb 2020 14:39:04 +0100 Subject: added volatile wounds --- src/systems/attacking.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/systems/attacking.rs') 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(); } -- cgit