From 4b5d60d4b6790ffe54a7d7bc779a4f474eae0dfb Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 6 Aug 2026 15:34:05 +0200 Subject: [PATCH] feat(trol): make ability numbers and keybinds BepInEx-configurable Adds TrolConfig.cs, following the established per-race pattern: one Configuration Manager section per topic (Passive Combat, Throw Rock, True Form, Log Weapon, Farming), plus the two ability keybinds (Throw Rock, True Form). Defaults match the previous hardcoded constants exactly. Fixes a real sync risk found while wiring it: True Form's scale (2.0 normal / 2.5 at tier 7+) was hardcoded independently in two places - the local transform routine in TrolRace and the remote-player sizing postfix in TrolPatches. Both now read the same TrolConfig.TrueFormScaleNormal/ TrueFormScaleAdvanced, so a retuned value can no longer make a Trol one size to themselves and another size to everyone else. Tier-gate thresholds and the small hardcoded "normal size by tier" table (1.2/1.25/1.30) stay untouched, same boundary drawn for every other race's progression data. Config sections stay bound alphabetically by race (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Trenta, Trol) in RacesOfValheim.Awake() - this is the last of the nine. --- JotunnModStub/RacesOfValheim.cs | 1 + JotunnModStub/Trol/TrolConfig.cs | 130 +++++++++++++++++++++++ JotunnModStub/Trol/TrolDamagePatches.cs | 19 ++-- JotunnModStub/Trol/TrolFarmingPatches.cs | 2 +- JotunnModStub/Trol/TrolPatches.cs | 13 ++- JotunnModStub/Trol/TrolRace.cs | 32 +++--- JotunnModStub/Trol/TrolRegenPatches.cs | 2 +- JotunnModStub/Trol/TrolSkillPatches.cs | 2 +- JotunnModStub/Trol/TrolStatusEffects.cs | 4 +- 9 files changed, 170 insertions(+), 35 deletions(-) create mode 100644 JotunnModStub/Trol/TrolConfig.cs diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 6307a83..09d87f8 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -35,6 +35,7 @@ namespace RacesOfValheim SkadiConfig.Bind(Config); SkeletonConfig.Bind(Config); TrentaConfigManagement.Bind(Config); + TrolConfig.Bind(Config); harmony.PatchAll(); gameObject.AddComponent(); gameObject.AddComponent(); diff --git a/JotunnModStub/Trol/TrolConfig.cs b/JotunnModStub/Trol/TrolConfig.cs new file mode 100644 index 0000000..de2c18e --- /dev/null +++ b/JotunnModStub/Trol/TrolConfig.cs @@ -0,0 +1,130 @@ +using UnityEngine; +using BepInEx.Configuration; + +namespace RacesOfValheim +{ + /// + /// Every tunable number and keybind behind the Trol's abilities, bound as BepInEx 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 every other race's layout). + /// + /// Tier-gate thresholds (which progression state unlocks each perk) are left as-is, same + /// boundary drawn for every other race's progression table - not exposed here. + /// + /// True Form's scale (Normal/Advanced) is read from both the local transform routine + /// (TrolRace) and the remote-sizing postfix (TrolPatches) - both now read the same + /// ConfigEntry rather than each carrying its own literal, so a retuned value can no longer + /// make a Trol one size to themselves and another to everyone else. + /// + public static class TrolConfig + { + // ─── Keybinds ────────────────────────────────────────────────────────── + public static ConfigEntry ThrowRockKey; + public static ConfigEntry TrueFormKey; + + // ─── Passive combat ────────────────────────────────────────────────── + public static ConfigEntry FireWeaknessMultiplier; + public static ConfigEntry BonemassMeleeBonus; + public static ConfigEntry YagluthMeleeBonus; + public static ConfigEntry TrueFormMeleeBonus; + public static ConfigEntry RegenMultiplierBonus; + public static ConfigEntry FavoredSkillXPMultiplier; + public static ConfigEntry CarryWeightBonusBase; + public static ConfigEntry CarryWeightBonusBonemass; + public static ConfigEntry CarryWeightBonusYagluth; + public static ConfigEntry ArmorBonusPerState; + + // ─── Throw Rock (tier 3+) ───────────────────────────────────────────── + public static ConfigEntry ThrowRockCooldown; + public static ConfigEntry ThrowRockCooldownTrueForm; + public static ConfigEntry ThrowRockBaseDamage; + public static ConfigEntry ThrowRockBonemassBonus; + public static ConfigEntry ThrowRockYagluthBonus; + public static ConfigEntry ThrowRockTrueFormBonus; + public static ConfigEntry ThrowRockProjectileVelocity; + public static ConfigEntry ThrowLogVelocity; + + // ─── True Form (tier 5+) ─────────────────────────────────────────────── + public static ConfigEntry TrueFormDuration; + public static ConfigEntry TrueFormCooldown; + public static ConfigEntry TrueFormScaleNormal; + public static ConfigEntry TrueFormScaleAdvanced; + + // ─── Log Weapon (tier 7+) ────────────────────────────────────────────── + public static ConfigEntry LogWeaponMaxDurability; + public static ConfigEntry LogWeaponDurabilityDrainPerHit; + + // ─── Farming ─────────────────────────────────────────────────────────── + public static ConfigEntry UnarmedFarmingDamageBonusPerState; + + public static void Bind(ConfigFile config) + { + const string keybinds = "Trol - Keybinds"; + ThrowRockKey = config.Bind(keybinds, "Throw Rock", new KeyboardShortcut(KeyCode.G), + new ConfigDescription("Throws a rock (or the log you're holding), tier 3+.")); + TrueFormKey = config.Bind(keybinds, "True Form", new KeyboardShortcut(KeyCode.H), + new ConfigDescription("Transform into (or revert from) True Form, tier 5+.")); + + const string combat = "Trol - Passive Combat"; + FireWeaknessMultiplier = config.Bind(combat, "Fire Weakness Multiplier", 1.5f, + new ConfigDescription("Multiplies incoming fire damage (1.5 = 50% weaker).", new AcceptableValueRange(1f, 3f))); + BonemassMeleeBonus = config.Bind(combat, "Bonemass Melee Bonus", 10f, + new ConfigDescription("Flat damage added to Clubs/Unarmed/Axes attacks, tier 4+.", new AcceptableValueRange(0f, 100f))); + YagluthMeleeBonus = config.Bind(combat, "Yagluth Melee Bonus", 5f, + new ConfigDescription("Additional flat damage added to Clubs/Unarmed/Axes attacks, tier 6+.", new AcceptableValueRange(0f, 100f))); + TrueFormMeleeBonus = config.Bind(combat, "True Form Melee Bonus", 40f, + new ConfigDescription("Flat damage added to Clubs/Unarmed/Axes attacks while in True Form.", new AcceptableValueRange(0f, 200f))); + RegenMultiplierBonus = config.Bind(combat, "Regen Multiplier Bonus", 0.10f, + new ConfigDescription("Health regen multiplier bonus, tier 3+ (0.10 = +10%).", new AcceptableValueRange(0f, 2f))); + FavoredSkillXPMultiplier = config.Bind(combat, "Favored Skill XP Multiplier", 2f, + new ConfigDescription("Multiplies XP gain for Clubs/Unarmed/Axes/Pickaxes/WoodCutting, tier 2+.", new AcceptableValueRange(0.5f, 5f))); + CarryWeightBonusBase = config.Bind(combat, "Carry Weight Bonus (Base)", 200f, + new ConfigDescription("Flat carry weight added, always active.", new AcceptableValueRange(0f, 1000f))); + CarryWeightBonusBonemass = config.Bind(combat, "Carry Weight Bonus (Bonemass)", 50f, + new ConfigDescription("Additional flat carry weight, tier 4+.", new AcceptableValueRange(0f, 500f))); + CarryWeightBonusYagluth = config.Bind(combat, "Carry Weight Bonus (Yagluth)", 50f, + new ConfigDescription("Additional flat carry weight, tier 6+.", new AcceptableValueRange(0f, 500f))); + ArmorBonusPerState = config.Bind(combat, "Armor Bonus Per State", 3f, + new ConfigDescription("Flat armor added, per progression state.", new AcceptableValueRange(0f, 20f))); + + const string throwRock = "Trol - Throw Rock"; + ThrowRockCooldown = config.Bind(throwRock, "Cooldown", 60f, + new ConfigDescription("Seconds between throws in human form.", new AcceptableValueRange(0f, 300f))); + ThrowRockCooldownTrueForm = config.Bind(throwRock, "Cooldown (True Form)", 15f, + new ConfigDescription("Seconds between throws while in True Form.", new AcceptableValueRange(0f, 300f))); + ThrowRockBaseDamage = config.Bind(throwRock, "Base Damage", 25f, + new ConfigDescription("Base blunt damage of a thrown rock (not used when throwing a log).", new AcceptableValueRange(0f, 200f))); + ThrowRockBonemassBonus = config.Bind(throwRock, "Bonemass Bonus", 10f, + new ConfigDescription("Additional damage, tier 4+.", new AcceptableValueRange(0f, 100f))); + ThrowRockYagluthBonus = config.Bind(throwRock, "Yagluth Bonus", 5f, + new ConfigDescription("Additional damage, tier 6+.", new AcceptableValueRange(0f, 100f))); + ThrowRockTrueFormBonus = config.Bind(throwRock, "True Form Bonus", 40f, + new ConfigDescription("Additional damage while in True Form.", new AcceptableValueRange(0f, 200f))); + ThrowRockProjectileVelocity = config.Bind(throwRock, "Rock Velocity", 20f, + new ConfigDescription("Travel speed of a thrown rock.", new AcceptableValueRange(1f, 60f))); + ThrowLogVelocity = config.Bind(throwRock, "Log Velocity", 60f, + new ConfigDescription("Travel speed of a thrown log (compensates for its weight/drag).", new AcceptableValueRange(1f, 150f))); + + const string trueForm = "Trol - True Form"; + TrueFormDuration = config.Bind(trueForm, "Duration", 60f, + new ConfigDescription("Seconds True Form lasts before automatically reverting.", new AcceptableValueRange(5f, 600f))); + TrueFormCooldown = config.Bind(trueForm, "Cooldown", 600f, + new ConfigDescription("Seconds between True Form activations.", new AcceptableValueRange(0f, 3600f))); + TrueFormScaleNormal = config.Bind(trueForm, "Scale", 2.0f, + new ConfigDescription("Model scale while in True Form, tier 5-6.", new AcceptableValueRange(1f, 4f))); + TrueFormScaleAdvanced = config.Bind(trueForm, "Scale (Tier 7+)", 2.5f, + new ConfigDescription("Model scale while in True Form, tier 7+.", new AcceptableValueRange(1f, 4f))); + + const string logWeapon = "Trol - Log Weapon"; + LogWeaponMaxDurability = config.Bind(logWeapon, "Max Durability", 6f, + new ConfigDescription("Hits a grabbed log weapon survives before breaking, tier 7+.", new AcceptableValueRange(1f, 50f))); + LogWeaponDurabilityDrainPerHit = config.Bind(logWeapon, "Durability Drain Per Hit", 1f, + new ConfigDescription("Durability spent per hit landed.", new AcceptableValueRange(0.1f, 10f))); + + const string farming = "Trol - Farming"; + UnarmedFarmingDamageBonusPerState = config.Bind(farming, "Unarmed Damage Bonus Per State", 3f, + new ConfigDescription("Extra chop/pickaxe damage when farming or mining unarmed, per progression state.", new AcceptableValueRange(0f, 20f))); + } + } +} diff --git a/JotunnModStub/Trol/TrolDamagePatches.cs b/JotunnModStub/Trol/TrolDamagePatches.cs index b858cba..c20d3f2 100644 --- a/JotunnModStub/Trol/TrolDamagePatches.cs +++ b/JotunnModStub/Trol/TrolDamagePatches.cs @@ -10,10 +10,10 @@ namespace RacesOfValheim { if (__instance == Player.m_localPlayer && TrolRace.IsTrol()) { - // Trols are weak to fire (take 50% more damage) + // Trols are weak to fire if (hit.m_damage.m_fire > 0f) { - hit.m_damage.m_fire *= 1.5f; + hit.m_damage.m_fire *= TrolConfig.FireWeaknessMultiplier.Value; } } @@ -21,37 +21,40 @@ namespace RacesOfValheim { if (BossProgressionManager.GetCurrentProgressionState() >= 4) // Bonemass { + float bonus = TrolConfig.BonemassMeleeBonus.Value; if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed) { - hit.m_damage.m_blunt += 10f; + hit.m_damage.m_blunt += bonus; } else if (hit.m_skill == Skills.SkillType.Axes) { - hit.m_damage.m_slash += 10f; + hit.m_damage.m_slash += bonus; } } if (BossProgressionManager.GetCurrentProgressionState() >= 6) // Yagluth { + float bonus = TrolConfig.YagluthMeleeBonus.Value; if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed) { - hit.m_damage.m_blunt += 5f; + hit.m_damage.m_blunt += bonus; } else if (hit.m_skill == Skills.SkillType.Axes) { - hit.m_damage.m_slash += 5f; + hit.m_damage.m_slash += bonus; } } if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode())) { + float bonus = TrolConfig.TrueFormMeleeBonus.Value; if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed) { - hit.m_damage.m_blunt += 40f; + hit.m_damage.m_blunt += bonus; } else if (hit.m_skill == Skills.SkillType.Axes) { - hit.m_damage.m_slash += 40f; + hit.m_damage.m_slash += bonus; } } } diff --git a/JotunnModStub/Trol/TrolFarmingPatches.cs b/JotunnModStub/Trol/TrolFarmingPatches.cs index be7c476..1e43a40 100644 --- a/JotunnModStub/Trol/TrolFarmingPatches.cs +++ b/JotunnModStub/Trol/TrolFarmingPatches.cs @@ -33,7 +33,7 @@ namespace RacesOfValheim else if (state >= 3) hit.m_toolTier = 1; // Elder (Bronze) else if (state >= 2) hit.m_toolTier = 1; // Eikthyr (Flint/Antler) - float damageBonus = state * 3f; + float damageBonus = state * TrolConfig.UnarmedFarmingDamageBonusPerState.Value; // Convert blunt damage to chop or pickaxe damage, plus progression bonus if (isTree) diff --git a/JotunnModStub/Trol/TrolPatches.cs b/JotunnModStub/Trol/TrolPatches.cs index 5c1a2c3..4fd11b1 100644 --- a/JotunnModStub/Trol/TrolPatches.cs +++ b/JotunnModStub/Trol/TrolPatches.cs @@ -149,7 +149,7 @@ namespace RacesOfValheim float targetScale = ScaleForState(state); if (isTrueFormActive) { - targetScale = state >= 7 ? 2.5f : 2.0f; + targetScale = state >= 7 ? TrolConfig.TrueFormScaleAdvanced.Value : TrolConfig.TrueFormScaleNormal.Value; } if (!isLocal) @@ -204,18 +204,18 @@ namespace RacesOfValheim string race = "Human"; ZNetView nview = __instance.GetComponent(); if (nview != null && nview.IsValid()) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human"); else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace; if (race == "Trol") { - // Base carry weight is 300. We add 200 to make it 500. + // Base carry weight is 300. We add a bonus to make it 500 by default. // If they wear Megingjord, it will become 500 + 150 = 650. - __result += 200f; + __result += TrolConfig.CarryWeightBonusBase.Value; int state = BossProgressionManager.GetCurrentProgressionState(); if (state >= 4) { - __result += 50f; // After Bonemass + __result += TrolConfig.CarryWeightBonusBonemass.Value; } if (state >= 6) { - __result += 50f; // After Yagluth + __result += TrolConfig.CarryWeightBonusYagluth.Value; } } } @@ -228,9 +228,8 @@ namespace RacesOfValheim { if (__instance == Player.m_localPlayer && TrolRace.IsTrol()) { - // +3 Armor per progression state (boss defeated) int state = BossProgressionManager.GetCurrentProgressionState(); - __result += 3f * state; + __result += TrolConfig.ArmorBonusPerState.Value * state; } } } diff --git a/JotunnModStub/Trol/TrolRace.cs b/JotunnModStub/Trol/TrolRace.cs index 5b7eb15..a132bc8 100644 --- a/JotunnModStub/Trol/TrolRace.cs +++ b/JotunnModStub/Trol/TrolRace.cs @@ -98,9 +98,9 @@ namespace RacesOfValheim } ItemDrop itemDrop = customWep.ItemPrefab.GetComponent(); - itemDrop.m_itemData.m_shared.m_maxDurability = 6f; + itemDrop.m_itemData.m_shared.m_maxDurability = TrolConfig.LogWeaponMaxDurability.Value; itemDrop.m_itemData.m_shared.m_useDurability = true; - itemDrop.m_itemData.m_shared.m_useDurabilityDrain = 1f; + itemDrop.m_itemData.m_shared.m_useDurabilityDrain = TrolConfig.LogWeaponDurabilityDrainPerHit.Value; itemDrop.m_itemData.m_shared.m_destroyBroken = false; itemDrop.m_itemData.m_shared.m_weight = 0f; itemDrop.m_itemData.m_shared.m_equipDuration = 0.1f; @@ -121,12 +121,12 @@ namespace RacesOfValheim if (RaceInput.Allowed) { - if (Input.GetKeyDown(KeyCode.G)) + if (TrolConfig.ThrowRockKey.Value.IsDown()) { TryThrowRock(); } - if (Input.GetKeyDown(KeyCode.H)) + if (TrolConfig.TrueFormKey.Value.IsDown()) { TryTrueForm(); } @@ -217,7 +217,9 @@ namespace RacesOfValheim if (visual != null) { Vector3 startScale = visual.transform.localScale; - float trueFormScale = BossProgressionManager.GetCurrentProgressionState() >= 7 ? 2.5f : 2.0f; + float trueFormScale = BossProgressionManager.GetCurrentProgressionState() >= 7 + ? TrolConfig.TrueFormScaleAdvanced.Value + : TrolConfig.TrueFormScaleNormal.Value; Vector3 targetScale = new Vector3(trueFormScale, trueFormScale, trueFormScale); while (elapsed < duration) @@ -277,7 +279,7 @@ namespace RacesOfValheim private System.Collections.IEnumerator ThrowRockRoutine() { bool isTrueForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode()); - float throwRockCooldown = isTrueForm ? 15f : 60f; + float throwRockCooldown = isTrueForm ? TrolConfig.ThrowRockCooldownTrueForm.Value : TrolConfig.ThrowRockCooldown.Value; var addedSE = Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_TrolThrowRockCooldown".GetStableHashCode(), true); if (addedSE != null) @@ -323,8 +325,8 @@ namespace RacesOfValheim if (rb != null) { - // 3x speed to compensate for log weight/drag - rb.velocity = Player.m_localPlayer.GetLookDir() * 60f; + // Compensates for log weight/drag + rb.velocity = Player.m_localPlayer.GetLookDir() * TrolConfig.ThrowLogVelocity.Value; // Add some slight rotation tumbling rb.angularVelocity = new Vector3(10f, 5f, 0f); } @@ -343,24 +345,24 @@ namespace RacesOfValheim if (proj != null) { HitData hitData = new HitData(); - hitData.m_damage.m_blunt = 25f; // Base troll rock - + hitData.m_damage.m_blunt = TrolConfig.ThrowRockBaseDamage.Value; + if (BossProgressionManager.GetCurrentProgressionState() >= 4) { - hitData.m_damage.m_blunt += 10f; // Bonemass bonus + hitData.m_damage.m_blunt += TrolConfig.ThrowRockBonemassBonus.Value; } if (BossProgressionManager.GetCurrentProgressionState() >= 6) { - hitData.m_damage.m_blunt += 5f; // Yagluth bonus + hitData.m_damage.m_blunt += TrolConfig.ThrowRockYagluthBonus.Value; } - + if (isTrueForm) { - hitData.m_damage.m_blunt += 40f; // True Form bonus + hitData.m_damage.m_blunt += TrolConfig.ThrowRockTrueFormBonus.Value; } hitData.SetAttacker(Player.m_localPlayer); - proj.Setup(Player.m_localPlayer, Player.m_localPlayer.GetLookDir() * 20f, -1f, hitData, null, null); + proj.Setup(Player.m_localPlayer, Player.m_localPlayer.GetLookDir() * TrolConfig.ThrowRockProjectileVelocity.Value, -1f, hitData, null, null); } } } diff --git a/JotunnModStub/Trol/TrolRegenPatches.cs b/JotunnModStub/Trol/TrolRegenPatches.cs index 36f1866..79f4009 100644 --- a/JotunnModStub/Trol/TrolRegenPatches.cs +++ b/JotunnModStub/Trol/TrolRegenPatches.cs @@ -12,7 +12,7 @@ namespace RacesOfValheim // After The Elder (Progression State >= 2) if (BossProgressionManager.GetCurrentProgressionState() >= 3) { - regenMultiplier *= 1.10f; // +10% passive health regeneration + regenMultiplier *= 1f + TrolConfig.RegenMultiplierBonus.Value; } } } diff --git a/JotunnModStub/Trol/TrolSkillPatches.cs b/JotunnModStub/Trol/TrolSkillPatches.cs index 8db9b8b..d07bc9b 100644 --- a/JotunnModStub/Trol/TrolSkillPatches.cs +++ b/JotunnModStub/Trol/TrolSkillPatches.cs @@ -23,7 +23,7 @@ namespace RacesOfValheim if (isTrolSkill) { - factor *= 2f; + factor *= TrolConfig.FavoredSkillXPMultiplier.Value; } } } diff --git a/JotunnModStub/Trol/TrolStatusEffects.cs b/JotunnModStub/Trol/TrolStatusEffects.cs index d61840f..e5277f6 100644 --- a/JotunnModStub/Trol/TrolStatusEffects.cs +++ b/JotunnModStub/Trol/TrolStatusEffects.cs @@ -35,7 +35,7 @@ namespace RacesOfValheim name = "SE_TrolTrueForm"; m_name = "True Form"; m_tooltip = "You have unleashed your inner troll!"; - m_ttl = 60f; // 1 minute duration + m_ttl = TrolConfig.TrueFormDuration.Value; GameObject itemPrefab = PrefabManager.Cache.GetPrefab("Stone"); if (itemPrefab != null) @@ -57,7 +57,7 @@ namespace RacesOfValheim name = "SE_TrolTrueFormCooldown"; m_name = "True Form Cooldown"; m_tooltip = "You are exhausted from your True Form."; - m_ttl = 600f; // 10 minutes cooldown + m_ttl = TrolConfig.TrueFormCooldown.Value; GameObject itemPrefab = PrefabManager.Cache.GetPrefab("Stone"); if (itemPrefab != null)