Compare commits
1 commit
localisati
...
fix-factio
| Author | SHA1 | Date | |
|---|---|---|---|
| a3b1666036 |
3 changed files with 78 additions and 3 deletions
25
JotunnModStub/Factions/FactionConfig.cs
Normal file
25
JotunnModStub/Factions/FactionConfig.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tunables for the Factions truce system, bound as BepInEx ConfigEntry - see
|
||||||
|
/// CONFIGURATION-MANAGER-HOWTO.md. Bound once, from RacesOfValheim.Awake().
|
||||||
|
/// </summary>
|
||||||
|
public static class FactionConfig
|
||||||
|
{
|
||||||
|
public static ConfigEntry<bool> ShareHostilityWithParty;
|
||||||
|
|
||||||
|
public static void Bind(ConfigFile config)
|
||||||
|
{
|
||||||
|
const string section = "Factions - Hostility";
|
||||||
|
|
||||||
|
ShareHostilityWithParty = config.Bind(section, "Share Hostility With Party", false,
|
||||||
|
new ConfigDescription(
|
||||||
|
"When enabled, a player's truce covers every faction any connected player's race " +
|
||||||
|
"belongs to - a Dvergar and an Aswid playing together are both left alone by the " +
|
||||||
|
"Mountain's mobs AND the Swamp's, not just their own. When disabled (default), each " +
|
||||||
|
"player is only exempted for their own race's faction."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -64,16 +64,65 @@ namespace RacesOfValheim
|
||||||
{ SkeletonVisuals.RaceId, PaludeMobs },
|
{ SkeletonVisuals.RaceId, PaludeMobs },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the race off the ZDO so remote players are recognised correctly - the same fix
|
||||||
|
/// DraughVisuals/TrentaVisuals already needed for their own per-player lookups.
|
||||||
|
/// player.m_customData is local save data, never networked, so a check reading it directly
|
||||||
|
/// only ever sees the truth for whichever client is doing the asking; on any other peer
|
||||||
|
/// (which is who actually owns a given mob's ZDO in multiplayer, most of the time) it is
|
||||||
|
/// empty or stale, wrong for every remote player. Falls back to m_customData only for the
|
||||||
|
/// main-menu preview, which has no ZNetView at all.
|
||||||
|
/// </summary>
|
||||||
|
private static string GetPlayerRace(Player player)
|
||||||
|
{
|
||||||
|
if (player == null) return "Human";
|
||||||
|
|
||||||
|
ZNetView nview = player.GetComponent<ZNetView>();
|
||||||
|
if (nview != null && nview.IsValid())
|
||||||
|
{
|
||||||
|
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
|
||||||
|
if (!string.IsNullOrEmpty(race)) return race;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string custom))
|
||||||
|
{
|
||||||
|
return custom;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Human";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryGetOwnFactionMobs(Player player, out HashSet<string> mobs)
|
||||||
|
{
|
||||||
|
return RaceFactionMobs.TryGetValue(GetPlayerRace(player), out mobs);
|
||||||
|
}
|
||||||
|
|
||||||
// Shared with FactionMerchantHoverPatch: a player should only get the "E - Talk"
|
// Shared with FactionMerchantHoverPatch: a player should only get the "E - Talk"
|
||||||
// hover prompt for a mob whose faction actually matches their own race.
|
// hover prompt for a mob whose faction actually matches their own race.
|
||||||
|
//
|
||||||
|
// With FactionConfig.ShareHostilityWithParty on, "their own race" widens to "any
|
||||||
|
// connected player's race" - a shared truce for the whole party rather than one drawn
|
||||||
|
// per player, so a Dvergar and an Aswid adventuring together are left alone by both the
|
||||||
|
// Mountain's mobs and the Swamp's.
|
||||||
public static bool IsSameFaction(Player player, Character monster)
|
public static bool IsSameFaction(Player player, Character monster)
|
||||||
{
|
{
|
||||||
if (player == null || monster == null) return false;
|
if (player == null || monster == null) return false;
|
||||||
if (!player.m_customData.TryGetValue("Race", out string race)) return false;
|
|
||||||
if (!RaceFactionMobs.TryGetValue(race, out HashSet<string> mobs)) return false;
|
|
||||||
|
|
||||||
string prefabName = monster.gameObject.name.Replace("(Clone)", "").Trim();
|
string prefabName = monster.gameObject.name.Replace("(Clone)", "").Trim();
|
||||||
return mobs.Contains(prefabName);
|
|
||||||
|
if (!FactionConfig.ShareHostilityWithParty.Value)
|
||||||
|
{
|
||||||
|
return TryGetOwnFactionMobs(player, out HashSet<string> mobs) && mobs.Contains(prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Player other in Player.GetAllPlayers())
|
||||||
|
{
|
||||||
|
if (TryGetOwnFactionMobs(other, out HashSet<string> mobs) && mobs.Contains(prefabName))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Postfix(Character a, Character b, ref bool __result)
|
public static void Postfix(Character a, Character b, ref bool __result)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace RacesOfValheim
|
||||||
AswidConfig.Bind(Config);
|
AswidConfig.Bind(Config);
|
||||||
DraughConfig.Bind(Config);
|
DraughConfig.Bind(Config);
|
||||||
DvergarConfigManagement.Bind(Config);
|
DvergarConfigManagement.Bind(Config);
|
||||||
|
FactionConfig.Bind(Config);
|
||||||
FenrirConfig.Bind(Config);
|
FenrirConfig.Bind(Config);
|
||||||
FurlingConfig.Bind(Config);
|
FurlingConfig.Bind(Config);
|
||||||
SkadiConfig.Bind(Config);
|
SkadiConfig.Bind(Config);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue