feat(trenta): grow a crown of branches, and fix(draugh): let everyone see the rot
Trenta: a greydwarf shaman trophy is hung on the player head bone and sunk into the skull until only the horns and branches clear it - the Furling wears a goblin head the same way, aimed at the opposite result. A trophy is a plain static mesh, so unlike the Dvergar hood there is no rig to collapse: the player own head does all the hiding, which makes the three offsets in TrentaConfig the entire look. They are a first pass and want eyeballing in game. Draugh: the smoke and the cloud of flies only ever existed on the client of the player wearing them. DraughRace is a single MonoBehaviour that looks at Player.m_localPlayer and nothing else, so in multiplayer every other player saw an ordinary, unrotted Viking. The build moved to DraughVisuals, which takes a Player, and RacesVisualController now grows the same aura on every remote Draugh it can see. Nothing is networked and nothing needs to be - each client reads the race off the ZDO and makes its own particles. Both hang off VisEquipment.UpdateVisuals or the visual controller, the two hooks that already run for remote players, so neither had to invent a sync path.
This commit is contained in:
parent
a5a64b3c6b
commit
67e445014f
7 changed files with 345 additions and 70 deletions
|
|
@ -112,71 +112,14 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The local player's half of the aura. The build itself moved to DraughVisuals so that
|
||||
/// RacesVisualController can grow the same one on every remote Draugh - this script only
|
||||
/// ever sees the player at the keyboard, which is why nobody else could see the rot.
|
||||
/// </summary>
|
||||
private void EnsureVFX(bool enable)
|
||||
{
|
||||
if (enable && Player.m_localPlayer != null)
|
||||
{
|
||||
if (draughVFX == null)
|
||||
{
|
||||
GameObject draugrPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("Draugr");
|
||||
if (draugrPrefab != null)
|
||||
{
|
||||
draughVFX = new GameObject("DraughAuraVFX");
|
||||
draughVFX.transform.SetParent(Player.m_localPlayer.transform, false);
|
||||
// Centro del giocatore invece che il pivot (piedi)
|
||||
draughVFX.transform.localPosition = new Vector3(0, 1f, 0);
|
||||
|
||||
// Find all ParticleSystems in Draugr prefab
|
||||
ParticleSystem[] pss = draugrPrefab.GetComponentsInChildren<ParticleSystem>(true);
|
||||
foreach (ParticleSystem ps in pss)
|
||||
{
|
||||
// We only want looping ambient effects (flies, smoke)
|
||||
if (ps.main.loop)
|
||||
{
|
||||
GameObject psCopy = Instantiate(ps.gameObject, draughVFX.transform);
|
||||
psCopy.name = ps.gameObject.name;
|
||||
psCopy.SetActive(true);
|
||||
|
||||
// Entrambi (fumo e mosche) partono esattamente dal centro
|
||||
psCopy.transform.localPosition = Vector3.zero;
|
||||
psCopy.transform.localRotation = ps.transform.localRotation;
|
||||
|
||||
string psName = psCopy.name.ToLower();
|
||||
|
||||
if (psName.Contains("flies"))
|
||||
{
|
||||
// Flies effect: leave as is
|
||||
}
|
||||
else if (psName.Contains("drip") || psName.Contains("drop") || psName.Contains("rain") || psName.Contains("splash"))
|
||||
{
|
||||
// Effetto 3 (pioggia): disattivato
|
||||
psCopy.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Smoke effect: scale reduced to 1.5f (-40% of 2.5f)
|
||||
psCopy.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||||
|
||||
var main = psCopy.GetComponent<ParticleSystem>().main;
|
||||
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (draughVFX != null && !draughVFX.activeSelf)
|
||||
{
|
||||
draughVFX.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (draughVFX != null && draughVFX.activeSelf)
|
||||
{
|
||||
draughVFX.SetActive(false);
|
||||
}
|
||||
}
|
||||
DraughVisuals.EnsureAura(Player.m_localPlayer, enable, ref draughVFX);
|
||||
}
|
||||
|
||||
public System.Collections.IEnumerator UndyingWillRoutine(Player p)
|
||||
|
|
|
|||
121
JotunnModStub/Draugh/DraughVisuals.cs
Normal file
121
JotunnModStub/Draugh/DraughVisuals.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Draugh's rot: the drifting smoke and the cloud of flies a Draugr carries, copied off the
|
||||
/// Draugr prefab and hung on a player.
|
||||
///
|
||||
/// This used to live inside DraughRace, which is a single MonoBehaviour that only ever looks at
|
||||
/// Player.m_localPlayer - so the aura existed on exactly one client, on exactly one player, and
|
||||
/// everyone else in a multiplayer session saw a perfectly clean corpse walking around. The build
|
||||
/// is here instead, taking a Player, so the local player and every remote one get the same
|
||||
/// treatment from their own client.
|
||||
///
|
||||
/// Nothing here is networked, and it does not need to be: every client can tell a Draugh from
|
||||
/// the race on the ZDO and grow its own copy of the particles.
|
||||
/// </summary>
|
||||
public static class DraughVisuals
|
||||
{
|
||||
public const string RaceId = "Draugh";
|
||||
|
||||
private const string AuraName = "DraughAuraVFX";
|
||||
|
||||
// Chest height rather than the pivot, which sits at the feet.
|
||||
private static readonly Vector3 AuraLocalPosition = new Vector3(0f, 1f, 0f);
|
||||
|
||||
// The Draugr's smoke is authored for a creature that stands taller than a player.
|
||||
private static readonly Vector3 SmokeScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||||
|
||||
/// <summary>
|
||||
/// Reads the race off the ZDO so remote players are recognised, falling back to
|
||||
/// m_customData for the main-menu preview which has no ZNetView.
|
||||
/// </summary>
|
||||
public static string GetPlayerRace(Player player)
|
||||
{
|
||||
if (player == null) return "Human";
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
|
||||
if (!string.IsNullOrEmpty(race)) return race;
|
||||
}
|
||||
|
||||
if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string custom))
|
||||
{
|
||||
return custom;
|
||||
}
|
||||
|
||||
return "Human";
|
||||
}
|
||||
|
||||
public static bool IsDraughPlayer(Player player) => GetPlayerRace(player) == RaceId;
|
||||
|
||||
/// <summary>
|
||||
/// Puts the aura on the player, or takes it away. Safe to call every frame: the particles
|
||||
/// are built once and then only toggled. The caller owns the instance - it is per-player,
|
||||
/// and a static would give the second Draugh in view the first one's aura.
|
||||
/// </summary>
|
||||
public static void EnsureAura(Player player, bool enable, ref GameObject aura)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (player == null) return;
|
||||
if (aura == null) aura = BuildAura(player);
|
||||
if (aura != null && !aura.activeSelf) aura.SetActive(true);
|
||||
}
|
||||
else if (aura != null && aura.activeSelf)
|
||||
{
|
||||
aura.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clones the Draugr's own looping particle systems onto the player. Looping is the filter
|
||||
/// that separates the ambient rot from one-shot hit and death effects.
|
||||
/// </summary>
|
||||
private static GameObject BuildAura(Player player)
|
||||
{
|
||||
GameObject draugrPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("Draugr");
|
||||
if (draugrPrefab == null) return null;
|
||||
|
||||
GameObject aura = new GameObject(AuraName);
|
||||
aura.transform.SetParent(player.transform, false);
|
||||
aura.transform.localPosition = AuraLocalPosition;
|
||||
|
||||
foreach (ParticleSystem ps in draugrPrefab.GetComponentsInChildren<ParticleSystem>(true))
|
||||
{
|
||||
if (!ps.main.loop) continue;
|
||||
|
||||
GameObject copy = Object.Instantiate(ps.gameObject, aura.transform);
|
||||
copy.name = ps.gameObject.name;
|
||||
copy.SetActive(true);
|
||||
|
||||
// Both the smoke and the flies start from the same point, the player's centre.
|
||||
copy.transform.localPosition = Vector3.zero;
|
||||
copy.transform.localRotation = ps.transform.localRotation;
|
||||
|
||||
string name = copy.name.ToLower();
|
||||
|
||||
if (name.Contains("flies"))
|
||||
{
|
||||
// The flies are the whole point - left exactly as the Draugr wears them.
|
||||
}
|
||||
else if (name.Contains("drip") || name.Contains("drop") || name.Contains("rain") || name.Contains("splash"))
|
||||
{
|
||||
// Dripping water reads as rain coming off the player. Not wanted.
|
||||
copy.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
copy.transform.localScale = SmokeScale;
|
||||
ParticleSystem.MainModule main = copy.GetComponent<ParticleSystem>().main;
|
||||
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
|
||||
}
|
||||
}
|
||||
|
||||
return aura;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue