fix: Grafvaettir drones mine copper, scrap and tin
The default Mining Targets list named MineRock_Copper, but Black Forest copper is rock4_copper, so drones thrown at copper found no target and hovered where they spawned. Add rock4_copper and mudpile, and move configs still on the old default. Drones now measure and aim at the nearest live hit area instead of the deposit root, which sits inside big rocks. Hits carry the drone as attacker: vanilla MineRock reads the attacker's ZDOID without a null check and threw on every tin hit.
This commit is contained in:
parent
373b0069dd
commit
bba81cbbf0
2 changed files with 44 additions and 15 deletions
|
|
@ -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)
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<Collider>())
|
||||
{
|
||||
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<Collider>();
|
||||
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<Character>());
|
||||
|
||||
destructible.Damage(hit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<float>(0f, 100f)));
|
||||
DroneZapInterval = config.Bind(drone, "Zap Interval", 2f, new ConfigDescription("Seconds between a drone's zaps.", new AcceptableValueRange<float>(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<float>(1f, 1000f)));
|
||||
|
||||
WildPickables = config.Bind(drone, "Wild Plants Harvested", "Pickable_Mushroom,Pickable_Dandelion,Pickable_Thistle,RaspberryBush,BlueberryBush,CloudberryBush",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue