diff options
| author | troido <troido@protonmail.com> | 2020-03-03 16:47:11 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-03 16:47:11 +0100 |
| commit | 9954b5cbaab27aaffcafa8723dcd5d1c99fa811f (patch) | |
| tree | 0133821c4fd3dfb7c5500204efaaa02f9bcc57fe /src/systems/attacking.rs | |
| parent | b98ea15acbebe8815f9316b5a8ef3393fdd1c3e6 (diff) | |
implemented autoretaliate
Diffstat (limited to 'src/systems/attacking.rs')
| -rw-r--r-- | src/systems/attacking.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index 6075bd5..9d10fee 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, AttackInbox, Dead, Position}, + components::{Health, AttackInbox, Dead, Position, Autofight}, resources::NewEntities, Template, util @@ -24,9 +24,22 @@ impl <'a> System<'a> for Attacking { WriteStorage<'a, Health>, WriteStorage<'a, Dead>, ReadStorage<'a, Position>, - Write<'a, NewEntities> + Write<'a, NewEntities>, + WriteStorage<'a, Autofight> ); - fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new): Self::SystemData) { + fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters): Self::SystemData) { + + for (entity, attacked, autofighter) in (&entities, &attackeds, &mut autofighters).join() { + for attack in &attacked.messages { + if attack.damage > 0 { + if let Some(attacker) = attack.attacker { + if healths.contains(attacker) && attacker != entity { + autofighter.target = Some(attacker); + } + } + } + } + } for (ent, health, attacked) in (&entities, &mut healths, &mut attackeds).join() { let mut wounded = false; for attack in attacked.messages.drain(..) { |
