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
|
|
@ -236,11 +236,16 @@ namespace RacesOfValheim {
|
|||
|
||||
SpawnPoofEffect();
|
||||
|
||||
if (ZNetScene.instance != null)
|
||||
{
|
||||
GameObject howlPrefab = ZNetScene.instance.GetPrefab("sfx_wolf_howl") ?? ZNetScene.instance.GetPrefab("sfx_fenring_idle");
|
||||
if (howlPrefab != null) Instantiate(howlPrefab, Player.m_localPlayer.transform.position, Quaternion.identity);
|
||||
}
|
||||
// The howl of the creature being turned into, read off that creature. This used to look
|
||||
// for "sfx_wolf_howl" and fall back to "sfx_fenring_idle": the first is not a prefab in
|
||||
// this game, and the second is real but is the creature's ambient grunt, so every
|
||||
// transformation announced itself with a small idle noise. FenrirCreatureSound exists for
|
||||
// exactly this - see the note at the top of FenrirBehaviors for how it reads a creature's
|
||||
// own voice off BaseAI.m_alertedEffects, which is the only route the Wolf and the Ulv
|
||||
// have. The two Fenring forms could do better: vanilla does ship "sfx_fenring_howl", a
|
||||
// real howl rather than an alert bark, and preferring it when it exists would cost four
|
||||
// lines here.
|
||||
FenrirCreatureSound.PlayHowl(CreaturePrefabFor(rules.Form), Player.m_localPlayer.transform.position);
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
|
|
@ -326,18 +331,26 @@ namespace RacesOfValheim {
|
|||
if (sparks != null) Instantiate(sparks, pos, Quaternion.identity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vanilla creature a form is built from. One place rather than two, because the howl
|
||||
/// that announces a transformation has to be read off the same creature the body comes from.
|
||||
/// </summary>
|
||||
private static string CreaturePrefabFor(FenrirProgression.FormType form)
|
||||
{
|
||||
switch (form)
|
||||
{
|
||||
case FenrirProgression.FormType.Wolf: return "Wolf";
|
||||
case FenrirProgression.FormType.Ulv: return "Ulv";
|
||||
case FenrirProgression.FormType.Fenring: return "Fenring";
|
||||
case FenrirProgression.FormType.Cultist: return "Fenring_Cultist";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private void ExecuteTransformation(FenrirProgression.FormRules rules)
|
||||
{
|
||||
Transform playerVisual = Player.m_localPlayer.transform.Find("Visual");
|
||||
string prefabName = "";
|
||||
|
||||
switch (rules.Form)
|
||||
{
|
||||
case FenrirProgression.FormType.Wolf: prefabName = "Wolf"; break;
|
||||
case FenrirProgression.FormType.Ulv: prefabName = "Ulv"; break;
|
||||
case FenrirProgression.FormType.Fenring: prefabName = "Fenring"; break;
|
||||
case FenrirProgression.FormType.Cultist: prefabName = "Fenring_Cultist"; break;
|
||||
}
|
||||
string prefabName = CreaturePrefabFor(rules.Form);
|
||||
|
||||
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(prefabName);
|
||||
|
||||
|
|
@ -363,9 +376,30 @@ namespace RacesOfValheim {
|
|||
currentTransformation = Instantiate(visual.gameObject, Player.m_localPlayer.transform);
|
||||
currentTransformation.transform.localPosition = Vector3.zero;
|
||||
currentTransformation.transform.localRotation = Quaternion.identity;
|
||||
// DEAD LINE, kept until somebody decides what it was for. The game has no type
|
||||
// called "AnimEvent" - the animation-event dispatcher is CharacterAnimEvent - and
|
||||
// GetComponent(string) matches a type name in full, so this has never found
|
||||
// anything and the Destroy has never run.
|
||||
Component animEvent = currentTransformation.GetComponent("AnimEvent");
|
||||
if (animEvent != null) Destroy(animEvent);
|
||||
|
||||
// The creature's own animations carry their sounds as events; this is what hears
|
||||
// them. On the object that owns the Animator, because that is where Unity delivers
|
||||
// an animation event - for the wolf that is WolfSmooth, two levels down, not the
|
||||
// Visual this method has in hand.
|
||||
Animator formAnimator = currentTransformation.GetComponentInChildren<Animator>(true);
|
||||
if (formAnimator != null)
|
||||
{
|
||||
formAnimator.gameObject.AddComponent<FormAnimEventSound>();
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[FenrirForm] animation-event listener on '{formAnimator.gameObject.name}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogWarning(
|
||||
"[FenrirForm] no Animator under the form; animation sounds will not play.");
|
||||
}
|
||||
|
||||
float ttl = rules.DurationMinutes > 0 ? (rules.DurationMinutes * 60f) : 0f;
|
||||
|
||||
if (prefabName == "Ulv")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue