feat(skeleton): show the race on the main-menu character preview

The body swap read the race off the ZDO and gave up when there was none, which
is exactly the situation on the menu preview - FejdStartup instantiates a Player
and calls PlayerProfile.LoadPlayerData on it, so the preview knows its own custom
data and therefore its race, but it has no business owning a network view. It now
falls back to m_customData the way every other race in the mod already does, so a
Skeleton character looks like one before you press Start.

The tier falls back the same way. In the menu there is no world loaded to have
killed anything, so the preview is the base skeleton whatever the character has
done elsewhere.

feat(dvergar): age into a starred dverger's colours

One star at Bonemass, two at Fader.

Nothing is picked by eye. A starred creature in Valheim is not a second model: it
is the same one recoloured by LevelEffects, whose LevelSetup list holds a
hue/saturation/value offset per star. Those offsets are read off the Dverger
prefab at runtime and applied to the race's own slate blue-grey, so the tiers land
on the tints the game itself uses and keep following them if the prefab changes.

The tier comes from the ZDO key DvergarRace already publishes, so a remote Dvergar
is coloured at their own standing rather than the observer's - which matters as
soon as anyone runs personal progression.

Crossing a tier pushes a colour refresh through immediately, since the tint is
only written from the UpdateColors postfix and Valheim runs that on its own
schedule. Same treatment the health malus already gets a few lines above.

The hood is deliberately untouched.
This commit is contained in:
kanym 2026-08-05 19:27:34 +02:00
commit eabc1c54bf
6 changed files with 189 additions and 7 deletions

View file

@ -16,6 +16,55 @@ namespace RacesOfValheim
/// </summary>
public static class SkeletonVisuals
{
public const string RaceId = "Skeleton";
/// <summary>
/// Reads the race off the ZDO, falling back to m_customData.
///
/// The fallback is what makes the race show up on the main-menu character preview.
/// FejdStartup.SetupCharacterPreview instantiates a Player and calls
/// PlayerProfile.LoadPlayerData on it, which restores m_customData - so the preview does
/// know it is a Skeleton. What it has no business having is a ZNetView, and reading the
/// race from the ZDO alone meant the body swap gave up before it ever looked.
/// </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 IsSkeletonPlayer(Player player) => GetPlayerRace(player) == RaceId;
/// <summary>
/// The tier a given player's body should be built for. The ZDO carries it so remote
/// players render at their own standing; without one - the menu preview - fall back to
/// whatever this client can work out, which in the menu is the base tier, since there is
/// no world loaded to have killed anything.
/// </summary>
public static int GetProgressionState(Player player)
{
ZNetView nview = player != null ? player.GetComponent<ZNetView>() : null;
if (nview != null && nview.IsValid())
{
return nview.GetZDO().GetInt("RacesOfValheim_SkeletonState", 0);
}
return BossProgressionManager.GetCurrentProgressionState();
}
// 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 =