RacesOfValheim/JotunnModStub/Factions/FactionsConfig.cs
Ferdinando a60f5e8217 fix(factions): make the truce switch cover every player truce, not one of five
Reported from a live game: with "Faction truce" off, a Trenta's Greydwarves
stayed friendly. The switch was working - it just was not switched over the
patch that mattered.

Five separate Harmony postfixes answer BaseAI.IsEnemy, and only
FactionHostilityPatch was gated. A Trenta reads its Black Forest truce from
RaceHostilityManager, which had no switch, so turning the faction one off
changed nothing visible. The same held for the Fenrir's wolves, the Aswid's
progression list, the Draugh's undead, the Sverm's invertebrates, the
Furling's Plains roster and the Skeleton's undead.

Gated all four player-facing ones behind the existing flag rather than
adding a switch each: from the player's side there is one question being
asked, and a switch that answers a fifth of it is worse than none.

DvergarMercenaryTrucePatch is deliberately left alone - it is a truce
between a hired thrall and a wild dvergr, two NPCs, and has nothing to do
with whether mobs come after the player.

Key stays "Faction truce" though its scope grew: renaming it would orphan
the entry in every .cfg already written, and the file beats the default in
code, so anyone who had switched it off would silently get the truce back.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 19:13:16 +02:00

58 lines
3.9 KiB
C#

using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// The two switches that turn the Factions feature off, bound as BepInEx ConfigEntry so they
/// show up in Configuration Manager - same shape as WarVultureConfig, which is the house model.
///
/// Two switches rather than one because the halves fail differently. The truce is invisible
/// when it works and only shows up as mobs that ignore you; the merchants are a whole second
/// interaction bolted onto creatures that vanilla never meant to talk. Anyone hunting a mod
/// conflict wants to rule out one without losing the other.
///
/// Both read live, on every call, rather than being cached at patch time: the patches stay
/// installed and answer "not my business" while a switch is off. That costs one bool read per
/// call and buys a toggle that takes effect without restarting the game - with one asymmetry
/// worth knowing about, spelled out on Merchants below.
/// </summary>
public static class FactionsConfig
{
public static ConfigEntry<bool> HostilityEnabled;
public static ConfigEntry<bool> MerchantsEnabled;
// Null-safe, defaulting to ON, for the same reason WarVultureConfig guards its own reads:
// a patch that somehow runs before Bind() should behave like the shipped default rather
// than throw. Awake() binds before harmony.PatchAll(), so this should never fire.
public static bool Hostility => HostilityEnabled?.Value ?? true;
public static bool Merchants => MerchantsEnabled?.Value ?? true;
public static void Bind(ConfigFile config)
{
const string factions = "Factions";
// Key kept as "Faction truce" even though it now covers the per-race truces too:
// renaming it would orphan the entry in every .cfg already written, and an existing
// .cfg beats the default in code - anyone who had switched this off would silently
// get the truce back.
HostilityEnabled = config.Bind(factions, "Faction truce", true,
new ConfigDescription("Mobs your race is at peace with leave you alone - they will not open a fight, " +
"hunt you during events, or smash structures near you. Turn this off and every " +
"creature treats you exactly as vanilla would. Covers BOTH halves, because both " +
"answer the same BaseAI.IsEnemy and a switch over only one of them changes " +
"nothing for most races: the faction rules in FactionHostilityPatch, and the " +
"per-race passives in RaceHostilityManager - Fenrir's wolves, Aswid's " +
"progression list, the Draugh's undead, the Trenta's Black Forest, the Sverm's " +
"invertebrates. Switching this off gives those five races up along with the " +
"faction truce. Hitting a mob still starts a fight either way: retaliation runs " +
"through BaseAI.OnDamaged, which no truce has a say over."));
MerchantsEnabled = config.Bind(factions, "Faction merchants", true,
new ConfigDescription("Certain mobs of your own faction can be traded with - 'E - Talk' opens a shop " +
"where you sell them what their kind wants. Turn this off and they are ordinary " +
"creatures again. Takes effect immediately for the prompt, the trade window and " +
"the no-hit protection; the hidden Trader component already grafted onto mobs " +
"that woke up earlier stays until they unload, but nothing will read it."));
}
}
}