From 6b890f71c44992ebd9f730277e9239b32994054d Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 5 Aug 2026 17:20:16 +0200 Subject: [PATCH] fix(skeleton): keep Undead Fortitude on the player, and light the skull The poison immunity fix before this one was necessary but not sufficient: it kept the damage modifiers current, on an effect that was not there. SE_SkeletonStats carries every damage modifier the race has - pierce and slash resistance, the weakness to blunt, and the poison immunity - and it was applied in exactly one place, the moment the player clicked Skeleton in the race menu. Status effects are not saved with a character and do not survive death, so from the next respawn or the next login onward a Skeleton simply had none of them. That is why a blob still poisoned a tier 5 Skeleton. It is now re-applied whenever it is missing. The Moder regeneration bonus was broken the same way round: SkeletonRace wrote m_healthRegenMultiplier onto the registered template, but SEMan.AddStatusEffect clones what it is given and adds the clone, so the write reached nobody. The effect now sets it on itself, alongside the modifiers it already rebuilds per tier. Also lights the skull. Cosmetic only, worn with the fire-tier model and nothing else. It is parented to the player and moved onto the head bone each frame rather than parented to the bone: the rig is authored at roughly 100x and a particle system inheriting that would put a bonfire where a candle belongs. --- JotunnModStub/Skeleton/SkeletonRace.cs | 138 ++++++++++++++++-- .../Skeleton/SkeletonStatusEffects.cs | 12 +- 2 files changed, 134 insertions(+), 16 deletions(-) diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index 5243096..bca6620 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -49,8 +49,19 @@ namespace RacesOfValheim Player.m_localPlayer.m_customData["Race"] == "Skeleton"; } + private static readonly int StatsEffectHash = "SE_SkeletonStats".GetStableHashCode(); + private float lastAuraTime = 0f; private GameObject fireAuraVFX = null; + + // Flames on the skull. Purely cosmetic, and deliberately not parented to the head bone: + // the player rig is authored at roughly 100x, which would blow the particle sizes up with + // it. Kept under the player and moved onto the bone each frame instead. + private GameObject headFlameVFX = null; + private Transform headFlameBone = null; + + // Above the head bone's own origin, which sits at the base of the skull. + private const float HeadFlameHeight = 0.18f; private static List[] cachedRealFoods = new List[9]; private List GetBestRealFoods(int state) @@ -210,6 +221,17 @@ namespace RacesOfValheim } } + // Undead Fortitude carries every one of the race's damage modifiers - the pierce and + // slash resistance, the weakness to blunt, and the poison immunity. It was applied in + // exactly one place: the moment the player clicked "Skeleton" in the race menu. Status + // effects are not saved with a character and do not survive death, so from the next + // respawn or the next login onward a Skeleton had none of them, which is why poison + // still landed at tiers that grant immunity. Put it back whenever it is missing. + if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect(StatsEffectHash)) + { + Player.m_localPlayer.GetSEMan().AddStatusEffect(StatsEffectHash, true); + } + int state = BossProgressionManager.GetCurrentProgressionState(); var rules = SkeletonProgression.GetRules(state); @@ -331,25 +353,19 @@ namespace RacesOfValheim } } - // Enhanced Health Regeneration + // Enhanced Health Regeneration. The multiplier itself now lives on the status effect, + // which sets it on the live instance - writing it here only ever reached the template + // SEMan clones from, so it changed nothing for the player. What stays here is the tick + // rate, which is the player's own field. if (rules.EnhancedRegen) { - if (skeletonStatsSE != null) - { - skeletonStatsSE.m_healthRegenMultiplier = 1.5f; - } - // Speed up regen ticks by 20% (1.25x faster timer accumulation) float currentTimer = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_foodRegenTimer").Value; HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_foodRegenTimer").SetValue(currentTimer + Time.deltaTime * 0.25f); } - else - { - if (skeletonStatsSE != null) - { - skeletonStatsSE.m_healthRegenMultiplier = 1.0f; - } - } + + // Flames on the skull, worn with the fire-tier model and nothing else. + EnsureHeadFlameVFX(rules.ModelPrefab == SkeletonProgression.FireModel); if (rules.FireAura) { @@ -366,6 +382,102 @@ namespace RacesOfValheim } } + /// + /// Flames burning on the skull. Cosmetic only - it deals nothing and blocks nothing. + /// + /// Built from the same particle source as the fire aura, small and tight rather than a + /// cloud, and left in world simulation space so the flames trail behind a running player + /// instead of riding rigidly on the bone. The object is parented to the player and moved + /// onto the head each frame rather than being parented to the head bone itself: the + /// player's rig is authored at roughly 100x, and a particle system inheriting that scale + /// would put a bonfire where a candle belongs. + /// + private void EnsureHeadFlameVFX(bool enable) + { + if (!enable) + { + if (headFlameVFX != null && headFlameVFX.activeSelf) headFlameVFX.SetActive(false); + return; + } + + if (Player.m_localPlayer == null) return; + + if (headFlameVFX == null) + { + Animator anim = Player.m_localPlayer.GetComponentInChildren(); + 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; + + headFlameVFX = new GameObject("SkeletonHeadFlameVFX"); + headFlameVFX.transform.SetParent(Player.m_localPlayer.transform, false); + + ParticleSystem ps = headFlameVFX.AddComponent(); + + 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; + + headFlameVFX.GetComponent().material = sourceRenderer.material; + + 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))); + } + + if (!headFlameVFX.activeSelf) headFlameVFX.SetActive(true); + + // Follows the skull without inheriting its scale. + if (headFlameBone != null) + { + headFlameVFX.transform.position = headFlameBone.position + Vector3.up * HeadFlameHeight; + } + } + private void EnsureFireAuraVFX(bool enable) { if (enable && Player.m_localPlayer != null) diff --git a/JotunnModStub/Skeleton/SkeletonStatusEffects.cs b/JotunnModStub/Skeleton/SkeletonStatusEffects.cs index 398cd7b..553a760 100644 --- a/JotunnModStub/Skeleton/SkeletonStatusEffects.cs +++ b/JotunnModStub/Skeleton/SkeletonStatusEffects.cs @@ -11,7 +11,7 @@ namespace RacesOfValheim public override void Setup(Character character) { base.Setup(character); - RebuildDamageMods(); + RebuildForState(); } public override void UpdateStatusEffect(float dt) @@ -24,10 +24,10 @@ namespace RacesOfValheim // arrived: killing the boss changed the rules, and nothing ever asked them again. // Everything else the race does re-reads GetRules per hit, which is why only the // modifiers looked broken. Re-check here instead; the state comparison makes it free. - RebuildDamageMods(); + RebuildForState(); } - private void RebuildDamageMods() + private void RebuildForState() { int state = BossProgressionManager.GetCurrentProgressionState(); if (state == m_appliedState) return; @@ -35,6 +35,12 @@ namespace RacesOfValheim SkeletonProgression.SkeletonRules rules = SkeletonProgression.GetRules(state); + // Set here, on the live effect, rather than by SkeletonRace on the registered + // template: SEMan.AddStatusEffect clones what it is given and adds the clone, so + // anything written to the template afterwards reaches nobody. That is why the Moder + // regeneration bonus never applied either. + m_healthRegenMultiplier = rules.EnhancedRegen ? 1.5f : 1.0f; + m_mods = new List { new HitData.DamageModPair { m_type = HitData.DamageType.Pierce, m_modifier = HitData.DamageModifier.Resistant },