fix(skeleton): let everyone see the burning skull
The head flame was built inside SkeletonRace, a single MonoBehaviour that only ever looks at Player.m_localPlayer, so the fire existed on one client and on one player. Everyone else saw a bare skull. Same shape as the Draugh aura, same fix: the build moves to SkeletonVisuals.HeadFlame, which takes a Player, and RacesVisualController grows one for every remote skeleton it can see. Held per player rather than statically - a static would hand the second skeleton in view the first one is fire. Nothing is networked and nothing needs to be: the tier is already on the ZDO, so each client works out for itself who should be alight. The remote path also still collapsed the jaw at Fader, the charred-twitcher leftover that was removed from the local path two commits ago - so other players would have gone on seeing a Fader with no mandible. It is a restore there now too.
This commit is contained in:
parent
f012c96911
commit
892b970df4
3 changed files with 170 additions and 142 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Jotunn.Managers;
|
using Jotunn.Managers;
|
||||||
using Jotunn.Entities;
|
using Jotunn.Entities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -54,55 +54,11 @@ namespace RacesOfValheim
|
||||||
private float lastAuraTime = 0f;
|
private float lastAuraTime = 0f;
|
||||||
private GameObject fireAuraVFX = null;
|
private GameObject fireAuraVFX = null;
|
||||||
|
|
||||||
// Flames on the skull. Purely cosmetic, and deliberately not parented to the head bone:
|
// The local player's burning skull. The build lives in SkeletonVisuals so that
|
||||||
// the player rig is authored at roughly 100x, which would blow the particle sizes up with
|
// RacesVisualController can grow the same one on every remote skeleton - this script only
|
||||||
// it. Kept under the player and moved onto the bone each frame instead.
|
// ever sees the player at the keyboard, which is why nobody else could see the fire.
|
||||||
private GameObject headFlameVFX = null;
|
private readonly SkeletonVisuals.HeadFlame headFlame = new SkeletonVisuals.HeadFlame();
|
||||||
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;
|
|
||||||
|
|
||||||
// Torch flames are authored for a fist-sized fire on a stick, so the skull wears a big
|
|
||||||
// multiple of one. This was briefly dropped to 1.1 to get a clear look at the jaw
|
|
||||||
// underneath; the blaze is the point, so it is back where it was.
|
|
||||||
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;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
private static GameObject ResolveFlameSource()
|
|
||||||
{
|
|
||||||
if (flameSourceResolved) return cachedFlameSource;
|
|
||||||
flameSourceResolved = true;
|
|
||||||
|
|
||||||
foreach (string name in FlameSourcePrefabs)
|
|
||||||
{
|
|
||||||
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
|
||||||
if (prefab == null) continue;
|
|
||||||
if (prefab.GetComponentsInChildren<ParticleSystem>(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<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
|
private static List<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
|
||||||
|
|
||||||
private List<ItemDrop.ItemData> GetBestRealFoods(int state)
|
private List<ItemDrop.ItemData> GetBestRealFoods(int state)
|
||||||
|
|
@ -235,7 +191,7 @@ namespace RacesOfValheim
|
||||||
// Human kept a burning skull and a collapsed jaw, since neither the flame nor the
|
// 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.
|
// jaw was ever switched back from outside the Skeleton branch below.
|
||||||
EnsureFireAuraVFX(false);
|
EnsureFireAuraVFX(false);
|
||||||
EnsureHeadFlameVFX(false);
|
headFlame.Apply(Player.m_localPlayer, false);
|
||||||
RestoreJawBone();
|
RestoreJawBone();
|
||||||
|
|
||||||
if (Player.m_localPlayer.transform.localScale != Vector3.one)
|
if (Player.m_localPlayer.transform.localScale != Vector3.one)
|
||||||
|
|
@ -400,7 +356,7 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flames on the skull, worn with the fire-tier model and nothing else.
|
// Flames on the skull, worn with the fire-tier model and nothing else.
|
||||||
EnsureHeadFlameVFX(rules.ModelPrefab == SkeletonProgression.FireModel);
|
headFlame.Apply(Player.m_localPlayer, rules.ModelPrefab == SkeletonProgression.FireModel);
|
||||||
|
|
||||||
if (rules.FireAura)
|
if (rules.FireAura)
|
||||||
{
|
{
|
||||||
|
|
@ -436,84 +392,6 @@ 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 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;
|
|
||||||
|
|
||||||
// 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<ParticleSystem>(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);
|
|
||||||
|
|
||||||
// So the holder's scale actually enlarges the fire rather than just spreading
|
|
||||||
// out where the particles spawn.
|
|
||||||
ParticleSystem.MainModule main = copy.GetComponent<ParticleSystem>().main;
|
|
||||||
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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<Light>(true))
|
|
||||||
{
|
|
||||||
light.range *= 0.5f;
|
|
||||||
light.intensity *= 0.6f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Anything that made the source a torch rather than a fire.
|
|
||||||
foreach (MonoBehaviour comp in headFlameVFX.GetComponentsInChildren<MonoBehaviour>(true))
|
|
||||||
{
|
|
||||||
Destroy(comp);
|
|
||||||
}
|
|
||||||
foreach (Collider col in headFlameVFX.GetComponentsInChildren<Collider>(true))
|
|
||||||
{
|
|
||||||
Destroy(col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
private void EnsureFireAuraVFX(bool enable)
|
||||||
{
|
{
|
||||||
if (enable && Player.m_localPlayer != null)
|
if (enable && Player.m_localPlayer != null)
|
||||||
|
|
|
||||||
150
JotunnModStub/Skeleton/SkeletonVisuals.cs
Normal file
150
JotunnModStub/Skeleton/SkeletonVisuals.cs
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Skeleton's cosmetics that any client can grow for itself.
|
||||||
|
///
|
||||||
|
/// The head flame started life inside SkeletonRace, which is a single MonoBehaviour that only
|
||||||
|
/// ever looks at Player.m_localPlayer - so the fire existed on one client, on one player, and
|
||||||
|
/// everyone else saw a bare skull. Same shape of bug as the Draugh's aura, and the same fix:
|
||||||
|
/// the build takes a Player, and each client grows a copy for every skeleton it can see.
|
||||||
|
///
|
||||||
|
/// Nothing here is networked and nothing needs to be. The tier is already on the ZDO, so every
|
||||||
|
/// client can work out for itself whether a given skeleton should be alight.
|
||||||
|
/// </summary>
|
||||||
|
public static class SkeletonVisuals
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
private static GameObject ResolveFlameSource()
|
||||||
|
{
|
||||||
|
if (flameSourceResolved) return cachedFlameSource;
|
||||||
|
flameSourceResolved = true;
|
||||||
|
|
||||||
|
foreach (string name in FlameSourcePrefabs)
|
||||||
|
{
|
||||||
|
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
||||||
|
if (prefab == null) continue;
|
||||||
|
if (prefab.GetComponentsInChildren<ParticleSystem>(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One player's burning skull. Cosmetic only - it deals nothing and blocks nothing.
|
||||||
|
///
|
||||||
|
/// Held per player rather than statically: a static would hand the second skeleton in view
|
||||||
|
/// the first one's fire. Call Apply every frame; it builds once and then only follows.
|
||||||
|
/// </summary>
|
||||||
|
public class HeadFlame
|
||||||
|
{
|
||||||
|
// Above the head bone's own origin, which sits at the base of the skull.
|
||||||
|
private const float Height = 0.18f;
|
||||||
|
|
||||||
|
// Torch flames are authored for a fist-sized fire on a stick, so the skull wears a big
|
||||||
|
// multiple of one.
|
||||||
|
private const float Scale = 1.8f;
|
||||||
|
|
||||||
|
private GameObject m_instance;
|
||||||
|
private Transform m_headBone;
|
||||||
|
|
||||||
|
public void Apply(Player player, bool enable)
|
||||||
|
{
|
||||||
|
if (!enable)
|
||||||
|
{
|
||||||
|
if (m_instance != null && m_instance.activeSelf) m_instance.SetActive(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
if (m_instance == null && !Build(player)) return;
|
||||||
|
|
||||||
|
if (!m_instance.activeSelf) m_instance.SetActive(true);
|
||||||
|
|
||||||
|
// Follows the skull without inheriting its scale.
|
||||||
|
if (m_headBone != null)
|
||||||
|
{
|
||||||
|
m_instance.transform.position = m_headBone.position + Vector3.up * Height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Returns false while the pieces it needs are not ready yet.</summary>
|
||||||
|
private bool Build(Player player)
|
||||||
|
{
|
||||||
|
Animator anim = player.GetComponentInChildren<Animator>();
|
||||||
|
m_headBone = anim != null ? anim.GetBoneTransform(HumanBodyBones.Head) : null;
|
||||||
|
if (m_headBone == null) return false; // rig not up yet; try again next frame
|
||||||
|
|
||||||
|
GameObject source = ResolveFlameSource();
|
||||||
|
if (source == null) return false; // already logged once by the resolver
|
||||||
|
|
||||||
|
// Deliberately not parented to the head bone: the player rig is authored at
|
||||||
|
// roughly 100x, and a particle system inheriting that would put a bonfire where a
|
||||||
|
// candle belongs. It hangs off the player and is moved onto the bone each frame.
|
||||||
|
m_instance = new GameObject("SkeletonHeadFlameVFX");
|
||||||
|
m_instance.transform.SetParent(player.transform, false);
|
||||||
|
m_instance.transform.localScale = Vector3.one * Scale;
|
||||||
|
|
||||||
|
// 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<ParticleSystem>(true))
|
||||||
|
{
|
||||||
|
GameObject copy = Object.Instantiate(ps.gameObject, m_instance.transform);
|
||||||
|
copy.name = ps.gameObject.name;
|
||||||
|
copy.transform.localPosition = Vector3.zero;
|
||||||
|
copy.transform.localRotation = Quaternion.identity;
|
||||||
|
copy.SetActive(true);
|
||||||
|
|
||||||
|
// So the holder's scale actually enlarges the fire rather than just spreading
|
||||||
|
// out where the particles spawn.
|
||||||
|
ParticleSystem.MainModule main = copy.GetComponent<ParticleSystem>().main;
|
||||||
|
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 m_instance.GetComponentsInChildren<Light>(true))
|
||||||
|
{
|
||||||
|
light.range *= 0.5f;
|
||||||
|
light.intensity *= 0.6f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Anything that made the source a torch rather than a fire.
|
||||||
|
foreach (MonoBehaviour comp in m_instance.GetComponentsInChildren<MonoBehaviour>(true))
|
||||||
|
{
|
||||||
|
Object.Destroy(comp);
|
||||||
|
}
|
||||||
|
foreach (Collider col in m_instance.GetComponentsInChildren<Collider>(true))
|
||||||
|
{
|
||||||
|
Object.Destroy(col);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,7 @@ namespace RacesOfValheim
|
||||||
private GameObject m_currentFormInstance = null;
|
private GameObject m_currentFormInstance = null;
|
||||||
private GameObject m_fireAuraVFX = null;
|
private GameObject m_fireAuraVFX = null;
|
||||||
private GameObject m_draughAuraVFX = null;
|
private GameObject m_draughAuraVFX = null;
|
||||||
|
private readonly SkeletonVisuals.HeadFlame m_skeletonHeadFlame = new SkeletonVisuals.HeadFlame();
|
||||||
private float m_lastFlightLog = 0f;
|
private float m_lastFlightLog = 0f;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
|
|
@ -148,27 +149,25 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide Jaw for Charred Twitcher
|
// Fader used to collapse this bone here too, for the charred twitcher it wore at
|
||||||
|
// that tier. That model is gone and the skeleton in its place has a jaw of its
|
||||||
|
// own, so this is only a restore now - the same as the local path. Without it,
|
||||||
|
// other players would still see a Fader with no mandible.
|
||||||
if (vis.m_bodyModel != null && vis.m_bodyModel.bones != null)
|
if (vis.m_bodyModel != null && vis.m_bodyModel.bones != null)
|
||||||
{
|
{
|
||||||
foreach (Transform bone in vis.m_bodyModel.bones)
|
foreach (Transform bone in vis.m_bodyModel.bones)
|
||||||
{
|
{
|
||||||
if (bone != null && bone.name.ToLower().Contains("jaw"))
|
if (bone == null || !bone.name.ToLower().Contains("jaw")) continue;
|
||||||
{
|
if (bone.localScale == Vector3.zero) bone.localScale = Vector3.one;
|
||||||
if (state >= 8)
|
break;
|
||||||
{
|
|
||||||
if (bone.localScale != Vector3.zero) bone.localScale = Vector3.zero;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (bone.localScale == Vector3.zero) bone.localScale = Vector3.one;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The burning skull, grown locally for whoever we are looking at. The tier is on the
|
||||||
|
// ZDO, so this client can work out for itself whether they should be alight.
|
||||||
|
m_skeletonHeadFlame.Apply(m_player, rules.ModelPrefab == SkeletonProgression.FireModel);
|
||||||
|
|
||||||
// Apply Scale
|
// Apply Scale
|
||||||
Vector3 targetScale = rules.ScaleMultiplier;
|
Vector3 targetScale = rules.ScaleMultiplier;
|
||||||
if (m_player.transform.localScale != targetScale)
|
if (m_player.transform.localScale != targetScale)
|
||||||
|
|
@ -269,6 +268,7 @@ namespace RacesOfValheim
|
||||||
if (m_currentFormInstance != null) Destroy(m_currentFormInstance);
|
if (m_currentFormInstance != null) Destroy(m_currentFormInstance);
|
||||||
EnsureFireAuraVFX(false);
|
EnsureFireAuraVFX(false);
|
||||||
DraughVisuals.EnsureAura(m_player, false, ref m_draughAuraVFX);
|
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.
|
// Takes the crown off a Trenta who has died or changed race; a no-op for everyone else.
|
||||||
TrentaVisuals.ApplyCrown(m_player);
|
TrentaVisuals.ApplyCrown(m_player);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue