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().
97 lines
4.6 KiB
C#
97 lines
4.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Turns a boss progression state into the set of Dvergar perks active at that tier, the same
|
|
/// way SkeletonProgression and SkadiProgression do for their races.
|
|
///
|
|
/// Nothing is decided here - every figure comes out of DvergarConfig - so the tuning pass can
|
|
/// happen without touching a single patch.
|
|
/// </summary>
|
|
public static class DvergarProgression
|
|
{
|
|
public struct DvergarRules
|
|
{
|
|
/// <summary>Points subtracted from max health at this tier.</summary>
|
|
public float HealthMalus;
|
|
|
|
/// <summary>Lightning added to every blow at this tier. Live from the base tier.</summary>
|
|
public float ElementalDamage;
|
|
|
|
/// <summary>Weapon skills the Dvergar is at home with, already filtered by tier.</summary>
|
|
public List<DvergarConfig.WeaponAffinity> Affinities;
|
|
|
|
public bool MiningAffinity;
|
|
public float SmithingDiscount;
|
|
public float TraderBuyDiscount;
|
|
public float TraderSellBonus;
|
|
public bool RunicPing;
|
|
public bool RunicOvercharge;
|
|
}
|
|
|
|
// GetRules runs from Update loops and from damage patches, so the per-state result is
|
|
// built once and handed back on every later call.
|
|
private static readonly DvergarRules[] cache = new DvergarRules[BossProgressionManager.MaxState + 1];
|
|
private static readonly bool[] cached = new bool[BossProgressionManager.MaxState + 1];
|
|
|
|
public static DvergarRules GetRules(int state)
|
|
{
|
|
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<DvergarConfig.WeaponAffinity> affinities = new List<DvergarConfig.WeaponAffinity>();
|
|
foreach (DvergarConfig.WeaponAffinity affinity in DvergarConfig.WeaponAffinities)
|
|
{
|
|
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
|
|
{
|
|
HealthMalus = DvergarConfig.Lookup(DvergarConfig.HealthMalusByState, state),
|
|
ElementalDamage = DvergarConfig.ElementalDamagePerState * state,
|
|
Affinities = affinities,
|
|
MiningAffinity = state >= DvergarConfig.MiningAffinityState,
|
|
SmithingDiscount = DvergarConfig.Lookup(DvergarConfig.SmithingDiscountByState, state),
|
|
TraderBuyDiscount = DvergarConfig.Lookup(DvergarConfig.TraderBuyDiscountByState, state),
|
|
TraderSellBonus = DvergarConfig.Lookup(DvergarConfig.TraderSellBonusByState, state),
|
|
RunicPing = state >= DvergarConfig.RunicPingState,
|
|
RunicOvercharge = state >= DvergarConfig.RunicOverchargeState
|
|
};
|
|
|
|
cache[state] = rules;
|
|
cached[state] = true;
|
|
return rules;
|
|
}
|
|
|
|
/// <summary>Rules for whatever tier the local player is currently on.</summary>
|
|
public static DvergarRules Current => GetRules(BossProgressionManager.GetCurrentProgressionState());
|
|
|
|
/// <summary>
|
|
/// The affinity covering a weapon skill at the current tier, or null when the Dvergar has
|
|
/// no particular feel for it. Mining counts as an affinity for stamina purposes only, so
|
|
/// it is deliberately not part of this list.
|
|
/// </summary>
|
|
public static DvergarConfig.WeaponAffinity? GetAffinity(Skills.SkillType skill, int state)
|
|
{
|
|
DvergarRules rules = GetRules(state);
|
|
foreach (DvergarConfig.WeaponAffinity affinity in rules.Affinities)
|
|
{
|
|
if (affinity.Skill == skill) return affinity;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|