summaryrefslogtreecommitdiff
path: root/src/systems/trapping.rs
blob: 35c66d085fc0b7902e4804eba924316176abde1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

use specs::{
	WriteStorage,
	ReadStorage,
	Entities,
	Read,
	System,
	Join
};

use crate::{
	components::{Health, AttackInbox, AttackMessage, Moved, Entered, Trap, Position},
	resources::Ground
};


pub struct Trapping;
impl <'a> System<'a> for Trapping {
	type SystemData = (
		Entities<'a>,
		WriteStorage<'a, AttackInbox>,
		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) {
					AttackInbox::add_message(&mut victims, *ent, AttackMessage{typ: trap.attack.clone(), attacker: Some(entity)});
				}
			}
		}
	}
}