Core/Player: update interaction checks, some info taken from client

This commit is contained in:
ariel- authored and Aokromes committed 2017-05-26 14:26:43 +02:00
1 parent f44b2ab7bb
commit 70f3879c32
1 file changed
+24 -21
+24 -21
View File
@@ -2559,8 +2559,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;
@@ -2568,33 +2568,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