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/Alfar/AlfarDrones.cs b/JotunnModStub/Alfar/AlfarDrones.cs index 7cef524..2564a4f 100644 --- a/JotunnModStub/Alfar/AlfarDrones.cs +++ b/JotunnModStub/Alfar/AlfarDrones.cs @@ -273,9 +273,13 @@ namespace RacesOfValheim } if (target == null || !target.gameObject.activeInHierarchy) target = FindDeposit(); - if (target == null) { ai.StopMoving(); return true; } + Vector3 point = Vector3.zero; + Collider area = target != null ? NearestArea(target, out point) : null; + if (area == null) { target = null; ai.StopMoving(); return true; } - Vector3 point = target.transform.position; + // Measured to the closest point of the rock, not to its root: a copper deposit's root + // 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); if (distance > 3.5f) @@ -287,7 +291,7 @@ namespace RacesOfValheim ai.StopMoving(); if (Time.time < nextStrike) return true; nextStrike = Time.time + 1f; - Strike(target); + Strike(target, area, point); return true; } @@ -324,7 +328,31 @@ namespace RacesOfValheim return best; } - private void Strike(Component deposit) + /// + /// The live hit area of the deposit closest to the drone, and the closest point on it. + /// MineRock and MineRock5 only take a hit on one of their own areas; a MineRock with an area + /// root (tin) keeps its base model collider apart, and a hit on that one is thrown away. + /// Broken areas are switched off, so only active colliders count. + /// + private Collider NearestArea(Component deposit, out Vector3 point) + { + point = Vector3.zero; + MineRock rock = deposit as MineRock; + GameObject root = rock != null && rock.m_areaRoot != null ? rock.m_areaRoot : deposit.gameObject; + + Collider best = null; + float bestDistance = float.MaxValue; + foreach (Collider collider in root.GetComponentsInChildren()) + { + if (collider == null || !collider.enabled) continue; + Vector3 closest = collider.bounds.ClosestPoint(transform.position); + float distance = Vector3.Distance(transform.position, closest); + if (distance < bestDistance) { best = collider; bestDistance = distance; point = closest; } + } + return best; + } + + private void Strike(Component deposit, Collider area, Vector3 point) { IDestructible destructible = deposit as IDestructible; if (destructible == null) return; @@ -334,16 +362,12 @@ namespace RacesOfValheim hit.m_toolTier = 100; hit.m_dodgeable = false; hit.m_blockable = false; - hit.m_point = deposit.transform.position; - hit.m_dir = (deposit.transform.position - transform.position).normalized; - - // MineRock5 picks the piece of the rock to hurt from the collider that was hit. - Collider collider = deposit.GetComponentInChildren(); - if (collider != null) - { - hit.m_hitCollider = collider; - hit.m_point = collider.bounds.center; - } + hit.m_hitCollider = area; + hit.m_point = point; + hit.m_dir = (area.bounds.center - transform.position).normalized; + // Vanilla MineRock (tin) reads the attacker's ZDOID for its hit effects without a null + // check: a hit with no attacker throws before the area can break. + hit.SetAttacker(GetComponent()); destructible.Damage(hit); } diff --git a/JotunnModStub/Alfar/AlfarNexusConfig.cs b/JotunnModStub/Alfar/AlfarNexusConfig.cs index 59c4020..84ffd4c 100644 --- a/JotunnModStub/Alfar/AlfarNexusConfig.cs +++ b/JotunnModStub/Alfar/AlfarNexusConfig.cs @@ -89,8 +89,13 @@ namespace RacesOfValheim DroneZapDamage = config.Bind(drone, "Zap Damage", 1f, new ConfigDescription("Lightning damage of a drone's defensive zap.", new AcceptableValueRange(0f, 100f))); DroneZapInterval = config.Bind(drone, "Zap Interval", 2f, new ConfigDescription("Seconds between a drone's zaps.", new AcceptableValueRange(0.2f, 30f))); - MinerDeposits = config.Bind(drone, "Mining Targets", "MineRock_Copper,MineRock_Tin,MineRock_Iron,silvervein,rock3_silver,giant_brain", + // Copper deposits are rock4_copper (and rock4_copper_frac once hit), crypt scrap is mudpile; + // the first default missed both, so a config still holding it is moved to the new one. + const string oldTargets = "MineRock_Copper,MineRock_Tin,MineRock_Iron,silvervein,rock3_silver,giant_brain"; + const string targets = "rock4_copper,MineRock_Copper,MineRock_Tin,MineRock_Iron,mudpile,silvervein,rock3_silver,giant_brain"; + MinerDeposits = config.Bind(drone, "Mining Targets", targets, new ConfigDescription("Comma separated parts of prefab names the mining drones dig (case does not matter). Soft tissue comes from giant_brain.")); + if (MinerDeposits.Value == oldTargets) MinerDeposits.Value = targets; MinerDamage = config.Bind(drone, "Mining Damage", 40f, new ConfigDescription("Pickaxe damage each mining drone does per second to a deposit.", new AcceptableValueRange(1f, 1000f))); WildPickables = config.Bind(drone, "Wild Plants Harvested", "Pickable_Mushroom,Pickable_Dandelion,Pickable_Thistle,RaspberryBush,BlueberryBush,CloudberryBush", 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; }