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.
This commit is contained in:
kanym 2026-08-06 15:34:05 +02:00
commit 4b5d60d4b6
9 changed files with 170 additions and 35 deletions

View file

@ -35,6 +35,7 @@ namespace RacesOfValheim
SkadiConfig.Bind(Config);
SkeletonConfig.Bind(Config);
TrentaConfigManagement.Bind(Config);
TrolConfig.Bind(Config);
harmony.PatchAll();
gameObject.AddComponent<FenrirRace>();
gameObject.AddComponent<SkadiRace>();

View file

@ -0,0 +1,130 @@
using UnityEngine;
using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// 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.
/// </summary>
public static class TrolConfig
{
// ─── Keybinds ──────────────────────────────────────────────────────────
public static ConfigEntry<KeyboardShortcut> ThrowRockKey;
public static ConfigEntry<KeyboardShortcut> TrueFormKey;
// ─── Passive combat ──────────────────────────────────────────────────
public static ConfigEntry<float> FireWeaknessMultiplier;
public static ConfigEntry<float> BonemassMeleeBonus;
public static ConfigEntry<float> YagluthMeleeBonus;
public static ConfigEntry<float> TrueFormMeleeBonus;
public static ConfigEntry<float> RegenMultiplierBonus;
public static ConfigEntry<float> FavoredSkillXPMultiplier;
public static ConfigEntry<float> CarryWeightBonusBase;
public static ConfigEntry<float> CarryWeightBonusBonemass;
public static ConfigEntry<float> CarryWeightBonusYagluth;
public static ConfigEntry<float> ArmorBonusPerState;
// ─── Throw Rock (tier 3+) ─────────────────────────────────────────────
public static ConfigEntry<float> ThrowRockCooldown;
public static ConfigEntry<float> ThrowRockCooldownTrueForm;
public static ConfigEntry<float> ThrowRockBaseDamage;
public static ConfigEntry<float> ThrowRockBonemassBonus;
public static ConfigEntry<float> ThrowRockYagluthBonus;
public static ConfigEntry<float> ThrowRockTrueFormBonus;
public static ConfigEntry<float> ThrowRockProjectileVelocity;
public static ConfigEntry<float> ThrowLogVelocity;
// ─── True Form (tier 5+) ───────────────────────────────────────────────
public static ConfigEntry<float> TrueFormDuration;
public static ConfigEntry<float> TrueFormCooldown;
public static ConfigEntry<float> TrueFormScaleNormal;
public static ConfigEntry<float> TrueFormScaleAdvanced;
// ─── Log Weapon (tier 7+) ──────────────────────────────────────────────
public static ConfigEntry<float> LogWeaponMaxDurability;
public static ConfigEntry<float> LogWeaponDurabilityDrainPerHit;
// ─── Farming ───────────────────────────────────────────────────────────
public static ConfigEntry<float> 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<float>(1f, 3f)));
BonemassMeleeBonus = config.Bind(combat, "Bonemass Melee Bonus", 10f,
new ConfigDescription("Flat damage added to Clubs/Unarmed/Axes attacks, tier 4+.", new AcceptableValueRange<float>(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<float>(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<float>(0f, 200f)));
RegenMultiplierBonus = config.Bind(combat, "Regen Multiplier Bonus", 0.10f,
new ConfigDescription("Health regen multiplier bonus, tier 3+ (0.10 = +10%).", new AcceptableValueRange<float>(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<float>(0.5f, 5f)));
CarryWeightBonusBase = config.Bind(combat, "Carry Weight Bonus (Base)", 200f,
new ConfigDescription("Flat carry weight added, always active.", new AcceptableValueRange<float>(0f, 1000f)));
CarryWeightBonusBonemass = config.Bind(combat, "Carry Weight Bonus (Bonemass)", 50f,
new ConfigDescription("Additional flat carry weight, tier 4+.", new AcceptableValueRange<float>(0f, 500f)));
CarryWeightBonusYagluth = config.Bind(combat, "Carry Weight Bonus (Yagluth)", 50f,
new ConfigDescription("Additional flat carry weight, tier 6+.", new AcceptableValueRange<float>(0f, 500f)));
ArmorBonusPerState = config.Bind(combat, "Armor Bonus Per State", 3f,
new ConfigDescription("Flat armor added, per progression state.", new AcceptableValueRange<float>(0f, 20f)));
const string throwRock = "Trol - Throw Rock";
ThrowRockCooldown = config.Bind(throwRock, "Cooldown", 60f,
new ConfigDescription("Seconds between throws in human form.", new AcceptableValueRange<float>(0f, 300f)));
ThrowRockCooldownTrueForm = config.Bind(throwRock, "Cooldown (True Form)", 15f,
new ConfigDescription("Seconds between throws while in True Form.", new AcceptableValueRange<float>(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<float>(0f, 200f)));
ThrowRockBonemassBonus = config.Bind(throwRock, "Bonemass Bonus", 10f,
new ConfigDescription("Additional damage, tier 4+.", new AcceptableValueRange<float>(0f, 100f)));
ThrowRockYagluthBonus = config.Bind(throwRock, "Yagluth Bonus", 5f,
new ConfigDescription("Additional damage, tier 6+.", new AcceptableValueRange<float>(0f, 100f)));
ThrowRockTrueFormBonus = config.Bind(throwRock, "True Form Bonus", 40f,
new ConfigDescription("Additional damage while in True Form.", new AcceptableValueRange<float>(0f, 200f)));
ThrowRockProjectileVelocity = config.Bind(throwRock, "Rock Velocity", 20f,
new ConfigDescription("Travel speed of a thrown rock.", new AcceptableValueRange<float>(1f, 60f)));
ThrowLogVelocity = config.Bind(throwRock, "Log Velocity", 60f,
new ConfigDescription("Travel speed of a thrown log (compensates for its weight/drag).", new AcceptableValueRange<float>(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<float>(5f, 600f)));
TrueFormCooldown = config.Bind(trueForm, "Cooldown", 600f,
new ConfigDescription("Seconds between True Form activations.", new AcceptableValueRange<float>(0f, 3600f)));
TrueFormScaleNormal = config.Bind(trueForm, "Scale", 2.0f,
new ConfigDescription("Model scale while in True Form, tier 5-6.", new AcceptableValueRange<float>(1f, 4f)));
TrueFormScaleAdvanced = config.Bind(trueForm, "Scale (Tier 7+)", 2.5f,
new ConfigDescription("Model scale while in True Form, tier 7+.", new AcceptableValueRange<float>(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<float>(1f, 50f)));
LogWeaponDurabilityDrainPerHit = config.Bind(logWeapon, "Durability Drain Per Hit", 1f,
new ConfigDescription("Durability spent per hit landed.", new AcceptableValueRange<float>(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<float>(0f, 20f)));
}
}
}

View file

@ -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;
}
}
}

View file

@ -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)

View file

@ -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<ZNetView>(); 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;
}
}
}

View file

@ -98,9 +98,9 @@ namespace RacesOfValheim
}
ItemDrop itemDrop = customWep.ItemPrefab.GetComponent<ItemDrop>();
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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -23,7 +23,7 @@ namespace RacesOfValheim
if (isTrolSkill)
{
factor *= 2f;
factor *= TrolConfig.FavoredSkillXPMultiplier.Value;
}
}
}

View file

@ -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<GameObject>("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<GameObject>("Stone");
if (itemPrefab != null)