From d8f1e6b7dcd87cb27004b265f02a758a3466cd27 Mon Sep 17 00:00:00 2001
From: timokoesters <timo@koesters.xyz>
Date: Thu, 1 Aug 2019 22:52:50 +0200
Subject: [PATCH 1/5] Remove knockback

---
 common/src/sys/combat.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs
index 80174be9e6..2417b16be8 100644
--- a/common/src/sys/combat.rs
+++ b/common/src/sys/combat.rs
@@ -54,8 +54,7 @@ impl<'a> System<'a> for Sys {
                             stat_b
                                 .health
                                 .change_by(-10, HealthSource::Attack { by: *uid }); // TODO: variable damage and weapon
-                            vel_b.0 += (pos_b.0 - pos.0).normalized() * 10.0;
-                            vel_b.0.z = 15.0;
+                            vel_b.0.z = 7.0;
                             let _ = force_updates.insert(b, ForceUpdate);
                         }
                     }

From a7731c9b15e9d5ed82b8314cb09298cc4f6a04c5 Mon Sep 17 00:00:00 2001
From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com>
Date: Fri, 2 Aug 2019 21:27:21 +0200
Subject: [PATCH 2/5] changed angle of attack, changed z offset on hit

---
 common/src/sys/combat.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs
index 2417b16be8..726bda64a5 100644
--- a/common/src/sys/combat.rs
+++ b/common/src/sys/combat.rs
@@ -48,13 +48,13 @@ impl<'a> System<'a> for Sys {
                         if entity != b
                             && !stat_b.is_dead
                             && pos.0.distance_squared(pos_b.0) < 50.0
-                            && ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0
+                            && ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 90.0
                         {
                             // Deal damage
                             stat_b
                                 .health
                                 .change_by(-10, HealthSource::Attack { by: *uid }); // TODO: variable damage and weapon
-                            vel_b.0.z = 7.0;
+                            vel_b.0.z = 4.0;
                             let _ = force_updates.insert(b, ForceUpdate);
                         }
                     }

From 4e59bb19c8296a43d41eff9fd5b0bcc26c758cda Mon Sep 17 00:00:00 2001
From: timokoesters <timo@koesters.xyz>
Date: Fri, 2 Aug 2019 22:25:33 +0200
Subject: [PATCH 3/5] Make hostile npcs back away when too close

---
 common/src/sys/agent.rs    | 85 +++++++++++++++++++++-----------------
 common/src/sys/movement.rs |  2 +-
 2 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs
index 82d887e997..e31aeeddbb 100644
--- a/common/src/sys/agent.rs
+++ b/common/src/sys/agent.rs
@@ -1,4 +1,4 @@
-use crate::comp::{Agent, Controller, Pos};
+use crate::comp::{Agent, Controller, Pos, Stats};
 use rand::{seq::SliceRandom, thread_rng};
 use specs::{Entities, Join, ReadStorage, System, WriteStorage};
 use vek::*;
