RacesOfValheim/JotunnModStub/RaceHostilityManager.cs
Ferdinando d0ed92c553 feat(trenta): add the Trenta race
A vegan, tree-born race unlocking new perks per boss defeated: skin/hair
tint, blocked non-vegan food, awakened seed foods after Eikthyr, a mob
hostility list, Photosynthesis, elemental resistances, Purple Rain after
the Elder, swim/poison/wet immunity after Bonemass, Last Stand and Thorns
after Moder, a Homecoming Portal after Yagluth, Hornet's Nest after the
Queen, and Muspell (a half-size Elder transformation with Stomp/Spike
attacks) after Fader.

Also fixes RaceScale never listing Trenta as self-sizing, which let a
shared Player.Update postfix fight Muspell's own scale changes every
frame.
2026-08-04 20:58:01 +02:00

88 lines
4.8 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;
}
}
// Trenta Race Logic - base passive, live from the start (no progression
// gate, unlike Aswid's escalating list above).
//
// IsEnemy=false is the only lever this patch has, and it produces one
// behaviour: the mob never initiates. It reads as two different relationships
// only in flavour text - Greyling/Greydwarf/Leech/Deathsquito "don't see" a
// Trenta as prey (root-kin, or simply nothing with blood to sense), while
// Fuling/Troll "choose" not to fight one - but there is no third state to code
// for: vanilla's own damage-response AI already makes any of them retaliate if
// the Trenta strikes first, same as it does for Fenrir's wolves above.
if (p.m_customData.ContainsKey("Race") && p.m_customData["Race"] == TrentaConfig.RaceId)
{
string prefabName = monster.gameObject.name.ToLower();
if (prefabName.Contains("greyling") || prefabName.Contains("greydwarf") ||
prefabName.Contains("fuling") || prefabName.Contains("troll") ||
prefabName.Contains("leech") || prefabName.Contains("deathsquito"))
{
__result = false;
}
}
}
}
}
}
}