mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Objects: Refactor private object checks into separate function
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user