summaryrefslogtreecommitdiff
path: root/src/systems/fight.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-02 00:45:21 +0100
committertroido <troido@protonmail.com>2020-03-02 00:45:21 +0100
commitd246537a28a7a71dfb2487d31d6fac3ccab5053d (patch)
tree885f89ee5605659edd7359279cf6d046ebb3fa3f /src/systems/fight.rs
parent32037d2247a4db1c1c09d63a7849f562b6081bfe (diff)
implemented autofight
Diffstat (limited to 'src/systems/fight.rs')
-rw-r--r--src/systems/fight.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/systems/fight.rs b/src/systems/fight.rs
index 2a663e3..182dba6 100644
--- a/src/systems/fight.rs
+++ b/src/systems/fight.rs
@@ -15,7 +15,8 @@ use crate::components::{
AttackInbox,
Fighter,
Health,
- ControlCooldown
+ ControlCooldown,
+ Autofight
};
use crate::controls::{Control};
@@ -33,25 +34,34 @@ impl <'a> System<'a> for Fight {
WriteStorage<'a, AttackInbox>,
ReadStorage<'a, Fighter>,
ReadStorage<'a, Health>,
- WriteStorage<'a, ControlCooldown>
+ WriteStorage<'a, ControlCooldown>,
+ WriteStorage<'a, Autofight>
);
- fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters): 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 {
- AttackInbox::add_message(&mut attacked, *ent, fighter.attack.clone());
- cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap();
+ target = Some(*ent);
break 'targets;
}
}
}
}
+ Control::AttackTarget(t) => {target = Some(*t);}
_ => {}
}
+ if let Some(ent) = target {
+ AttackInbox::add_message(&mut attacked, ent, fighter.attack.clone());
+ cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap();
+ if let Some(autofighter) = autofighters.get_mut(entity){
+ autofighter.target = Some(ent);
+ }
+ }
}
}
}