From 1ca5b5bcadc3f7e16c841646ab0d77289acb8a88 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 29 Mar 2021 17:20:45 -0400 Subject: [PATCH] Core/Objects: Refactor private object checks into separate function Port From (https://github.com/TrinityCore/TrinityCore/commit/f21270b987211041b95d6befa7192d313692920d) --- Source/Game/Combat/ThreatManager.cs | 4 ++-- Source/Game/Entities/Object/WorldObject.cs | 22 +++++++++++++++++++--- Source/Game/Maps/GridNotifiers.cs | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Source/Game/Combat/ThreatManager.cs b/Source/Game/Combat/ThreatManager.cs index 4d3366d99..1208a8a21 100644 --- a/Source/Game/Combat/ThreatManager.cs +++ b/Source/Game/Combat/ThreatManager.cs @@ -87,8 +87,8 @@ namespace Game.Combat uint redirectThreadPct = victim.GetRedirectThreatPercent(); Unit redirectTarget = victim.GetRedirectThreatTarget(); - // If victim is personnal spawn, redirect all aggro to summoner - if (victim.IsPrivateObject() && GetOwner().IsPrivateObject() && GetOwner().CanSeeOrDetect(victim)) + // If victim is personal spawn, redirect all aggro to summoner + if (victim.IsPrivateObject() && (!GetOwner().IsPrivateObject() || !GetOwner().CheckPrivateObjectOwnerVisibility(victim))) { redirectThreadPct = 100; redirectTarget = Global.ObjAccessor.GetUnit(GetOwner(), victim.GetPrivateObjectOwner()); diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 7cc60526d..a35b2c070 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -1100,20 +1100,36 @@ namespace Game.Entities return 0.0f; } + public bool CheckPrivateObjectOwnerVisibility(WorldObject seer) + { + if (!IsPrivateObject()) + return true; + + // Owner of this private object + if (_privateObjectOwner == seer.GetGUID()) + return true; + + // Another private object of the same owner + if (_privateObjectOwner == seer.GetPrivateObjectOwner()) + return true; + + return false; + } + public bool CanSeeOrDetect(WorldObject obj, bool ignoreStealth = false, bool distanceCheck = false, bool checkAlert = false) { if (this == obj) return true; - if (!obj.GetPrivateObjectOwner().IsEmpty()) - return GetGUID() == obj.GetPrivateObjectOwner() || GetPrivateObjectOwner() == obj.GetPrivateObjectOwner(); - if (obj.IsNeverVisibleFor(this) || CanNeverSee(obj)) return false; if (obj.IsAlwaysVisibleFor(this) || CanAlwaysSee(obj)) return true; + if (!obj.CheckPrivateObjectOwnerVisibility(this)) + return false; + bool corpseVisibility = false; if (distanceCheck) { diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 65da2928b..7655d95c4 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2300,7 +2300,7 @@ namespace Game.Maps public bool Invoke(Creature u) { - if (u.GetDeathState() != DeathState.Dead && u.GetEntry() == i_entry && u.IsAlive() == i_alive && i_obj.IsWithinDistInMap(u, i_range) && u.CanSeeOrDetect(i_obj)) + if (u.GetDeathState() != DeathState.Dead && u.GetEntry() == i_entry && u.IsAlive() == i_alive && i_obj.IsWithinDistInMap(u, i_range) && u.CheckPrivateObjectOwnerVisibility(i_obj)) { i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check return true;