rendered paste bodyGridDefines.h:
typedef TYPELIST_2(Creature, Player) UnitTypes;
DynamicObject.cpp:
DynamicObject::Update {
..
CellPair p(MaNGOS::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY()));
Cell cell = RedZone::GetZone(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
MaNGOS::DynamicObjectUpdater notifier(*this);
TypeContainerVisitor<MaNGOS::DynamicObjectUpdater, TypeMapContainer<UnitTypes> > object_notifier(notifier);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId()));
}
DynamicObject.h
#ifndef MANGOSSERVER_DYNAMICOBJECT_H
#define MANGOSSERVER_DYNAMICOBJECT_H
#include "Object.h"
#include "GridDefines.h"
struct SpellEntry;
class DynamicObject : public Object
{
public:
DynamicObject();
bool Create(uint32 guidlow, Unit *caster, uint32 spellId, uint32 effIndex, float x, float y, float z, int32 duration, float radius);
void Update(uint32 p_time);
void Delete();
bool isFinished() {return deleteThis;}
uint32 GetSpellId() const { return m_spellId; }
uint32 GetEffIndex() const { return m_effIndex; }
uint32 GetDuration() const { return m_aliveDuration; }
Unit* GetCaster() const { return m_caster; }
float GetRadius() const { return m_radius; }
protected:
Unit* m_caster;
uint32 m_spellId;
uint32 m_effIndex;
int32 m_aliveDuration;
time_t m_nextThinkTime;
bool deleteThis;
float m_radius;
};
namespace MaNGOS
{
struct MANGOS_DLL_DECL DynamicObjectUpdater
{
const DynamicObject &owner;
DynamicObjectUpdater(const DynamicObject &owner) : owner(owner) {}
template<class T> inline void Visit(std::map<OBJECT_HANDLE, T *> &m)
{
for(typename std::map<OBJECT_HANDLE, T*>::iterator itr=m.begin(); itr != m.end(); ++itr)
{
if(itr->second->isAlive() && !itr->second->isInFlight() )
{
if(owner.GetCaster()->IsFriendlyTo(itr->second) || iter->second->HasAura(owner.GetSpellId(), owner.GetEffIndex()))
continue;
if(owner.GetDistanceSq(itr->second) < owner.GetRadius() * owner.GetRadius() )
{
SpellEntry *spellInfo = sSpellStore.LookupEntry(owner.GetSpellId());
Aura* Aur = new Aura(spellInfo, owner.GetEffIndex(), itr->second, owner.GetCaster(), NULL);
itr->second->AddAura(Aur);
}
}
}
}
};
}
#endif