diff options
| author | troido <troido@protonmail.com> | 2020-02-23 22:12:21 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-23 22:12:21 +0100 |
| commit | f422238d7aaae0ff1b2d560a71a99b0a881ad338 (patch) | |
| tree | c335cb8eee47d34953f7d4cd96c195958d223202 /src/systems/trapping.rs | |
| parent | 613952f918b8d72a3e397dc46be309b2320c6ad0 (diff) | |
players can get damage from traps
Diffstat (limited to 'src/systems/trapping.rs')
| -rw-r--r-- | src/systems/trapping.rs | 46 |
1 files changed, 46 insertions, 0 deletions
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()); + + } + } + } + } +} + |
