From f422238d7aaae0ff1b2d560a71a99b0a881ad338 Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 23 Feb 2020 22:12:21 +0100 Subject: players can get damage from traps --- src/systems/trapping.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/systems/trapping.rs (limited to 'src/systems/trapping.rs') diff --git a/src/systems/trapping.rs b/src/systems/trapping.rs new file mode 100644 index 0000000..144cd94 --- /dev/null +++ b/src/systems/trapping.rs @@ -0,0 +1,46 @@ + +use specs::{ + WriteStorage, + ReadStorage, + Entities, + Read, + System, + Join +}; + +use crate::{ + components::{Health, Attacked, Moved, Entered, Trap, Position}, + resources::Ground +}; + + +pub struct Trapping; +impl <'a> System<'a> for Trapping { + type SystemData = ( + Entities<'a>, + WriteStorage<'a, Attacked>, + ReadStorage<'a, Health>, + ReadStorage<'a, Moved>, + ReadStorage<'a, Entered>, + ReadStorage<'a, Trap>, + ReadStorage<'a, Position>, + Read<'a, Ground> + ); + fn run(&mut self, (entities, mut victims, healths, moves, entereds, traps, positions, ground): Self::SystemData) { + + for (entity, _entered, trap, position) in (&entities, &entereds, &traps, &positions).join() { + for ent in ground.cells.get(&position.pos).unwrap(){ + if ent != &entity && moves.contains(*ent) && healths.contains(*ent) { + victims + .entry(*ent) + .unwrap() + .or_insert_with(Attacked::default) + .attacks + .push(trap.attack.clone()); + + } + } + } + } +} + -- cgit