RacesOfValheim/JotunnModStub/RaceHostilityManager.cs
2026-08-02 08:30:53 +02:00

67 lines
3.3 KiB
C#

using HarmonyLib;
using UnityEngine;
namespace RacesOfValheim
{
// --- RACE HOSTILITY MANAGER ---
// This script manages which mobs should not attack the player based on their race.
// For now, it manages wolves, ulvs, fenrings, and cultists for the Fenrir race.
[HarmonyPatch(typeof(BaseAI), nameof(BaseAI.IsEnemy), new System.Type[] { typeof(Character), typeof(Character) })]
public static class RaceHostilityManager
{
public static void Postfix(Character a, Character b, ref bool __result)
{
if (!__result) return; // If already not enemies, skip
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 != null && monster != null)
{
Player p = playerCharacter as Player;
if (p != null)
{
// Fenrir Race Logic
if (p.m_customData.ContainsKey("Race") && p.m_customData["Race"] == "Fenrir")
{
string prefabName = monster.gameObject.name.ToLower();
if (prefabName.Contains("wolf") || prefabName.Contains("fenring") ||
prefabName.Contains("ulv") || prefabName.Contains("cultist"))
{
__result = false;
}
}
// Aswid Race Logic
if (p.m_customData.ContainsKey("Race") && p.m_customData["Race"] == "Aswid")
{
string prefabName = monster.gameObject.name.ToLower();
int state = BossProgressionManager.GetCurrentProgressionState();
if (state >= 2 && prefabName.Contains("boar")) __result = false;
if (state >= 3 && prefabName.Contains("bear")) __result = false;
if (state >= 4 && (prefabName.Contains("leech") || prefabName.Contains("ghost") || prefabName.Contains("wraith"))) __result = false;
if (state >= 5 && prefabName.Contains("wolf")) __result = false;
if (state >= 6 && (prefabName.Contains("lox") || prefabName.Contains("deathsquito"))) __result = false;
if (state >= 7 && (prefabName.Contains("hare") || prefabName.Contains("gjall"))) __result = false;
if (state >= 8 && (prefabName.Contains("asksvin") || prefabName.Contains("volture") || prefabName.Contains("vulture") || prefabName.Contains("valkyrie"))) __result = false;
}
// Draugh Race Logic
if (p.m_customData.ContainsKey("Race") && p.m_customData["Race"] == "Draugh")
{
string prefabName = monster.gameObject.name.ToLower();
if (prefabName.Contains("skeleton") || prefabName.Contains("draugr") ||
prefabName.Contains("ghost") || prefabName.Contains("wraith"))
{
__result = false;
}
}
}
}
}
}
}