Merge branch 'fix-grafvaettir-mining': Grafvaettir miners reach the deposit
This commit is contained in:
commit
00a30d9b34
2 changed files with 76 additions and 7 deletions
|
|
@ -105,6 +105,10 @@ namespace RacesOfValheim
|
|||
|
||||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||
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<CharacterDrop>(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<AlfarMiner> All = new List<AlfarMiner>();
|
||||
|
||||
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<MineRock5>();
|
||||
if (deposit == null) deposit = collider.GetComponentInParent<MineRock>();
|
||||
if (deposit == null) deposit = collider.GetComponentInParent<Destructible>();
|
||||
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<MineRock5>();
|
||||
if (deposit == null) deposit = collider.GetComponentInParent<MineRock>();
|
||||
if (deposit == null) deposit = collider.GetComponentInParent<Destructible>();
|
||||
return deposit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
public static void DebugReport(Player player)
|
||||
{
|
||||
var lines = new List<string>();
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue