diff options
| author | troido <troido@protonmail.com> | 2020-03-02 00:45:21 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-02 00:45:21 +0100 |
| commit | d246537a28a7a71dfb2487d31d6fac3ccab5053d (patch) | |
| tree | 885f89ee5605659edd7359279cf6d046ebb3fa3f /src/systems/controlinput.rs | |
| parent | 32037d2247a4db1c1c09d63a7849f562b6081bfe (diff) | |
implemented autofight
Diffstat (limited to 'src/systems/controlinput.rs')
| -rw-r--r-- | src/systems/controlinput.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs index 17bc40f..6d5b4ea 100644 --- a/src/systems/controlinput.rs +++ b/src/systems/controlinput.rs @@ -8,8 +8,11 @@ use specs::{ Join }; -use crate::components::{Controller, Player, ControlCooldown}; -use crate::resources::{Input}; +use crate::{ + components::{Controller, Player, ControlCooldown, Autofight}, + resources::{Input}, + controls::Control +}; pub struct ControlInput; @@ -19,14 +22,26 @@ impl <'a> System<'a> for ControlInput { Write<'a, Input>, WriteStorage<'a, Controller>, ReadStorage<'a, Player>, - ReadStorage<'a, ControlCooldown> + ReadStorage<'a, ControlCooldown>, + WriteStorage<'a, Autofight> ); - fn run(&mut self, (entities, mut input, mut controllers, players, cooldowns): Self::SystemData) { + fn run(&mut self, (entities, mut input, mut controllers, players, cooldowns, mut autofighters): Self::SystemData) { controllers.clear(); for (player, entity, ()) in (&players, &entities, !&cooldowns).join() { if let Some(control) = input.actions.remove(&player.id){ - let _ = controllers.insert(entity, Controller{control: control}); + controllers.insert(entity, Controller{control: control}).unwrap(); + if let Some(autofighter) = autofighters.get_mut(entity) { + autofighter.target = None; + } + } else if let Some(autofighter) = autofighters.get_mut(entity) { + if let Some(target) = autofighter.target { + if !entities.is_alive(target) { + autofighter.target = None; + } else { + controllers.insert(entity, Controller{control: Control::AttackTarget(target)}).unwrap(); + } + } } } } |
