Skip to content

Commit

Permalink
Core/Objects: Refactor private object checks into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Mar 28, 2021
1 parent 1082a66 commit f21270b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/server/game/Combat/ThreatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ void ThreatManager::doAddThreat(Unit* victim, float threat)
uint32 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 = ObjectAccessor::GetUnit(*GetOwner(), victim->GetPrivateObjectOwner());
Expand Down
22 changes: 19 additions & 3 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,20 +1411,36 @@ float WorldObject::GetSightRange(WorldObject const* target) const
return 0.0f;
}

bool WorldObject::CheckPrivateObjectOwnerVisibility(WorldObject const* seer) const
{
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;
}

bool WorldObject::CanSeeOrDetect(WorldObject const* obj, bool ignoreStealth, bool distanceCheck, bool checkAlert) const
{
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)
{
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
bool IsPrivateObject() const { return !_privateObjectOwner.IsEmpty(); }
ObjectGuid GetPrivateObjectOwner() const { return _privateObjectOwner; }
void SetPrivateObjectOwner(ObjectGuid const& owner) { _privateObjectOwner = owner; }
bool CheckPrivateObjectOwnerVisibility(WorldObject const* seer) const;

protected:
std::string m_name;
Expand Down
6 changes: 5 additions & 1 deletion src/server/game/Grids/Notifiers/GridNotifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,11 @@ namespace Trinity

bool operator()(Creature* u)
{
if (u->getDeathState() != DEAD && u->GetEntry() == i_entry && u->IsAlive() == i_alive && i_obj.IsWithinDistInMap(u, i_range) && u->CanSeeOrDetect(&i_obj))
if (u->getDeathState() != 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;
Expand Down

0 comments on commit f21270b

Please sign in to comment.