From 78fce06b4747b22d037e425ac97518f18f143d18 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 8 Sep 2021 13:17:53 +0100 Subject: [PATCH] Allowed players to assist NPCs in fights without problems by tweaking aggro rules --- server/src/sys/agent.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 896f917dfe..e20382103c 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -160,8 +160,7 @@ pub struct ReadData<'a> { combos: ReadStorage<'a, Combo>, } -// This is 3.1 to last longer than the last damage timer (3.0 seconds) -const DAMAGE_MEMORY_DURATION: f64 = 3.1; +const DAMAGE_MEMORY_DURATION: f64 = 0.25; const FLEE_DURATION: f32 = 3.0; const MAX_FOLLOW_DIST: f32 = 12.0; const MAX_PATH_DIST: f32 = 170.0; @@ -507,10 +506,20 @@ impl<'a> System<'a> for Sys { // than the old target, or if the old target // had not triggered aggro (the new target // has because damage always triggers it) - !old_tgt.aggro_on - || tgt_pos.0.distance(pos.0) + let old_tgt_not_threat = !old_tgt.aggro_on; + let old_tgt_further = + tgt_pos.0.distance(pos.0) < old_tgt_pos.0.distance(pos.0) - * FUZZY_DIST_COMPARISON + * FUZZY_DIST_COMPARISON; + let new_tgt_hostile = read_data + .alignments + .get(attacker) + .zip(alignment) + .map_or(false, |(attacker, us)| { + us.hostile_towards(*attacker) + }); + old_tgt_not_threat + || (old_tgt_further && new_tgt_hostile) } else { true }