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.
This commit is contained in:
kanym 2026-08-05 17:20:16 +02:00
commit 6b890f71c4
2 changed files with 134 additions and 16 deletions

View file

@ -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<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
private List<ItemDrop.ItemData> 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<float>("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
}
}
/// <summary>
/// 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.
/// </summary>
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<Animator>();
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<GameObject>("vfx_smoke") ??
PrefabManager.Cache.GetPrefab<GameObject>("vfx_surtling_death");
ParticleSystemRenderer sourceRenderer =
sourceVFX != null ? sourceVFX.GetComponentInChildren<ParticleSystemRenderer>() : null;
if (sourceRenderer == null) return;
headFlameVFX = new GameObject("SkeletonHeadFlameVFX");
headFlameVFX.transform.SetParent(Player.m_localPlayer.transform, false);
ParticleSystem ps = headFlameVFX.AddComponent<ParticleSystem>();
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<ParticleSystemRenderer>().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)