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:
parent
93157632a4
commit
eabc1c54bf
6 changed files with 189 additions and 7 deletions
|
|
@ -47,6 +47,109 @@ namespace RacesOfValheim
|
|||
|
||||
public static bool IsDvergarPlayer(Player player) => GetPlayerRace(player) == DvergarConfig.RaceId;
|
||||
|
||||
// ─── Star colours ────────────────────────────────────────────────────
|
||||
|
||||
// Read once per session, failure included.
|
||||
private static LevelEffects.LevelSetup[] cachedStarSetups;
|
||||
private static bool starSetupsResolved;
|
||||
|
||||
/// <summary>
|
||||
/// How many stars the Dvergar's colouring has earned: one at Bonemass, two at Fader.
|
||||
/// </summary>
|
||||
public static int GetStarTier(int state)
|
||||
{
|
||||
if (state >= DvergarConfig.TwoStarState) return 2;
|
||||
if (state >= DvergarConfig.OneStarState) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The skin tint for a player at their current standing: the race's own slate blue-grey,
|
||||
/// shifted by the hue/saturation/value offsets a real dverger of that star count wears.
|
||||
///
|
||||
/// Valheim does not give a starred creature a different model or a different colour - it
|
||||
/// gives the same material an HSV offset through LevelEffects. Reading those offsets off
|
||||
/// the creature prefab rather than picking two colours by eye means the tiers land on the
|
||||
/// exact tints the game uses, and keeps following them if the prefab ever changes.
|
||||
/// </summary>
|
||||
public static Color GetSkinColor(Player player)
|
||||
{
|
||||
LevelEffects.LevelSetup setup = GetStarSetup(GetStarTier(GetProgressionState(player)));
|
||||
if (setup == null) return DvergarConfig.SkinColor;
|
||||
|
||||
return ShiftHsv(DvergarConfig.SkinColor, setup.m_hue, setup.m_saturation, setup.m_value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tier this particular Dvergar should be coloured for. DvergarRace publishes it to
|
||||
/// the ZDO every frame, so a remote player is shown at their own standing rather than the
|
||||
/// observer's - which matters the moment anyone runs personal progression. Falls back to
|
||||
/// this client's own reckoning when there is no ZDO, which is the main-menu preview.
|
||||
/// </summary>
|
||||
private static int GetProgressionState(Player player)
|
||||
{
|
||||
ZNetView nview = player != null ? player.GetComponent<ZNetView>() : null;
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
int published = nview.GetZDO().GetInt(DvergarConfig.StateZdoKey, 0);
|
||||
if (published > 0) return published;
|
||||
}
|
||||
|
||||
return BossProgressionManager.GetCurrentProgressionState();
|
||||
}
|
||||
|
||||
private static LevelEffects.LevelSetup GetStarSetup(int tier)
|
||||
{
|
||||
if (tier <= 0) return null;
|
||||
|
||||
LevelEffects.LevelSetup[] setups = ResolveStarSetups();
|
||||
if (setups == null || setups.Length == 0) return null;
|
||||
|
||||
// m_levelSetups[0] is one star, [1] is two - the game indexes it as level - 2.
|
||||
int index = Mathf.Min(tier - 1, setups.Length - 1);
|
||||
return setups[index];
|
||||
}
|
||||
|
||||
private static LevelEffects.LevelSetup[] ResolveStarSetups()
|
||||
{
|
||||
if (starSetupsResolved) return cachedStarSetups;
|
||||
starSetupsResolved = true;
|
||||
|
||||
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(DvergarConfig.DvergerPrefabName);
|
||||
LevelEffects effects = prefab != null ? prefab.GetComponentInChildren<LevelEffects>(true) : null;
|
||||
|
||||
if (effects == null || effects.m_levelSetups == null || effects.m_levelSetups.Count == 0)
|
||||
{
|
||||
Jotunn.Logger.LogWarning(
|
||||
$"[Dvergar] No LevelEffects setups on '{DvergarConfig.DvergerPrefabName}'; " +
|
||||
"star colouring stays at the base tint.");
|
||||
return null;
|
||||
}
|
||||
|
||||
cachedStarSetups = effects.m_levelSetups.ToArray();
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[Dvergar] Star colours resolved: {cachedStarSetups.Length} setups from " +
|
||||
$"'{DvergarConfig.DvergerPrefabName}'.");
|
||||
return cachedStarSetups;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies an HSV offset the way the creature shader does - hue wraps, the other two
|
||||
/// clamp - so the result is the same shift a starred dverger gets, on our colour.
|
||||
/// </summary>
|
||||
private static Color ShiftHsv(Color color, float hue, float saturation, float value)
|
||||
{
|
||||
Color.RGBToHSV(color, out float h, out float s, out float v);
|
||||
|
||||
h = Mathf.Repeat(h + hue, 1f);
|
||||
s = Mathf.Clamp01(s + saturation);
|
||||
v = Mathf.Clamp01(v + value);
|
||||
|
||||
Color shifted = Color.HSVToRGB(h, s, v);
|
||||
shifted.a = color.a;
|
||||
return shifted;
|
||||
}
|
||||
|
||||
// ─── Scale ───────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue