warvulture
This commit is contained in:
parent
4559e0b9e1
commit
e9d6e78ec8
15 changed files with 1041 additions and 489 deletions
|
|
@ -69,13 +69,33 @@ 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 (!__result) return; // already not enemies, nothing to add
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue