An eighth race built on the existing per-race pattern: a MonoBehaviour driver registered from Awake, a progression table keyed on the boss state, an SE_Stats carrier, and Harmony patches for the individual perks. The helmet slot stays free. Whatever the player equips keeps every one of its stats and only its mesh is swapped for the dvergr hood, which is the Skeleton's helmet handling turned into a replacement rather than a plain hide. Every percentage the spec left open lives in DvergurConfig as a named value and is marked TODO there, so tuning the race never means touching the logic. The knobs are static readonly rather than const so that switching a perk off with a zero does not fold its guard into dead code.
72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Driver for the Dvergur: a short, stocky smith who trades a slice of health for an affinity
|
|
/// with hammer, bow, axe and crossbow, a knack for mining and the ear of Haldor and Hildir.
|
|
///
|
|
/// Only the per-frame upkeep lives here. The perks themselves are Harmony patches in
|
|
/// DvergurPatches, the two eitr abilities are in DvergurAbilities, and every number they use
|
|
/// comes from DvergurConfig by way of DvergurProgression.
|
|
/// </summary>
|
|
public class DvergurRace : MonoBehaviour
|
|
{
|
|
public static DvergurRace Instance;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void CreateModAssets()
|
|
{
|
|
DvergurStatusEffects.RegisterStatusEffects();
|
|
}
|
|
|
|
public static bool IsDvergur()
|
|
{
|
|
return Player.m_localPlayer != null &&
|
|
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
|
|
Player.m_localPlayer.m_customData["Race"] == DvergurConfig.RaceId;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Player player = Player.m_localPlayer;
|
|
if (player == null) return;
|
|
|
|
if (!IsDvergur())
|
|
{
|
|
DvergurVisuals.Apply(player);
|
|
return;
|
|
}
|
|
|
|
DvergurVisuals.Apply(player);
|
|
|
|
if (player.IsDead()) return;
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
|
|
// Keep the passive carrier attached. It is re-added rather than assumed because a
|
|
// respawn, a death or a world load all clear the player's status effects.
|
|
if (DvergurStatusEffects.StatsSE != null)
|
|
{
|
|
int hash = DvergurConfig.StatsSE.GetStableHashCode();
|
|
if (!player.GetSEMan().HaveStatusEffect(hash))
|
|
{
|
|
player.GetSEMan().AddStatusEffect(hash, true);
|
|
}
|
|
}
|
|
|
|
// Published for remote clients, matching how the Skeleton replicates its tier.
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid())
|
|
{
|
|
nview.GetZDO().Set(DvergurConfig.StateZdoKey, state);
|
|
}
|
|
|
|
DvergurAbilities.Tick(player, state);
|
|
}
|
|
}
|
|
}
|