diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index cfe78d4..4746139 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -232,6 +232,12 @@ namespace RacesOfValheim { 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; @@ -334,16 +340,84 @@ namespace RacesOfValheim Jotunn.Logger.LogInfo($"=== END {prefabName.ToUpper()} DEBUG INFO ==="); } + /// + /// 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". + /// + private static bool ColdSpellKeyPressed() + { + KeyCode key = SkadiConfig.ColdSpellKey.Value.MainKey; + return key != KeyCode.None && Input.GetKeyDown(key); + } + + private static readonly System.Collections.Generic.HashSet coldSpellBails = + new System.Collections.Generic.HashSet(); + + /// One step of the cast, said before it is taken. Once per distinct step. + private static void ColdSpellStep(string step) + { + if (coldSpellBails.Add("step:" + step)) + { + Jotunn.Logger.LogInfo($"[Skadi] Cold Spell: {step}."); + } + } + + /// + /// 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. + /// + 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(); + foreach (Component comp in prefab.GetComponents()) + { + if (comp != null && !(comp is Transform)) parts.Add(comp.GetType().Name); + } + + return $"{path}' root={prefab.transform.parent == null} carries=[{string.Join(", ", parts.ToArray())}]"; + } + + /// Says why a press did not become a cast, once per reason per session. + 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) { - if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; - if (isTransformed) return; // Do not cast human spell while in dragon form + bool pressed = ColdSpellKeyPressed(); + + 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 // 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 // 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. // 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. 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 // the Mistlands onward, so the old HaveEitr gate left it unusable for five tiers. @@ -378,8 +456,17 @@ namespace RacesOfValheim zanim.SetTrigger("gpower"); } + if (coldSpellBails.Add("cast")) Jotunn.Logger.LogInfo("[Skadi] Cold Spell cast."); + 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"); + } } /// @@ -402,10 +489,31 @@ namespace RacesOfValheim 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("StaffIceShards"); - if (staffPrefab == null) yield break; + if (staffPrefab == null) + { + ColdSpellStep("'StaffIceShards' did not resolve - no shards fired"); + yield break; + } ItemDrop staffDrop = staffPrefab.GetComponent(); - 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; GameObject projPrefab = null; @@ -418,7 +526,13 @@ namespace RacesOfValheim { 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; @@ -446,7 +560,19 @@ namespace RacesOfValheim 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)); + + 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(); if (proj != null)