From da896179fd6c4d4f407900d13a0d98a12cf8bb87 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 26 Sep 2026 01:41:00 +0200 Subject: [PATCH] feat(fenrir): howl on demand, in every form The howl key was only ever read by the two Fenring forms. As a wolf or an Ulv it did nothing at all - not a misconfiguration, the classes simply never looked at it. All four forms read it now. The wolf and the Ulv perform the creature's own howl animation and NO SOUND IS SPAWNED, because their clip already carries one: 'C_Hawl' fires an animation event at 0.39s holding sfx_wolf_haul, and the game's own AnimationEffect plays it. The audio comes out of the animation, at the instant the animation means it to, which no prefab fired on a keypress can match. Spawning one as well would be a second howl over the first. A trigger is looked for before a state, and that is about multiplayer rather than tidiness: FenrirAttackSync replicates trigger names, so a howl fired through a trigger is one the other clients see and hear, while Animator.Play is local and nobody else knows. Which route was taken is logged once per creature, and if neither exists the log prints the animator's whole parameter list rather than leaving another keypress that quietly does nothing. The Fenring and the Cultist have no howl clip in vanilla - 19 and 18 clips, none of them a howl, and their taunt fires no sound event - so they keep the Taunt animation and take the wolf's howl as their voice. Co-Authored-By: Claude Opus 5 --- JotunnModStub/Fenrir/FenrirBehaviors.cs | 141 +++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index 380f47c..70137f4 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -93,6 +93,71 @@ namespace RacesOfValheim if (!Play(FireRoar, position, "fire roar")) PlayAlertedEffects("Fenring_Cultist", position); } + /// + /// State names to try when a creature has no howl trigger. 'C_Hawl' first, and that spelling + /// is not a typo here - it is the game's, on the wolf's own clip. + /// + private static readonly string[] HowlStates = { "C_Hawl", "C_Howl", "Hawl", "Howl", "Taunt" }; + + /// + /// Makes the worn creature perform its own howl, and says whether it could. + /// + /// WORTH KNOWING BEFORE READING THE CODE: on the wolf this brings the sound with it. Its howl + /// clip carries the sound as an animation event - 'C_Hawl' fires Effect at 0.39s holding + /// sfx_wolf_haul - and the game's own AnimationEffect, which sits beside the Animator on the + /// form, plays it. So for the wolf and the Ulv there is no sound to spawn at all: play the + /// animation and the howl comes out of it, at the instant the animation means it to. + /// + /// A TRIGGER IS TRIED BEFORE A STATE, and the reason is multiplayer rather than tidiness. + /// FenrirAttackSync replicates trigger names, so a howl fired through a trigger is a howl the + /// other clients see and hear. Animator.Play is local: it works, and nobody else knows. + /// comes back non-null exactly when the caller has something + /// worth publishing. + /// + public static bool TryHowlAnimation(Animator animator, string creature, out string triggerName) + { + triggerName = null; + if (animator == null || animator.runtimeAnimatorController == null) return false; + + foreach (AnimatorControllerParameter p in animator.parameters) + { + if (p.type != AnimatorControllerParameterType.Trigger) continue; + + string lower = p.name.ToLower(); + if (!lower.Contains("hawl") && !lower.Contains("howl") && !lower.Contains("taunt")) continue; + + animator.SetTrigger(p.name); + triggerName = p.name; + LogHowlRouteOnce(creature, $"trigger '{p.name}'"); + return true; + } + + foreach (string state in HowlStates) + { + int hash = Animator.StringToHash(state); + if (!animator.HasState(0, hash)) continue; + + animator.Play(hash, 0); + LogHowlRouteOnce(creature, $"state '{state}', played directly - local only, " + + "no trigger exists to replicate it"); + return true; + } + + // Nothing matched, so say what there was to match against. A keypress that does nothing is + // the thing this whole exercise started from. + List parameters = new List(); + foreach (AnimatorControllerParameter p in animator.parameters) parameters.Add($"{p.name}({p.type})"); + LogHowlRouteOnce(creature, + "no howl trigger and no howl state. Parameters: " + string.Join(", ", parameters.ToArray()) + + ". Run 'dumpanim " + creature + "' for its clip list"); + return false; + } + + private static void LogHowlRouteOnce(string creature, string route) + { + if (logged.Add("howl/" + creature)) Jotunn.Logger.LogInfo($"[FenrirForm] howl for '{creature}': {route}."); + } + /// Instantiates the first name that resolves and is safe. True if anything played. private static bool Play(string[] prefabNames, Vector3 position, string label) { @@ -1094,7 +1159,13 @@ namespace RacesOfValheim if (isGrounded && RaceInput.Allowed) { - if (RaceInput.AttackDown(0)) // Left Click + // The howl, on the same key as every other form. It used to be read only by the + // two Fenring forms, so pressing it as a wolf did nothing at all. + if (!isAttacking && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys()) + { + StartCoroutine(WolfHowlRoutine()); + } + else if (RaceInput.AttackDown(0)) // Left Click { StartCoroutine(WolfAttackRoutine("attack1", FenrirConfig.WolfAttack1Damage.Value, 0.6f, 0.2f)); } @@ -1123,6 +1194,36 @@ namespace RacesOfValheim } } + + /// + /// The howl on demand, which for this creature is the animation and nothing else: its clip + /// carries the sound as an event, so spawning one on top would be a second howl over the + /// first. The prefab is only reached if the animator turns out to have no howl at all. + /// + private IEnumerator WolfHowlRoutine() + { + isAttacking = true; + + try { wolfAnim.SetFloat("forward_speed", 0f); } catch {} + try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {} + + string trigger; + if (FenrirCreatureSound.TryHowlAnimation(wolfAnim, "Wolf", out trigger)) + { + if (trigger != null) FenrirAttackSync.Publish(trigger); + } + else + { + FenrirCreatureSound.PlayHowl("Wolf", Player.m_localPlayer.transform.position); + } + + // The wolf's howl clip runs 3.13s. Held a little past it so the form does not snap back + // into a bite the instant the sound ends. + yield return new WaitForSeconds(3.3f); + + isAttacking = false; + } + private IEnumerator WolfAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay) { isAttacking = true; @@ -1268,7 +1369,13 @@ namespace RacesOfValheim if (isGrounded && RaceInput.Allowed) { - if (RaceInput.AttackDown(0)) // Left Click + // The howl, on the same key as every other form. It used to be read only by the + // two Fenring forms, so pressing it as a wolf did nothing at all. + if (!isAttacking && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys()) + { + StartCoroutine(UlvHowlRoutine()); + } + else if (RaceInput.AttackDown(0)) // Left Click { StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvBiteDamage.Value, 0.6f, 0.2f)); } @@ -1298,6 +1405,36 @@ namespace RacesOfValheim } } + + /// + /// The howl on demand, which for this creature is the animation and nothing else: its clip + /// carries the sound as an event, so spawning one on top would be a second howl over the + /// first. The prefab is only reached if the animator turns out to have no howl at all. + /// + private IEnumerator UlvHowlRoutine() + { + isAttacking = true; + + try { ulvAnim.SetFloat("forward_speed", 0f); } catch {} + try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {} + + string trigger; + if (FenrirCreatureSound.TryHowlAnimation(ulvAnim, "Ulv", out trigger)) + { + if (trigger != null) FenrirAttackSync.Publish(trigger); + } + else + { + FenrirCreatureSound.PlayHowl("Ulv", Player.m_localPlayer.transform.position); + } + + // The wolf's howl clip runs 3.13s. Held a little past it so the form does not snap back + // into a bite the instant the sound ends. + yield return new WaitForSeconds(3.3f); + + isAttacking = false; + } + private IEnumerator UlvAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay) { isAttacking = true;