aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/game/Entities/Player/Player.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 0802908a9cf..713b2a860f9 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -2105,8 +2105,8 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid const& guid, NPCFlags npcFl
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;
@@ -2114,33 +2114,36 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid const& guid, NPCFlags npcFl
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", "Player::GetGameObjectIfCanInteractWith: GameObject '%s' (%s) is too far away from player '%s' (%s) to be used by him (Distance: %f, maximal %f is allowed)",
- go->GetGOInfo()->name.c_str(), go->GetGUID().ToString().c_str(), GetName().c_str(), GetGUID().ToString().c_str(), 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 %f is allowed)",
- go->GetGOInfo()->name.c_str(), go->GetGUID().ToString().c_str(), GetName().c_str(), GetGUID().ToString().c_str(), go->GetDistance(this), go->GetInteractionDistance());
- }
- }
+ if (go->GetGoType() != type)
+ return nullptr;
- return nullptr;
+ return go;
}
bool Player::IsUnderWater() const