Stationary Hammer piece cloned from DvergerMageFire: scans a configurable radius for hostile, non-Mountain-faction, non-player Characters and fires its own fireball (real attack data pulled off Humanoid.m_defaultItems, grounded in an in-game dumpelder dump, not guessed). Fire-only for this first pass; Ice/Support are a later append to the same pattern. Several in-game fixes along the way: a missing piece icon (Jotunn silently drops any piece without one), a missing known-piece teach on spawn (same fix RaceMenuWard already needed), a kinematic Rigidbody fighting Character's own velocity writes, and MonsterAI needing to be disabled rather than destroyed - several vanilla systems (EnemyHud, most likely damage registration too) assume any combat-relevant Character has one. FactionHostilityPatch gains a public IsMountainFactionMob accessor so the construct's target filter shares the same Mountain roster as the rest of Factions instead of a second hand-maintained list.
96 lines
4.3 KiB
C#
96 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using HarmonyLib;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
// "Mobs of a faction don't attack players of the same faction" - the core Factions
|
|
// rule from the brainstorm. RaceHostilityManager.cs already grants some of this
|
|
// (Fenrir/Aswid/Draugh/Trenta), but several races have no coverage at all (Trol,
|
|
// Furling, Skadi, Dvergar, Skeleton), and none of it lines up race-for-race with the
|
|
// three Factions groupings. Both patches postfix the same vanilla method, so this one
|
|
// simply layers the full, faction-consistent ruleset on top without touching the
|
|
// older file - a player already exempted there stays exempted, this only adds pairs.
|
|
//
|
|
// Without this, a matching-faction mob keeps fighting the player, which is why the
|
|
// Trader's "E to use" prompt never has a chance to come up: BaseAI.UpdateAI() is
|
|
// still busy chasing/attacking every frame.
|
|
[HarmonyPatch(typeof(BaseAI), nameof(BaseAI.IsEnemy), new System.Type[] { typeof(Character), typeof(Character) })]
|
|
public static class FactionHostilityPatch
|
|
{
|
|
private static readonly HashSet<string> NeraForestaMobs = new HashSet<string>
|
|
{
|
|
"Greydwarf", "Greydwarf_Elite", "Greydwarf_Shaman",
|
|
"Fuling", "GoblinBrute", "GoblinShaman",
|
|
"Troll",
|
|
};
|
|
|
|
private static readonly HashSet<string> MontagnaMobs = new HashSet<string>
|
|
{
|
|
"Hatchling", // Drake
|
|
"Wolf", "Ulv", "Fenring", "Fenring_Cultist",
|
|
"Dverger", "DvergerMageFire", "DvergerMageIce", "DvergerMageSupport", "DvergerAshlands",
|
|
};
|
|
|
|
private static readonly HashSet<string> PaludeMobs = new HashSet<string>
|
|
{
|
|
"Ghost", "Skeleton", "Skeleton_Poison", // Skeleton, Rancid remains
|
|
"Draugr", "Draugr_Elite",
|
|
"Wraith", "Leech", "Abomination",
|
|
"Blob", "BlobElite", "BlobTar", // Blob, Oozer, Growth
|
|
};
|
|
|
|
// Every race id ever assigned to m_customData["Race"] for the nine playable races,
|
|
// grouped by which faction's mobs they get along with (see RacesOfValheim.cs for
|
|
// where each string is set, and DvergarRace.cs's LegacyRaceId for the old save value).
|
|
private static readonly Dictionary<string, HashSet<string>> RaceFactionMobs = new Dictionary<string, HashSet<string>>
|
|
{
|
|
{ TrentaConfig.RaceId, NeraForestaMobs },
|
|
{ "Trol", NeraForestaMobs },
|
|
{ "Furling", NeraForestaMobs },
|
|
|
|
{ "Skadi", MontagnaMobs },
|
|
{ "Fenrir", MontagnaMobs },
|
|
{ DvergarConfig.RaceId, MontagnaMobs },
|
|
{ DvergarRace.LegacyRaceId, MontagnaMobs },
|
|
|
|
{ "Aswid", PaludeMobs },
|
|
{ "Draugh", PaludeMobs },
|
|
{ SkeletonVisuals.RaceId, PaludeMobs },
|
|
};
|
|
|
|
// Shared with FactionMerchantHoverPatch: a player should only get the "E - Talk"
|
|
// hover prompt for a mob whose faction actually matches their own race.
|
|
public static bool IsSameFaction(Player player, Character monster)
|
|
{
|
|
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();
|
|
return mobs.Contains(prefabName);
|
|
}
|
|
|
|
// Shared with DvergarFireConstruct's target scan, so its friendly-fire filter reads off
|
|
// the same Mountain roster as everything else in Factions rather than a second
|
|
// hand-maintained copy of it.
|
|
public static bool IsMountainFactionMob(string prefabName)
|
|
{
|
|
return MontagnaMobs.Contains(prefabName);
|
|
}
|
|
|
|
public static void Postfix(Character a, Character b, ref bool __result)
|
|
{
|
|
if (!__result) return; // already not enemies, nothing to add
|
|
if (a == null || b == null) return;
|
|
|
|
Character playerCharacter = a.IsPlayer() ? a : (b.IsPlayer() ? b : null);
|
|
Character monster = a.IsPlayer() ? b : (b.IsPlayer() ? a : null);
|
|
if (!(playerCharacter is Player p) || monster == null) return;
|
|
|
|
if (IsSameFaction(p, monster))
|
|
{
|
|
__result = false;
|
|
}
|
|
}
|
|
}
|
|
}
|