Add the Race Menu Ward; WIP on remote Trol/Skadi visuals

Race Menu Ward: a buildable ward (2 wood, hammer/Misc, no crafting station)
that manages your race outside the debug console - reset the race, switch
between the server's boss progression and your own, and advance that personal
progression by offering a boss's secondary drop to it. One is placed near the
sacrificial stones on first load of a world, by the host only.

BossProgressionManager grows a personal mode alongside the world one. The tier
is stored on the character rather than the world, so a personal tier travels
with the player between servers instead of being tied to whichever world
unlocked it. resetrace and the ward now share RacesOfValheim.ResetRace so both
paths clean up identical state.

Also in progress, and NOT yet working: remote Trol sizing and remote Skadi
flight. Both are computed from the observer instead of the observed -

- Remote Trols are scaled from the observing player's own progression, and
  never show True Form, because SE_TrolTrueForm only exists on the transformed
  player's client. Each Trol now publishes its state and True Form flag onto
  its own ZDO for others to read.
- Remote Skadi dragons sink to the terrain regardless of the altitude being
  replicated: Character.m_flying is only ever set on the flying player's
  client, so observers run grounded motion under gravity. Flight is mirrored
  through the ZDO and the remote copy's rigidbody gravity is disabled while it
  lasts.

Neither has fixed the symptom yet, so both paths keep a throttled diagnostic
log reporting what each observer actually computes. Committed to get the
instrumentation onto the branch, not because it works.

Packaging no longer hardcodes another machine's desktop path: Thunderstore and
Nexus zips go to dist/ on Release builds only, and the DLL is copied into
Valheim only when VALHEIM_INSTALL actually points at a plugins folder.
This commit is contained in:
kanym 2026-08-02 08:45:47 +02:00
commit 5350ebda5d
7 changed files with 636 additions and 76 deletions

View file

@ -88,45 +88,88 @@ namespace RacesOfValheim
[HarmonyPatch(typeof(Player), "Update")]
public static class Trol_PlayerUpdate_Patch
{
// Published by each player onto their own ZDO. The size a Trol should be depends on that
// Trol's progression and True Form, both of which used to be read from whoever happened to
// be looking - so observers sized remote Trols from their own tier, and never saw True
// Form at all because the status effect only exists on the transformed player's client.
public const string StateKey = "RacesOfValheim_State";
public const string TrueFormKey = "RacesOfValheim_TrolTrueForm";
private static float lastRemoteLog = 0f;
private static float ScaleForState(int state)
{
if (state >= 6) return 1.30f;
if (state >= 4) return 1.25f;
return 1.2f;
}
public static void Postfix(Player __instance)
{
if (__instance == null) return;
string race = "Human"; ZNetView nview = __instance.GetComponent<ZNetView>(); if (nview != null && nview.IsValid()) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human"); else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace; if (race == "Trol")
{
// Scale player visuals up by 20%
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
// Prevent overriding scale while transforming or in True Form
bool isTrueFormActive = __instance.GetSEMan() != null && __instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
bool isTransforming = (__instance == Player.m_localPlayer && TrolRace.Instance != null && TrolRace.Instance.isTransforming);
if (!isTrueFormActive && !isTransforming)
{
float targetScale = 1.2f;
int state = BossProgressionManager.GetCurrentProgressionState();
if (state >= 6) targetScale = 1.30f;
else if (state >= 4) targetScale = 1.25f;
if (visual != null && visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale))
{
visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale);
}
ZNetView nview = __instance.GetComponent<ZNetView>();
bool zdoReady = nview != null && nview.IsValid();
string race = "Human";
if (zdoReady) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace;
bool isLocal = __instance == Player.m_localPlayer;
bool isTrueFormActive;
int state;
if (isLocal)
{
state = BossProgressionManager.GetCurrentProgressionState();
isTrueFormActive = __instance.GetSEMan() != null &&
__instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
// Publish so everyone else can size this character correctly.
if (zdoReady)
{
nview.GetZDO().Set(StateKey, state);
nview.GetZDO().Set(TrueFormKey, isTrueFormActive);
}
}
else
{
// Reset scale if not Trol
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
int state = BossProgressionManager.GetCurrentProgressionState();
float targetScale = 1.2f;
if (state >= 6) targetScale = 1.30f;
else if (state >= 4) targetScale = 1.25f;
state = zdoReady ? nview.GetZDO().GetInt(StateKey, BossProgressionManager.MinState) : BossProgressionManager.MinState;
isTrueFormActive = zdoReady && nview.GetZDO().GetBool(TrueFormKey, false);
}
if (visual != null && visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale))
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
if (visual == null) return;
float targetScale = ScaleForState(state);
// TEMPORARY: remote Trol sizing still is not showing up for observers and static
// reading has not explained why, so report what each observer actually computes.
if (!isLocal && Time.time - lastRemoteLog > 2f)
{
lastRemoteLog = Time.time;
Jotunn.Logger.LogInfo(
$"[TrolSync] remote '{__instance.GetPlayerName()}' race='{race}' zdoReady={zdoReady} " +
$"state={state} trueForm={isTrueFormActive} target={targetScale:F2} " +
$"currentScale={visual.transform.localScale.x:F2} rootScale={__instance.transform.localScale.x:F2}");
}
if (race == "Trol")
{
// Prevent overriding scale while transforming or in True Form
bool isTransforming = isLocal && TrolRace.Instance != null && TrolRace.Instance.isTransforming;
if (!isTrueFormActive && !isTransforming &&
visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale))
{
visual.transform.localScale = Vector3.one;
visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale);
}
}
else if (visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale))
{
// Reset scale if not Trol
visual.transform.localScale = Vector3.one;
}
}
}