feat(dvergur): add the Dvergur race scaffold

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.
This commit is contained in:
kanym 2026-08-02 21:45:44 +02:00
commit 3ec51aeb45
10 changed files with 1365 additions and 1 deletions

View file

@ -32,6 +32,7 @@ namespace RacesOfValheim
gameObject.AddComponent<FurlingRace>();
gameObject.AddComponent<TrolRace>();
gameObject.AddComponent<DraughRace>();
gameObject.AddComponent<DvergurRace>();
PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets;
CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand());
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
@ -72,6 +73,8 @@ namespace RacesOfValheim
player.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode());
player.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode());
player.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode());
player.GetSEMan().RemoveStatusEffect(DvergurConfig.StatsSE.GetStableHashCode());
player.GetSEMan().RemoveStatusEffect(DvergurConfig.OverchargeSE.GetStableHashCode());
ZNetView nview = player.GetComponent<ZNetView>();
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human");
@ -93,6 +96,7 @@ namespace RacesOfValheim
FurlingRace.Instance.CreateModAssets();
TrolRace.Instance.CreateModAssets();
DraughRace.Instance.CreateModAssets();
DvergurRace.Instance.CreateModAssets();
}
// --- RACE SELECTION UI ---
public void ShowRaceSelectionMenu()
@ -233,6 +237,9 @@ namespace RacesOfValheim
CreateRaceButtonWithConfirm("Trol", new Vector2(150, -20), GetTrolIcon(), "Massive brute strength. Towering over others but slow to react.", SelectTrol);
CreateRaceButtonWithConfirm("Draugh", new Vector2(450, -20), GetDraughIcon(), "A decaying undead warrior fueled by dark magic and extreme metal.", SelectDraugh);
// Row 3 (y = -140)
CreateRaceButtonWithConfirm("Dvergur", new Vector2(-450, -140), GetDvergurIcon(), "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.", SelectDvergur);
GUIManager.BlockInput(true);
}
@ -575,6 +582,45 @@ namespace RacesOfValheim
return null;
}
private void SelectDvergur()
{
if (Player.m_localPlayer != null)
{
Player.m_localPlayer.m_customData["Race"] = DvergurConfig.RaceId;
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", DvergurConfig.RaceId);
Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergurConfig.StatsSE.GetStableHashCode(), true);
// The Dvergur keeps its own skin - only the silhouette and the hood change, so
// UpdateVisuals is enough and UpdateColors has nothing to do here.
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
if (visEq != null)
{
visEq.GetType().GetMethod("UpdateVisuals", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
}
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Dvergur.");
CloseRaceSelectionMenu();
}
}
private Sprite GetDvergurIcon()
{
GameObject prefab = PrefabManager.Cache.GetPrefab<ItemDrop>("HelmetDverger")?.gameObject;
if (prefab == null) prefab = PrefabManager.Cache.GetPrefab<ItemDrop>("DvergrKeyFragment")?.gameObject;
if (prefab == null) prefab = PrefabManager.Cache.GetPrefab<ItemDrop>("Copper")?.gameObject;
if (prefab != null)
{
ItemDrop drop = prefab.GetComponent<ItemDrop>();
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
{
return drop.m_itemData.m_shared.m_icons[0];
}
}
return null;
}
public void CloseRaceSelectionMenu()
{
if (raceSelectionMenu != null)