chore: F8 shows what each Grafvaettir hit did on arrival

Patches on Destructible.RPC_Damage, MineRock.RPC_Hit and MineRock5.DamageArea record, for hits from a miner, the health before and after, the damage left after resistances, the pickaxe damage and the tool tier against the rock's minimum. 'sent, no RPC' means the hit never reached the deposit's owner.
This commit is contained in:
kanym 2026-10-29 20:37:31 +01:00
commit 1420db796b

View file

@ -272,6 +272,7 @@ namespace RacesOfValheim
private Component target; private Component target;
private float lastDistance = -1f; private float lastDistance = -1f;
private int strikes; private int strikes;
private string lastHit = "none";
public static readonly List<AlfarMiner> All = new List<AlfarMiner>(); public static readonly List<AlfarMiner> All = new List<AlfarMiner>();
@ -431,7 +432,7 @@ namespace RacesOfValheim
private void Strike(Component deposit, Collider area, Vector3 point) private void Strike(Component deposit, Collider area, Vector3 point)
{ {
IDestructible destructible = deposit as IDestructible; IDestructible destructible = deposit as IDestructible;
if (destructible == null) return; if (destructible == null) { lastHit = $"{deposit.GetType().Name} is not IDestructible"; return; }
HitData hit = new HitData(); HitData hit = new HitData();
hit.m_damage.m_pickaxe = AlfarNexusConfig.MinerDamage.Value; hit.m_damage.m_pickaxe = AlfarNexusConfig.MinerDamage.Value;
@ -445,9 +446,79 @@ namespace RacesOfValheim
// check: a hit with no attacker throws before the area can break. // check: a hit with no attacker throws before the area can break.
hit.SetAttacker(GetComponent<Character>()); hit.SetAttacker(GetComponent<Character>());
// Overwritten by the RPC patches below if the hit reaches the deposit's owner.
lastHit = "sent, no RPC";
destructible.Damage(hit); destructible.Damage(hit);
} }
// ─── F8 diagnostics: what each hit did on arrival ──────────────────────
private static AlfarMiner MinerOf(HitData hit)
{
Character attacker = hit != null ? hit.GetAttacker() : null;
return attacker != null ? attacker.GetComponent<AlfarMiner>() : null;
}
private static void Record(HitData hit, string kind, float before, float after, int minTier)
{
AlfarMiner miner = MinerOf(hit);
if (miner == null) return;
miner.lastHit = $"{kind} hp {before:0.#}->{after:0.#} dmg {hit.GetTotalDamage():0.#} " +
$"pick {hit.m_damage.m_pickaxe:0.#} tier {hit.m_toolTier}/{minTier}";
}
[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
public static class Alfar_Miner_DestructibleHit_Patch
{
private static float Health(Destructible d)
{
ZNetView nview = d.GetComponent<ZNetView>();
return nview != null && nview.IsValid() ? nview.GetZDO().GetFloat(ZDOVars.s_health, d.m_health) : -1f;
}
public static void Prefix(Destructible __instance, HitData hit, out float __state)
{
__state = MinerOf(hit) != null ? Health(__instance) : -1f;
}
public static void Postfix(Destructible __instance, HitData hit, float __state)
{
if (MinerOf(hit) == null) return;
Record(hit, "Destructible", __state, Health(__instance), __instance.m_minToolTier);
}
}
[HarmonyPatch(typeof(MineRock), "RPC_Hit")]
public static class Alfar_Miner_MineRockHit_Patch
{
private static float Health(MineRock rock, int area)
{
ZNetView nview = rock.GetComponent<ZNetView>();
return nview != null && nview.IsValid() ? nview.GetZDO().GetFloat("Health" + area, rock.GetHealth()) : -1f;
}
public static void Prefix(MineRock __instance, HitData hit, int hitAreaIndex, out float __state)
{
__state = MinerOf(hit) != null ? Health(__instance, hitAreaIndex) : -1f;
}
public static void Postfix(MineRock __instance, HitData hit, int hitAreaIndex, float __state)
{
if (MinerOf(hit) == null) return;
Record(hit, $"MineRock area {hitAreaIndex}", __state, Health(__instance, hitAreaIndex), __instance.m_minToolTier);
}
}
[HarmonyPatch(typeof(MineRock5), "DamageArea")]
public static class Alfar_Miner_MineRock5Hit_Patch
{
public static void Postfix(MineRock5 __instance, int hitAreaIndex, HitData hit, bool __result)
{
if (MinerOf(hit) == null) return;
Record(hit, $"MineRock5 area {hitAreaIndex} damaged={__result}", -1f, -1f, __instance.m_minToolTier);
}
}
private static Component DepositOf(Collider collider) private static Component DepositOf(Collider collider)
{ {
Component deposit = collider.GetComponentInParent<MineRock5>(); Component deposit = collider.GetComponentInParent<MineRock5>();
@ -479,7 +550,7 @@ namespace RacesOfValheim
string targetName = miner.target != null ? Utils.GetPrefabName(miner.target.gameObject) : "none"; 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: " + 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} " + $"target {targetName} dist {miner.lastDistance:0.0} strikes {miner.strikes} " +
$"age {Now - miner.bornAt:0}s centre {miner.Centre} r {miner.Radius:0}"); $"age {Now - miner.bornAt:0}s centre {miner.Centre} r {miner.Radius:0} | last hit: {miner.lastHit}");
} }
foreach (string line in lines) foreach (string line in lines)