diff options
author | megamage <none@none> | 2009-08-28 14:19:14 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-08-28 14:19:14 -0500 |
commit | 6de6557bf0baa323046497f2d793c805d69b630b (patch) | |
tree | c7b0c9840e8f9d946318476b0b908a80c6fef71c | |
parent | 3d9326c4b7ec086790d0476f9864cd7d201e9495 (diff) |
*Fix a crash caused by gm command .object move and so on
--HG--
branch : trunk
-rw-r--r-- | src/game/Level2.cpp | 22 | ||||
-rw-r--r-- | src/game/Object.cpp | 29 | ||||
-rw-r--r-- | src/game/Object.h | 2 | ||||
-rw-r--r-- | src/game/Unit.cpp | 19 | ||||
-rw-r--r-- | src/game/Unit.h | 1 |
5 files changed, 37 insertions, 36 deletions
diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index ed4527dcc5b..bd09c69af08 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -638,13 +638,10 @@ bool ChatHandler::HandleGameObjectTurnCommand(const char* args) o = chr->GetOrientation(); } - Map* map = obj->GetMap(); - map->Remove(obj,false); - obj->Relocate(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), o); obj->UpdateRotationFields(); - - map->Add(obj); + obj->DestroyForNearbyPlayers(); + ObjectAccessor::UpdateObjectVisibility(obj); obj->SaveToDB(); obj->Refresh(); @@ -686,13 +683,9 @@ bool ChatHandler::HandleGameObjectMoveCommand(const char* args) if (!px) { Player *chr = m_session->GetPlayer(); - - Map* map = obj->GetMap(); - map->Remove(obj,false); - obj->Relocate(chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), obj->GetOrientation()); - - map->Add(obj); + obj->DestroyForNearbyPlayers(); + ObjectAccessor::UpdateObjectVisibility(obj); } else { @@ -710,12 +703,9 @@ bool ChatHandler::HandleGameObjectMoveCommand(const char* args) return false; } - Map* map = obj->GetMap(); - map->Remove(obj,false); - obj->Relocate(x, y, z, obj->GetOrientation()); - - map->Add(obj); + obj->DestroyForNearbyPlayers(); + ObjectAccessor::UpdateObjectVisibility(obj); } obj->SaveToDB(); diff --git a/src/game/Object.cpp b/src/game/Object.cpp index d98784bc602..45ffbc36c4e 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -2303,3 +2303,32 @@ void WorldObject::PlayDirectSound( uint32 sound_id, Player* target /*= NULL*/ ) else SendMessageToSet( &data, true ); } + +void WorldObject::DestroyForNearbyPlayers() +{ + if(!IsInWorld()) + return; + + std::list<Unit*> targets; + Trinity::AnyUnitInObjectRangeCheck check(this, World::GetMaxVisibleDistance()); + Trinity::UnitListSearcher<Trinity::AnyUnitInObjectRangeCheck> searcher(this, targets, check); + VisitNearbyWorldObject(World::GetMaxVisibleDistance(), searcher); + for(std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) + { + Player *plr = dynamic_cast<Player*>(*iter); + if(!plr) + continue; + + if(plr == this) + continue; + + if(!plr->HaveAtClient(this)) + continue; + + if(isType(TYPEMASK_UNIT) && ((Unit*)this)->GetCharmerGUID() == plr->GetGUID()) // TODO: this is for puppet + continue; + + DestroyForPlayer(plr); + plr->m_clientGUIDs.erase(GetGUID()); + } +} diff --git a/src/game/Object.h b/src/game/Object.h index 3b568ef225f..d46d6a45479 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -556,6 +556,8 @@ class TRINITY_DLL_SPEC WorldObject : public Object void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange); void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange); + void DestroyForNearbyPlayers(); + bool isActiveObject() const { return m_isActive; } void setActive(bool isActiveObject); void SetWorldObject(bool apply); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index e80ccf019f2..7c404474908 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -10845,25 +10845,6 @@ bool Unit::canDetectStealthOf(Unit const* target, float distance) const return distance < visibleDistance; } -void Unit::DestroyForNearbyPlayers() -{ - if(!IsInWorld()) - return; - - std::list<Unit*> targets; - Trinity::AnyUnitInObjectRangeCheck check(this, World::GetMaxVisibleDistance()); - Trinity::UnitListSearcher<Trinity::AnyUnitInObjectRangeCheck> searcher(this, targets, check); - VisitNearbyWorldObject(World::GetMaxVisibleDistance(), searcher); - for(std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) - if(*iter != this && (*iter)->GetTypeId() == TYPEID_PLAYER - && ((Player*)(*iter))->HaveAtClient(this) - && GetCharmerGUID() != (*iter)->GetGUID()) // TODO: this is for puppet - { - DestroyForPlayer((Player*)(*iter)); - ((Player*)(*iter))->m_clientGUIDs.erase(GetGUID()); - } -} - void Unit::SetVisibility(UnitVisibility x) { m_Visibility = x; diff --git a/src/game/Unit.h b/src/game/Unit.h index 2242ed6b915..18c578376c6 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1602,7 +1602,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject // Visibility system UnitVisibility GetVisibility() const { return m_Visibility; } void SetVisibility(UnitVisibility x); - void DestroyForNearbyPlayers(); // common function for visibility checks for player/creatures with detection code virtual bool canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList = false, bool is3dDistance = true) const = 0; |