From 6ad4791b11b6fbb9b90204af5289d04b12a42a63 Mon Sep 17 00:00:00 2001
From: Joshua Barretto <joshua.s.barretto@gmail.com>
Date: Sat, 14 Aug 2021 11:09:33 +0100
Subject: [PATCH] Improved aggro system to reduce hyper-focused enemies

---
 server/src/sys/agent.rs | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs
index ede5d366d7..be0444f0de 100644
--- a/server/src/sys/agent.rs
+++ b/server/src/sys/agent.rs
@@ -495,9 +495,19 @@ impl<'a> System<'a> for Sys {
                                                     if let Some(old_tgt_pos) =
                                                         read_data.positions.get(old_tgt.target)
                                                     {
-                                                        !old_tgt.aggro_on
-                                                            || old_tgt_pos.0.distance_squared(pos.0)
-                                                                < tgt_pos.0.distance_squared(pos.0)
+                                                        // Fuzzy factor that makes it harder for
+                                                        // players to cheese enemies by making them
+                                                        // quickly flip aggro between two players.
+                                                        // It
+                                                        // does this by only switching aggro if the
+                                                        // new target is closer to the enemy by a
+                                                        // specific proportional threshold.
+                                                        const FUZZY_DIST_COMPARISON: f32 = 0.8;
+                                                        // Only switch to new target if it is closer
+                                                        // than the old target
+                                                        tgt_pos.0.distance(pos.0)
+                                                            < old_tgt_pos.0.distance(pos.0)
+                                                                * FUZZY_DIST_COMPARISON
                                                     } else {
                                                         true
                                                     }