*Update active object code.
--HG-- branch : trunk
This commit is contained in:
@@ -1662,7 +1662,7 @@ void Creature::setDeathState(DeathState s)
|
|||||||
{
|
{
|
||||||
SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
|
SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
|
||||||
SetUInt32Value(UNIT_NPC_FLAGS, 0);
|
SetUInt32Value(UNIT_NPC_FLAGS, 0);
|
||||||
if(!isPet())
|
//if(!isPet())
|
||||||
setActive(false);
|
setActive(false);
|
||||||
|
|
||||||
if(!isPet() && GetCreatureInfo()->SkinLootId)
|
if(!isPet() && GetCreatureInfo()->SkinLootId)
|
||||||
|
|||||||
@@ -53,17 +53,7 @@ void DynamicObject::AddToWorld()
|
|||||||
void DynamicObject::RemoveFromWorld()
|
void DynamicObject::RemoveFromWorld()
|
||||||
{
|
{
|
||||||
///- Remove the dynamicObject from the accessor
|
///- Remove the dynamicObject from the accessor
|
||||||
if(IsInWorld())
|
if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this);
|
||||||
{
|
|
||||||
// Make sure the object is back to grid container for removal as farsight targets
|
|
||||||
// are switched to world container on creation and they are also set to active
|
|
||||||
if (isActiveObject())
|
|
||||||
{
|
|
||||||
GetMap()->SwitchGridContainers(this, false);
|
|
||||||
setActive(false);
|
|
||||||
}
|
|
||||||
ObjectAccessor::Instance().RemoveObject(this);
|
|
||||||
}
|
|
||||||
WorldObject::RemoveFromWorld();
|
WorldObject::RemoveFromWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-7
@@ -269,6 +269,15 @@ void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell)
|
|||||||
obj->SetCurrentCell(cell);
|
obj->SetCurrentCell(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void Map::AddToGrid(DynamicObject* obj, NGridType *grid, Cell const& cell)
|
||||||
|
{
|
||||||
|
if(obj->isActiveObject()) // only farsight
|
||||||
|
(*grid)(cell.CellX(), cell.CellY()).AddWorldObject<DynamicObject>(obj, obj->GetGUID());
|
||||||
|
else
|
||||||
|
(*grid)(cell.CellX(), cell.CellY()).AddGridObject<DynamicObject>(obj, obj->GetGUID());
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell)
|
void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell)
|
||||||
{
|
{
|
||||||
@@ -311,6 +320,15 @@ void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void Map::RemoveFromGrid(DynamicObject* obj, NGridType *grid, Cell const& cell)
|
||||||
|
{
|
||||||
|
if(obj->isActiveObject()) // only farsight
|
||||||
|
(*grid)(cell.CellX(), cell.CellY()).RemoveWorldObject<DynamicObject>(obj, obj->GetGUID());
|
||||||
|
else
|
||||||
|
(*grid)(cell.CellX(), cell.CellY()).RemoveGridObject<DynamicObject>(obj, obj->GetGUID());
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Map::SwitchGridContainers(T* obj, bool apply)
|
void Map::SwitchGridContainers(T* obj, bool apply)
|
||||||
{
|
{
|
||||||
@@ -321,18 +339,18 @@ void Map::SwitchGridContainers(T* obj, bool apply)
|
|||||||
|
|
||||||
if(apply)
|
if(apply)
|
||||||
{
|
{
|
||||||
assert(!grid.GetWorldObject(obj->GetGUID(), obj));
|
if(!grid.RemoveGridObject<T>(obj, obj->GetGUID())
|
||||||
|
|| !grid.AddWorldObject<T>(obj, obj->GetGUID()))
|
||||||
{
|
{
|
||||||
grid.RemoveGridObject<T>(obj, obj->GetGUID());
|
assert(false);
|
||||||
grid.AddWorldObject<T>(obj, obj->GetGUID());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(!grid.GetGridObject(obj->GetGUID(), obj));
|
if(!grid.RemoveWorldObject<T>(obj, obj->GetGUID())
|
||||||
|
|| !grid.AddGridObject<T>(obj, obj->GetGUID()))
|
||||||
{
|
{
|
||||||
grid.RemoveWorldObject<T>(obj, obj->GetGUID());
|
assert(false);
|
||||||
grid.AddGridObject<T>(obj, obj->GetGUID());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,7 +446,7 @@ void Map::LoadGrid(float x, float y)
|
|||||||
{
|
{
|
||||||
CellPair pair = Trinity::ComputeCellPair(x, y);
|
CellPair pair = Trinity::ComputeCellPair(x, y);
|
||||||
Cell cell(pair);
|
Cell cell(pair);
|
||||||
EnsureGridLoaded(cell, NULL);
|
EnsureGridLoaded(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::Add(Player *player)
|
bool Map::Add(Player *player)
|
||||||
|
|||||||
@@ -1070,11 +1070,30 @@ WorldObject::WorldObject()
|
|||||||
m_isActive = false;
|
m_isActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldObject::SetWorldObject(bool on)
|
||||||
|
{
|
||||||
|
if(!IsInWorld())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(GetTypeId() == TYPEID_UNIT)
|
||||||
|
{
|
||||||
|
if(!((Creature*)this)->isPet())
|
||||||
|
GetMap()->SwitchGridContainers((Creature*)this, on);
|
||||||
|
}
|
||||||
|
/*else if(GetTypeId() == TYPEID_DYNAMICOBJECT)
|
||||||
|
{
|
||||||
|
GetMap()->SwitchGridContainers((DynamicObject*)this, on);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
void WorldObject::setActive( bool on )
|
void WorldObject::setActive( bool on )
|
||||||
{
|
{
|
||||||
if(m_isActive==on)
|
if(m_isActive==on)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(GetTypeId() == TYPEID_PLAYER)
|
||||||
|
return;
|
||||||
|
|
||||||
bool world = IsInWorld();
|
bool world = IsInWorld();
|
||||||
|
|
||||||
Map* map;
|
Map* map;
|
||||||
|
|||||||
@@ -486,6 +486,7 @@ class TRINITY_DLL_SPEC WorldObject : public Object
|
|||||||
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
|
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
|
||||||
bool isActiveObject() const { return m_isActive; }
|
bool isActiveObject() const { return m_isActive; }
|
||||||
void setActive(bool isActiveObject);
|
void setActive(bool isActiveObject);
|
||||||
|
void SetWorldObject(bool apply);
|
||||||
template<class NOTIFIER> void VisitNearbyObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); }
|
template<class NOTIFIER> void VisitNearbyObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); }
|
||||||
template<class NOTIFIER> void VisitNearbyGridObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); }
|
template<class NOTIFIER> void VisitNearbyGridObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); }
|
||||||
template<class NOTIFIER> void VisitNearbyWorldObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); }
|
template<class NOTIFIER> void VisitNearbyWorldObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); }
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ Pet::Pet(PetType type) : Creature()
|
|||||||
m_CreatureCategoryCooldowns.clear();
|
m_CreatureCategoryCooldowns.clear();
|
||||||
m_autospells.clear();
|
m_autospells.clear();
|
||||||
m_declinedname = NULL;
|
m_declinedname = NULL;
|
||||||
m_isActive = true;
|
//m_isActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pet::~Pet()
|
Pet::~Pet()
|
||||||
|
|||||||
@@ -3497,11 +3497,8 @@ void Spell::EffectAddFarsight(uint32 i)
|
|||||||
dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
|
dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
|
||||||
m_caster->AddDynObject(dynObj);
|
m_caster->AddDynObject(dynObj);
|
||||||
|
|
||||||
Map* map = dynObj->GetMap();
|
dynObj->setActive(true); //must before add to map to be put in world container
|
||||||
map->LoadGrid(dynObj->GetPositionX(), dynObj->GetPositionY()); // In case the spell is casted into a different grid by player
|
dynObj->GetMap()->Add(dynObj); //grid will also be loaded
|
||||||
map->Add(dynObj);
|
|
||||||
dynObj->setActive(true); // Keep the grid updated even if there are no players in it
|
|
||||||
map->SwitchGridContainers(dynObj, true); // Needed for forwarding player packets
|
|
||||||
|
|
||||||
// Need to update visibility of object for client to accept farsight guid
|
// Need to update visibility of object for client to accept farsight guid
|
||||||
((Player*)m_caster)->UpdateVisibilityOf(dynObj);
|
((Player*)m_caster)->UpdateVisibilityOf(dynObj);
|
||||||
|
|||||||
+6
-12
@@ -8502,25 +8502,19 @@ void Unit::SetCharm(Unit* pet)
|
|||||||
|
|
||||||
void Unit::AddPlayerToVision(Player* plr)
|
void Unit::AddPlayerToVision(Player* plr)
|
||||||
{
|
{
|
||||||
if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT
|
setActive(true);
|
||||||
&& !((Creature*)this)->isPet())
|
if(m_sharedVision.empty())
|
||||||
{
|
SetWorldObject(true);
|
||||||
setActive(true);
|
|
||||||
GetMap()->SwitchGridContainers((Creature*)this, true);
|
|
||||||
}
|
|
||||||
m_sharedVision.push_back(plr);
|
m_sharedVision.push_back(plr);
|
||||||
plr->SetFarsightTarget(this);
|
plr->SetFarsightTarget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::RemovePlayerFromVision(Player* plr)
|
void Unit::RemovePlayerFromVision(Player* plr)
|
||||||
{
|
{
|
||||||
|
setActive(false);
|
||||||
m_sharedVision.remove(plr);
|
m_sharedVision.remove(plr);
|
||||||
if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT
|
if(m_sharedVision.empty())
|
||||||
&& !((Creature*)this)->isPet())
|
SetWorldObject(false);
|
||||||
{
|
|
||||||
GetMap()->SwitchGridContainers((Creature*)this, false);
|
|
||||||
setActive(false);
|
|
||||||
}
|
|
||||||
plr->ClearFarsight();
|
plr->ClearFarsight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user