RacesOfValheim/JotunnModStub/Dvergar/DvergarConfig.cs
kanym 3607d7323d feat(dvergar): make ability numbers and keybinds BepInEx-configurable
Adds DvergarConfigManagement.cs rather than reusing the DvergarConfig
name: that existing class is a different kind of thing - identity
constants that must never change (renaming RaceId would orphan saved
characters), hand-tuned cosmetic placement numbers (eye/hood position),
and per-tier tables (health malus, smithing/trader discounts) left alone
under the same boundary drawn for every other race's progression table.

Only the genuine ability knobs move: Runic Ping and Runic Overcharge
(cost, radius, duration, cooldown, marker light) each get a Configuration
Manager section, plus mining and weapon-affinity percentages under
Passive Combat, plus the two keybinds. DvergarConfig's fields for those
now forward to DvergarConfigManagement (same const-to-property trick used
for Skadi), so all 109 existing call sites across 11 files kept working
unchanged except the two keybind consumers (DvergarAbilities,
RaceCompendium's in-game ability text), which now read the live
configured key so a rebind stays reflected everywhere it's shown.

Weapon-affinity DamagePercent/StaminaPercent are overridden with the live
config value inside DvergarProgression.GetRules rather than baked into
the static WeaponAffinities array, since that array evaluates at
class-load time - before RacesOfValheim.Awake() calls Bind - and would
risk a null-reference on the ConfigEntry.

Config sections stay bound alphabetically by race (Aswid, Draugh,
Dvergar, Skadi) in RacesOfValheim.Awake().
2026-08-06 13:56:00 +02:00

402 lines
25 KiB
C#

using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// Every tunable number the Dvergar uses, in one place.
///
/// The race was specced with most percentages still open, so nothing here is baked into the
/// logic: DvergarProgression reads these to build its per-tier rules and the patches read the
/// rules, never a literal. Retuning the race means editing this file only.
///
/// Values still marked TODO are placeholders chosen to be playable, not final.
/// </summary>
public static class DvergarConfig
{
// ─── Identity ────────────────────────────────────────────────────────
// "Dvergar" is provisional. It is the value stored in m_customData["Race"] and in the
// ZDO, so renaming it after players have chosen the race would orphan their characters.
public const string RaceId = "Dvergar";
public const string StatsSE = "SE_DvergarStats";
public const string OverchargeSE = "SE_DvergarOvercharge";
public const string RunicPingCdSE = "SE_DvergarRunicPingCooldown";
public const string OverchargeCdSE = "SE_DvergarOverchargeCooldown";
// Mirrors the ZDO key layout the other races use, so remote clients can read the tier
// without having the local player's progression state.
public const string StateZdoKey = "RacesOfValheim_DvergarState";
// ─── Model ───────────────────────────────────────────────────────────
// Applied to the player's "Visual" child rather than the root transform, the way Furling
// does it: scaling the root would drag the collider and camera pivot along with it.
// Tuning knobs are static readonly rather than const throughout: a const folds at compile
// time, which turns "is this perk switched off?" guards into dead code the moment a knob
// is set to zero, and would bake the old value into any assembly built against this one.
// Nudged up from the 0.70 the spec asked for: -30% read as too small next to a human once
// it was actually on screen.
public static readonly float VisualScale = 0.78f; // -22% versus a human
// ─── Skin ────────────────────────────────────────────────────────────
// Written straight onto the body material's _SkinColor by the UpdateColors postfix, which
// is the only thing that actually tints a player - see the comment on that patch.
//
// This is a multiplier over the human skin texture, not a replacement, so a value near
// (1,1,1) changes nothing anyone can see. The first attempt at (0.72, 0.74, 0.82) was
// exactly that mistake: correct code, invisible result. Every race that reads clearly
// commits to a channel - Trol (0.1, 0.6, 0.7), Furling (0.3, 0.8, 0.3) - so the Dvergar
// does too: a cold, dark slate blue-grey.
public static readonly Color SkinColor = new Color(0.42f, 0.52f, 0.68f, 1f);
// Dvergr are white-haired. The hood hides most of it, but the beard shows.
public static readonly Color HairColor = new Color(0.85f, 0.87f, 0.92f, 1f);
// ─── Star colours ────────────────────────────────────────────────────
// A starred dverger is not a different model: Valheim recolours the same one with a
// LevelEffects component, whose LevelSetup list carries a hue/saturation/value offset per
// star and an optional emissive colour for the eyes. Setup 0 is one star, setup 1 is two.
//
// Nothing here hardcodes a colour. The offsets are read off the creature prefab at
// runtime, so the race ages into exactly the tints the game itself uses - and follows
// them if a patch ever changes them.
public const int OneStarState = 4; // Bonemass
public const int TwoStarState = 8; // Fader
// Those offsets are authored against a dverger's own texture. Ours is a multiplier over
// the human skin, where white means "no tint at all" - so an offset that brightens and
// desaturates far enough lands on white and hands back an ordinary pink human. That is
// exactly what the two-star tier did. These bounds keep every tier recognisably the same
// colour, shifted rather than washed out.
public const float StarMinSaturation = 0.25f;
public const float StarMinValue = 0.20f;
public const float StarMaxValue = 0.85f;
// Two stars is hand-picked rather than derived, because the derivation cannot express
// what it is asking for. A multiplier can darken a texture and it can bias a texture, but
// it cannot desaturate one: the pink is in the human skin map, and multiplying by grey
// keeps every bit of it, only dimmer. So the two-star tier says "stone" the only way this
// channel can - dark, and cold enough to sit on top of the pink rather than under it.
//
// To tune: raise all three together for a lighter dvergr, and widen the gap between R and
// B for a colder one. Keeping R below B is what holds the flesh tone down.
public static readonly Color TwoStarSkinColor = new Color(0.34f, 0.37f, 0.44f, 1f);
// ─── Glowing eyes ────────────────────────────────────────────────────
// A player's eyes are painted into the skin texture, and Custom/Player has no emission
// channel to light them with - so a Dvergar wears two small emissive quads over them
// instead. Nothing else in the mod does this, so there was no working example to copy;
// the Aswid's red eyes were never built at all, only cleaned up.
//
// Metres from the head bone, which sits at the base of the skull, along the player's own
// forward and up. The eyes are parented to that bone, so all of this rides the head
// animation, and every offset scales with the race.
//
// Do not reintroduce Character.m_eye as a starting point. It reads like the right
// reference and is not: it is where the camera goes, half a metre above the head bone,
// and starting from it put the eyes in the treetops. That was measured, not guessed -
// the trace is in the commit history.
// These are pre-scale numbers: a Dvergar renders at 0.78, so 0.105 forward lands about
// 0.082m out from the bone at the base of the skull.
//
// EyeForward has less room than it looks, and both ends of it are measured rather than
// guessed: 0.067 buries the eyes completely behind the face, 0.140 stands them off the
// skull in profile. 0.105 is the far end of what still reads as inset.
//
// The eye is a large ball buried deep, not a small one balanced on the surface. What shows
// is the slice of it that breaks the face - a spherical cap - so the face itself decides
// the shape and the glow can never float off the cheek. Push the centre in to shrink the
// cap, pull it out to grow one.
//
// Sized off two measurements. At a centre of 82mm with an 8mm radius the eyes were
// visible; at 74mm with the same radius they were gone. So the face sits about 86mm from
// the head bone. All values here are pre-scale - a Dvergar renders at 0.78.
//
// The cap grows far faster than the depth that makes it, and faster still on a big ball:
// a 30mm radius clearing the face by 9mm showed a 43mm cap, most of a face. Radius is
// halved for that reason - it does not only shrink the cap, it halves how violently the
// cap answers to a millimetre of depth, which is the difference between tuning this and
// fighting it. 15mm of radius clearing by 4mm gives about 20mm of eye.
// Depth and radius move together. The centre can only go deeper if the ball grows to
// reach the face from further back - sink one without the other and the eye is simply
// gone, since at a 15mm radius it cleared the face by 2mm and had nothing to spare.
//
// So a centimetre further in is a centimetre more radius: centre ~63mm out, radius ~24mm,
// still clearing by about 2mm. Same size of eye, sitting deeper, and the cap is flatter
// for it - which is what reads as set into the skull rather than resting on it.
public static readonly float EyeSeparation = 0.032f; // half the distance between them
public static readonly float EyeForward = 0.081f; // centre ~63mm out
public static readonly float EyeHeight = 0.181f; // ~15mm lower than before
public static readonly float EyeSize = 0.062f; // ~48mm across, so a 24mm radius
// How hard the eyes burn. The colours the game gives a starred dverger are HDR - one star
// is (0, 4, 3.3) - and anything past 1 clips to white on the way to the bloom pass, which
// is why the centres read as white lamps rather than as teal. Scaling them down brings
// the colour back as much as it lowers the brightness.
public static readonly float EyeGlowStrength = 0.3f;
// Applied to the model's left eye alone - the one on your right as you look at it.
//
// The two are placed symmetrically and do not come out symmetrical, because the face they
// emerge through is not flat: nearer the midline the skull juts forward, nearer the temple
// it falls away, so a ball that meets the receding side shows more of itself. With a 24mm
// radius spanning that curve the difference is a visible few millimetres of cap. Rather
// than shrink both and lose the socket depth, the one that comes out proud is taken down
// on its own.
//
// If the wrong eye shrinks, the sideways axis resolved the other way round: apply this to
// index 1 in PlaceEyes instead of index 0.
public static readonly float LeftEyeSizeMultiplier = 0.85f;
// Base glow, before any star. The tiers replace it with the emissive colours the game
// itself gives a starred dverger - RGBA(0, 4, 3.3) at one star and RGBA(12, 0, 8.8) at
// two, both far past 1, which is exactly what makes them bloom rather than just look
// bright.
public static readonly Color BaseEyeColor = new Color(0f, 2.2f, 1.8f, 1f);
// ─── Cosmetic hood ───────────────────────────────────────────────────
// The helmet slot itself stays free — whatever the player equips keeps all of its stats,
// only the mesh is swapped.
//
// The hood is lifted straight off the Dvergr NPC rather than off the Dverger Circlet item:
// the circlet is a metal band, not the hood the race is meant to wear.
//
// Two facts out of dumpdverger decide how this is done.
//
// The prefab holds one renderer, 'dvergr', whose mesh reports zero triangles - it ships
// with Read/Write disabled, so its vertices and indices cannot be touched at runtime and
// no amount of submesh carving will ever produce geometry.
//
// But its rig carries a dedicated hat1/hat2/hat3 bone chain under 'head'. The hood is
// skinned to those bones and nothing else is, so the hood can be isolated by collapsing
// every other bone to zero scale rather than by editing the mesh at all.
public const string DvergerPrefabName = "Dverger";
// The child of the prefab holding the armature and the renderer.
public const string DvergerVisualName = "Visual";
// Root of the hat bone chain, and the bone whose collapse hides everything else.
public const string HoodBoneName = "hat1";
public const string BodyRootBoneName = "Root";
// Bone the hood is hung from on the player's own rig.
public const string PlayerHeadBoneName = "Head";
// Nudges on top of the automatic alignment, which already puts the hat bone on the player's
// head bone. Scale is the one most likely to need a look: the hood is authored for a Dvergr
// skull, not a human one.
public static readonly Vector3 HoodOffsetPosition = Vector3.zero;
public static readonly Vector3 HoodOffsetRotation = Vector3.zero;
public static readonly float HoodExtraScale = 1f;
// ─── Health malus ────────────────────────────────────────────────────
// Indexed by progression state; index 0 is unused so the state number indexes directly.
// Base -10, growing to -20 once The Queen falls. Left as a plain per-tier table, same
// boundary drawn everywhere else in this mod (Skadi's progression table included) -
// not exposed through Configuration Manager.
public static readonly float[] HealthMalusByState =
{
0f, // (unused)
10f, // 1 Base
10f, // 2 Eikthyr
10f, // 3 The Elder
13f, // 4 Bonemass
15f, // 5 Moder
17.5f, // 6 Yagluth TODO: spec says -17/-18, pick one
20f, // 7 The Queen
20f // 8 Fader
};
// A Dvergar must never be reduced below this, however the malus and food line up.
// Forwards to DvergarConfigManagement (BepInEx ConfigEntry) so every existing call site
// keeps reading DvergarConfig.MinMaxHealth unchanged - see that class for why this one
// field, and not the rest of this file, is configurable.
public static float MinMaxHealth => DvergarConfigManagement.MinMaxHealth.Value;
// ─── Elemental affinity ──────────────────────────────────────────────
// Runes in the blood: every blow the Dvergar lands carries lightning.
//
// Deliberately the same shape as Skadi's Ice Affinity - live from the base tier and
// growing by a flat step per progression state, so +2 at Base through +16 after Fader -
// with lightning in place of frost. SkadiDamagePatch is the reference; like it, this
// applies to every blow the player lands, not only melee.
public static float ElementalDamagePerState => DvergarConfigManagement.ElementalDamagePerState.Value;
public static readonly HitData.DamageType ElementalDamageType = HitData.DamageType.Lightning;
// ─── Weapon affinity ─────────────────────────────────────────────────
// Bonus damage plus a stamina discount on the attack. Neither scales with the tier - a
// tier only ever adds a new weapon to the list - and skill XP is deliberately untouched.
//
// DamagePercent and StaminaPercent below are fallback shape values only: identical across
// every weapon today, and DvergarProgression.GetRules overrides both with
// DvergarConfigManagement's live (and configurable) values before handing rules out - see
// the comment there. FlatDamage and StaminaFlat stay literal zero-and-unconfigured: both
// are currently inert placeholders (FlatDamage's whole effect is gated behind
// `if (affinity.FlatDamage > 0f)` in DvergarPatches, which never fires at zero).
public struct WeaponAffinity
{
public Skills.SkillType Skill;
public int UnlockState;
public HitData.DamageType FlatDamageType; // channel the flat bonus lands on
public float FlatDamage; // TODO
public float DamagePercent; // fallback shape only, see above
public float StaminaPercent; // fallback shape only, see above
public float StaminaFlat; // TODO, flat stamina refunded
public string DisplayName;
}
public static readonly WeaponAffinity[] WeaponAffinities =
{
new WeaponAffinity
{
Skill = Skills.SkillType.Clubs, UnlockState = 1,
FlatDamageType = HitData.DamageType.Blunt,
FlatDamage = 0f, DamagePercent = 0.15f,
StaminaPercent = 0.20f, StaminaFlat = 0f,
DisplayName = "Hammer"
},
new WeaponAffinity
{
Skill = Skills.SkillType.Bows, UnlockState = 2,
FlatDamageType = HitData.DamageType.Pierce,
FlatDamage = 0f, DamagePercent = 0.15f,
StaminaPercent = 0.20f, StaminaFlat = 0f,
DisplayName = "Bow"
},
new WeaponAffinity
{
Skill = Skills.SkillType.Axes, UnlockState = 3,
FlatDamageType = HitData.DamageType.Slash,
FlatDamage = 0f, DamagePercent = 0.15f,
StaminaPercent = 0.20f, StaminaFlat = 0f,
DisplayName = "Axe"
},
new WeaponAffinity
{
Skill = Skills.SkillType.Crossbows, UnlockState = 6,
FlatDamageType = HitData.DamageType.Pierce,
FlatDamage = 0f, DamagePercent = 0.15f,
StaminaPercent = 0.20f, StaminaFlat = 0f,
DisplayName = "Crossbow"
}
};
// ─── Mining affinity ─────────────────────────────────────────────────
// Unlocks alongside the antler pickaxe.
public const int MiningAffinityState = 2;
// Faster mining is modelled as extra pickaxe damage per swing rather than a swing-rate
// change: rock HP is what actually gates how long a vein takes. Forward to
// DvergarConfigManagement (BepInEx ConfigEntry) - see that class.
public static float MiningDamageMultiplier => DvergarConfigManagement.MiningDamageMultiplier.Value;
public static float MiningStaminaPercent => DvergarConfigManagement.MiningStaminaPercent.Value;
// Chance for a mined vein to yield an extra unit of ore. 0 disables the yield half of
// the affinity and leaves it purely a speed/stamina perk.
public static float MiningExtraDropChance => DvergarConfigManagement.MiningExtraDropChance.Value;
// Matched against the drop prefab name, lowercased, by Contains.
public static readonly string[] OreDropNames =
{
"copperore", "tinore", "ironscrap", "silverore", "blackmetalscrap", "flametalore"
};
// ─── Smithing / jewelry ──────────────────────────────────────────────
// Percentage saved on the metal cost of crafting and upgrading. Starts at Bonemass and
// caps at Moder. Indexed by progression state.
public static readonly float[] SmithingDiscountByState =
{
0f, // (unused)
0f, // 1 Base
0f, // 2 Eikthyr
0f, // 3 The Elder
0.20f, // 4 Bonemass
0.40f, // 5 Moder - cap
0.40f, // 6 Yagluth
0.40f, // 7 The Queen
0.40f // 8 Fader
};
// Only these resources are discounted, which is what keeps the perk to smithing and
// jewelry rather than quietly cheapening every wooden wall the player puts up.
public static readonly string[] DiscountedResourceNames =
{
"copper", "tin", "bronze", "iron", "silver", "blackmetal", "flametal",
"ironnails", "bronzenails", "copperore", "tinore", "silverore", "flametalore",
"ruby", "amber", "amberpearl", "coins", "silvernecklace"
};
// ─── Haldor / Hildir favour ──────────────────────────────────────────
// Both halves of the trade: a discount on what the traders charge, and a bonus on what
// they pay for trophies and hunting rewards. Indexed by progression state.
public static readonly float[] TraderBuyDiscountByState =
{
0f, // (unused)
0f, // 1 Base
0f, // 2 Eikthyr
0f, // 3 The Elder
0.10f, // 4 Bonemass - step 1 TODO
0.15f, // 5 Moder - step 2 TODO
0.20f, // 6 Yagluth - step 3 TODO
0.25f, // 7 The Queen - full TODO
0.25f // 8 Fader
};
public static readonly float[] TraderSellBonusByState =
{
0f, // (unused)
0f, // 1 Base
0f, // 2 Eikthyr
0f, // 3 The Elder
0.10f, // 4 Bonemass - step 1 TODO
0.20f, // 5 Moder - step 2 TODO
0.30f, // 6 Yagluth - step 3 TODO
0.40f, // 7 The Queen - full TODO
0.40f // 8 Fader
};
// ─── Runic Ping (Yagluth) ────────────────────────────────────────────
// The keybind used to live here as a KeyCode const; it is now DvergarConfigManagement's
// RunicPingKey (a rebindable KeyboardShortcut), read directly by DvergarAbilities.
public const int RunicPingState = 6;
// Every numeric knob below forwards to DvergarConfigManagement (BepInEx ConfigEntry) -
// see that class for why these, and not the colours, are configurable.
public static float RunicPingEitrCost => DvergarConfigManagement.RunicPingEitrCost.Value;
public static float RunicPingRadius => DvergarConfigManagement.RunicPingRadius.Value;
public static float RunicPingDuration => DvergarConfigManagement.RunicPingDuration.Value;
public static float RunicPingCooldown => DvergarConfigManagement.RunicPingCooldown.Value;
public static readonly Color RunicPingOreColor = new Color(0.4f, 0.8f, 1f);
public static readonly Color RunicPingEnemyColor = new Color(1f, 0.35f, 0.35f);
public static float RunicPingLightRange => DvergarConfigManagement.RunicPingLightRange.Value;
public static float RunicPingLightIntensity => DvergarConfigManagement.RunicPingLightIntensity.Value;
// Vein prefabs are matched on name, lowercased, by Contains - MineRock5_Copper,
// silvervein, rock4_copper and friends all fall out of this list.
public static readonly string[] RunicPingVeinNames =
{
"copper", "tin", "silvervein", "obsidian", "meteorite", "flametal", "mudpile", "leviathan"
};
// ─── Runic Overcharge (Fader) ────────────────────────────────────────
// The keybind used to live here as a KeyCode const; it is now DvergarConfigManagement's
// RunicOverchargeKey (a rebindable KeyboardShortcut), read directly by DvergarAbilities.
public const int RunicOverchargeState = 8;
public static float RunicOverchargeEitrCost => DvergarConfigManagement.RunicOverchargeEitrCost.Value;
public static float RunicOverchargeMultiplier => DvergarConfigManagement.RunicOverchargeMultiplier.Value; // applied to physical damage
public static float RunicOverchargeWindow => DvergarConfigManagement.RunicOverchargeWindow.Value; // seconds the charge is held
public static float RunicOverchargeCooldown => DvergarConfigManagement.RunicOverchargeCooldown.Value;
// ─── Helpers ─────────────────────────────────────────────────────────
/// <summary>Clamped table lookup, so a state outside 1..8 can never index out of range.</summary>
public static float Lookup(float[] table, int state)
{
if (table == null || table.Length == 0) return 0f;
int index = Mathf.Clamp(state, BossProgressionManager.MinState, table.Length - 1);
return table[index];
}
}
}