*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)
|
||||
SetUInt32Value(UNIT_NPC_FLAGS, 0);
|
||||
if(!isPet())
|
||||
//if(!isPet())
|
||||
setActive(false);
|
||||
|
||||
if(!isPet() && GetCreatureInfo()->SkinLootId)
|
||||
|
||||
@@ -53,17 +53,7 @@ void DynamicObject::AddToWorld()
|
||||
void DynamicObject::RemoveFromWorld()
|
||||
{
|
||||
///- Remove the dynamicObject from the accessor
|
||||
if(IsInWorld())
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this);
|
||||
WorldObject::RemoveFromWorld();
|
||||
}
|
||||
|
||||
|
||||
+25
-7
@@ -269,6 +269,15 @@ void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& 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>
|
||||
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>
|
||||
void Map::SwitchGridContainers(T* obj, bool apply)
|
||||
{
|
||||
@@ -321,18 +339,18 @@ void Map::SwitchGridContainers(T* obj, bool 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());
|
||||
grid.AddWorldObject<T>(obj, obj->GetGUID());
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
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());
|
||||
grid.AddGridObject<T>(obj, obj->GetGUID());
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,7 +446,7 @@ void Map::LoadGrid(float x, float y)
|
||||
{
|
||||
CellPair pair = Trinity::ComputeCellPair(x, y);
|
||||
Cell cell(pair);
|
||||
EnsureGridLoaded(cell, NULL);
|
||||
EnsureGridLoaded(cell);
|
||||
}
|
||||
|
||||
bool Map::Add(Player *player)
|
||||
|
||||
@@ -1070,11 +1070,30 @@ WorldObject::WorldObject()
|
||||
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 )
|
||||
{
|
||||
if(m_isActive==on)
|
||||
return;
|
||||
|
||||
if(GetTypeId() == TYPEID_PLAYER)
|
||||
return;
|
||||
|
||||
bool world = IsInWorld();
|
||||
|
||||
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);
|
||||
bool isActiveObject() const { return m_isActive; }
|
||||
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 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); }
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ Pet::Pet(PetType type) : Creature()
|
||||
m_CreatureCategoryCooldowns.clear();
|
||||
m_autospells.clear();
|
||||
m_declinedname = NULL;
|
||||
m_isActive = true;
|
||||
//m_isActive = true;
|
||||
}
|
||||
|
||||
Pet::~Pet()
|
||||
|
||||
@@ -3497,11 +3497,8 @@ void Spell::EffectAddFarsight(uint32 i)
|
||||
dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
|
||||
m_caster->AddDynObject(dynObj);
|
||||
|
||||
Map* map = dynObj->GetMap();
|
||||
map->LoadGrid(dynObj->GetPositionX(), dynObj->GetPositionY()); // In case the spell is casted into a different grid by player
|
||||
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
|
||||
dynObj->setActive(true); //must before add to map to be put in world container
|
||||
dynObj->GetMap()->Add(dynObj); //grid will also be loaded
|
||||
|
||||
// Need to update visibility of object for client to accept farsight guid
|
||||
((Player*)m_caster)->UpdateVisibilityOf(dynObj);
|
||||
|
||||
+5
-11
@@ -8502,25 +8502,19 @@ void Unit::SetCharm(Unit* pet)
|
||||
|
||||
void Unit::AddPlayerToVision(Player* plr)
|
||||
{
|
||||
if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT
|
||||
&& !((Creature*)this)->isPet())
|
||||
{
|
||||
setActive(true);
|
||||
GetMap()->SwitchGridContainers((Creature*)this, true);
|
||||
}
|
||||
if(m_sharedVision.empty())
|
||||
SetWorldObject(true);
|
||||
m_sharedVision.push_back(plr);
|
||||
plr->SetFarsightTarget(this);
|
||||
}
|
||||
|
||||
void Unit::RemovePlayerFromVision(Player* plr)
|
||||
{
|
||||
m_sharedVision.remove(plr);
|
||||
if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT
|
||||
&& !((Creature*)this)->isPet())
|
||||
{
|
||||
GetMap()->SwitchGridContainers((Creature*)this, false);
|
||||
setActive(false);
|
||||
}
|
||||
m_sharedVision.remove(plr);
|
||||
if(m_sharedVision.empty())
|
||||
SetWorldObject(false);
|
||||
plr->ClearFarsight();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user