feat(skadi): say why a Cold Spell press did not cast, and log each step of the cast

Every gate on the spell was silent, so "it does nothing" looked the same as
"it was never pressed". Each refusal now logs its reason once per session,
and the cast logs each step before taking it, because the crash it chases
kills the process without a stack trace. The prefab descriptions run after
the Instantiate, so reading them can't be what makes the spawn safe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kanym 2026-09-26 18:12:34 +02:00
commit 97d02855e5

View file

@ -232,6 +232,12 @@ namespace RacesOfValheim
{ {
HandleColdSpell(rules); HandleColdSpell(rules);
} }
else if (ColdSpellKeyPressed())
{
ColdSpellBail(!rules.ColdSpell
? $"the tier does not grant it - state {BossProgressionManager.GetCurrentProgressionState()}, needs 2"
: "RaceInput.Allowed is false - a GUI has the input");
}
if (isTransformingSequence) return; if (isTransformingSequence) return;
@ -334,16 +340,84 @@ namespace RacesOfValheim
Jotunn.Logger.LogInfo($"=== END {prefabName.ToUpper()} DEBUG INFO ==="); Jotunn.Logger.LogInfo($"=== END {prefabName.ToUpper()} DEBUG INFO ===");
} }
/// <summary>
/// Whether the Cold Spell's own key went down this frame, read raw and with no gate at all.
/// Only for the diagnostics below: five different conditions can swallow this spell and every
/// one of them is silent, so "it does nothing" was impossible to tell apart from "it was
/// never pressed".
/// </summary>
private static bool ColdSpellKeyPressed()
{
KeyCode key = SkadiConfig.ColdSpellKey.Value.MainKey;
return key != KeyCode.None && Input.GetKeyDown(key);
}
private static readonly System.Collections.Generic.HashSet<string> coldSpellBails =
new System.Collections.Generic.HashSet<string>();
/// <summary>One step of the cast, said before it is taken. Once per distinct step.</summary>
private static void ColdSpellStep(string step)
{
if (coldSpellBails.Add("step:" + step))
{
Jotunn.Logger.LogInfo($"[Skadi] Cold Spell: {step}.");
}
}
/// <summary>
/// What a borrowed prefab actually is. The root flag matters for the same reason it did on
/// the Skeleton's fire aura: a parented object is a node inside somebody else's hierarchy,
/// not a prefab, and spawning one on its own is how this mod has crashed before.
/// </summary>
private static string Describe(GameObject prefab)
{
if (prefab == null) return "null";
string path = prefab.name;
for (Transform t = prefab.transform.parent; t != null; t = t.parent) path = t.name + "/" + path;
var parts = new System.Collections.Generic.List<string>();
foreach (Component comp in prefab.GetComponents<Component>())
{
if (comp != null && !(comp is Transform)) parts.Add(comp.GetType().Name);
}
return $"{path}' root={prefab.transform.parent == null} carries=[{string.Join(", ", parts.ToArray())}]";
}
/// <summary>Says why a press did not become a cast, once per reason per session.</summary>
private static void ColdSpellBail(string reason)
{
if (coldSpellBails.Add(reason))
{
Jotunn.Logger.LogInfo($"[Skadi] Cold Spell key pressed but not cast: {reason}.");
}
}
private void HandleColdSpell(SkadiProgression.FormRules rules) private void HandleColdSpell(SkadiProgression.FormRules rules)
{ {
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; bool pressed = ColdSpellKeyPressed();
if (isTransformed) return; // Do not cast human spell while in dragon form
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead())
{
if (pressed) ColdSpellBail("the player is dead");
return;
}
if (isTransformed)
{
if (pressed) ColdSpellBail("you are in a dragon form");
return;
}
// Hammer, hoe or cultivator in hand: every build button is vanilla's. Middle mouse is // Hammer, hoe or cultivator in hand: every build button is vanilla's. Middle mouse is
// Remove on the keyboard, and on the pad JoySecondaryAttack shares its physical button // Remove on the keyboard, and on the pad JoySecondaryAttack shares its physical button
// with JoyRemove (Classic) or JoyPlace (Alt2) - read off ZInput.AddGamepad*Buttons - so // with JoyRemove (Classic) or JoyPlace (Alt2) - read off ZInput.AddGamepad*Buttons - so
// each piece built or removed also cast the spell and drained the stamina for it. // each piece built or removed also cast the spell and drained the stamina for it.
if (Player.m_localPlayer.InPlaceMode()) return; if (Player.m_localPlayer.InPlaceMode())
{
if (pressed) ColdSpellBail("a hammer, hoe or cultivator is in hand");
return;
}
// Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey. // Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey.
// On a gamepad, the secondary attack button (the pad's own middle-mouse equivalent) - // On a gamepad, the secondary attack button (the pad's own middle-mouse equivalent) -
@ -354,7 +428,11 @@ namespace RacesOfValheim
{ {
// The improved cast is a burst rather than a rapid-fire, so it waits longer. // The improved cast is a burst rather than a rapid-fire, so it waits longer.
float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN; float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN;
if (Time.time - lastSpellTime < cooldown) return; if (Time.time - lastSpellTime < cooldown)
{
ColdSpellBail($"it is on cooldown - {cooldown - (Time.time - lastSpellTime):F1}s left of {cooldown:F0}s");
return;
}
// Stamina, never eitr: the spell unlocks at Eikthyr but eitr food only exists from // Stamina, never eitr: the spell unlocks at Eikthyr but eitr food only exists from
// the Mistlands onward, so the old HaveEitr gate left it unusable for five tiers. // the Mistlands onward, so the old HaveEitr gate left it unusable for five tiers.
@ -378,8 +456,17 @@ namespace RacesOfValheim
zanim.SetTrigger("gpower"); zanim.SetTrigger("gpower");
} }
if (coldSpellBails.Add("cast")) Jotunn.Logger.LogInfo("[Skadi] Cold Spell cast.");
StartCoroutine(ColdSpellKickCoroutine(rules)); StartCoroutine(ColdSpellKickCoroutine(rules));
} }
else if (pressed)
{
// The key physically went down and the wrapper still said no. That is the last place
// left for this to fail, and the only one with no condition of its own above it.
ColdSpellBail($"'{SkadiConfig.ColdSpellKey.Value.MainKey}' went down but " +
"IsDownIgnoringHeldKeys refused it");
}
} }
/// <summary> /// <summary>
@ -402,10 +489,31 @@ namespace RacesOfValheim
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) yield break; if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) yield break;
// EVERY STEP BELOW IS SAID BEFORE IT IS TAKEN, once per session. Casting this spell exits
// the process outright - no exception, no stack, the log simply stops - which is the same
// signature as sfx_fenring_howl, the sound that cannot be spawned either. The only reason
// we know where either one dies is that the line before it had already been flushed.
ColdSpellStep("resolving 'StaffIceShards'");
GameObject staffPrefab = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards"); GameObject staffPrefab = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards");
if (staffPrefab == null) yield break; if (staffPrefab == null)
{
ColdSpellStep("'StaffIceShards' did not resolve - no shards fired");
yield break;
}
ItemDrop staffDrop = staffPrefab.GetComponent<ItemDrop>(); ItemDrop staffDrop = staffPrefab.GetComponent<ItemDrop>();
if (staffDrop == null) yield break; if (staffDrop == null)
{
ColdSpellStep("'StaffIceShards' has no ItemDrop - no shards fired");
yield break;
}
// NOT described here, deliberately, and this is an experiment rather than a style choice.
// Describe() reads the prefab's components, and reading them may be what forces a
// soft-referenced asset to finish loading - which would mean the diagnostic was quietly
// fixing the crash it was added to measure. Both descriptions now run AFTER the shards
// are spawned, so nothing touches either prefab before the Instantiate that was dying.
// If the crash comes back, the touch was the fix and becomes a real one. If it does not,
// the crash was never about loading.
string projName = rules.ImprovedColdSpell ? "hatchling_cold_projectile" : null; string projName = rules.ImprovedColdSpell ? "hatchling_cold_projectile" : null;
GameObject projPrefab = null; GameObject projPrefab = null;
@ -418,7 +526,13 @@ namespace RacesOfValheim
{ {
projPrefab = staffDrop.m_itemData.m_shared.m_attack.m_attackProjectile; // Default Staff of Frost projectile projPrefab = staffDrop.m_itemData.m_shared.m_attack.m_attackProjectile; // Default Staff of Frost projectile
} }
if (projPrefab == null) yield break; if (projPrefab == null)
{
ColdSpellStep("no projectile prefab at all - no shards fired");
yield break;
}
ColdSpellStep("projectile chosen from " +
(projName != null ? $"'{projName}' or the staff" : "the staff"));
int count = rules.ImprovedColdSpell ? IMPROVED_SPELL_SHARDS : 1; int count = rules.ImprovedColdSpell ? IMPROVED_SPELL_SHARDS : 1;
@ -446,8 +560,20 @@ namespace RacesOfValheim
Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 1.4f + lookDir * 0.6f; Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 1.4f + lookDir * 0.6f;
ColdSpellStep($"instantiating shard {i + 1} of {count}");
GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(lookDir)); GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(lookDir));
ColdSpellStep("shard instantiated");
// Described only now that a shard has survived being spawned, so the reading itself
// cannot be what made the spawning safe. See the note above the staff lookup.
if (i == 0)
{
ColdSpellStep($"staff was '{Describe(staffPrefab)}");
ColdSpellStep($"projectile was '{Describe(projPrefab)}");
}
Projectile proj = projInstance.GetComponent<Projectile>(); Projectile proj = projInstance.GetComponent<Projectile>();
if (proj != null) if (proj != null)
{ {