diff --git a/JotunnModStub/AnimatorDump.cs b/JotunnModStub/AnimatorDump.cs new file mode 100644 index 0000000..edb5e40 --- /dev/null +++ b/JotunnModStub/AnimatorDump.cs @@ -0,0 +1,303 @@ +using System.Collections.Generic; +using Jotunn.Entities; +using Jotunn.Managers; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// Reads out a creature's animator, because guessing at animation has cost this mod real time: + /// a howl that was looked for under three wrong names, a taunt animation nobody knew played, and + /// a sound prefab that killed the process when spawned on its own. + /// + /// WHAT UNITY LETS US SEE AT RUNTIME, and what it does not, because the line matters: + /// + /// Readable. Every parameter with its type. Every layer. Every CLIP in the controller with its + /// name and length, through RuntimeAnimatorController.animationClips - so a creature's whole + /// vocabulary can be listed without ever wearing it. And every AnimationEvent on every clip: + /// the instant, the method name it calls, and its parameters. That last one is where a sound + /// fired by an animation lives, which is the thing this was written to find. + /// + /// Not readable. The state machine. States and transitions live in AnimatorController, which is + /// an editor-only type, and GetCurrentAnimatorStateInfo hands back hashes with no names. States + /// can only be guessed and then confirmed: AnimatorStateInfo.IsName("Layer.Name") answers yes or + /// no, and Animator.Play takes a state name we can try and then verify by reading back which + /// clip actually started. + /// + /// So "catch the howl and trigger just that stretch" is possible, in this order: list the clips + /// here, find the one that looks like a howl, look at its events to see whether the sound is + /// wired into the animation, then Play the state and CrossFade back to idle at the point wanted. + /// Worth knowing before starting: if the sound is an animation event, playing the clip alone will + /// not make it, because events are dispatched to a component on the animated object and Valheim's + /// dispatcher is CharacterAnimEvent. The animation is the prize; the audio we already play + /// ourselves. + /// + public class DumpAnimCommand : ConsoleCommand + { + public override string Name => "dumpanim"; + + public override string Help => + "[DEBUG] dumpanim - lists a creature's animator parameters, layers, clips and " + + "every animation event on them. dumpanim live - logs which clip each animator under you " + + "starts playing, as it happens; run it again to stop."; + + public override void Run(string[] args) + { + if (args.Length == 0) + { + Console.instance.Print("dumpanim | dumpanim live"); + return; + } + + if (args[0].ToLower() == "live") + { + ToggleWatcher(); + return; + } + + DumpPrefab(args[0]); + } + + /// + /// Everything the controller of can play. Reads a prefab in + /// memory, so it needs no transformation and cannot disturb a live one. + /// + private static void DumpPrefab(string prefabName) + { + GameObject prefab = PrefabManager.Cache.GetPrefab(prefabName); + if (prefab == null) + { + Report($"[Anim] '{prefabName}' is not in the prefab cache."); + return; + } + + Animator[] animators = prefab.GetComponentsInChildren(true); + if (animators.Length == 0) + { + // Not a creature. Say what it is anyway: this is also how a sound prefab gets looked + // at without being spawned, which matters for the ones that cannot safely be spawned. + Report($"[Anim] '{prefabName}' has no Animator. Contents:"); + foreach (Transform t in prefab.GetComponentsInChildren(true)) + { + Jotunn.Logger.LogInfo($"[Anim] '{PathOf(t)}' [{ComponentsOf(t.gameObject)}]"); + DescribeAudio(t.gameObject); + } + return; + } + + Report($"[Anim] '{prefabName}': {animators.Length} animator(s)."); + + foreach (Animator animator in animators) + { + RuntimeAnimatorController controller = animator.runtimeAnimatorController; + Report($"[Anim] on '{PathOf(animator.transform)}' controller " + + $"'{(controller != null ? controller.name : "none")}'"); + + // What else lives on that object, because an animation event is delivered to THESE + // components and nowhere else. CharacterAnimEvent showing up here is the game's own + // receiver; a form that carries it is a form where vanilla is already handling - or + // already failing to handle - every event the clips fire. + Jotunn.Logger.LogInfo($"[Anim] receivers: [{ComponentsOf(animator.gameObject)}]"); + + if (controller == null) continue; + + foreach (AnimatorControllerParameter p in animator.parameters) + { + Jotunn.Logger.LogInfo($"[Anim] param {p.name} ({p.type})"); + } + + for (int i = 0; i < animator.layerCount; i++) + { + Jotunn.Logger.LogInfo($"[Anim] layer {i} '{animator.GetLayerName(i)}'"); + } + + AnimationClip[] clips = controller.animationClips; + Report($"[Anim] {clips.Length} clip(s):"); + + foreach (AnimationClip clip in clips) + { + if (clip == null) continue; + + AnimationEvent[] events = clip.events; + Jotunn.Logger.LogInfo( + $"[Anim] '{clip.name}' {clip.length:F2}s loop={clip.isLooping} " + + $"events={events.Length}"); + + foreach (AnimationEvent e in events) + { + // The object reference is the interesting one: a sound wired into an + // animation arrives here as the asset itself, name included. + string reference = e.objectReferenceParameter != null + ? $" ref='{e.objectReferenceParameter.name}' ({e.objectReferenceParameter.GetType().Name})" + : ""; + Jotunn.Logger.LogInfo( + $"[Anim] @{e.time:F2}s {e.functionName}(" + + $"string='{e.stringParameter}' float={e.floatParameter:F2} " + + $"int={e.intParameter}){reference}"); + } + } + } + } + + private static void ToggleWatcher() + { + if (Player.m_localPlayer == null) + { + Console.instance.Print("dumpanim live needs you to be in the world."); + return; + } + + AnimatorWatcher existing = Player.m_localPlayer.GetComponent(); + if (existing != null) + { + Object.Destroy(existing); + Report("[Anim] live watch off."); + return; + } + + Player.m_localPlayer.gameObject.AddComponent(); + Report("[Anim] live watch on: every clip change under you, as it happens."); + } + + /// + /// Why a sound prefab is or is not audible when it is simply instantiated. + /// + /// The AudioSource settings say whether anything starts by itself, and ZSFX's own fields say + /// what it would play if asked - it keeps a LIST of clips and chooses at play time, so a + /// prefab whose AudioSource has no clip is normal rather than broken. Read through reflection + /// because these are the game's private serialized fields. + /// + private static void DescribeAudio(GameObject go) + { + AudioSource audio = go.GetComponent(); + if (audio != null) + { + Jotunn.Logger.LogInfo( + $"[Anim] AudioSource playOnAwake={audio.playOnAwake} " + + $"clip='{(audio.clip != null ? audio.clip.name : "none")}' " + + $"volume={audio.volume:F2} spatialBlend={audio.spatialBlend:F2} " + + $"range={audio.minDistance:F1}-{audio.maxDistance:F1} loop={audio.loop} " + + $"mixer='{(audio.outputAudioMixerGroup != null ? audio.outputAudioMixerGroup.name : "none")}'"); + } + + foreach (Component comp in go.GetComponents()) + { + if (comp == null || comp.GetType().Name != "ZSFX") continue; + + List fields = new List(); + foreach (System.Reflection.FieldInfo f in comp.GetType().GetFields( + System.Reflection.BindingFlags.Instance | + System.Reflection.BindingFlags.Public | + System.Reflection.BindingFlags.NonPublic)) + { + object value = f.GetValue(comp); + System.Array array = value as System.Array; + if (array == null) + { + fields.Add($"{f.Name}={value}"); + continue; + } + + // The elements, not just the count. m_audioClips is where a sound's actual clips + // live, and whether they are AudioClips or unloaded soft references is the whole + // question when a sound spawns and stays silent. + List elements = new List(); + for (int e = 0; e < array.Length && e < 4; e++) + { + object item = array.GetValue(e); + Object asObject = item as Object; + elements.Add(item == null + ? "null" + : $"{item.GetType().Name}:'{(asObject != null ? asObject.name : item.ToString())}'"); + } + fields.Add($"{f.Name}[{array.Length}]={{{string.Join(", ", elements.ToArray())}}}"); + } + + Jotunn.Logger.LogInfo($"[Anim] ZSFX {string.Join(" ", fields.ToArray())}"); + Jotunn.Logger.LogInfo( + $"[Anim] ZSFX methods: {string.Join(", ", MethodNamesOf(comp))}"); + } + } + + private static string[] MethodNamesOf(Component comp) + { + List names = new List(); + foreach (System.Reflection.MethodInfo m in comp.GetType().GetMethods( + System.Reflection.BindingFlags.Instance | + System.Reflection.BindingFlags.Public | + System.Reflection.BindingFlags.DeclaredOnly)) + { + names.Add(m.Name + "(" + m.GetParameters().Length + ")"); + } + return names.ToArray(); + } + + /// The component type names on one object, Transform left out as noise. + private static string ComponentsOf(GameObject go) + { + List names = new List(); + foreach (Component comp in go.GetComponents()) + { + if (comp != null && !(comp is Transform)) names.Add(comp.GetType().Name); + } + return string.Join(", ", names.ToArray()); + } + + private static string PathOf(Transform t) + { + string path = t.name; + for (Transform p = t.parent; p != null; p = p.parent) path = p.name + "/" + path; + return path; + } + + /// To the log and to the console both, since one of the two is always the wrong one. + private static void Report(string line) + { + Jotunn.Logger.LogInfo(line); + if (Console.instance != null) Console.instance.Print(line); + } + + /// + /// Watches every animator under the player and says when one starts a different clip. + /// + /// Only the change is logged, not the state: an animator asked every frame would fill the log + /// with the idle it is already playing. The heaviest clip is the one reported, because during + /// a transition two are live at once and the heavier one is the one being watched on screen. + /// + private class AnimatorWatcher : MonoBehaviour + { + private readonly Dictionary last = new Dictionary(); + + private void Update() + { + foreach (Animator animator in GetComponentsInChildren(true)) + { + if (animator == null || animator.runtimeAnimatorController == null) continue; + + AnimatorClipInfo[] playing = animator.GetCurrentAnimatorClipInfo(0); + if (playing.Length == 0) continue; + + AnimationClip heaviest = null; + float weight = -1f; + foreach (AnimatorClipInfo info in playing) + { + if (info.clip != null && info.weight > weight) + { + heaviest = info.clip; + weight = info.weight; + } + } + if (heaviest == null) continue; + + string previous; + if (last.TryGetValue(animator, out previous) && previous == heaviest.name) continue; + + last[animator] = heaviest.name; + Jotunn.Logger.LogInfo( + $"[Anim] live: '{PathOf(animator.transform)}' -> '{heaviest.name}' " + + $"{heaviest.length:F2}s weight={weight:F2} events={heaviest.events.Length}"); + } + } + } + } +} diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index 3078f06..b1f1cd2 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -708,7 +708,17 @@ namespace RacesOfValheim { isTransformingSequence = true; - GameObject poofPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_surtling_death"); + // WAS "vfx_surtling_death", WHICH IS NOT A PREFAB IN THIS GAME. The surtling has no + // death effect under any spelling, so this resolved to nothing and the Mist Form has + // always appeared and disappeared with no puff at all - both here and in + // RevertMistFormRoutine. Kept as a note rather than a fallback: a name vanilla does not + // use is a free slot for any mod that ships one, which is how another mod's weapon trail + // became the Skeleton's fire aura (see SkeletonVisuals.EnsureFireAura). + // + // The Wraith's own death effect reads as mist by construction, which is what this wanted, + // and it is already the right creature: the form borrows the Wraith's Visual a few lines + // below. If the look wants changing, that effect is the thing to alter. + GameObject poofPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_wraith_death"); if (poofPrefab != null) Instantiate(poofPrefab, Player.m_localPlayer.transform.position, Quaternion.identity); Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_MistForm".GetStableHashCode(), true); @@ -763,7 +773,9 @@ namespace RacesOfValheim { isTransformingSequence = true; - GameObject poofPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_surtling_death"); + // The same puff as going in - see TransformIntoMistRoutine for why the old name never + // resolved to anything. + GameObject poofPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_wraith_death"); if (poofPrefab != null) Instantiate(poofPrefab, Player.m_localPlayer.transform.position, Quaternion.identity); Transform playerVisual = Player.m_localPlayer.transform.Find("Visual"); diff --git a/JotunnModStub/Aswid/AswidStatusEffects.cs b/JotunnModStub/Aswid/AswidStatusEffects.cs index f87e9bb..ac3ab3f 100644 --- a/JotunnModStub/Aswid/AswidStatusEffects.cs +++ b/JotunnModStub/Aswid/AswidStatusEffects.cs @@ -114,13 +114,13 @@ namespace RacesOfValheim { var aswidStats = ScriptableObject.CreateInstance(); aswidStats.name = "SE_AswidStats"; - aswidStats.m_icon = PrefabManager.Cache.GetPrefab("TrophyBat")?.m_itemData.m_shared.m_icons[0]; + aswidStats.m_icon = PrefabManager.Cache.GetPrefab("TrophyDeathsquito")?.m_itemData.m_shared.m_icons[0]; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(aswidStats, fixReference: false)); var batForm = ScriptableObject.CreateInstance(); batForm.name = "SE_BatForm"; - batForm.m_icon = PrefabManager.Cache.GetPrefab("TrophyBat")?.m_itemData.m_shared.m_icons[0]; + batForm.m_icon = PrefabManager.Cache.GetPrefab("TrophyDeathsquito")?.m_itemData.m_shared.m_icons[0]; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(batForm, fixReference: false)); diff --git a/JotunnModStub/Aswid/AswidThrall.cs b/JotunnModStub/Aswid/AswidThrall.cs index 816517e..35d1562 100644 --- a/JotunnModStub/Aswid/AswidThrall.cs +++ b/JotunnModStub/Aswid/AswidThrall.cs @@ -117,7 +117,10 @@ namespace RacesOfValheim m_ai.SetFollowTarget(user.gameObject); } - GameObject vfx = ZNetScene.instance.GetPrefab("vfx_surtling_death"); + // "vfx_surtling_death" was asked for here and is not a prefab in this game, so dominating + // a creature happened with no effect at all. The generic body-sized puff, rather than the + // Wraith's mist the Mist Form wears: nothing about domination is misty. + GameObject vfx = ZNetScene.instance.GetPrefab("vfx_corpse_destruction_medium"); if (vfx) Instantiate(vfx, m_character.transform.position, Quaternion.identity); user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} dominated!"); diff --git a/JotunnModStub/Draugh/DraughConfig.cs b/JotunnModStub/Draugh/DraughConfig.cs index 8f3c8fe..8aa0a88 100644 --- a/JotunnModStub/Draugh/DraughConfig.cs +++ b/JotunnModStub/Draugh/DraughConfig.cs @@ -33,6 +33,7 @@ namespace RacesOfValheim // ─── Undead Fortitude (tier 4+: crit on staggered, death aura) ────────── public static ConfigEntry StaggerCritMultiplier; public static ConfigEntry DeathAuraRadius; + public static ConfigEntry HumanMeatNourishmentMultiplier; // ─── North Wind (tier 5+: AoE frost on parry, on the same cooldown) ────── public static ConfigEntry NorthWindCooldown; @@ -79,6 +80,10 @@ namespace RacesOfValheim new ConfigDescription("Multiplies physical damage dealt to staggered enemies, tier 4+.", new AcceptableValueRange(1f, 3f))); DeathAuraRadius = config.Bind(fortitude, "Death Aura Radius", 100f, new ConfigDescription("Meters within which an ally's death drops Human Meat for you, tier 4+.", new AcceptableValueRange(10f, 300f))); + // A multiplier rather than absolute numbers: Human Meat is built from Blood Pudding's own + // nourishment at start-up, and those are the game's values, not ours to hardcode. + HumanMeatNourishmentMultiplier = config.Bind(fortitude, "Human Meat Nourishment Multiplier", 1f, + new ConfigDescription("Scales Human Meat's health, stamina and eitr against the Blood Pudding it is built from. Read once at start-up.", new AcceptableValueRange(0.1f, 3f))); const string northWind = "Draugh - North Wind"; NorthWindCooldown = config.Bind(northWind, "Cooldown", 20f, diff --git a/JotunnModStub/Draugh/DraughHumanMeat.cs b/JotunnModStub/Draugh/DraughHumanMeat.cs new file mode 100644 index 0000000..6ba3293 --- /dev/null +++ b/JotunnModStub/Draugh/DraughHumanMeat.cs @@ -0,0 +1,140 @@ +using Jotunn.Entities; +using Jotunn.Managers; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// Human Meat, the Bonemass-tier reward: an ally who dies near a Draugh leaves a piece of + /// themselves behind, and only a Draugh can stomach it. + /// + /// THIS ITEM DID NOT EXIST. Two places in the mod already used it - the drop in + /// DraughProgressionPatches.Draugh_DeathAura_Patch and the "fatal to the living" block in + /// DraughFoodPatches - and both looked it up by the name "HumanMeat", which nothing registered. + /// So the drop never happened and the block never fired: a perk the README has promised since + /// 1.4 with no item behind it. The two consumers are unchanged; what was missing was the + /// producer. + /// + /// BUILT FROM TWO VANILLA ITEMS, one for the look and one for the numbers: + /// + /// RawMeat gives the clone its model and icon, because that is what a piece of somebody looks + /// like, and because the Draugh's whole food identity is raw flesh. + /// + /// BloodPudding gives the nourishment, copied field by field at start-up rather than written + /// down here. Blood Pudding is a real cooked food in the game's own progression, so its + /// numbers are balanced against the rest of it, and reading them means this item follows any + /// change the game makes to them. DraughConfig.HumanMeatNourishmentMultiplier scales them. + /// Its stamina is folded into health rather than copied across - see the note further down. + /// + /// RawMeat is a Material in vanilla - raw meat is not edible - so m_itemType is forced to + /// Consumable. That is the one assumption in here worth knowing about: the alternative, which + /// DraughRace.CreateModAssets uses for its EdibleUncooked_ items, is to clone the COOKED item and + /// dress it as the raw one, which gets consumability for free but keeps the cooked model. If the + /// game ever refuses to eat this, that is the fallback, and the log line below prints exactly + /// what was produced so it can be told apart from a missing prefab. + /// + internal static class DraughHumanMeat + { + /// The name the two consumers look it up by. Changing it breaks both. + public const string PrefabName = "HumanMeat"; + + private const string LookSource = "RawMeat"; + private const string NourishmentSource = "BloodPudding"; + + /// + /// Darkens the meat and pulls it towards blood, so a stack of Human Meat is not mistaken for + /// the deer meat it is built from. Multiplied into the material's own colour, so it darkens + /// whatever the texture already is rather than replacing it. + /// + private static readonly Color Tint = new Color(0.62f, 0.34f, 0.38f, 1f); + + /// + /// Called from DraughRace.CreateModAssets, which is to say while vanilla prefabs are + /// available and before anything can ask for this item. + /// + public static void Register() + { + ItemDrop look = FindItem(LookSource); + ItemDrop nourishment = FindItem(NourishmentSource); + + if (look == null || nourishment == null) + { + // Nothing is registered rather than a half-built item: the two consumers both check + // for null, so no meat is a quiet no-op, while a nameless inedible one is not. + Jotunn.Logger.LogWarning( + $"[Draugh] Human Meat not registered: '{LookSource}' " + + $"{(look == null ? "missing" : "ok")}, '{NourishmentSource}' " + + $"{(nourishment == null ? "missing" : "ok")}."); + return; + } + + CustomItem item = new CustomItem(PrefabName, LookSource); + ItemDrop.ItemData.SharedData shared = item.ItemDrop.m_itemData.m_shared; + ItemDrop.ItemData.SharedData source = nourishment.m_itemData.m_shared; + + shared.m_name = "Human Meat"; + shared.m_description = "A piece of somebody. The living gag on it; you do not."; + + // Raw meat is a Material in vanilla, so none of the food fields below would be read + // without this. + shared.m_itemType = ItemDrop.ItemData.ItemType.Consumable; + + // BLOOD PUDDING'S STAMINA GOES ONTO HEALTH, AND STAMINA IS LEFT AT ZERO. A Draugh does + // not use stamina, so nourishment spent there is nourishment thrown away - the food + // slot would look full while giving the race half of what it cost. Adding the two + // together keeps the item worth the same as the pudding it is balanced against, which + // is the point of reading the pudding at all. + float scale = DraughConfig.HumanMeatNourishmentMultiplier.Value; + shared.m_food = (source.m_food + source.m_foodStamina) * scale; + shared.m_foodStamina = 0f; + shared.m_foodEitr = source.m_foodEitr * scale; + shared.m_foodRegen = source.m_foodRegen; + shared.m_foodBurnTime = source.m_foodBurnTime; + shared.m_maxStackSize = source.m_maxStackSize; + shared.m_consumeStatusEffect = source.m_consumeStatusEffect; + + Recolour(item.ItemDrop.gameObject); + + ItemManager.Instance.AddItem(item); + + Jotunn.Logger.LogInfo( + $"[Draugh] Human Meat registered from '{LookSource}' + '{NourishmentSource}': " + + $"type={shared.m_itemType} food={shared.m_food:F0} stamina={shared.m_foodStamina:F0} " + + $"eitr={shared.m_foodEitr:F0} regen={shared.m_foodRegen:F0} " + + $"burn={shared.m_foodBurnTime:F0}s stack={shared.m_maxStackSize}."); + } + + private static ItemDrop FindItem(string prefabName) + { + GameObject prefab = PrefabManager.Cache.GetPrefab(prefabName); + return prefab != null ? prefab.GetComponent() : null; + } + + /// + /// Tints the clone's own materials, on copies. + /// + /// The clone's renderers still point at the vanilla RawMeat materials, which are shared with + /// every piece of raw meat in the world - writing a colour into one of those would tint the + /// lot. Each renderer gets its own copy instead, which this prefab then owns. + /// + private static void Recolour(GameObject root) + { + foreach (Renderer renderer in root.GetComponentsInChildren(true)) + { + Material[] materials = renderer.sharedMaterials; + if (materials == null) continue; + + for (int i = 0; i < materials.Length; i++) + { + if (materials[i] == null) continue; + + Material copy = new Material(materials[i]); + if (copy.HasProperty("_Color")) copy.color = copy.color * Tint; + materials[i] = copy; + } + + renderer.sharedMaterials = materials; + } + } + } +} diff --git a/JotunnModStub/Draugh/DraughProgressionPatches.cs b/JotunnModStub/Draugh/DraughProgressionPatches.cs index 8162551..f56ce0f 100644 --- a/JotunnModStub/Draugh/DraughProgressionPatches.cs +++ b/JotunnModStub/Draugh/DraughProgressionPatches.cs @@ -98,8 +98,16 @@ namespace RacesOfValheim attacker.ApplyDamage(poisonSplash, true, false); - // Visual effect for splash - UnityEngine.Object.Instantiate(ZNetScene.instance.GetPrefab("vfx_OozeHit"), attacker.GetCenterPoint(), Quaternion.identity); + // Visual effect for splash. "vfx_OozeHit" is not a prefab in this game - + // the blob's hit effect is vfx_blob_hit - and this was the one dead name + // in the mod that was passed to Instantiate unguarded, so every + // successful parry threw ArgumentException here and took the North Wind + // nova below down with it. + GameObject splashVfx = ZNetScene.instance.GetPrefab("vfx_blob_hit"); + if (splashVfx != null) + { + UnityEngine.Object.Instantiate(splashVfx, attacker.GetCenterPoint(), Quaternion.identity); + } // Stage 5: North Wind (AoE Frost) if (state >= 5) diff --git a/JotunnModStub/Draugh/DraughRace.cs b/JotunnModStub/Draugh/DraughRace.cs index a9f130f..9362f5c 100644 --- a/JotunnModStub/Draugh/DraughRace.cs +++ b/JotunnModStub/Draugh/DraughRace.cs @@ -23,6 +23,10 @@ namespace RacesOfValheim // Draugr is ever set up as a bench. DraughSpawner.Register(); + // The Bonemass-tier drop. Registered here for the same reason as the pile: two places in + // the mod already look it up by name, and until now nothing created it. + DraughHumanMeat.Register(); + // Generate EdibleUncooked prefabs for Draugh raw food logic foreach (var mapping in DraughFoodPatches.rawToCookedMapping) { diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index 2d1180c..70137f4 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using BepInEx; using HarmonyLib; using Jotunn.Configs; @@ -10,32 +11,267 @@ using UnityEngine.UI; // Added for UI namespace RacesOfValheim { /// - /// Howl vocalisation, borrowed from the real creature instead of guessed at. Wolves and their - /// kin do not carry a standalone "sfx_wolf_howl"-style prefab that PlaySFX's - /// PrefabManager.Cache lookup could ever find - dumpdverger's own hierarchy dump for - /// Fenring_Cultist shows no ZSFX anywhere on it. + /// The voice of the creature a Fenrir is wearing. /// - /// BaseAI.m_idleSound was the first guess and was wrong in a quieter way: it is real, but it - /// is the creature's passive ambient noise (DoIdleSound, on a timer while it is doing nothing - /// in particular) - a small grunt, not a howl, and it played back sounding like whatever - /// generic "the form did something" cue the transformation itself already uses. What a - /// creature actually vocalises WHEN IT SPOTS SOMETHING is BaseAI.m_alertedEffects, fired from - /// SetAlerted(true) - reading that off the real "Fenring"/"Fenring_Cultist" prefab and calling - /// Create() plays the same aggressive bark the creature itself makes going on alert. + /// THE HISTORY MATTERS HERE, because two reasonable-sounding answers were tried and both were + /// silent, and the note that used to sit in this place asserted the second one worked. + /// + /// "sfx_wolf_howl" was the first guess. There is no such prefab in the game. + /// + /// BaseAI.m_idleSound was the second. Real, but it is the creature's ambient grunt on a timer + /// (DoIdleSound) - the wrong sound even when it plays. + /// + /// BaseAI.m_alertedEffects was the third, on the reasoning that a creature's alert bark is the + /// nearest thing it has to a howl and that these creatures carry no standalone ZSFX at all. + /// That last part is simply not true - see the table below - and calling Create() on a PREFAB's + /// EffectList produced nothing audible in testing while instantiating a sound prefab directly, + /// two lines away in the same file, worked. So the alert-list route is now the last resort + /// rather than the plan. + /// + /// What actually plays is a real prefab, instantiated the same way the claw and the landing thud + /// are. Every name below was checked against the game's own asset manifest. Note "sfx_wolf_haul", + /// which is the wolf's howl under the game's own misspelling - that single typo is most of why + /// nobody found it by searching for "howl". /// internal static class FenrirCreatureSound { + /// + /// Per creature, best first, and every name checked against the game's own asset manifest. + /// The Ulv has no vocalisation of its own in vanilla beyond sfx_ulv_death, so it borrows the + /// wolf's. "sfx_wolf_haul" is the wolf's howl under the game's own misspelling, which is most + /// of why nobody found it by searching for "howl". + /// + /// THE FENRING BORROWS THE WOLF'S HOWL. It has none of its own: its 19 clips carry no howl, + /// and its taunt fires no sound event at all. Its own "sfx_fenring_howl" is in Suspect below + /// and must not be spawned. Its alert bark stays as the second entry - that is its real voice, + /// just not an ululation. + /// + private static readonly Dictionary Howls = new Dictionary + { + { "Wolf", new[] { "sfx_wolf_haul", "sfx_wolf_alerted" } }, + { "Ulv", new[] { "sfx_wolf_haul", "sfx_wolf_alerted" } }, + { "Fenring", new[] { "sfx_wolf_haul", "sfx_fenring_alerted" } }, + { "Fenring_Cultist", new[] { "sfx_wolf_haul", "sfx_fenring_alerted" } }, + }; + + /// The cue that opens the cultist's fire breath: its own fire-claw snarl. + private static readonly string[] FireRoar = { "sfx_fenring_fireclaw" }; + + /// + /// PREFABS THAT RESOLVE AND MUST NOT BE INSTANTIATED. + /// + /// "sfx_fenring_howl" exists, resolves through the cache to a real GameObject, and takes the + /// process down with it - not an exception BepInEx can catch, a hard exit. It killed the game + /// the first time a Fenrir transformation reached it, and the only reason we know which prefab + /// did it is that its log line had been flushed a moment before. + /// + /// Best guess is that it is not a standalone sound at all but a node belonging to the + /// creature's own rig, fired by that creature's animator and meaningless off it. Described + /// here rather than deleted, because the description is what will settle that - and because a + /// name nobody records is a name somebody adds back. + /// + private static readonly HashSet Suspect = new HashSet { "sfx_fenring_howl" }; + + // Said once per name, because "the howl is silent" cost two rounds of testing to notice and + // the log said nothing either time. + private static readonly HashSet logged = new HashSet(); + public static void PlayHowl(string sourcePrefabName, Vector3 position) + { + string[] names; + if (Howls.TryGetValue(sourcePrefabName, out names) && Play(names, position, sourcePrefabName)) + { + return; + } + + // A form not in the table, or one whose whole list was refused, still gets a voice. + PlayAlertedEffects(sourcePrefabName, position); + } + + public static void PlayFireRoar(Vector3 position) + { + 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) + { + foreach (string name in prefabNames) + { + GameObject prefab = PrefabManager.Cache.GetPrefab(name); + if (prefab == null) continue; + + // BEFORE the Instantiate, not after. Anything that goes the way sfx_fenring_howl went + // now names itself, and says what it is, while the log can still be written. + if (logged.Add(name)) Describe(label, name, prefab); + + if (Suspect.Contains(name)) continue; + + // A parented object is not a prefab, it is a node inside somebody else's hierarchy. + // Spawning one on its own is the thing this route is suspected of getting wrong. + if (prefab.transform.parent != null) continue; + + Spawn(prefab, position); + return true; + } + + return false; + } + + /// + /// Spawns a sound prefab without letting it write itself into the save. + /// + /// SOME VANILLA SOUND PREFABS CARRY A ZNetView. "sfx_fenring_alerted" is one - the Describe + /// line below printed it, which is how this was noticed. A ZNetView that wakes with no init + /// ZDO calls ZDOMan.CreateNewZDO at its position, marks itself persistent, stamps itself with + /// the prefab hash and registers with the scene. On a sound played every time somebody howls + /// or swings a claw, that is one persistent "there is a noise here" record per swing, saved + /// with the world. It is the same bug that left burnt-in torches in people's worlds; the long + /// version is on SkeletonVisuals.BorrowEffect. + /// + /// ZNetView.StartGhostInit is the game's own answer, not ours: between the two calls a + /// ZNetView comes up with no ZDO at all. Cheaper and far less invasive than stripping the + /// component off a copy, and free on the prefabs that carry no ZNetView. + /// + /// The finally matters. Leaving ghost init switched on because an Instantiate threw would + /// break every ZNetView created afterwards, for the rest of the session. + /// + public static void Spawn(GameObject prefab, Vector3 position) + { + if (prefab == null) return; + + ZNetView.StartGhostInit(); + try + { + Object.Instantiate(prefab, position, Quaternion.identity); + } + finally + { + ZNetView.FinishGhostInit(); + } + + // NOT FOLLOWED BY A Play() CALL, and that took a while to establish. ZSFX is ticked by + // CustomUpdate rather than Unity's Update, so it starts on a later frame: reading + // AudioSource.isPlaying straight after this says false for every sound there is, and + // nudging Play() in on top of a prefab whose own m_playOnAwake is already set is as + // likely to interrupt it as to help. Every sound this mod spawns self-starts. If one ever + // turns up that does not - m_playOnAwake false, checked with "dumpanim " - that is + // the moment to call ZSFX.Play() here, and not before. + } + + /// + /// What a resolved sound actually is: where it sits in its own hierarchy, and what it carries. + /// The root flag is the one to read first - see Play. + /// + private static void Describe(string label, string name, GameObject prefab) + { + string path = prefab.name; + for (Transform t = prefab.transform.parent; t != null; t = t.parent) path = t.name + "/" + path; + + List parts = new List(); + foreach (Component comp in prefab.GetComponentsInChildren(true)) + { + if (comp != null && !(comp is Transform)) parts.Add(comp.GetType().Name); + } + + Jotunn.Logger.LogInfo( + $"[FenrirForm] {label}: '{name}' -> '{path}' root={prefab.transform.parent == null} " + + $"suspect={Suspect.Contains(name)} carries=[{string.Join(", ", parts.ToArray())}]"); + } + + /// + /// The creature's alert EffectList, kept as a fallback. Not trusted as the primary any more: + /// it is what left every howl in the mod silent. + /// + private static void PlayAlertedEffects(string sourcePrefabName, Vector3 position) { GameObject source = PrefabManager.Cache.GetPrefab(sourcePrefabName); BaseAI ai = source != null ? source.GetComponent() : null; - if (ai == null || ai.m_alertedEffects == null) + if (ai == null || ai.m_alertedEffects == null || ai.m_alertedEffects.m_effectPrefabs == null || + ai.m_alertedEffects.m_effectPrefabs.Length == 0) { - Jotunn.Logger.LogWarning($"[FenrirForm] No BaseAI.m_alertedEffects found on '{sourcePrefabName}'."); + if (logged.Add(sourcePrefabName + "-alerted")) + { + Jotunn.Logger.LogWarning( + $"[FenrirForm] No sound for '{sourcePrefabName}': nothing from its table was " + + "playable and its BaseAI.m_alertedEffects is empty."); + } return; } ai.m_alertedEffects.Create(position, Quaternion.identity); + if (logged.Add(sourcePrefabName + "-alerted")) + { + Jotunn.Logger.LogWarning( + $"[FenrirForm] '{sourcePrefabName}': fell through to BaseAI.m_alertedEffects " + + $"({ai.m_alertedEffects.m_effectPrefabs.Length} effect(s)). This route has been " + + "silent before - if you hear nothing, that is why."); + } } } @@ -193,8 +429,9 @@ namespace RacesOfValheim flames = FenrirAttackSync.SpawnFlames(player); // The roar that opens the breath, once per start, the same cue the owner hears. - GameObject sfx = PrefabManager.Cache.GetPrefab("sfx_cultist_attack_fire_start"); - if (sfx != null) Instantiate(sfx, player.transform.position, Quaternion.identity); + // "sfx_cultist_attack_fire_start" was asked for here and there is no sfx_cultist_* + // prefab in the game at all; the fenring's own fire-claw snarl is the real one. + FenrirCreatureSound.PlayFireRoar(player.transform.position); } else if (!fire && flames != null) { Destroy(flames); flames = null; } @@ -221,7 +458,7 @@ namespace RacesOfValheim GameObject sfx = PrefabManager.Cache.GetPrefab(name); if (sfx != null) { - Instantiate(sfx, player.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(sfx, player.transform.position); return; } } @@ -333,7 +570,7 @@ namespace RacesOfValheim GameObject sfx = PrefabManager.Cache.GetPrefab(name); if (sfx != null) { - Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(sfx, Player.m_localPlayer.transform.position); return; } } @@ -365,19 +602,19 @@ namespace RacesOfValheim fenrirAnim.SetFloat("sideway_speed", 0f); fenrirAnim.SetTrigger(triggerName); - FenrirAttackSync.Publish(triggerName, "sfx_fenring_attack", "sfx_fenring_attack_claw", "sfx_wolf_attack"); - PlaySFX("sfx_fenring_attack", "sfx_fenring_attack_claw", "sfx_wolf_attack"); + // The swing. The chain here used to be "sfx_fenring_attack", "sfx_fenring_attack_claw", + // "sfx_wolf_attack", and only the last of those is a prefab in this game - so a Fenring + // has been swinging with a wolf's voice, through a fallback, while the creature's own + // sound sat there unused under a different name. + FenrirAttackSync.Publish(triggerName, "sfx_fenring_claw_start"); + PlaySFX("sfx_fenring_claw_start"); yield return new WaitForSeconds(dmgDelay); - if (ZNetScene.instance != null) - { - GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_fenring_attack"); - if (attackSfx != null) - { - Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity); - } - } + // The hit, as opposed to the swing PlaySFX covers above. This asked for + // "sfx_fenring_attack" on its own, which is not a prefab in this game, so the claw landed + // in silence - same dead name as the jump attack's, same replacement. + PlaySFX("sfx_fenring_claw_hit"); ExecuteClawDamage(baseDamage); @@ -404,16 +641,12 @@ namespace RacesOfValheim // Aspettiamo che l'animazione si carichi (0.75s) yield return new WaitForSeconds(0.75f); - if (ZNetScene.instance != null) - { - GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_fenring_attack"); - if (attackSfx != null) - { - Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity); - } - } + // The impact sound used to be played HERE, which is mid-air: the jump has not started + // yet, let alone landed. It now fires at the end of the dash, next to the damage. It also + // asked for "sfx_fenring_attack", which is not a prefab in this game, so it was silent + // either way. - // Invece di una singola spinta di velocità (che viene subito annullata da Valheim), + // Invece di una singola spinta di velocità (che viene subito annullata da Valheim), // muoviamo esplicitamente il personaggio fotogramma per fotogramma per 0.2 secondi float dashDuration = 0.2f; float elapsedDash = 0f; @@ -438,7 +671,9 @@ namespace RacesOfValheim yield return new WaitForFixedUpdate(); } - // Infliggiamo il danno al termine dello scatto + // Infliggiamo il danno al termine dello scatto, che è anche il momento dell'atterraggio: + // il suono d'impatto va qui, non prima dello scatto. + PlaySFX("sfx_fenring_claw_hit"); ExecuteClawDamage(FenrirConfig.FenringJumpAttackDamage.Value); // Tempo per riprendersi dall'atterraggio prima di potersi muovere di nuovo @@ -620,7 +855,7 @@ namespace RacesOfValheim GameObject sfx = PrefabManager.Cache.GetPrefab(name); if (sfx != null) { - Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(sfx, Player.m_localPlayer.transform.position); return; } } @@ -658,7 +893,8 @@ namespace RacesOfValheim cultistAnim.SetBool("attack_fire", true); FenrirAttackSync.PublishFire(true); - PlaySFX("sfx_cultist_attack_fire_start"); + // Same cue the remote mirror plays - see the fire branch in the sync behaviour above. + FenrirCreatureSound.PlayFireRoar(Player.m_localPlayer.transform.position); cultistAnim.SetTrigger("attack_flames"); FenrirAttackSync.Publish("attack_flames"); @@ -770,11 +1006,11 @@ namespace RacesOfValheim // Per il Cultista usiamo esplicitamente il trigger dell'artigliata cultistAnim.SetTrigger("attack_claw"); - FenrirAttackSync.Publish("attack_claw", "sfx_cultist_attack", "sfx_fenring_attack", "sfx_wolf_attack"); + FenrirAttackSync.Publish("attack_claw", "sfx_fenring_claw_start"); yield return new WaitForSeconds(0.4f); - PlaySFX("sfx_cultist_attack", "sfx_fenring_attack", "sfx_wolf_attack"); + PlaySFX("sfx_fenring_claw_start"); ExecuteClawDamage(FenrirConfig.CultistClawDamage.Value); @@ -796,12 +1032,12 @@ namespace RacesOfValheim cultistAnim.SetFloat("sideway_speed", 0f); cultistAnim.SetTrigger("attack_claw_double"); - FenrirAttackSync.Publish("attack_claw_double", "sfx_cultist_attack_double", "sfx_cultist_attack", "sfx_fenring_attack"); + FenrirAttackSync.Publish("attack_claw_double", "sfx_fenring_claw_start"); // L'animazione double claw è più lunga, facciamo il danno un po' dopo yield return new WaitForSeconds(0.6f); - PlaySFX("sfx_cultist_attack_double", "sfx_cultist_attack", "sfx_fenring_attack"); + PlaySFX("sfx_fenring_claw_start"); ExecuteClawDamage(FenrirConfig.CultistDoubleClawDamage.Value); @@ -923,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)); } @@ -946,12 +1188,42 @@ namespace RacesOfValheim GameObject sfx = PrefabManager.Cache.GetPrefab(name); if (sfx != null) { - Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(sfx, Player.m_localPlayer.transform.position); return; } } } + + /// + /// 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; @@ -969,7 +1241,7 @@ namespace RacesOfValheim GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wolf_attack"); if (attackSfx != null) { - Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(attackSfx, Player.m_localPlayer.transform.position); } } @@ -1097,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)); } @@ -1121,12 +1399,42 @@ namespace RacesOfValheim GameObject sfx = PrefabManager.Cache.GetPrefab(name); if (sfx != null) { - Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(sfx, Player.m_localPlayer.transform.position); return; } } } + + /// + /// 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; @@ -1135,17 +1443,12 @@ namespace RacesOfValheim try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {} try { ulvAnim.SetTrigger(triggerName); } catch {} - FenrirAttackSync.Publish(triggerName, "sfx_ulv_attack", "sfx_wolf_attack", "sfx_fenring_attack"); + FenrirAttackSync.Publish(triggerName, "sfx_wolf_attack"); - // Scegli il suono appropriato per l'attacco - if (triggerName == "attack_bite") - { - PlaySFX("sfx_ulv_attack", "sfx_wolf_attack", "sfx_fenring_attack"); - } - else - { - PlaySFX("sfx_ulv_attack", "sfx_wolf_attack", "sfx_fenring_attack"); - } + // Un solo suono per entrambi i trigger. I due rami esistevano per scegliere fra + // "sfx_ulv_attack" e il ripiego sul lupo, ma l'Ulv non ha un prefab d'attacco in vanilla + // - c'e solo sfx_ulv_death - quindi entrambi suonavano il lupo comunque. + PlaySFX("sfx_wolf_attack"); yield return new WaitForSeconds(dmgDelay); @@ -1154,7 +1457,7 @@ namespace RacesOfValheim GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wood_hit"); if (attackSfx != null) { - Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(attackSfx, Player.m_localPlayer.transform.position); } } @@ -1241,8 +1544,8 @@ namespace RacesOfValheim try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {} try { ulvAnim.SetTrigger("attack_slash"); } catch {} - FenrirAttackSync.Publish("attack_slash", "sfx_ulv_attack", "sfx_wolf_attack"); - PlaySFX("sfx_ulv_attack", "sfx_wolf_attack"); + FenrirAttackSync.Publish("attack_slash", "sfx_wolf_attack"); + PlaySFX("sfx_wolf_attack"); yield return new WaitForSeconds(0.3f); // Wait 0.3s before leaping @@ -1267,7 +1570,7 @@ namespace RacesOfValheim GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wood_hit"); if (attackSfx != null) { - Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity); + FenrirCreatureSound.Spawn(attackSfx, Player.m_localPlayer.transform.position); } } diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index 784cffd..4e55a80 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -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); @@ -316,25 +321,36 @@ namespace RacesOfValheim { if (Player.m_localPlayer == null) return; Vector3 pos = Player.m_localPlayer.transform.position + Vector3.up; - GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction"); + // Vanilla's puff carries a size suffix and has no bare "vfx_corpse_destruction" - so + // this used to resolve to nothing and the body swap happened in plain view, with only + // the sparks below to soften it. _medium is the one built for a body this size. + GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction_medium"); if (smoke != null) Instantiate(smoke, pos, Quaternion.identity); GameObject sparks = PrefabManager.Cache.GetPrefab("vfx_HitSparks"); if (sparks != null) Instantiate(sparks, pos, Quaternion.identity); } + /// + /// 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. + /// + 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(prefabName); @@ -360,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(true); + if (formAnimator != null) + { + formAnimator.gameObject.AddComponent(); + 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") diff --git a/JotunnModStub/Fenrir/FormAnimEventSound.cs b/JotunnModStub/Fenrir/FormAnimEventSound.cs new file mode 100644 index 0000000..4fdea87 --- /dev/null +++ b/JotunnModStub/Fenrir/FormAnimEventSound.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// 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. + /// + internal class FormAnimEventSound : MonoBehaviour + { + private static readonly HashSet logged = new HashSet(); + + /// + /// 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. + /// + 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."); + } + } + + /// + /// 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. + /// + public void Effect(AnimationEvent e) + { + if (standDown) return; + + GameObject prefab = e.objectReferenceParameter as GameObject; + if (prefab == null) return; + + bool audible = prefab.GetComponentInChildren(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); + } + } +} diff --git a/JotunnModStub/RaceRadial.cs b/JotunnModStub/RaceRadial.cs index f381421..3e4e0da 100644 --- a/JotunnModStub/RaceRadial.cs +++ b/JotunnModStub/RaceRadial.cs @@ -49,7 +49,7 @@ namespace RacesOfValheim new Entry { Race = "Fenrir", Label = "Cultist Form", Key = () => FenrirConfig.CultistFormKey, Icon = "TrophyCultist" }, new Entry { Race = "Fenrir", Label = "Howl", Key = () => FenrirConfig.HowlKey, Icon = "TrophyUlv" }, - new Entry { Race = "Aswid", Label = "Bat Form", Key = () => AswidConfig.BatFormKey, Icon = "TrophyBat" }, + new Entry { Race = "Aswid", Label = "Bat Form", Key = () => AswidConfig.BatFormKey, Icon = "TrophyDeathsquito" }, new Entry { Race = "Aswid", Label = "Mist Form", Key = () => AswidConfig.MistFormKey, Icon = "TrophyWraith" }, new Entry { Race = "Aswid", Label = "Eclipse", Key = () => AswidConfig.EclipseKey, Icon = "TrophyFader" }, new Entry { Race = "Aswid", Label = "Tame", Key = () => AswidConfig.TameKey, Icon = "TrophyWolf" }, diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 7061303..c703e24 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -79,6 +79,7 @@ namespace RacesOfValheim CommandManager.Instance.AddConsoleCommand(new FenrirPackSpawnCommand()); CommandManager.Instance.AddConsoleCommand(new DumpPotionsCommand()); CommandManager.Instance.AddConsoleCommand(new ListPrefabsCommand()); + CommandManager.Instance.AddConsoleCommand(new DumpAnimCommand()); } /// @@ -695,7 +696,10 @@ namespace RacesOfValheim private Sprite GetTrolIcon() { GameObject trophyPrefab = PrefabManager.Cache.GetPrefab("TrophyFrostTroll")?.gameObject; - if (trophyPrefab == null) trophyPrefab = PrefabManager.Cache.GetPrefab("TrophyTroll")?.gameObject; + // TrophyForestTroll, not "TrophyTroll": the latter is not a prefab in this game, so the + // fallback could never fire and the name sat here as a free slot for any mod that + // happens to ship one. See SkeletonVisuals.EnsureFireAura for what that costs. + if (trophyPrefab == null) trophyPrefab = PrefabManager.Cache.GetPrefab("TrophyForestTroll")?.gameObject; if (trophyPrefab != null) { ItemDrop trophyDrop = trophyPrefab.GetComponent(); diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index af64056..cfe78d4 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -690,7 +690,10 @@ namespace RacesOfValheim if (Player.m_localPlayer == null) return; Vector3 pos = Player.m_localPlayer.transform.position + Vector3.up; - GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction"); + // _medium, not a bare "vfx_corpse_destruction": that name is not in the game, so this + // resolved to nothing and the swap into a drake happened in plain view. See + // FenrirRace.SpawnPoofEffect for the same fix. + GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction_medium"); if (smoke != null) Instantiate(smoke, pos, Quaternion.identity); GameObject sparks = PrefabManager.Cache.GetPrefab("vfx_HitSparks"); diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 78b1cf2..10fdf7d 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -283,6 +283,14 @@ namespace RacesOfValheim if (skeletonBodyTransform == null) { GameObject skelPrefab = PrefabManager.Cache.GetPrefab(rules.ModelPrefab); + + // The cache answers by name alone, and every magic mod named in the + // purple-smoke report carries an object of its own called "Skeleton" - + // which is this race's own tier-0 model name. So far the vanilla + // creature has always won; the log is here to say so, or to say which + // mod's object took its place. See SkeletonVisuals.EnsureFireAura. + SkeletonVisuals.LogResolvedPrefabOnce("model " + rules.ModelPrefab, skelPrefab); + if (skelPrefab == null) { // The human body was switched off two lines up, so an unresolved diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index 90311d6..3f0a3cb 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -279,7 +279,7 @@ namespace RacesOfValheim // only path taken once they stop being one. A Fader-tier Skeleton who reset to // Human kept a burning skull and a collapsed jaw, since neither the flame nor the // jaw was ever switched back from outside the Skeleton branch below. - EnsureFireAuraVFX(false); + SkeletonVisuals.EnsureFireAura(Player.m_localPlayer, false, ref fireAuraVFX); headFlame.Apply(Player.m_localPlayer, false); RestoreJawBone(); @@ -446,7 +446,7 @@ namespace RacesOfValheim if (rules.FireAura) { - EnsureFireAuraVFX(true); + SkeletonVisuals.EnsureFireAura(Player.m_localPlayer, true, ref fireAuraVFX); if (Time.time - lastAuraTime >= SkeletonConfig.FireAuraTickInterval.Value) { ApplyFireAura(); @@ -455,7 +455,7 @@ namespace RacesOfValheim } else { - EnsureFireAuraVFX(false); + SkeletonVisuals.EnsureFireAura(Player.m_localPlayer, false, ref fireAuraVFX); } } @@ -478,79 +478,6 @@ namespace RacesOfValheim } } - private void EnsureFireAuraVFX(bool enable) - { - if (enable && Player.m_localPlayer != null) - { - if (fireAuraVFX == null) - { - // Look for a smoke or fog effect to tint as fire fog - GameObject sourceVFX = PrefabManager.Cache.GetPrefab("vfx_smoke") ?? - PrefabManager.Cache.GetPrefab("vfx_surtling_death"); - - fireAuraVFX = new GameObject("SkeletonFireAuraVFX"); - fireAuraVFX.transform.SetParent(Player.m_localPlayer.transform, false); - fireAuraVFX.transform.localPosition = new Vector3(0, 1f, 0); - - if (sourceVFX != null) - { - ParticleSystem[] pss = sourceVFX.GetComponentsInChildren(); - if (pss.Length > 0) - { - ParticleSystem ps = fireAuraVFX.AddComponent(); - var main = ps.main; - main.loop = true; - main.duration = 1f; - main.startLifetime = 1.5f; - main.startSize = new ParticleSystem.MinMaxCurve(1.5f, 3f); - main.startSpeed = 0f; - main.simulationSpace = ParticleSystemSimulationSpace.World; - - var renderer = fireAuraVFX.GetComponent(); - renderer.material = pss[0].GetComponent().material; - - var shape = ps.shape; - shape.shapeType = ParticleSystemShapeType.Sphere; - shape.radius = 4.5f; // Similar to the damage radius - - var emission = ps.emission; - emission.rateOverTime = 40f; - - // Add a fire-like color gradient - var colorOverLifetime = ps.colorOverLifetime; - colorOverLifetime.enabled = true; - Gradient grad = new Gradient(); - grad.SetKeys( - new GradientColorKey[] { - new GradientColorKey(new Color(1f, 0.8f, 0.2f), 0.0f), // Yellow - new GradientColorKey(new Color(1f, 0.3f, 0.0f), 0.5f), // Orange/Red - new GradientColorKey(new Color(0.2f, 0.0f, 0.0f), 1.0f) // Dark red/smoke - }, - new GradientAlphaKey[] { - new GradientAlphaKey(0.0f, 0.0f), - new GradientAlphaKey(0.6f, 0.2f), - new GradientAlphaKey(0.6f, 0.8f), - new GradientAlphaKey(0.0f, 1.0f) - } - ); - colorOverLifetime.color = grad; - } - } - } - if (!fireAuraVFX.activeSelf) - { - fireAuraVFX.SetActive(true); - } - } - else - { - if (fireAuraVFX != null && fireAuraVFX.activeSelf) - { - fireAuraVFX.SetActive(false); - } - } - } - private void ApplyFireAura() { if (Player.m_localPlayer == null) return; diff --git a/JotunnModStub/Skeleton/SkeletonVisuals.cs b/JotunnModStub/Skeleton/SkeletonVisuals.cs index 825b64a..5f82dbc 100644 --- a/JotunnModStub/Skeleton/SkeletonVisuals.cs +++ b/JotunnModStub/Skeleton/SkeletonVisuals.cs @@ -169,6 +169,49 @@ namespace RacesOfValheim (passengers.Count == 0 ? "." : ", stripped " + string.Join(", ", passengers.ToArray()) + ".")); } + /// + /// Says what a borrowed-by-name prefab actually resolved to: which object, where it sits in + /// ITS OWN hierarchy, and the material and shader the first particle on it carries. Once per + /// name per session, so it costs a handful of lines and answers the question that took a + /// bundle extractor to answer the first time. + /// + /// READ THE root FLAG FIRST. A root-level object is a real prefab and almost certainly the + /// vanilla one. A parented one is a child node that Jotunn's cache picked up because nothing + /// better in memory answered to that name - which is what happens when the name does not + /// exist in vanilla at all, and is exactly how another mod's weapon trail ended up worn as + /// this race's fire aura. See EnsureFireAura. + /// + private static readonly HashSet loggedResolutions = new HashSet(); + + public static void LogResolvedPrefabOnce(string wanted, GameObject resolved) + { + if (!loggedResolutions.Add(wanted)) return; + + if (resolved == null) + { + Jotunn.Logger.LogWarning($"[Skeleton] Prefab lookup '{wanted}' resolved to NOTHING."); + return; + } + + string path = resolved.name; + for (Transform t = resolved.transform.parent; t != null; t = t.parent) + { + path = t.name + "/" + path; + } + + ParticleSystem first = resolved.GetComponentInChildren(true); + ParticleSystemRenderer psr = first != null ? first.GetComponent() : null; + Material material = psr != null ? psr.sharedMaterial : null; + + Jotunn.Logger.LogInfo( + $"[Skeleton] Prefab lookup '{wanted}' resolved to '{path}' " + + $"(root={resolved.transform.parent == null}) " + + $"particle='{(first != null ? first.name : "none")}' " + + $"material='{(material != null ? material.name : "none")}' " + + $"shader='{(material != null && material.shader != null ? material.shader.name : "none")}' " + + $"startColor={(first != null ? first.main.startColor.color.ToString() : "-")}"); + } + private static GameObject cachedFlameSource; private static bool flameSourceResolved; @@ -306,6 +349,50 @@ namespace RacesOfValheim return copy; } + /// + /// The fire aura's visual, and the reason it now has none. + /// + /// The aura itself (SkeletonRace.ApplyFireAura) burns everything inside FireAuraRadius from + /// Moder on and is untouched. What is gone is the way it used to try to show itself: + /// + /// PrefabManager.Cache.GetPrefab<GameObject>("vfx_smoke") + /// ?? PrefabManager.Cache.GetPrefab<GameObject>("vfx_surtling_death") + /// + /// NEITHER NAME EXISTS IN VALHEIM. Checked against the game's own asset manifest: there is no + /// vfx_smoke, and no surtling death effect under any spelling. In a plain install both + /// lookups came back null, no particle system was ever added, and this aura has never been + /// visible to anybody since the day it was written. + /// + /// A dead branch would be harmless if the lookup were harmless. It is not. PrefabManager.Cache + /// is, in Jotunn's own words, a "global cache of Unity Objects by asset name" built with + /// Resources.FindObjectsOfTypeAll, so it answers with anything in memory - including the + /// contents of every other mod's asset bundle - and its tie-break for a duplicate name ends + /// in "the newly discovered object replaces the cached one". A name vanilla does not use has + /// no vanilla candidate to beat, which leaves it a free slot for whoever ships one. + /// + /// Somebody shipped one. With Magic_Supremacy installed the lookup resolved to + /// 'EncounterCreatureRikoMountain_DO/vfx_smoke' - a CHILD node of one of that mod's + /// creatures, carrying the material 'club_trail_riko_DO' on the shader + /// 'Dreanegade/ParticleAlphaEmission'. A weapon trail, on an emissive shader, sprayed through + /// a 4.5m sphere centred on the player: the purple smoke around the burning skull this race + /// was reported for, on every client that could see the skeleton. + /// + /// So the aura is invisible deliberately now, which costs it nothing it ever had. To give it + /// a look, build it the way HeadFlame does: resolve a prefab under a name vanilla really uses + /// (ResolveFlameSource already holds one that works) and clone it through BorrowEffect, + /// instead of hand-rolling a particle system around a material taken by name. + /// + public static void EnsureFireAura(Player player, bool enable, ref GameObject aura) + { + // Nothing is built, so there is nothing to switch on either way - but a leftover is + // destroyed rather than left riding the player, which is what a session that swapped + // this assembly in mid-flight would otherwise be stuck with. + if (aura == null) return; + + Object.Destroy(aura); + aura = null; + } + /// /// One player's burning skull. Cosmetic only - it deals nothing and blocks nothing. /// diff --git a/JotunnModStub/Trenta/TrentaAbilities.cs b/JotunnModStub/Trenta/TrentaAbilities.cs index 8e8e3c9..4380e28 100644 --- a/JotunnModStub/Trenta/TrentaAbilities.cs +++ b/JotunnModStub/Trenta/TrentaAbilities.cs @@ -233,13 +233,27 @@ namespace RacesOfValheim if (!vfxMaterialResolved) { vfxMaterialResolved = true; - GameObject source = PrefabManager.Cache.GetPrefab(TrentaConfig.PurpleRainVfxSourcePrefab) - ?? PrefabManager.Cache.GetPrefab("vfx_smoke"); + // The "vfx_smoke" fallback that used to sit here is gone. That name is not a prefab + // in this game, so it could only ever resolve to another mod's object - and with + // Magic_Supremacy installed it resolved to a weapon trail, which is what put purple + // smoke on the Skeleton (see SkeletonVisuals.EnsureFireAura). Purple Rain is purple + // by design, so the same theft here would never have looked wrong enough to report. + // + // Losing the fallback means a miss is now a miss. Said out loud, because the resolve + // is cached for the session either way and a silent one would be invisible: 1.0 + // loads creature assets lazily, so the Shaman is not guaranteed to be in memory. + GameObject source = PrefabManager.Cache.GetPrefab(TrentaConfig.PurpleRainVfxSourcePrefab); if (source != null) { ParticleSystemRenderer sourceRenderer = source.GetComponentInChildren(true); if (sourceRenderer != null) cachedVfxMaterial = sourceRenderer.material; } + else + { + Jotunn.Logger.LogWarning( + $"[Trenta] Purple Rain: '{TrentaConfig.PurpleRainVfxSourcePrefab}' not in the prefab " + + "cache; falling back to Unity's default particle material for this session."); + } } GameObject vfx = new GameObject("TrentaPurpleRainVFX"); diff --git a/JotunnModStub/Trenta/TrentaMuspell.cs b/JotunnModStub/Trenta/TrentaMuspell.cs index 01157a9..6f7fbf6 100644 --- a/JotunnModStub/Trenta/TrentaMuspell.cs +++ b/JotunnModStub/Trenta/TrentaMuspell.cs @@ -141,7 +141,12 @@ namespace RacesOfValheim if (player == null) return; Vector3 pos = player.transform.position + Vector3.up; - GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction"); + // _large rather than the _medium the other two forms use: the Muspell is the biggest + // thing this mod turns a player into, and a body-sized puff does not cover it. A bare + // "vfx_corpse_destruction" is not a prefab in this game, so until now the Muspell was + // the one transformation with no covering effect of any kind - Fenrir and Skadi at least + // had their sparks. + GameObject smoke = PrefabManager.Cache.GetPrefab("vfx_corpse_destruction_large"); if (smoke != null) Object.Instantiate(smoke, pos, Quaternion.identity); } diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index ecff680..686a831 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -173,8 +173,9 @@ namespace RacesOfValheim m_player.transform.localScale = targetScale; } - // Fire Aura VFX - EnsureFireAuraVFX(rules.FireAura); + // Deliberately draws nothing - see SkeletonVisuals.EnsureFireAura for why. Called + // anyway so reinstating the visual needs no change here. + SkeletonVisuals.EnsureFireAura(m_player, rules.FireAura, ref m_fireAuraVFX); } private void UpdateFenrirVisuals() @@ -263,7 +264,7 @@ namespace RacesOfValheim PlayerVisualHider.Show(playerVisual, "zdosync-revert"); if (m_currentFormInstance != null) Destroy(m_currentFormInstance); - EnsureFireAuraVFX(false); + SkeletonVisuals.EnsureFireAura(m_player, false, ref m_fireAuraVFX); DraughVisuals.EnsureAura(m_player, false, ref m_draughAuraVFX); m_skeletonHeadFlame.Apply(m_player, false); // Takes the crown off a Trenta who has died or changed race; a no-op for everyone else. @@ -283,70 +284,5 @@ namespace RacesOfValheim m_lastFenrirForm = ""; m_lastSkadiForm = ""; } - - private void EnsureFireAuraVFX(bool enable) - { - if (enable) - { - if (m_fireAuraVFX == null) - { - GameObject sourceVFX = Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_smoke") ?? - Jotunn.Managers.PrefabManager.Cache.GetPrefab("vfx_surtling_death"); - - m_fireAuraVFX = new GameObject("SkeletonFireAuraVFX"); - m_fireAuraVFX.transform.SetParent(m_player.transform, false); - m_fireAuraVFX.transform.localPosition = new Vector3(0, 1f, 0); - - if (sourceVFX != null) - { - ParticleSystem[] pss = sourceVFX.GetComponentsInChildren(); - if (pss.Length > 0) - { - ParticleSystem ps = m_fireAuraVFX.AddComponent(); - var main = ps.main; - main.loop = true; - main.duration = 1f; - main.startLifetime = 1.5f; - main.startSize = new ParticleSystem.MinMaxCurve(1.5f, 3f); - main.startSpeed = 0f; - main.simulationSpace = ParticleSystemSimulationSpace.World; - - var renderer = m_fireAuraVFX.GetComponent(); - renderer.material = pss[0].GetComponent().material; - - var shape = ps.shape; - shape.shapeType = ParticleSystemShapeType.Sphere; - shape.radius = 4.5f; - - var emission = ps.emission; - emission.rateOverTime = 40f; - - var colorOverLifetime = ps.colorOverLifetime; - colorOverLifetime.enabled = true; - Gradient grad = new Gradient(); - grad.SetKeys( - new GradientColorKey[] { - new GradientColorKey(new Color(1f, 0.8f, 0.2f), 0.0f), - new GradientColorKey(new Color(1f, 0.3f, 0.0f), 0.5f), - new GradientColorKey(new Color(0.2f, 0.0f, 0.0f), 1.0f) - }, - new GradientAlphaKey[] { - new GradientAlphaKey(0.0f, 0.0f), - new GradientAlphaKey(0.6f, 0.2f), - new GradientAlphaKey(0.6f, 0.8f), - new GradientAlphaKey(0.0f, 1.0f) - } - ); - colorOverLifetime.color = grad; - } - } - } - if (!m_fireAuraVFX.activeSelf) m_fireAuraVFX.SetActive(true); - } - else - { - if (m_fireAuraVFX != null && m_fireAuraVFX.activeSelf) m_fireAuraVFX.SetActive(false); - } - } } } diff --git a/README.md b/README.md index 010b03d..d3141fa 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Three races grow a pair of their own, refused by the holster key and never dragg - **Base:** Born Dead, Buried Alive. -20% Slash/Pierce/Blunt; +50% Fire/Spirit taken. Poison resistant. Eats only raw flesh, eyes, entrails, blood. Swamp undead ignore you. - **Eikthyr:** Immune to Wet, swim faster, regen when wet/swimming. - **Elder:** Toxic Trace – attacks poison over time. -- **Bonemass:** Flesh and the Power It Holds – humanoids drop Human Meat food. Corpse Run permanently active. +- **Bonemass:** Flesh and the Power It Holds – a player who dies inside your death aura leaves Human Meat behind, yourself included. Only a Draugh can eat it. Corpse Run permanently active. - **Moder:** Parrying unleashes freezing nova (20s CD). - **Yagluth:** Zombie Ritual – fatal damage = ghost state, immune to damage, Eitr drains, die if Eitr hits 0. Raw food gives Eitr. - **Queen:** Swarm of Terror – being hit summons 2 Seeker Broods to fight for you.