summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/attacking.rs19
-rw-r--r--src/systems/fight.rs7
2 files changed, 19 insertions, 7 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(..) {
diff --git a/src/systems/fight.rs b/src/systems/fight.rs
index 703ea4a..88305e2 100644
--- a/src/systems/fight.rs
+++ b/src/systems/fight.rs
@@ -54,9 +54,6 @@ impl <'a> System<'a> for Fight {
}
Control::AttackTarget(t) => {
if *t == entity { // don't knock yourself out
- if let Some(autofighter) = autofighters.get_mut(entity){
- autofighter.target = None;
- }
} else if let Some(target_position) = positions.get(*t){
if position.pos.distance_to(target_position.pos) <= fighter.range {
target = Some(*t);
@@ -66,7 +63,9 @@ impl <'a> System<'a> for Fight {
_ => {}
}
if let Some(ent) = target {
- AttackInbox::add_message(&mut attacked, ent, fighter.attack.clone());
+ let mut attack = fighter.attack.clone();
+ attack.attacker = Some(entity);
+ AttackInbox::add_message(&mut attacked, ent, attack);
cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap();
if let Some(autofighter) = autofighters.get_mut(entity){
autofighter.target = Some(ent);