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 ++++++++++++++++++--- src/systems/mod.rs | 4 +++- src/systems/volate.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/systems/volate.rs (limited to 'src/systems') 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(); } diff --git a/src/systems/mod.rs b/src/systems/mod.rs index b1d0994..28cd128 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -12,6 +12,7 @@ mod attacking; mod trapping; mod fight; mod heal; +mod volate; pub use self::{ controlinput::ControlInput, @@ -26,5 +27,6 @@ pub use self::{ attacking::Attacking, trapping::Trapping, fight::Fight, - heal::Heal + heal::Heal, + volate::Volate }; diff --git a/src/systems/volate.rs b/src/systems/volate.rs new file mode 100644 index 0000000..8cfa826 --- /dev/null +++ b/src/systems/volate.rs @@ -0,0 +1,34 @@ + +use specs::{ + Read, + WriteStorage, + Entities, + System, + Join +}; + +use crate::{ + components::{Volatile, Removed}, + resources::TimeStamp +}; + +pub struct Volate; +impl <'a> System<'a> for Volate { + type SystemData = ( + Entities<'a>, + WriteStorage<'a, Volatile>, + WriteStorage<'a, Removed>, + Read<'a, TimeStamp> + ); + fn run(&mut self, (entities, mut volatiles, mut removals, timestamp): Self::SystemData) { + for (ent, volatile) in (&entities, &mut volatiles).join() { + if let Some(time) = volatile.end_time { + if time <= timestamp.time { + removals.insert(ent, Removed).unwrap(); + } + } else { + volatile.end_time = Some(timestamp.time + volatile.delay); + } + } + } +} -- cgit