fix(fenrir): give the forms a voice, and stop the sounds writing to the save
Every sound the Fenrir forms played was looked up by a name, and most of those names are not prefabs in this game. The chains hid it: PlaySFX walks its arguments and stops at the first that resolves, so a claw that asked for "sfx_fenring_attack", "sfx_fenring_attack_claw", "sfx_wolf_attack" had a Fenring swinging with a wolf's voice through a fallback nobody noticed. The cultist's double claw asked for three dead names in a row and was silent from the day it was written. The creatures do have their own sounds. The forms now use them: sfx_fenring_claw_start for the swing, sfx_fenring_claw_hit for the landing, sfx_fenring_fireclaw to open the fire breath. The Ulv keeps the wolf's, since vanilla ships it nothing but sfx_ulv_death. THE HOWL WAS NEVER A PREFAB TO LOOK UP. It is an AnimationEvent inside the wolf's 'C_Hawl' clip, firing at 0.39s with the sound handed over as an object reference - and a player in wolf form idles through that clip and howls out loud already, with the game's own AnimationEffect doing the work. Three spellings of one word are why this took so long to find: the clip is 'C_Hawl', the sound is 'sfx_wolf_haul', and the mod was looking for 'sfx_wolf_howl', the only correct spelling of the three and the only one that does not exist. The Fenring has no howl of its own at all, so it borrows the wolf's over its Taunt. The jump attack's impact moved to where the jump lands, next to the damage, instead of firing before the dash while the form is still standing. FenrirCreatureSound.Spawn is the other half. Some vanilla sound prefabs carry a ZNetView - sfx_fenring_alerted does - and one that wakes with no init ZDO writes a persistent record into the world, once per swing. Spawning now runs inside ZNetView.StartGhostInit, the game's own answer, so no ZDO is made. All nine sound spawns in these forms go through it. sfx_fenring_howl resolves to an ordinary sound prefab and hard-exits the process when spawned on its own. It is named in a Suspect set, described in the log and never instantiated, because a name nobody records is a name somebody adds back. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
276ff93834
commit
9907cae292
3 changed files with 363 additions and 74 deletions
89
JotunnModStub/Fenrir/FormAnimEventSound.cs
Normal file
89
JotunnModStub/Fenrir/FormAnimEventSound.cs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Plays the sounds Valheim wires into a creature's own animation clips, for a player wearing
|
||||
/// that creature.
|
||||
///
|
||||
/// THE HOWL WAS NEVER A PREFAB TO LOOK UP. It is an AnimationEvent. The wolf's animator carries a
|
||||
/// clip called 'C_Hawl' whose single event, at 0.39s, calls a method named Effect and hands it the
|
||||
/// sound as an object reference:
|
||||
///
|
||||
/// 'C_Hawl' 3.13s loop=True events=1
|
||||
/// @0.39s Effect() ref='sfx_wolf_haul' (GameObject)
|
||||
///
|
||||
/// Two things follow from that, and both are better than what the mod was doing. First, the clip
|
||||
/// already plays on its own: a player in wolf form idles through 'C_Hawl' like any other idle, so
|
||||
/// the howl animation costs nothing to get. Second, the sound belongs at 0.39s into that clip and
|
||||
/// nowhere else, which is something no amount of instantiating a prefab on a keypress can match.
|
||||
///
|
||||
/// Three names, three spellings, and that is the whole reason this took so long to find: the clip
|
||||
/// is 'C_Hawl', the sound is 'sfx_wolf_haul', and the mod was looking for 'sfx_wolf_howl' - the
|
||||
/// only correct spelling of the three, and the only one that does not exist.
|
||||
///
|
||||
/// Unity calls Effect BY NAME on the components of the GameObject that owns the Animator, so this
|
||||
/// has to sit there and the method must keep that name.
|
||||
/// </summary>
|
||||
internal class FormAnimEventSound : MonoBehaviour
|
||||
{
|
||||
private static readonly HashSet<string> logged = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Off whenever the game's own receiver is on this object, which in practice is always.
|
||||
///
|
||||
/// A player in wolf form idles through 'C_Hawl' and howls, out loud, with no help from this
|
||||
/// class - confirmed in game. AnimationEffect, which sits beside the Animator on the form
|
||||
/// along with CharacterAnimEvent, is doing that already. Two receivers for one event means two
|
||||
/// howls, so this stands down and stays only as cover for a form that turns out not to carry
|
||||
/// one. The log says which of the two happened, once per form, so nobody has to wonder.
|
||||
/// </summary>
|
||||
private bool standDown;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
standDown = GetComponent("AnimationEffect") != null;
|
||||
|
||||
if (logged.Add("attach/" + name))
|
||||
{
|
||||
Jotunn.Logger.LogInfo(
|
||||
standDown
|
||||
? $"[FenrirForm] '{name}' already carries AnimationEffect; leaving animation sounds to it."
|
||||
: $"[FenrirForm] '{name}' has no AnimationEffect; handling animation sounds here.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CALLED BY UNITY from an AnimationEvent. Do not rename, and do not make it private.
|
||||
///
|
||||
/// Only object references are taken, and only when they carry audio. The clips also fire
|
||||
/// Effect with a string and no reference - 'Jump' does, with string='jump' - and that form
|
||||
/// means "look something up", which is a different job and somebody else's. The audio test is
|
||||
/// there because an animation can reference anything at all, and a form is not the place to
|
||||
/// find out what spawning an arbitrary vanilla object does.
|
||||
/// </summary>
|
||||
public void Effect(AnimationEvent e)
|
||||
{
|
||||
if (standDown) return;
|
||||
|
||||
GameObject prefab = e.objectReferenceParameter as GameObject;
|
||||
if (prefab == null) return;
|
||||
|
||||
bool audible = prefab.GetComponentInChildren<AudioSource>(true) != null;
|
||||
|
||||
if (logged.Add(prefab.name))
|
||||
{
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[FenrirForm] animation event Effect on '{name}' -> '{prefab.name}' " +
|
||||
$"audio={audible}{(audible ? "" : ", skipped")}.");
|
||||
}
|
||||
|
||||
if (!audible) return;
|
||||
|
||||
// Through the same ghost-init spawn as everything else here: some vanilla sound prefabs
|
||||
// carry a ZNetView, and this one fires every time the animation comes round.
|
||||
FenrirCreatureSound.Spawn(prefab, transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue