aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-05-23 20:18:45 -0300
committerfunjoker <funjoker109@gmail.com>2020-06-14 23:49:03 +0200
commit412af93a28185474ad26bbd6f133e5b6f31d296d (patch)
tree2e1d35a8c456a9802d1bd783ebad1b794ee3a1fb
parent282e1f152d91ecab544a7732db0caeb6ce40f1cb (diff)
Core/Player: update interaction checks, some info taken from client
(cherry picked from commit d03e97d53f8dcabe006773d3377842bc091359a9)
-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