From 3c81b8f1304eb8f05dedf54d2650d97e6ae965e6 Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 29 Oct 2026 01:55:48 +0100 Subject: [PATCH] fix: Alfar drones and Sverm workers work instead of wandering HandsToVanilla gave the tick to MonsterAI whenever BaseAI.FindClosestEnemy returned someone. Vanilla takes its first match at any distance and only checks maxDistance after that, so any wild creature in the loaded zones counted. The tamed MonsterAI then idled around and the work loop never ran. Check the distance ourselves. --- JotunnModStub/Alfar/AlfarDroneAI.cs | 6 +++++- JotunnModStub/Butler/BoneServantAI.cs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/JotunnModStub/Alfar/AlfarDroneAI.cs b/JotunnModStub/Alfar/AlfarDroneAI.cs index 59d8fea..9da8077 100644 --- a/JotunnModStub/Alfar/AlfarDroneAI.cs +++ b/JotunnModStub/Alfar/AlfarDroneAI.cs @@ -301,7 +301,11 @@ namespace RacesOfValheim else if (Time.time >= m_nextFightScan) { m_nextFightScan = Time.time + FightScanInterval; - if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null) + // FindClosestEnemy takes its first match at ANY distance (it only compares against + // maxDistance once it holds one), so with a deer anywhere in the loaded zones it never + // returned null and vanilla kept the tick: the drone idled about instead of working. + Character enemy = BaseAI.FindClosestEnemy(m_character, transform.position, FightRange); + if (enemy != null && Vector3.Distance(enemy.transform.position, transform.position) <= FightRange) { m_fightUntil = Time.time + FightLinger; } diff --git a/JotunnModStub/Butler/BoneServantAI.cs b/JotunnModStub/Butler/BoneServantAI.cs index db77b6d..073d718 100644 --- a/JotunnModStub/Butler/BoneServantAI.cs +++ b/JotunnModStub/Butler/BoneServantAI.cs @@ -270,7 +270,11 @@ namespace RacesOfValheim else if (Time.time >= m_nextFightScan) { m_nextFightScan = Time.time + FightScanInterval; - if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null) + // FindClosestEnemy takes its first match at ANY distance (it only compares against + // maxDistance once it holds one), so with a deer anywhere in the loaded zones it never + // returned null and vanilla kept the tick: the worker idled about instead of working. + Character enemy = BaseAI.FindClosestEnemy(m_character, transform.position, FightRange); + if (enemy != null && Vector3.Distance(enemy.transform.position, transform.position) <= FightRange) { m_fightUntil = Time.time + FightLinger; }