summaryrefslogtreecommitdiff
path: root/src/systems/fight.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems/fight.rs')
-rw-r--r--src/systems/fight.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/systems/fight.rs b/src/systems/fight.rs
index 00aeb3e..47b5811 100644
--- a/src/systems/fight.rs
+++ b/src/systems/fight.rs
@@ -17,7 +17,8 @@ use crate::components::{
Fighter,
Health,
ControlCooldown,
- Autofight
+ Autofight,
+ Faction
};
use crate::controls::{Control};
@@ -36,17 +37,18 @@ impl <'a> System<'a> for Fight {
ReadStorage<'a, Fighter>,
ReadStorage<'a, Health>,
WriteStorage<'a, ControlCooldown>,
- WriteStorage<'a, Autofight>
+ WriteStorage<'a, Autofight>,
+ ReadStorage<'a, Faction>
);
- fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions): Self::SystemData) {
for (entity, controller, position, fighter) in (&entities, &controllers, &positions, &fighters).join(){
let mut target = None;
match &controller.control {
Control::Attack(directions) => {
'targets: for direction in directions {
for ent in ground.cells.get(&(position.pos + direction.to_position())).unwrap_or(&HashSet::new()) {
- if healths.contains(*ent) && *ent != entity {
+ if healths.contains(*ent) && *ent != entity && Faction::is_enemy_entity(&factions, entity, *ent) {
target = Some(*ent);
break 'targets;
}