diff --git a/JotunnModStub/Dvergar/DvergarAbilities.cs b/JotunnModStub/Dvergar/DvergarAbilities.cs index 67bb3b8..b0f0dc4 100644 --- a/JotunnModStub/Dvergar/DvergarAbilities.cs +++ b/JotunnModStub/Dvergar/DvergarAbilities.cs @@ -26,12 +26,12 @@ namespace RacesOfValheim DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state); - if (rules.RunicPing && Input.GetKeyDown(DvergarConfig.RunicPingKey)) + if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDown()) { TryRunicPing(player); } - if (rules.RunicOvercharge && Input.GetKeyDown(DvergarConfig.RunicOverchargeKey)) + if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDown()) { TryRunicOvercharge(player); } diff --git a/JotunnModStub/Dvergar/DvergarConfig.cs b/JotunnModStub/Dvergar/DvergarConfig.cs index 38c21f8..854efd0 100644 --- a/JotunnModStub/Dvergar/DvergarConfig.cs +++ b/JotunnModStub/Dvergar/DvergarConfig.cs @@ -191,7 +191,9 @@ namespace RacesOfValheim // ─── 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. + // 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) @@ -206,7 +208,10 @@ namespace RacesOfValheim }; // A Dvergar must never be reduced below this, however the malus and food line up. - public static readonly float MinMaxHealth = 5f; + // 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. @@ -215,21 +220,28 @@ namespace RacesOfValheim // 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 readonly float ElementalDamagePerState = 2f; + 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; // TODO, share of physical damage added - public float StaminaPercent; // TODO, share of attack stamina refunded + 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; } @@ -275,13 +287,14 @@ namespace RacesOfValheim 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. - public static readonly float MiningDamageMultiplier = 1.20f; // TODO: 20% faster? - public static readonly float MiningStaminaPercent = 0.40f; // TODO: or 40% less stamina? + // 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 readonly float MiningExtraDropChance = 0.25f; // TODO + public static float MiningExtraDropChance => DvergarConfigManagement.MiningExtraDropChance.Value; // Matched against the drop prefab name, lowercased, by Contains. public static readonly string[] OreDropNames = @@ -344,18 +357,21 @@ namespace RacesOfValheim }; // ─── Runic Ping (Yagluth) ──────────────────────────────────────────── - public const int RunicPingState = 6; - public const KeyCode RunicPingKey = KeyCode.G; + // 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; - public static readonly float RunicPingEitrCost = 25f; // TODO - public static readonly float RunicPingRadius = 40f; // TODO - public static readonly float RunicPingDuration = 10f; // TODO - public static readonly float RunicPingCooldown = 20f; // TODO + // 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 readonly float RunicPingLightRange = 8f; - public static readonly float RunicPingLightIntensity = 2f; + 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. @@ -365,13 +381,14 @@ namespace RacesOfValheim }; // ─── Runic Overcharge (Fader) ──────────────────────────────────────── - public const int RunicOverchargeState = 8; - public const KeyCode RunicOverchargeKey = KeyCode.H; + // 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 readonly float RunicOverchargeEitrCost = 60f; // TODO - public static readonly float RunicOverchargeMultiplier = 4f; // TODO, applied to physical damage - public static readonly float RunicOverchargeWindow = 15f; // seconds the charge is held - public static readonly float RunicOverchargeCooldown = 60f; // TODO + 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 ───────────────────────────────────────────────────────── /// Clamped table lookup, so a state outside 1..8 can never index out of range. diff --git a/JotunnModStub/Dvergar/DvergarConfigManagement.cs b/JotunnModStub/Dvergar/DvergarConfigManagement.cs new file mode 100644 index 0000000..b9be848 --- /dev/null +++ b/JotunnModStub/Dvergar/DvergarConfigManagement.cs @@ -0,0 +1,111 @@ +using UnityEngine; +using BepInEx.Configuration; + +namespace RacesOfValheim +{ + /// + /// The BepInEx-configurable slice of the Dvergar's numbers, bound as ConfigEntry so they show + /// up in Configuration Manager without touching code - see CONFIGURATION-MANAGER-HOWTO.md. + /// Bound once, from RacesOfValheim.Awake(). One section per topic (matches + /// SkadiConfig/AswidConfig/DraughConfig's layout). + /// + /// Named separately from the pre-existing DvergarConfig (rather than folding into it) because + /// that class is a different kind of thing: identity constants that must never change once a + /// player has the race (RaceId, status effect names - renaming them would orphan saved + /// characters), hand-tuned cosmetic placement numbers (eye/hood position - exposing those as + /// sliders would just let someone accidentally break the model), and per-tier tables (health + /// malus, smithing/trader discounts - the same "leave alone" boundary drawn for every other + /// race's progression table). Only the genuine ability knobs - Runic Ping/Overcharge and their + /// two keybinds, mining and weapon-affinity percentages - belong here. DvergarConfig's own + /// fields for those now forward to this class (see the comments there), so every existing call + /// site kept working unchanged. + /// + /// One caveat worth knowing: DvergarProgression.GetRules caches its result per progression + /// state the first time that state is reached. ElementalDamagePerState and the weapon-affinity + /// percentages below are read into that cache, so retuning them mid-session only affects tiers + /// the cache hasn't already built - a relog (or reaching a new tier) picks up the new value. + /// Runic Ping/Overcharge and mining read their config live on every use and are unaffected. + /// + public static class DvergarConfigManagement + { + // ─── Keybinds ────────────────────────────────────────────────────────── + public static ConfigEntry RunicPingKey; + public static ConfigEntry RunicOverchargeKey; + + // ─── Passive combat ────────────────────────────────────────────────── + public static ConfigEntry ElementalDamagePerState; + public static ConfigEntry MinMaxHealth; + public static ConfigEntry WeaponAffinityDamagePercent; + public static ConfigEntry WeaponAffinityStaminaPercent; + + // ─── Mining ──────────────────────────────────────────────────────────── + public static ConfigEntry MiningDamageMultiplier; + public static ConfigEntry MiningStaminaPercent; + public static ConfigEntry MiningExtraDropChance; + + // ─── Runic Ping (tier 6+) ───────────────────────────────────────────── + public static ConfigEntry RunicPingEitrCost; + public static ConfigEntry RunicPingRadius; + public static ConfigEntry RunicPingDuration; + public static ConfigEntry RunicPingCooldown; + public static ConfigEntry RunicPingLightRange; + public static ConfigEntry RunicPingLightIntensity; + + // ─── Runic Overcharge (tier 8) ──────────────────────────────────────── + public static ConfigEntry RunicOverchargeEitrCost; + public static ConfigEntry RunicOverchargeMultiplier; + public static ConfigEntry RunicOverchargeWindow; + public static ConfigEntry RunicOverchargeCooldown; + + public static void Bind(ConfigFile config) + { + const string keybinds = "Dvergar - Keybinds"; + RunicPingKey = config.Bind(keybinds, "Runic Ping", new KeyboardShortcut(KeyCode.G), + new ConfigDescription("Lights up ore veins and hidden enemies nearby, tier 6+.")); + RunicOverchargeKey = config.Bind(keybinds, "Runic Overcharge", new KeyboardShortcut(KeyCode.H), + new ConfigDescription("Loads the next favoured-weapon blow with bonus damage, tier 8.")); + + const string combat = "Dvergar - Passive Combat"; + ElementalDamagePerState = config.Bind(combat, "Elemental Damage Per State", 2f, + new ConfigDescription("Lightning added to every blow the player lands, multiplied by the current progression state.", new AcceptableValueRange(0f, 10f))); + MinMaxHealth = config.Bind(combat, "Minimum Max Health", 5f, + new ConfigDescription("A Dvergar's max health is never reduced below this, however the per-tier malus lines up.", new AcceptableValueRange(1f, 50f))); + WeaponAffinityDamagePercent = config.Bind(combat, "Weapon Affinity Damage Percent", 0.15f, + new ConfigDescription("Extra physical damage with a favoured weapon (Hammer/Bow/Axe/Crossbow), as a fraction.", new AcceptableValueRange(0f, 1f))); + WeaponAffinityStaminaPercent = config.Bind(combat, "Weapon Affinity Stamina Percent", 0.20f, + new ConfigDescription("Stamina refunded on attacks with a favoured weapon, as a fraction.", new AcceptableValueRange(0f, 1f))); + + const string mining = "Dvergar - Mining"; + MiningDamageMultiplier = config.Bind(mining, "Damage Multiplier", 1.20f, + new ConfigDescription("Multiplies pickaxe damage against rock, tier 2+.", new AcceptableValueRange(1f, 3f))); + MiningStaminaPercent = config.Bind(mining, "Stamina Discount Percent", 0.40f, + new ConfigDescription("Stamina saved per pickaxe swing, as a fraction.", new AcceptableValueRange(0f, 1f))); + MiningExtraDropChance = config.Bind(mining, "Extra Ore Drop Chance", 0.25f, + new ConfigDescription("Chance a mined vein yields one extra unit of ore. 0 disables the yield half of the affinity.", new AcceptableValueRange(0f, 1f))); + + const string ping = "Dvergar - Runic Ping"; + RunicPingEitrCost = config.Bind(ping, "Eitr Cost", 25f, + new ConfigDescription("Eitr spent per cast.", new AcceptableValueRange(0f, 100f))); + RunicPingRadius = config.Bind(ping, "Radius", 40f, + new ConfigDescription("Meters within which ore veins and hidden enemies are marked.", new AcceptableValueRange(5f, 100f))); + RunicPingDuration = config.Bind(ping, "Marker Duration", 10f, + new ConfigDescription("Seconds a marker light stays lit.", new AcceptableValueRange(1f, 60f))); + RunicPingCooldown = config.Bind(ping, "Cooldown", 20f, + new ConfigDescription("Seconds between casts.", new AcceptableValueRange(0f, 300f))); + RunicPingLightRange = config.Bind(ping, "Marker Light Range", 8f, + new ConfigDescription("Range of each marker light.", new AcceptableValueRange(1f, 30f))); + RunicPingLightIntensity = config.Bind(ping, "Marker Light Intensity", 2f, + new ConfigDescription("Intensity of each marker light.", new AcceptableValueRange(0.1f, 10f))); + + const string overcharge = "Dvergar - Runic Overcharge"; + RunicOverchargeEitrCost = config.Bind(overcharge, "Eitr Cost", 60f, + new ConfigDescription("Eitr spent to load a charge.", new AcceptableValueRange(0f, 200f))); + RunicOverchargeMultiplier = config.Bind(overcharge, "Damage Multiplier", 4f, + new ConfigDescription("Multiplies physical damage on the blow that discharges the loaded weapon.", new AcceptableValueRange(1f, 10f))); + RunicOverchargeWindow = config.Bind(overcharge, "Charge Window", 15f, + new ConfigDescription("Seconds a loaded charge is held before it lapses unused.", new AcceptableValueRange(1f, 60f))); + RunicOverchargeCooldown = config.Bind(overcharge, "Cooldown", 60f, + new ConfigDescription("Seconds between casts.", new AcceptableValueRange(0f, 300f))); + } + } +} diff --git a/JotunnModStub/Dvergar/DvergarProgression.cs b/JotunnModStub/Dvergar/DvergarProgression.cs index f3bcc57..5469a11 100644 --- a/JotunnModStub/Dvergar/DvergarProgression.cs +++ b/JotunnModStub/Dvergar/DvergarProgression.cs @@ -41,10 +41,21 @@ namespace RacesOfValheim state = Mathf.Clamp(state, BossProgressionManager.MinState, BossProgressionManager.MaxState); if (cached[state]) return cache[state]; + // DamagePercent/StaminaPercent are overridden from DvergarConfigManagement here + // rather than in the WeaponAffinities array itself: that array is a static readonly + // field evaluated at class-load time, which can run before RacesOfValheim.Awake() + // calls DvergarConfigManagement.Bind - reading .Value there would risk a + // null-reference on the ConfigEntry. Reading it here, when rules are actually built, + // is always after Bind has run. List affinities = new List(); foreach (DvergarConfig.WeaponAffinity affinity in DvergarConfig.WeaponAffinities) { - if (state >= affinity.UnlockState) affinities.Add(affinity); + if (state < affinity.UnlockState) continue; + + DvergarConfig.WeaponAffinity live = affinity; + live.DamagePercent = DvergarConfigManagement.WeaponAffinityDamagePercent.Value; + live.StaminaPercent = DvergarConfigManagement.WeaponAffinityStaminaPercent.Value; + affinities.Add(live); } DvergarRules rules = new DvergarRules diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index 58f907e..0ddbc5f 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -109,10 +109,10 @@ namespace RacesOfValheim sb.AppendLine($"[Bonemass Unlock] Kin of the Traders (Passive): Haldor and Hildir know their own. Their prices drop by {rules.TraderBuyDiscount * 100f:0}% for you, and what they pay for your trophies and hunting rewards rises by {rules.TraderSellBonus * 100f:0}%.\n"); if (rules.RunicPing) - sb.AppendLine($"[Yagluth Unlock] Runic Ping ('{DvergarConfig.RunicPingKey}' Key): Spend {DvergarConfig.RunicPingEitrCost:0} eitr to send a pulse through the stone. For {DvergarConfig.RunicPingDuration:0} seconds every ore vein and every hidden enemy within {DvergarConfig.RunicPingRadius:0} meters is lit for you alone.\n"); + sb.AppendLine($"[Yagluth Unlock] Runic Ping ('{DvergarConfigManagement.RunicPingKey.Value}' Key): Spend {DvergarConfig.RunicPingEitrCost:0} eitr to send a pulse through the stone. For {DvergarConfig.RunicPingDuration:0} seconds every ore vein and every hidden enemy within {DvergarConfig.RunicPingRadius:0} meters is lit for you alone.\n"); if (rules.RunicOvercharge) - sb.AppendLine($"[Fader Unlock] Runic Overcharge ('{DvergarConfig.RunicOverchargeKey}' Key): Spend {DvergarConfig.RunicOverchargeEitrCost:0} eitr to load the runes. Your next blow with a favoured weapon lands with {DvergarConfig.RunicOverchargeMultiplier:0}x its weight. Hold the charge no longer than {DvergarConfig.RunicOverchargeWindow:0} seconds or it bleeds away.\n"); + sb.AppendLine($"[Fader Unlock] Runic Overcharge ('{DvergarConfigManagement.RunicOverchargeKey.Value}' Key): Spend {DvergarConfig.RunicOverchargeEitrCost:0} eitr to load the runes. Your next blow with a favoured weapon lands with {DvergarConfig.RunicOverchargeMultiplier:0}x its weight. Hold the charge no longer than {DvergarConfig.RunicOverchargeWindow:0} seconds or it bleeds away.\n"); knownTexts["Dvergar Secrets"] = sb.ToString(); } diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index feacc11..438a60d 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -29,6 +29,7 @@ namespace RacesOfValheim // ordering in-game. Keep new races' Bind() calls slotted in alphabetically here. AswidConfig.Bind(Config); DraughConfig.Bind(Config); + DvergarConfigManagement.Bind(Config); SkadiConfig.Bind(Config); harmony.PatchAll(); gameObject.AddComponent();