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
|
|
@ -52,6 +52,27 @@ namespace RacesOfValheim
|
|||
|
||||
public static readonly Color HairColor = new Color(0.06f, 0.28f, 0.08f, 1f);
|
||||
|
||||
// ─── Crown of branches ───────────────────────────────────────────────
|
||||
// A greydwarf shaman wears a crown of horns and dead wood, and it is the one piece of
|
||||
// vanilla art that says "this one grew rather than was born". The whole trophy is hung on
|
||||
// the player's head bone and then sunk into the skull until only the branches clear it -
|
||||
// the same trick the Furling uses to wear a goblin head, aimed at a different result.
|
||||
public const string CrownTrophyPrefabName = "TrophyGreydwarfShaman";
|
||||
|
||||
// Bone the crown is hung from on the player's own rig.
|
||||
public const string PlayerHeadBoneName = "Head";
|
||||
|
||||
// These three are the ones to eyeball in game; everything else about the crown is fixed.
|
||||
// Valheim's player rig is authored at roughly 100x, which is why bone-local numbers are
|
||||
// this small - the Furling's goblin head sits at 0.0058 for comparison.
|
||||
//
|
||||
// Y is up in the head bone's frame, so lowering it sinks the trophy deeper and shows less
|
||||
// of the crown. Too high and a shrunken greydwarf face floats out of the player's own; too
|
||||
// low and the branches disappear into the scalp.
|
||||
public static readonly Vector3 CrownOffsetPosition = new Vector3(0.0005f, 0.0008f, 0f);
|
||||
public static readonly Vector3 CrownOffsetRotation = new Vector3(-90f, 0f, 90f);
|
||||
public static readonly float CrownScale = 0.0070f;
|
||||
|
||||
// ─── Progression tables ──────────────────────────────────────────────
|
||||
// Indexed by progression state; index 0 is unused so the state number indexes directly.
|
||||
// 1 Base, 2 Eikthyr, 3 The Elder, 4 Bonemass, 5 Moder, 6 Yagluth, 7 The Queen, 8 Fader.
|
||||
|
|
|
|||
|
|
@ -62,6 +62,25 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hangs the crown of branches on, for every player local and remote, whenever Valheim
|
||||
/// rebuilds their visuals - which is also the moment a rebuilt body model would have
|
||||
/// thrown the old crown away with the old head bone.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
||||
public static class Trenta_VisEquipment_UpdateVisuals_Patch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (__instance == null || !__instance.m_isPlayer) return;
|
||||
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null) return;
|
||||
|
||||
TrentaVisuals.ApplyCrown(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Diet (vegan restriction, digestion doubling, awakened seeds) lives in
|
||||
// TrentaFoodPatches.cs, the way DraughFoodPatches.cs holds the Draugh's equivalent.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
|
|
@ -44,10 +45,164 @@ namespace RacesOfValheim
|
|||
// Body scale goes on the player's "Visual" child, not the root transform - scaling the
|
||||
// root drags the collider and the camera pivot with it. RaceScale owns the list of races
|
||||
// that resize, so the Trenta has to be added there rather than fighting it per-frame.
|
||||
//
|
||||
// Extra meshes (bark, foliage) are hung off a bone of the player's rig and hidden by
|
||||
// collapsing every unwanted bone to zero scale - a creature prefab's mesh usually ships
|
||||
// with Read/Write disabled and cannot be carved at runtime. DvergarVisuals.ApplyHood is
|
||||
// the worked example.
|
||||
|
||||
// ─── Crown of branches ───────────────────────────────────────────────
|
||||
|
||||
private const string CrownName = "TrentaCrown";
|
||||
|
||||
// Resolved once per session, failure included, so a missing prefab cannot turn into a
|
||||
// per-frame log and the prefab lookup does not run again for every player in view.
|
||||
private static GameObject cachedCrownVisual;
|
||||
private static bool crownResolved;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps the crown in step with who the player is. Safe to call every frame: it checks
|
||||
/// whether the crown is already there and does nothing when it is.
|
||||
/// </summary>
|
||||
public static void ApplyCrown(Player player)
|
||||
{
|
||||
VisEquipment visEq = player != null ? player.GetComponent<VisEquipment>() : null;
|
||||
if (visEq == null) return;
|
||||
|
||||
if (IsTrentaPlayer(player) && !player.IsDead())
|
||||
{
|
||||
EnsureCrown(visEq);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveCrown(visEq);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hangs a greydwarf shaman trophy on the player's head, sunk far enough into the skull
|
||||
/// that only the horns and branches clear it.
|
||||
///
|
||||
/// A trophy is a plain static mesh, so unlike the Dvergar's hood there is no rig to
|
||||
/// collapse and no submesh to isolate - the whole thing is instantiated and then buried,
|
||||
/// and the player's own head does the hiding. Which means the three numbers in
|
||||
/// TrentaConfig are the entire look: get the depth wrong and a tiny greydwarf face floats
|
||||
/// in front of the player's.
|
||||
/// </summary>
|
||||
private static void EnsureCrown(VisEquipment visEq)
|
||||
{
|
||||
if (visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return;
|
||||
|
||||
Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, TrentaConfig.PlayerHeadBoneName);
|
||||
if (playerHead == null) return;
|
||||
|
||||
if (playerHead.Find(CrownName) != null) return; // already wearing it
|
||||
|
||||
GameObject source = ResolveCrownVisual();
|
||||
if (source == null) return; // already logged once by the resolver
|
||||
|
||||
// Instantiated inactive so the trophy's own Awake never runs - it would register a
|
||||
// pickup, a hover prompt and a rigidbody on the player's head.
|
||||
bool wasActive = source.activeSelf;
|
||||
source.SetActive(false);
|
||||
GameObject crown = Object.Instantiate(source, playerHead, false);
|
||||
source.SetActive(wasActive);
|
||||
|
||||
crown.name = CrownName;
|
||||
StripComponents(crown);
|
||||
crown.SetActive(true);
|
||||
|
||||
crown.transform.localPosition = TrentaConfig.CrownOffsetPosition;
|
||||
crown.transform.localRotation = Quaternion.Euler(TrentaConfig.CrownOffsetRotation);
|
||||
crown.transform.localScale = Vector3.one * TrentaConfig.CrownScale;
|
||||
|
||||
ApplyDitherShader(crown);
|
||||
}
|
||||
|
||||
private static void RemoveCrown(VisEquipment visEq)
|
||||
{
|
||||
if (visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return;
|
||||
|
||||
Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, TrentaConfig.PlayerHeadBoneName);
|
||||
Transform crown = playerHead != null ? playerHead.Find(CrownName) : null;
|
||||
if (crown == null) return;
|
||||
|
||||
// Destroy is deferred to the end of the frame, so rename first: without that, every
|
||||
// call until it actually goes away finds it again and queues another destroy.
|
||||
crown.name = CrownName + "_Removed";
|
||||
Object.Destroy(crown.gameObject);
|
||||
}
|
||||
|
||||
private static GameObject ResolveCrownVisual()
|
||||
{
|
||||
if (crownResolved) return cachedCrownVisual;
|
||||
crownResolved = true;
|
||||
|
||||
ItemDrop trophy = PrefabManager.Cache.GetPrefab<ItemDrop>(TrentaConfig.CrownTrophyPrefabName);
|
||||
if (trophy == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning(
|
||||
$"[Trenta] Prefab '{TrentaConfig.CrownTrophyPrefabName}' not found; no crown.");
|
||||
return null;
|
||||
}
|
||||
|
||||
cachedCrownVisual = trophy.gameObject;
|
||||
Jotunn.Logger.LogInfo($"[Trenta] Crown source resolved to '{TrentaConfig.CrownTrophyPrefabName}'.");
|
||||
return cachedCrownVisual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strips everything that would make a dropped item behave like one: the ItemDrop itself,
|
||||
/// hover prompts and physics, plus the LODGroup, which is not a MonoBehaviour and would
|
||||
/// otherwise hide the mesh at the distances it was authored for as a floor pickup.
|
||||
/// </summary>
|
||||
private static void StripComponents(GameObject obj)
|
||||
{
|
||||
foreach (MonoBehaviour comp in obj.GetComponentsInChildren<MonoBehaviour>(true))
|
||||
{
|
||||
Object.DestroyImmediate(comp);
|
||||
}
|
||||
foreach (LODGroup lod in obj.GetComponentsInChildren<LODGroup>(true))
|
||||
{
|
||||
Object.DestroyImmediate(lod);
|
||||
}
|
||||
foreach (Rigidbody body in obj.GetComponentsInChildren<Rigidbody>(true))
|
||||
{
|
||||
Object.DestroyImmediate(body);
|
||||
}
|
||||
foreach (Collider col in obj.GetComponentsInChildren<Collider>(true))
|
||||
{
|
||||
Object.DestroyImmediate(col);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Without the creature shader the crown ignores the camera's dither fade and fills the
|
||||
/// screen in first person; its own textures are kept.
|
||||
/// </summary>
|
||||
private static void ApplyDitherShader(GameObject obj)
|
||||
{
|
||||
Shader dither = Shader.Find("Custom/Creature");
|
||||
if (dither == null) return;
|
||||
|
||||
foreach (Renderer renderer in obj.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer.material != null) renderer.material.shader = dither;
|
||||
}
|
||||
}
|
||||
|
||||
private static Transform FindBoneByName(Transform[] bones, string targetBoneName)
|
||||
{
|
||||
if (bones == null || string.IsNullOrEmpty(targetBoneName)) return null;
|
||||
|
||||
foreach (Transform bone in bones)
|
||||
{
|
||||
if (bone != null && bone.name == targetBoneName) return bone;
|
||||
}
|
||||
|
||||
string target = targetBoneName.ToLower();
|
||||
foreach (Transform bone in bones)
|
||||
{
|
||||
if (bone == null) continue;
|
||||
string name = bone.name.ToLower();
|
||||
if (name == target || name.Contains(target) || target.Contains(name)) return bone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue