feat(factions): optional group grudge, kin within 20 m join the fight

Joacwoo's request. With "Grudge spreads to kin" on (off by default),
hitting a creature at peace with you gives the same grudge to every
creature of that faction within "Grudge spread radius" (20 m) and
alerts them, like vanilla's Dvergr with a human. Only creatures whose
AI runs on this machine are told, since that is where a grudge is
read.
This commit is contained in:
kanym 2026-11-05 13:05:03 +01:00
commit 5530f7dc3d
3 changed files with 47 additions and 1 deletions

View file

@ -121,6 +121,35 @@ namespace RacesOfValheim
if (monster == null || monster.IsPlayer()) return;
Remember(monster, attacker);
if (FactionsConfig.GrudgeSpreads && attacker is Player player) SpreadToKin(monster, player);
}
}
/// <summary>
/// Vanilla's Dvergr camp, for every faction ("Grudge spreads to kin", off by default): hit
/// a creature that is at peace with you and its kin around it take up the same grudge.
///
/// Only the creatures this machine runs the AI for are told, because a grudge is read where
/// the AI runs (see WHERE IT RUNS above). The creatures around the one that was hit are
/// nearly always simulated by the same client; one owned by another player's machine stays
/// at peace until it is hit itself.
/// </summary>
private static void SpreadToKin(Character monster, Player player)
{
string race = FactionHostilityPatch.GetPlayerRace(player);
if (!FactionHostilityPatch.IsAlliedMob(race, monster.gameObject.name)) return;
Vector3 center = monster.transform.position;
float radius = FactionsConfig.GrudgeSpreadMeters;
foreach (Character other in Character.GetAllCharacters())
{
if (other == null || other == monster || other.IsPlayer() || other.IsDead() || other.IsTamed()) continue;
if (!other.IsOwner()) continue;
if (Vector3.Distance(other.transform.position, center) > radius) continue;
if (!FactionHostilityPatch.IsAlliedMob(race, other.gameObject.name)) continue;
Remember(other, player);
other.GetBaseAI()?.Alert();
}
}
}