diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.h | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 45 |
3 files changed, 26 insertions, 23 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 818397ee1fd..1ef38424073 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -2407,7 +2407,7 @@ void GameObject::GetRespawnPosition(float &x, float &y, float &z, float* ori /* *ori = GetOrientation(); } -float GameObject::GetInteractionDistance() +float GameObject::GetInteractionDistance() const { switch (GetGoType()) { diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index cdc2dcf36b1..f6421f9af02 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -895,7 +895,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> float GetStationaryO() const override { if (GetGOInfo()->type != GAMEOBJECT_TYPE_MO_TRANSPORT) return m_stationaryPosition.GetOrientation(); return GetOrientation(); } void RelocateStationaryPosition(float x, float y, float z, float o) { m_stationaryPosition.Relocate(x, y, z, o); } - float GetInteractionDistance(); + float GetInteractionDistance() const; void UpdateModelPosition(); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index d02754210de..fb447b78375 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2442,8 +2442,8 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid const& guid, uint32 npcflag if (creature->GetReactionTo(this) <= REP_UNFRIENDLY) return nullptr; - // not too far - if (!creature->IsWithinDistInMap(this, INTERACTION_DISTANCE)) + // not too far, taken from CGGameUI::SetInteractTarget + if (!creature->IsWithinDistInMap(this, creature->GetCombatReach() + 4.0f)) return nullptr; return creature; @@ -2451,33 +2451,36 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid const& guid, uint32 npcflag GameObject* Player::GetGameObjectIfCanInteractWith(ObjectGuid const& guid) const { - if (GameObject* go = GetMap()->GetGameObject(guid)) - { - if (go->IsWithinDistInMap(this, go->GetInteractionDistance())) - return go; + if (!guid) + return nullptr; - TC_LOG_DEBUG("maps", "GetGameObjectIfCanInteractWith: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him (distance=%f, maximal %f is allowed)", go->GetGOInfo()->name.c_str(), - go->GetGUID().GetCounter(), GetName().c_str(), GetGUID().GetCounter(), go->GetDistance(this), go->GetInteractionDistance()); - } + if (!IsInWorld()) + return nullptr; - return nullptr; + if (IsInFlight()) + return nullptr; + + // exist + GameObject* go = ObjectAccessor::GetGameObject(*this, guid); + if (!go) + return nullptr; + + if (!go->IsWithinDistInMap(this, go->GetInteractionDistance())) + return nullptr; + + return go; } GameObject* Player::GetGameObjectIfCanInteractWith(ObjectGuid const& guid, GameobjectTypes type) const { - if (GameObject* go = GetMap()->GetGameObject(guid)) - { - if (go->GetGoType() == type) - { - if (go->IsWithinDistInMap(this, go->GetInteractionDistance())) - return go; + GameObject* go = GetGameObjectIfCanInteractWith(guid); + if (!go) + return nullptr; - TC_LOG_DEBUG("maps", "Player::GetGameObjectIfCanInteractWith: GameObject '%s' (%s) is too far away from player '%s' (%s) to be used by him (Distance: %f, maximal 10 is allowed)", - go->GetGOInfo()->name.c_str(), go->GetGUID().ToString().c_str(), GetName().c_str(), GetGUID().ToString().c_str(), go->GetDistance(this)); - } - } + if (go->GetGoType() != type) + return nullptr; - return nullptr; + return go; } bool Player::IsUnderWater() const |