From 1c0f2d233fc0e9762b8be5b810e2037f3eb55e02 Mon Sep 17 00:00:00 2001 From: n0n4m3 Date: Sat, 19 Dec 2009 20:02:38 +0100 Subject: Fix problem with max pet distance from owner. by VladimirMangos --HG-- branch : trunk --- src/game/Pet.cpp | 4 ++-- src/game/Pet.h | 2 -- src/game/Player.cpp | 23 ++++++++++++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 373f611094b..58a561c3a6f 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -514,8 +514,8 @@ void Pet::Update(uint32 diff) { // unsummon pet that lost owner Player* owner = GetOwner(); - if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) - //if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && (owner->GetCharmGUID() && (owner->GetCharmGUID() != GetGUID()))) || (isControlled() && !owner->GetPetGUID())) + if(!owner || (!IsWithinDistInMap(owner, GetMap()->GetVisibilityDistance()) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) + //if(!owner || (!IsWithinDistInMap(owner, GetMap()->GetVisibilityDistance()) && (owner->GetCharmGUID() && (owner->GetCharmGUID() != GetGUID()))) || (isControlled() && !owner->GetPetGUID())) { Remove(PET_SAVE_NOT_IN_SLOT, true); return; diff --git a/src/game/Pet.h b/src/game/Pet.h index 0028b5038f9..17df70b0a65 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -116,8 +116,6 @@ typedef std::vector AutoSpellList; #define ACTIVE_SPELLS_MAX 4 -#define OWNER_MAX_DISTANCE 100.0f - #define PET_FOLLOW_DIST 1 #define PET_FOLLOW_ANGLE (M_PI/2) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index f5577198dd1..a9b0b95307c 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -1394,8 +1394,8 @@ void Player::Update( uint32 p_time ) SendUpdateToOutOfRangeGroupMembers(); Pet* pet = GetPet(); - if (pet && !IsWithinDistInMap(pet, OWNER_MAX_DISTANCE) && !pet->isPossessed()) - //if(pet && !IsWithinDistInMap(pet, OWNER_MAX_DISTANCE) && (GetCharmGUID() && (pet->GetGUID() != GetCharmGUID()))) + if (pet && !pet->IsWithinDistInMap(this, GetMap()->GetVisibilityDistance()) && !pet->isPossessed()) + //if(pet && !pet->IsWithinDistInMap(this, GetMap()->GetVisibilityDistance()) && (GetCharmGUID() && (pet->GetGUID() != GetCharmGUID()))) RemovePet(pet, PET_SAVE_NOT_IN_SLOT, true); //we should execute delayed teleports only for alive(!) players @@ -1748,7 +1748,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati if (!(options & TELE_TO_NOT_UNSUMMON_PET)) { //same map, only remove pet if out of range for new position - if(pet && !pet->IsWithinDist3d(x,y,z, OWNER_MAX_DISTANCE)) + if(pet && !pet->IsWithinDist3d(x,y,z, GetMap()->GetVisibilityDistance())) UnsummonPetTemporaryIfAny(); } @@ -19302,12 +19302,27 @@ inline void UpdateVisibilityOf_helper(std::set& s64, Player* target, std v.insert(target); } +template +inline void BeforeVisibilityDestroy(T* /*t*/, Player* /*p*/) +{ +} + +template<> +inline void BeforeVisibilityDestroy(Creature* t, Player* p) +{ + if (p->GetPetGUID()==t->GetGUID() && ((Creature*)t)->isPet()) + ((Pet*)t)->Remove(PET_SAVE_NOT_IN_SLOT, true); +} + void Player::UpdateVisibilityOf(WorldObject* target) { if(HaveAtClient(target)) { if(!target->isVisibleForInState(this, true)) { + if (target->GetTypeId()==TYPEID_UNIT) + BeforeVisibilityDestroy((Creature*)target,this); + target->DestroyForPlayer(this); m_clientGUIDs.erase(target->GetGUID()); @@ -19359,6 +19374,8 @@ void Player::UpdateVisibilityOf(T* target, UpdateData& data, std::set& vi { if(!target->isVisibleForInState(this,true)) { + BeforeVisibilityDestroy(target,this); + target->BuildOutOfRangeUpdateBlock(&data); m_clientGUIDs.erase(target->GetGUID()); -- cgit v1.2.3