diff --git a/src/game/Corpse.cpp b/src/game/Corpse.cpp index 68abcc3b7..4964d2ef2 100644 --- a/src/game/Corpse.cpp +++ b/src/game/Corpse.cpp @@ -49,14 +49,18 @@ Corpse::~Corpse() void Corpse::AddToWorld() { ///- Register the corpse for guid lookup - if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); + if(!IsInWorld()) + ObjectAccessor::Instance().AddObject(this); + Object::AddToWorld(); } void Corpse::RemoveFromWorld() { ///- Remove the corpse from the accessor - if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); + if(IsInWorld()) + ObjectAccessor::Instance().RemoveObject(this); + Object::RemoveFromWorld(); } @@ -77,7 +81,7 @@ bool Corpse::Create( uint32 guidlow, Player *owner) if(!IsPositionValid()) { sLog.outError("Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", - guidlow,owner->GetName(),owner->GetPositionX(), owner->GetPositionY()); + guidlow, owner->GetName(), owner->GetPositionX(), owner->GetPositionY()); return false; } @@ -118,7 +122,7 @@ void Corpse::SaveToDB() void Corpse::DeleteBonesFromWorld() { - assert(GetType()==CORPSE_BONES); + assert(GetType() == CORPSE_BONES); Corpse* corpse = ObjectAccessor::GetCorpse(*this, GetGUID()); if (!corpse) @@ -147,7 +151,7 @@ bool Corpse::LoadFromDB(uint32 guid, QueryResult *result) // 0 1 2 3 4 5 6 7 8 9 result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,data,time,corpse_type,instance,phaseMask FROM corpse WHERE guid = '%u'",guid); - if( ! result ) + if( !result ) { sLog.outError("Corpse (GUID: %u) not found in table `corpse`, can't load. ",guid); return false; @@ -155,13 +159,17 @@ bool Corpse::LoadFromDB(uint32 guid, QueryResult *result) Field *fields = result->Fetch(); - if(!LoadFromDB(guid,fields)) + if(!LoadFromDB(guid, fields)) { - if (!external) delete result; + if (!external) + delete result; + return false; } - if (!external) delete result; + if (!external) + delete result; + return true; } @@ -183,13 +191,15 @@ bool Corpse::LoadFromDB(uint32 guid, Field *fields) return false; } - m_time = time_t(fields[6].GetUInt64()); - m_type = CorpseType(fields[7].GetUInt32()); + m_time = time_t(fields[6].GetUInt64()); + m_type = CorpseType(fields[7].GetUInt32()); + if(m_type >= MAX_CORPSE_TYPE) { sLog.outError("Corpse (guidlow %d, owner %d) have wrong corpse type, not load.",GetGUIDLow(),GUID_LOPART(GetOwnerGUID())); return false; } + uint32 instanceid = fields[8].GetUInt32(); uint32 phaseMask = fields[9].GetUInt32(); @@ -199,13 +209,13 @@ bool Corpse::LoadFromDB(uint32 guid, Field *fields) // place SetInstanceId(instanceid); SetMapId(mapid); - SetPhaseMask(phaseMask,false); - Relocate(positionX,positionY,positionZ,ort); + SetPhaseMask(phaseMask, false); + Relocate(positionX, positionY, positionZ, ort); if(!IsPositionValid()) { sLog.outError("Corpse (guidlow %d, owner %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", - GetGUIDLow(),GUID_LOPART(GetOwnerGUID()),GetPositionX(),GetPositionY()); + GetGUIDLow(), GUID_LOPART(GetOwnerGUID()), GetPositionX(), GetPositionY()); return false; } @@ -216,5 +226,5 @@ bool Corpse::LoadFromDB(uint32 guid, Field *fields) bool Corpse::isVisibleForInState(Player const* u, bool inVisibleList) const { - return IsInWorld() && u->IsInWorld() && IsWithinDistInMap(u,World::GetMaxVisibleDistanceForObject()+(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false); + return IsInWorld() && u->IsInWorld() && IsWithinDistInMap(u, World::GetMaxVisibleDistanceForObject() + (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false); } diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp index e9adad27c..89c6a7545 100644 --- a/src/game/DynamicObject.cpp +++ b/src/game/DynamicObject.cpp @@ -39,14 +39,18 @@ DynamicObject::DynamicObject() : WorldObject() void DynamicObject::AddToWorld() { ///- Register the dynamicObject for guid lookup - if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); + if(!IsInWorld()) + ObjectAccessor::Instance().AddObject(this); + Object::AddToWorld(); } void DynamicObject::RemoveFromWorld() { ///- Remove the dynamicObject from the accessor - if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); + if(IsInWorld()) + ObjectAccessor::Instance().RemoveObject(this); + Object::RemoveFromWorld(); } @@ -55,7 +59,7 @@ bool DynamicObject::Create( uint32 guidlow, Unit *caster, uint32 spellId, uint32 SetInstanceId(caster->GetInstanceId()); WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT, caster->GetMapId(), caster->GetPhaseMask()); - Relocate(x,y,z,0); + Relocate(x, y, z, 0); if(!IsPositionValid()) { @@ -78,14 +82,13 @@ bool DynamicObject::Create( uint32 guidlow, Unit *caster, uint32 spellId, uint32 m_radius = radius; m_effIndex = effIndex; m_spellId = spellId; - m_casterGuid = caster->GetGUID(); return true; } Unit* DynamicObject::GetCaster() const { // can be not found in some cases - return ObjectAccessor::GetUnit(*this,m_casterGuid); + return ObjectAccessor::GetUnit(*this, GetCasterGUID()); } void DynamicObject::Update(uint32 p_time) @@ -111,7 +114,7 @@ void DynamicObject::Update(uint32 p_time) cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - MaNGOS::DynamicObjectUpdater notifier(*this,caster); + MaNGOS::DynamicObjectUpdater notifier(*this, caster); TypeContainerVisitor world_object_notifier(notifier); TypeContainerVisitor grid_object_notifier(notifier); @@ -136,12 +139,12 @@ void DynamicObject::Delete() void DynamicObject::Delay(int32 delaytime) { m_aliveDuration -= delaytime; - for(AffectedSet::iterator iunit= m_affected.begin();iunit != m_affected.end();++iunit) + for(AffectedSet::iterator iunit= m_affected.begin(); iunit != m_affected.end(); ++iunit) if (*iunit) (*iunit)->DelayAura(m_spellId, m_effIndex, delaytime); } bool DynamicObject::isVisibleForInState(Player const* u, bool inVisibleList) const { - return IsInWorld() && u->IsInWorld() && IsWithinDistInMap(u,World::GetMaxVisibleDistanceForObject()+(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false); + return IsInWorld() && u->IsInWorld() && IsWithinDistInMap(u, World::GetMaxVisibleDistanceForObject() + (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false); } diff --git a/src/game/DynamicObject.h b/src/game/DynamicObject.h index ed19dc28f..3db328055 100644 --- a/src/game/DynamicObject.h +++ b/src/game/DynamicObject.h @@ -39,7 +39,7 @@ class DynamicObject : public WorldObject uint32 GetSpellId() const { return m_spellId; } uint32 GetEffIndex() const { return m_effIndex; } uint32 GetDuration() const { return m_aliveDuration; } - uint64 GetCasterGUID() const { return m_casterGuid; } + uint64 GetCasterGUID() const { return GetUInt64Value(DYNAMICOBJECT_CASTER); } Unit* GetCaster() const; float GetRadius() const { return m_radius; } bool IsAffecting(Unit *unit) const { return m_affected.find(unit) != m_affected.end(); } @@ -58,7 +58,6 @@ class DynamicObject : public WorldObject bool isActiveObject() const { return false; } protected: - uint64 m_casterGuid; uint32 m_spellId; uint32 m_effIndex; int32 m_aliveDuration;