@@ -8,14 +8,15 @@ pub struct Sys;
 impl<'a> System<'a> for Sys {
     type SystemData = (
         Entities<'a>,
-        WriteStorage<'a, Agent>,
         ReadStorage<'a, Pos>,
+        ReadStorage<'a, Stats>,
+        WriteStorage<'a, Agent>,
         WriteStorage<'a, Controller>,
     );
 
-    fn run(&mut self, (entities, mut agents, positions, mut controllers): Self::SystemData) {
-        for (entity, agent, pos, controller) in
-            (&entities, &mut agents, &positions, &mut controllers).join()
+    fn run(&mut self, (entities, positions, stats, mut agents, mut controllers): Self::SystemData) {
+        for (entity, pos, agent, controller) in
+            (&entities, &positions, &mut agents, &mut controllers).join()
         {
             match agent {
                 Agent::Wanderer(bearing) => {
@@ -60,52 +61,58 @@ impl<'a> System<'a> for Sys {
                 }
                 Agent::Enemy { bearing, target } => {
                     const SIGHT_DIST: f32 = 30.0;
+                    let mut choose_new = false;
 
-                    let choose_new = match target.map(|tgt| positions.get(tgt)).flatten() {
-                        Some(tgt_pos) => {
-                            let dist = Vec2::<f32>::from(tgt_pos.0 - pos.0).magnitude();
-                            if dist < 2.0 {
-                                controller.move_dir = Vec2::zero();
+                    if let Some((Some(target_pos), Some(target_stats))) =
+                        target.map(|target| (positions.get(target), stats.get(target)))
+                    {
+                        let dist = Vec2::<f32>::from(target_pos.0 - pos.0).magnitude();
+                        if target_stats.is_dead {
+                            choose_new = true;
+                        } else if dist < 3.0 {
+                            // Get more distance
+                            controller.move_dir =
+                                Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * -0.96;
+                        } else if dist < 4.0 {
+                            // Fight and slowly move closer
+                            controller.move_dir =
+                                Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.01;
 
-                                if rand::random::<f32>() < 0.05 {
-                                    controller.attack = true;
-                                } else {
-                                    controller.attack = false;
-                                }
-
-                                false
-                            } else if dist < SIGHT_DIST {
-                                controller.move_dir =
-                                    Vec2::<f32>::from(tgt_pos.0 - pos.0).normalized();
-
-                                false
+                            if rand::random::<f32>() < 0.1 {
+                                controller.attack = true;
                             } else {
-                                true
+                                controller.attack = false;
                             }
+                        } else if dist < SIGHT_DIST {
+                            controller.move_dir =
+                                Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.96;
+                        } else {
+                            choose_new = true;
                         }
-                        None => {
-                            *bearing +=
-                                Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
-                                    * 0.1
-                                    - *bearing * 0.005;
+                    } else {
+                        *bearing +=
+                            Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
+                                * 0.1
+                                - *bearing * 0.005;
 
-                            controller.move_dir = if bearing.magnitude_squared() > 0.1 {
-                                bearing.normalized()
-                            } else {
-                                Vec2::zero()
-                            };
-                            true
-                        }
-                    };
+                        controller.move_dir = if bearing.magnitude_squared() > 0.1 {
+                            bearing.normalized()
+                        } else {
+                            Vec2::zero()
+                        };
+
+                        choose_new = true;
+                    }
 
                     if choose_new && rand::random::<f32>() < 0.1 {
-                        let entities = (&entities, &positions)
+                        let entities = (&entities, &positions, &stats)
                             .join()
-                            .filter(|(e, e_pos)| {
+                            .filter(|(e, e_pos, e_stats)| {
                                 Vec2::<f32>::from(e_pos.0 - pos.0).magnitude() < SIGHT_DIST
                                     && *e != entity
+                                    && !e_stats.is_dead
                             })
-                            .map(|(e, _)| e)
+                            .map(|(e, _, _)| e)
                             .collect::<Vec<_>>();
 
                         let mut rng = thread_rng();
diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs
index f278655d72..68ab82e9ef 100644
--- a/common/src/sys/movement.rs
+++ b/common/src/sys/movement.rs
@@ -126,7 +126,7 @@ impl<'a> System<'a> for Sys {
             }
 
             // Set direction based on velocity when on the ground
-            if Vec2::<f32>::from(vel.0).magnitude_squared() > 0.1 {
+            if Vec2::<f32>::from(vel.0).magnitude_squared() > 0.0001 {
                 ori.0 = Lerp::lerp(
                     ori.0,
                     vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0),

From 5288ae2fcf8abfe6eaa2ac5defa2d9dc336dc36b Mon Sep 17 00:00:00 2001
From: timokoesters <timo@koesters.xyz>
Date: Fri, 2 Aug 2019 22:50:19 +0200
Subject: [PATCH 4/5] Fix combat animations for non humanoids

---
 voxygen/src/scene/figure.rs | 48 +++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs
index a43774169b..c9ce0fdcb4 100644
--- a/voxygen/src/scene/figure.rs
+++ b/voxygen/src/scene/figure.rs
@@ -767,24 +767,30 @@ impl FigureMgr {
                     };
 
                     let target_skeleton = match animation_info.animation {
-                        comp::Animation::Run => anim::quadruped::RunAnimation::update_skeleton(
-                            state.skeleton_mut(),
-                            (vel.0.magnitude(), time),
-                            animation_info.time,
-                            skeleton_attr,
-                        ),
-                        comp::Animation::Idle => anim::quadruped::IdleAnimation::update_skeleton(
-                            state.skeleton_mut(),
-                            time,
-                            animation_info.time,
-                            skeleton_attr,
-                        ),
-                        comp::Animation::Jump => anim::quadruped::JumpAnimation::update_skeleton(
-                            state.skeleton_mut(),
-                            (vel.0.magnitude(), time),
-                            animation_info.time,
-                            skeleton_attr,
-                        ),
+                        comp::Animation::Run | comp::Animation::Crun => {
+                            anim::quadruped::RunAnimation::update_skeleton(
+                                state.skeleton_mut(),
+                                (vel.0.magnitude(), time),
+                                animation_info.time,
+                                skeleton_attr,
+                            )
+                        }
+                        comp::Animation::Idle | comp::Animation::Cidle => {
+                            anim::quadruped::IdleAnimation::update_skeleton(
+                                state.skeleton_mut(),
+                                time,
+                                animation_info.time,
+                                skeleton_attr,
+                            )
+                        }
+                        comp::Animation::Jump | comp::Animation::Cjump => {
+                            anim::quadruped::JumpAnimation::update_skeleton(
+                                state.skeleton_mut(),
+                                (vel.0.magnitude(), time),
+                                animation_info.time,
+                                skeleton_attr,
+                            )
+                        }
 
                         // TODO!
                         _ => state.skeleton_mut().clone(),
@@ -807,7 +813,7 @@ impl FigureMgr {
                     };
 
                     let target_skeleton = match animation_info.animation {
-                        comp::Animation::Run => {
+                        comp::Animation::Run | comp::Animation::Crun => {
                             anim::quadrupedmedium::RunAnimation::update_skeleton(
                                 state.skeleton_mut(),
                                 (vel.0.magnitude(), time),
@@ -815,7 +821,7 @@ impl FigureMgr {
                                 skeleton_attr,
                             )
                         }
-                        comp::Animation::Idle => {
+                        comp::Animation::Idle | comp::Animation::Cidle => {
                             anim::quadrupedmedium::IdleAnimation::update_skeleton(
                                 state.skeleton_mut(),
                                 time,
@@ -823,7 +829,7 @@ impl FigureMgr {
                                 skeleton_attr,
                             )
                         }
-                        comp::Animation::Jump => {
+                        comp::Animation::Jump | comp::Animation::Cjump => {
                             anim::quadrupedmedium::JumpAnimation::update_skeleton(
                                 state.skeleton_mut(),
                                 (vel.0.magnitude(), time),

From 929cd5ee297119a5c8784b519329103c8ce2af85 Mon Sep 17 00:00:00 2001
From: Joshua Barretto <joshua.s.barretto@gmail.com>
Date: Sat, 3 Aug 2019 13:01:54 +0100
Subject: [PATCH 5/5] Made enemies actually attack

---
 common/src/sys/agent.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs
index e31aeeddbb..c41dde878f 100644
--- a/common/src/sys/agent.rs
+++ b/common/src/sys/agent.rs
@@ -69,14 +69,14 @@ impl<'a> System<'a> for Sys {
                         let dist = Vec2::<f32>::from(target_pos.0 - pos.0).magnitude();
                         if target_stats.is_dead {
                             choose_new = true;
-                        } else if dist < 3.0 {
+                        } else if dist < 1.5 {
                             // Get more distance
                             controller.move_dir =
                                 Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * -0.96;
                         } else if dist < 4.0 {
                             // Fight and slowly move closer
                             controller.move_dir =
-                                Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.01;
+                                Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.1;
 
                             if rand::random::<f32>() < 0.1 {
                                 controller.attack = true;