From be8c7c59d3469774bb76fc9ba650a4a499e605c9 Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 29 Oct 2026 19:33:08 +0100 Subject: [PATCH] fix: Grafvaettir miners fly low enough to strike deposits Vanilla's flying MoveTo lifts the goal to m_flyAltitudeMin above whatever solid lies under it, the rock top included, so the miners hovered over a deposit just out of the 3.5 m reach and never struck. The Grafvaettir now flies 0.5-2 m up and strikes within 4 m. Mining Targets is read again when the config line changes, so an edit in game counts without a restart. F8 also prints what the camera looks at (deposit kind, on the list or not) and each live miner's target, distance and strikes. --- JotunnModStub/Alfar/AlfarDrones.cs | 82 +++++++++++++++++++++++++++--- JotunnModStub/RaceMeleeReach.cs | 1 + 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/JotunnModStub/Alfar/AlfarDrones.cs b/JotunnModStub/Alfar/AlfarDrones.cs index 2564a4f..f3bb69f 100644 --- a/JotunnModStub/Alfar/AlfarDrones.cs +++ b/JotunnModStub/Alfar/AlfarDrones.cs @@ -105,6 +105,10 @@ namespace RacesOfValheim BaseAI ai = prefab.GetComponent(); if (ai != null) ai.m_randomMoveRange = 5f; + // A flyer's MoveTo lifts its goal to m_flyAltitudeMin above whatever solid is under it, + // the rock top included: at the vanilla height the miners hovered over a deposit out of + // reach and never struck. + if (ai != null && miner) { ai.m_flyAltitudeMin = 0.5f; ai.m_flyAltitudeMax = 2f; } foreach (CharacterDrop drops in prefab.GetComponentsInChildren(true)) { @@ -251,9 +255,18 @@ namespace RacesOfValheim public float Radius = 12f; public float LiveSeconds = 120f; + private const float Reach = 4f; + private float born; private float nextStrike; private Component target; + private float lastDistance = -1f; + private int strikes; + + public static readonly List All = new List(); + + private void OnEnable() { All.Add(this); } + private void OnDisable() { All.Remove(this); } private static readonly System.Reflection.MethodInfo MoveToMethod = AccessTools.Method(typeof(BaseAI), "MoveTo", new[] { typeof(float), typeof(Vector3), typeof(float), typeof(bool) }); @@ -281,8 +294,9 @@ namespace RacesOfValheim // sits at its base inside the mesh, so a drone aiming there stopped on top of the rock // and never came within reach. float distance = Vector3.Distance(transform.position, point); + lastDistance = distance; - if (distance > 3.5f) + if (distance > Reach) { if (MoveToMethod != null) MoveToMethod.Invoke(ai, new object[] { dt, point + Vector3.up * 1.5f, 2f, true }); return true; @@ -292,14 +306,29 @@ namespace RacesOfValheim if (Time.time < nextStrike) return true; nextStrike = Time.time + 1f; Strike(target, area, point); + strikes++; return true; } private static string[] names; - private static string[] Deposits => names ?? (names = AlfarNexusConfig.MinerDeposits.Value.Split( - new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries)); + private static string namesSource; - private bool IsPrecious(string prefabName) + // Read again when the config line changes, so an edit in game counts without a restart. + private static string[] Deposits + { + get + { + string value = AlfarNexusConfig.MinerDeposits.Value; + if (names == null || namesSource != value) + { + namesSource = value; + names = value.Split(new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); + } + return names; + } + } + + private static bool IsPrecious(string prefabName) { foreach (string wanted in Deposits) { @@ -314,9 +343,7 @@ namespace RacesOfValheim float bestDistance = float.MaxValue; foreach (Collider collider in Physics.OverlapSphere(Centre, Radius, ~0, QueryTriggerInteraction.Ignore)) { - Component deposit = collider.GetComponentInParent(); - if (deposit == null) deposit = collider.GetComponentInParent(); - if (deposit == null) deposit = collider.GetComponentInParent(); + Component deposit = DepositOf(collider); if (deposit == null) continue; string prefabName = Utils.GetPrefabName(deposit.gameObject); @@ -372,6 +399,47 @@ namespace RacesOfValheim destructible.Damage(hit); } + private static Component DepositOf(Collider collider) + { + Component deposit = collider.GetComponentInParent(); + if (deposit == null) deposit = collider.GetComponentInParent(); + if (deposit == null) deposit = collider.GetComponentInParent(); + return deposit; + } + + /// + /// F8 readout: what the camera looks at (is it a deposit, of which kind, on the list?) and + /// what each live miner is doing (its target, how far, how many strikes). + /// + public static void DebugReport(Player player) + { + var lines = new List(); + Transform aim = GameCamera.instance != null ? GameCamera.instance.transform : player.transform; + if (Physics.Raycast(aim.position, aim.forward, out RaycastHit hit, 50f, ~0, QueryTriggerInteraction.Ignore)) + { + Component deposit = DepositOf(hit.collider); + string prefabName = deposit != null ? Utils.GetPrefabName(deposit.gameObject) : Utils.GetPrefabName(hit.collider.transform.root.gameObject); + lines.Add($"[RoV graf] look: {hit.collider.name} on {prefabName} " + + (deposit != null ? $"{deposit.GetType().Name} listed={IsPrecious(prefabName)}" : "not a deposit")); + } + else lines.Add("[RoV graf] look: nothing within 50m"); + + foreach (AlfarMiner miner in All) + { + if (miner == null) continue; + string targetName = miner.target != null ? Utils.GetPrefabName(miner.target.gameObject) : "none"; + lines.Add($"[RoV graf] miner {Vector3.Distance(miner.transform.position, player.transform.position):0}m away: " + + $"target {targetName} dist {miner.lastDistance:0.0} strikes {miner.strikes} " + + $"age {Time.time - miner.born:0}s centre {miner.Centre} r {miner.Radius:0}"); + } + + foreach (string line in lines) + { + Debug.Log(line); + player.Message(MessageHud.MessageType.TopLeft, line); + } + } + [HarmonyPatch(typeof(MonsterAI), "UpdateAI")] public static class Alfar_Miner_UpdateAI_Patch { diff --git a/JotunnModStub/RaceMeleeReach.cs b/JotunnModStub/RaceMeleeReach.cs index 4b2d66b..b852480 100644 --- a/JotunnModStub/RaceMeleeReach.cs +++ b/JotunnModStub/RaceMeleeReach.cs @@ -124,6 +124,7 @@ namespace RacesOfValheim if (__instance != Player.m_localPlayer || !Input.GetKeyDown(KeyCode.F8)) return; RaceMeleeReach.DebugOn = !RaceMeleeReach.DebugOn; __instance.Message(MessageHud.MessageType.TopLeft, $"[RoV reach] debug {(RaceMeleeReach.DebugOn ? "on" : "off")}"); + AlfarMiner.DebugReport(__instance); } } }