diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 4767e6c..0498b8b 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -298,14 +298,13 @@ namespace RacesOfValheim Transform[] newBones = new Transform[newSmr.bones.Length]; for (int i = 0; i < newSmr.bones.Length; i++) { - Transform matchedBone = FindBoneByName(playerBones, newSmr.bones[i].name); - newBones[i] = matchedBone != null ? matchedBone : playerBones[0]; + newBones[i] = ResolveBone(playerBones, newSmr.bones[i]); } newSmr.bones = newBones; - + if (newSmr.rootBone != null) { - newSmr.rootBone = FindBoneByName(playerBones, newSmr.rootBone.name) ?? playerBones[0]; + newSmr.rootBone = ResolveBone(playerBones, newSmr.rootBone); } } @@ -397,6 +396,32 @@ namespace RacesOfValheim catch (System.Exception e) { } } + /// + /// Finds the player bone a creature bone should be skinned to. + /// + /// A creature rig carries bones a human rig has no answer for - a jaw above all, but + /// also teeth and tails. Those used to fall back to bones[0], the root, which skinned + /// the mandible to the hips and left it hanging off the side of the skull. Follow the + /// creature's own hierarchy upward instead until something matches, so a jaw lands on + /// the head and rides it. It cannot open any more, which no player will notice, and it + /// is attached, which every player did. + /// + private static Transform ResolveBone(Transform[] playerBones, Transform sourceBone) + { + if (sourceBone == null) return playerBones[0]; + + Transform direct = FindBoneByName(playerBones, sourceBone.name); + if (direct != null) return direct; + + for (Transform parent = sourceBone.parent; parent != null; parent = parent.parent) + { + Transform match = FindBoneByName(playerBones, parent.name); + if (match != null) return match; + } + + return playerBones[0]; + } + private static Transform FindBoneByName(Transform[] bones, string skelBoneName) { // Exact match first diff --git a/JotunnModStub/Skeleton/SkeletonProgression.cs b/JotunnModStub/Skeleton/SkeletonProgression.cs index 1225a90..2e6d9d6 100644 --- a/JotunnModStub/Skeleton/SkeletonProgression.cs +++ b/JotunnModStub/Skeleton/SkeletonProgression.cs @@ -49,6 +49,11 @@ namespace RacesOfValheim public const string SummonPrefabName = "Skeleton_friendly"; + // Fader's dead stand taller than everyone else's. Applied to the player's root transform, + // which is how this race has always sized itself - so it carries the collider, the camera + // pivot and every equipment attachment up with it, rather than only the mesh. + public static readonly UnityEngine.Vector3 FaderScale = UnityEngine.Vector3.one * 1.15f; + /// /// Every tier, exactly as the race's published progression describes it. The table had /// drifted a long way from that description - poison immunity arrived two tiers late, @@ -115,6 +120,7 @@ namespace RacesOfValheim { rules.LifestealPercent = 0.35f; rules.MaxSummons = 5; + rules.ScaleMultiplier = FaderScale; } return rules; diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index bca6620..9ba8679 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -62,6 +62,46 @@ namespace RacesOfValheim // Above the head bone's own origin, which sits at the base of the skull. private const float HeadFlameHeight = 0.18f; + + // Torch flames are authored for a fist-sized fire on a stick. This is the two knobs to + // turn if the skull ends up wearing a bonfire or a birthday candle. + private const float HeadFlameScale = 1.8f; + + // Fire sources in preference order. The torch is an item every world has; the ground + // torch and the fire pit are the building pieces to fall back on. + private static readonly string[] FlameSourcePrefabs = + { + "Torch", "piece_groundtorch_wood", "piece_groundtorch", "fire_pit" + }; + + private static GameObject cachedFlameSource; + private static bool flameSourceResolved; + + /// + /// Finds a vanilla prefab that carries real fire particles. Resolved once per session, + /// failure included, so a miss cannot turn into a per-frame log. + /// + private static GameObject ResolveFlameSource() + { + if (flameSourceResolved) return cachedFlameSource; + flameSourceResolved = true; + + foreach (string name in FlameSourcePrefabs) + { + GameObject prefab = PrefabManager.Cache.GetPrefab(name); + if (prefab == null) continue; + if (prefab.GetComponentsInChildren(true).Length == 0) continue; + + Jotunn.Logger.LogInfo($"[Skeleton] Head flame source resolved to '{name}'."); + cachedFlameSource = prefab; + return cachedFlameSource; + } + + Jotunn.Logger.LogWarning( + "[Skeleton] No fire prefab resolved (" + string.Join(", ", FlameSourcePrefabs) + + "); the skull stays unlit."); + return null; + } private static List[] cachedRealFoods = new List[9]; private List GetBestRealFoods(int state) @@ -408,65 +448,47 @@ namespace RacesOfValheim headFlameBone = anim != null ? anim.GetBoneTransform(HumanBodyBones.Head) : null; if (headFlameBone == null) return; // rig not up yet; try again next frame - GameObject sourceVFX = PrefabManager.Cache.GetPrefab("vfx_smoke") ?? - PrefabManager.Cache.GetPrefab("vfx_surtling_death"); - ParticleSystemRenderer sourceRenderer = - sourceVFX != null ? sourceVFX.GetComponentInChildren() : null; - if (sourceRenderer == null) return; + GameObject source = ResolveFlameSource(); + if (source == null) return; // already logged once by the resolver headFlameVFX = new GameObject("SkeletonHeadFlameVFX"); headFlameVFX.transform.SetParent(Player.m_localPlayer.transform, false); + headFlameVFX.transform.localScale = Vector3.one * HeadFlameScale; - ParticleSystem ps = headFlameVFX.AddComponent(); + // Real fire is cloned rather than built by hand. The first attempt at this made a + // particle system from scratch on the smoke material, and a hand-rolled gradient + // over a smoke sprite reads as a wisp, not a burning skull. + foreach (ParticleSystem ps in source.GetComponentsInChildren(true)) + { + GameObject copy = Instantiate(ps.gameObject, headFlameVFX.transform); + copy.name = ps.gameObject.name; + copy.transform.localPosition = Vector3.zero; + copy.transform.localRotation = Quaternion.identity; + copy.SetActive(true); - var main = ps.main; - main.loop = true; - main.duration = 1f; - main.startLifetime = new ParticleSystem.MinMaxCurve(0.35f, 0.6f); - main.startSize = new ParticleSystem.MinMaxCurve(0.18f, 0.38f); - main.startSpeed = new ParticleSystem.MinMaxCurve(0.4f, 0.9f); - main.simulationSpace = ParticleSystemSimulationSpace.World; + // So the holder's scale actually enlarges the fire rather than just spreading + // out where the particles spawn. + ParticleSystem.MainModule main = copy.GetComponent().main; + main.scalingMode = ParticleSystemScalingMode.Hierarchy; + } - headFlameVFX.GetComponent().material = sourceRenderer.material; + // A torch's own light is tuned to light a corridor from waist height; on a head it + // blows out the whole face. Keep the glow, lose the floodlight. + foreach (Light light in headFlameVFX.GetComponentsInChildren(true)) + { + light.range *= 0.5f; + light.intensity *= 0.6f; + } - var shape = ps.shape; - shape.shapeType = ParticleSystemShapeType.Sphere; - shape.radius = 0.11f; - - var emission = ps.emission; - emission.rateOverTime = 28f; - - // Straight up, so it reads as burning rather than drifting. - var velocity = ps.velocityOverLifetime; - velocity.enabled = true; - velocity.space = ParticleSystemSimulationSpace.World; - velocity.y = new ParticleSystem.MinMaxCurve(0.5f); - - var colorOverLifetime = ps.colorOverLifetime; - colorOverLifetime.enabled = true; - Gradient grad = new Gradient(); - grad.SetKeys( - new GradientColorKey[] - { - new GradientColorKey(new Color(1f, 0.95f, 0.55f), 0.0f), // pale yellow core - new GradientColorKey(new Color(1f, 0.45f, 0.05f), 0.45f), // orange - new GradientColorKey(new Color(0.35f, 0.05f, 0.0f), 1.0f) // ember, guttering out - }, - new GradientAlphaKey[] - { - new GradientAlphaKey(0.0f, 0.0f), - new GradientAlphaKey(0.8f, 0.15f), - new GradientAlphaKey(0.5f, 0.7f), - new GradientAlphaKey(0.0f, 1.0f) - } - ); - colorOverLifetime.color = grad; - - // Tapers as it rises, the way a flame narrows toward its tip. - var sizeOverLifetime = ps.sizeOverLifetime; - sizeOverLifetime.enabled = true; - sizeOverLifetime.size = new ParticleSystem.MinMaxCurve( - 1f, new AnimationCurve(new Keyframe(0f, 0.6f), new Keyframe(0.3f, 1f), new Keyframe(1f, 0.15f))); + // Anything that made the source a torch rather than a fire. + foreach (MonoBehaviour comp in headFlameVFX.GetComponentsInChildren(true)) + { + Destroy(comp); + } + foreach (Collider col in headFlameVFX.GetComponentsInChildren(true)) + { + Destroy(col); + } } if (!headFlameVFX.activeSelf) headFlameVFX.SetActive(true);