diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index ef2d09c..86d25fc 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -99,6 +99,36 @@ namespace RacesOfValheim /// private static readonly string[] HowlStates = { "C_Hawl", "C_Howl", "Hawl", "Howl", "Taunt" }; + /// + /// The creatures whose howl ANIMATION already carries the sound, so playing a prefab as well + /// would be a second howl over the first. + /// + /// ONLY THE WOLF. Its 'C_Hawl' fires an Effect event at 0.39s holding sfx_wolf_haul. The Ulv + /// is the same family on the same rig and its 'Idle Howl' carries no event at all - checked + /// with "dumpanim Ulv", which reads events=0 on that clip. Assuming the two behaved alike is + /// what made the Ulv mouth a silent howl: the animation played, the code took that as proof + /// the sound was coming, and nothing was ever spawned. + /// + private static readonly HashSet HowlAnimationHasSound = new HashSet { "Wolf" }; + + /// + /// One howl: the creature's own animation where it has one, and a sound unless that animation + /// is already bringing it. The four forms call this and nothing else. + /// + public static void Howl(Animator animator, string creature, Vector3 position) + { + string trigger; + bool animated = TryHowlAnimation(animator, creature, out trigger); + + // A trigger replicates to the other clients; a state played directly does not. + if (animated && trigger != null) FenrirAttackSync.Publish(trigger); + + if (!animated || !HowlAnimationHasSound.Contains(creature)) + { + PlayHowl(creature, position); + } + } + /// /// Makes the worn creature perform its own howl, and says whether it could. /// @@ -1216,9 +1246,9 @@ 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. + /// The howl on demand. For the wolf it is the animation and nothing else: 'C_Hawl' carries + /// the sound as an event, so spawning a prefab on top would be a second howl over the first. + /// FenrirCreatureSound.Howl knows which creatures those are. /// private IEnumerator WolfHowlRoutine() { @@ -1227,15 +1257,7 @@ namespace RacesOfValheim 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); - } + FenrirCreatureSound.Howl(wolfAnim, "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. @@ -1427,9 +1449,10 @@ 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. + /// The howl on demand. The Ulv animates one and carries NO sound with it - 'Idle Howl' has no + /// events at all - so unlike the wolf it needs a prefab played over the animation. Assuming + /// the two behaved alike is what left this howl silent; FenrirCreatureSound.Howl holds the + /// distinction now. /// private IEnumerator UlvHowlRoutine() { @@ -1438,19 +1461,11 @@ namespace RacesOfValheim 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); - } + FenrirCreatureSound.Howl(ulvAnim, "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); + // The Ulv's 'Idle Howl' runs 3.67s. Held a little past it so the form does not snap + // back into a bite the instant it ends. + yield return new WaitForSeconds(3.8f); isAttacking = false; }