Merge branch 'war-vulture' into main
Sverm Ravager Strain (replacing the Stinger Morph), Trenta Elder Root, the Trol food and Black Forest truce work, and the faction FindEnemy patch. Conflicts resolved: - FactionHostilityPatch.cs: both sides added a class at the same spot and they cover different holes, so both are kept - FactionStaticTargetPatch (main, stops same-faction mobs smashing structures) and FactionHuntPlayerPatch (war-vulture, closes the HuntPlayer fall-through). - RaceCompendium.cs: both branches independently fixed the same off-by-one in the Trol's progression gates. Took main's wording, which matches the code - Axes are in the melee bonus (TrolDamagePatches sends them to m_slash), the 4th food slot has no gate at all, and Yagluth is +5 not +10 (TrolConfig.YagluthMeleeBonus). Kept war-vulture's two new lines, the Kindling fire weakness and the Black Forest truce. - Package/manifest.json: 1.4.8, which is what the root manifest and PluginVersion already said. RacesOfValheim.cs referenced SvermConfig.StingerSE/StingerCdSE, which war-vulture renamed to Ravager. Git merged those lines without a conflict and the result did not compile; renamed. Also in this commit: - Factions on/off switches (FactionsConfig): "Faction truce" and "Faction merchants", both default on, both read live so they take effect without a restart. The truce gates its three postfixes; the merchants gate the Character.Awake setup plus every behavioural patch, so turning them off drops the prompt and the trade window on mobs already awake. - SerpentMeat sells for 200 instead of 1 at the Fuling bench, moved to keep the list's ascending price order (the sell panel renders it as declared). - DraughFoodPatches mapped "SerpentMeatRaw", which is not a prefab; the internal id is SerpentMeat, so serpent meat never cooked for a Draugh. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
commit
34bdf35325
33 changed files with 1829 additions and 573 deletions
|
|
@ -70,15 +70,36 @@ namespace RacesOfValheim
|
|||
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;
|
||||
string race = GetPlayerRace(player);
|
||||
if (race == null) return false;
|
||||
if (!RaceFactionMobs.TryGetValue(race, out HashSet<string> mobs)) return false;
|
||||
|
||||
string prefabName = monster.gameObject.name.Replace("(Clone)", "").Trim();
|
||||
return mobs.Contains(prefabName);
|
||||
}
|
||||
|
||||
// m_customData is the local save file's dictionary: it is only ever populated for
|
||||
// the client's own m_localPlayer, so IsEnemy running on a remote AI owner (a
|
||||
// dedicated server, or any other nearby player who ends up owning the mob's ZDO)
|
||||
// read an empty dictionary here and treated every truce as hostile. Every other
|
||||
// race-aware patch in this project reads "RacesOfValheim_Race" off the ZDO instead
|
||||
// because that field actually replicates - check it first, and only fall back to
|
||||
// m_customData for the single-player/local-owner case where the ZDO hasn't been
|
||||
// written yet (e.g. brand new character before the race pick's Set() call runs).
|
||||
public static string GetPlayerRace(Player player)
|
||||
{
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
string zdoRace = nview.GetZDO().GetString("RacesOfValheim_Race", "");
|
||||
if (!string.IsNullOrEmpty(zdoRace)) return zdoRace;
|
||||
}
|
||||
return player.m_customData.TryGetValue("Race", out string race) ? race : null;
|
||||
}
|
||||
|
||||
public static void Postfix(Character a, Character b, ref bool __result)
|
||||
{
|
||||
if (!FactionsConfig.Hostility) return;
|
||||
if (!__result) return; // already not enemies, nothing to add
|
||||
if (a == null || b == null) return;
|
||||
|
||||
|
|
@ -116,6 +137,7 @@ namespace RacesOfValheim
|
|||
|
||||
public static void Postfix(MonsterAI __instance)
|
||||
{
|
||||
if (!FactionsConfig.Hostility) return;
|
||||
Traverse targetStatic = Traverse.Create(__instance).Field("m_targetStatic");
|
||||
if (targetStatic.GetValue() == null) return;
|
||||
|
||||
|
|
@ -132,4 +154,32 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsEnemy is not the only way a mob picks the player, and the other way ignores it
|
||||
// completely. BaseAI.FindEnemy() walks every character asking IsEnemy - which both truce
|
||||
// patches above answer - but when that walk comes up empty and the creature HuntPlayer()s,
|
||||
// it falls through to Player.GetClosestPlayer(transform.position, 200f) and returns whoever
|
||||
// it finds, without asking anything about factions.
|
||||
//
|
||||
// That fall-through is why the Black Forest truce looked broken to the Trol's testers:
|
||||
// MonsterAI.UpdateAI turns hunting on for every IsEventCreature() while an event is running,
|
||||
// and the events that reach a Trol are "the forest is moving" (Greydwarves), "you are being
|
||||
// hunted" (Trolls) and the Fuling army - the exact three they named. Anything a SpawnSystem
|
||||
// entry or a TriggerSpawner flags with huntPlayer arrives by the same door.
|
||||
//
|
||||
// Filtering the RESULT rather than restating the rule keeps one source of truth: the public
|
||||
// instance IsEnemy(Character) calls the static overload both postfixes above hook, so this
|
||||
// honours whatever the faction sets and RaceHostilityManager's per-race lists already agree
|
||||
// on. Retaliation is untouched - a mob the player hits is targeted through
|
||||
// BaseAI.OnDamaged/SetTarget, which never goes near FindEnemy.
|
||||
[HarmonyPatch(typeof(BaseAI), "FindEnemy")]
|
||||
public static class FactionHuntPlayerPatch
|
||||
{
|
||||
public static void Postfix(BaseAI __instance, ref Character __result)
|
||||
{
|
||||
if (!FactionsConfig.Hostility) return;
|
||||
if (__result == null || !__result.IsPlayer()) return;
|
||||
if (!__instance.IsEnemy(__result)) __result = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue