fix(factions): allied mobs spare a race's buildings with nobody home

FactionStaticTargetPatch only vetoed a mob's piece target while an
allied player stood within 100 m. Inside a troll cave that was the
collapse bug: the Trol walks out, the resident Troll (its prefab has
m_attackPlayerObjects) finds nobody to stop it, and the cooking station
built there is in pieces when the Trol comes back.

Every piece now carries the race of its builder on its ZDO, stamped in
Piece.SetCreator at placement, and in Piece.Awake for older pieces the
first time their builder loads them, so no timer and no scan. An
allied mob of that race can't pick the piece as a target and its blows
do it no damage, which also covers a swing at a foreign wall that
would have hit the Trol's workbench next to it. A mob holding a grudge
against the builder gets no such truce.
This commit is contained in:
kanym 2026-10-17 15:50:41 +02:00
commit b566adbfb9
2 changed files with 128 additions and 0 deletions

View file

@ -212,6 +212,14 @@ namespace RacesOfValheim
Character monster = Traverse.Create(__instance).Field<Character>("m_character").Value;
if (monster == null) return;
// A piece an allied race built is never a target, with or without anyone around.
// See FactionPieceTruce.
if (targetStatic.GetValue() is Component target && FactionPieceTruce.Protects(target.gameObject, monster))
{
targetStatic.SetValue(null);
return;
}
foreach (Player player in Player.GetAllPlayers())
{
if (Vector3.Distance(player.transform.position, monster.transform.position) > FactionCheckRange) continue;