mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-27 07:36:23 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -18,6 +18,7 @@ class DynamicObject;
|
||||
class GameObject;
|
||||
class Pet;
|
||||
class Player;
|
||||
class ObjectGuid;
|
||||
|
||||
#define MAX_NUMBER_OF_CELLS 8
|
||||
|
||||
@@ -46,6 +47,7 @@ class Player;
|
||||
// Creature used instead pet to simplify *::Visit templates (not required duplicate code for Creature->Pet case)
|
||||
typedef TYPELIST_5(GameObject, Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/) AllWorldObjectTypes;
|
||||
typedef TYPELIST_4(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/) AllGridObjectTypes;
|
||||
typedef TYPELIST_5(Creature, GameObject, DynamicObject, Pet, Corpse) AllMapStoredObjectTypes;
|
||||
|
||||
typedef GridRefManager<Corpse> CorpseMapType;
|
||||
typedef GridRefManager<Creature> CreatureMapType;
|
||||
@@ -68,6 +70,7 @@ typedef NGrid<MAX_NUMBER_OF_CELLS, Player, AllWorldObjectTypes, AllGridObjectTyp
|
||||
|
||||
typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer;
|
||||
typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer;
|
||||
typedef TypeUnorderedMapContainer<AllMapStoredObjectTypes, ObjectGuid> MapStoredObjectTypesContainer;
|
||||
|
||||
template<uint32 LIMIT>
|
||||
struct CoordPair
|
||||
|
||||
@@ -61,14 +61,14 @@ void VisibleNotifier::SendToSelf()
|
||||
}
|
||||
}
|
||||
|
||||
for (Player::ClientGUIDs::const_iterator it = vis_guids.begin(); it != vis_guids.end(); ++it)
|
||||
for (GuidUnorderedSet::const_iterator it = vis_guids.begin(); it != vis_guids.end(); ++it)
|
||||
{
|
||||
if (WorldObject* obj = ObjectAccessor::GetWorldObject(i_player, *it))
|
||||
if (i_largeOnly != obj->IsVisibilityOverridden())
|
||||
continue;
|
||||
|
||||
// pussywizard: static transports are removed only in RemovePlayerFromMap and here if can no longer detect (eg. phase changed)
|
||||
if (IS_TRANSPORT_GUID(*it))
|
||||
if ((*it).IsTransport())
|
||||
if (GameObject* staticTrans = i_player.GetMap()->GetGameObject(*it))
|
||||
if (i_player.CanSeeOrDetect(staticTrans, false, true))
|
||||
continue;
|
||||
@@ -76,7 +76,7 @@ void VisibleNotifier::SendToSelf()
|
||||
i_player.m_clientGUIDs.erase(*it);
|
||||
i_data.AddOutOfRangeGUID(*it);
|
||||
|
||||
if (IS_PLAYER_GUID(*it))
|
||||
if ((*it).IsPlayer())
|
||||
{
|
||||
Player* player = ObjectAccessor::FindPlayer(*it);
|
||||
if (player && player->IsInMap(&i_player))
|
||||
@@ -127,7 +127,7 @@ void VisibleChangesNotifier::Visit(CreatureMapType& m)
|
||||
void VisibleChangesNotifier::Visit(DynamicObjectMapType& m)
|
||||
{
|
||||
for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (IS_PLAYER_GUID(iter->GetSource()->GetCasterGUID()))
|
||||
if (iter->GetSource()->GetCasterGUID().IsPlayer())
|
||||
if (Unit* caster = iter->GetSource()->GetCaster())
|
||||
if (Player* player = caster->ToPlayer())
|
||||
if (player->m_seer == iter->GetSource())
|
||||
@@ -245,7 +245,7 @@ void MessageDistDeliverer::Visit(DynamicObjectMapType& m)
|
||||
for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
{
|
||||
DynamicObject* target = iter->GetSource();
|
||||
if (!IS_PLAYER_GUID(target->GetCasterGUID()) || !target->InSamePhase(i_phaseMask))
|
||||
if (!target->GetCasterGUID().IsPlayer() || !target->InSamePhase(i_phaseMask))
|
||||
continue;
|
||||
|
||||
// Xinef: Check whether the dynobject allows to see through it
|
||||
@@ -311,7 +311,7 @@ void MessageDistDelivererToHostile::Visit(DynamicObjectMapType& m)
|
||||
for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
{
|
||||
DynamicObject* target = iter->GetSource();
|
||||
if (!IS_PLAYER_GUID(target->GetCasterGUID()) || !target->InSamePhase(i_phaseMask))
|
||||
if (!target->GetCasterGUID().IsPlayer() || !target->InSamePhase(i_phaseMask))
|
||||
continue;
|
||||
|
||||
if (target->GetExactDist2dSq(i_source) > i_distSq)
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace acore
|
||||
struct VisibleNotifier
|
||||
{
|
||||
Player& i_player;
|
||||
Player::ClientGUIDs vis_guids;
|
||||
GuidUnorderedSet vis_guids;
|
||||
std::vector<Unit*>& i_visibleNow;
|
||||
bool i_gobjOnly;
|
||||
bool i_largeOnly;
|
||||
@@ -718,18 +718,6 @@ namespace acore
|
||||
NearestGameObjectTypeInObjectRangeCheck(NearestGameObjectTypeInObjectRangeCheck const&);
|
||||
};
|
||||
|
||||
class GameObjectWithDbGUIDCheck
|
||||
{
|
||||
public:
|
||||
GameObjectWithDbGUIDCheck(uint32 db_guid) : i_db_guid(db_guid) {}
|
||||
bool operator()(GameObject const* go) const
|
||||
{
|
||||
return go->GetDBTableGUIDLow() == i_db_guid;
|
||||
}
|
||||
private:
|
||||
uint32 i_db_guid;
|
||||
};
|
||||
|
||||
// Unit checks
|
||||
|
||||
class MostHPMissingInRange
|
||||
@@ -859,18 +847,6 @@ namespace acore
|
||||
float i_range;
|
||||
};
|
||||
|
||||
class CreatureWithDbGUIDCheck
|
||||
{
|
||||
public:
|
||||
CreatureWithDbGUIDCheck(uint32 lowguid) : i_lowguid(lowguid) {}
|
||||
bool operator()(Creature* u)
|
||||
{
|
||||
return u->GetDBTableGUIDLow() == i_lowguid;
|
||||
}
|
||||
private:
|
||||
uint32 i_lowguid;
|
||||
};
|
||||
|
||||
class AnyFriendlyUnitInObjectRangeCheck
|
||||
{
|
||||
public:
|
||||
@@ -1402,21 +1378,21 @@ namespace acore
|
||||
class ObjectGUIDCheck
|
||||
{
|
||||
public:
|
||||
ObjectGUIDCheck(uint64 GUID, bool equals) : _GUID(GUID), _equals(equals) {}
|
||||
ObjectGUIDCheck(ObjectGuid GUID, bool equals) : _GUID(GUID), _equals(equals) {}
|
||||
bool operator()(WorldObject const* object)
|
||||
{
|
||||
return (object->GetGUID() == _GUID) == _equals;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64 _GUID;
|
||||
ObjectGuid _GUID;
|
||||
bool _equals;
|
||||
};
|
||||
|
||||
class UnitAuraCheck
|
||||
{
|
||||
public:
|
||||
UnitAuraCheck(bool present, uint32 spellId, uint64 casterGUID = 0) : _present(present), _spellId(spellId), _casterGUID(casterGUID) {}
|
||||
UnitAuraCheck(bool present, uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty) : _present(present), _spellId(spellId), _casterGUID(casterGUID) {}
|
||||
bool operator()(Unit const* unit) const
|
||||
{
|
||||
return unit->HasAura(_spellId, _casterGUID) == _present;
|
||||
@@ -1430,7 +1406,7 @@ namespace acore
|
||||
private:
|
||||
bool _present;
|
||||
uint32 _spellId;
|
||||
uint64 _casterGUID;
|
||||
ObjectGuid _casterGUID;
|
||||
};
|
||||
|
||||
class AllWorldObjectsInExactRange
|
||||
|
||||
@@ -23,7 +23,7 @@ class ObjectWorldLoader
|
||||
{
|
||||
public:
|
||||
explicit ObjectWorldLoader(ObjectGridLoader& gloader)
|
||||
: i_cell(gloader.i_cell), i_map(gloader.i_map), i_grid(gloader.i_grid), i_corpses (0)
|
||||
: i_cell(gloader.i_cell), i_map(gloader.i_map), i_grid(gloader.i_grid), i_corpses(gloader.i_corpses)
|
||||
{}
|
||||
|
||||
void Visit(CorpseMapType& m);
|
||||
@@ -33,9 +33,9 @@ public:
|
||||
private:
|
||||
Cell i_cell;
|
||||
Map* i_map;
|
||||
public:
|
||||
NGridType& i_grid;
|
||||
uint32 i_corpses;
|
||||
public:
|
||||
uint32& i_corpses;
|
||||
};
|
||||
|
||||
template<class T> void ObjectGridLoader::SetObjectCell(T* /*obj*/, CellCoord const& /*cellCoord*/)
|
||||
@@ -93,7 +93,7 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<T>&
|
||||
for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
|
||||
{
|
||||
T* obj = new T;
|
||||
uint32 guid = *i_guid;
|
||||
ObjectGuid::LowType guid = *i_guid;
|
||||
//LOG_INFO("server", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
|
||||
if (!obj->LoadFromDB(guid, map))
|
||||
{
|
||||
@@ -110,7 +110,7 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<Gam
|
||||
{
|
||||
for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
|
||||
{
|
||||
uint32 guid = *i_guid;
|
||||
ObjectGuid::LowType guid = *i_guid;
|
||||
GameObjectData const* data = sObjectMgr->GetGOData(guid);
|
||||
GameObject* obj = data && sObjectMgr->IsGameObjectStaticTransport(data->id) ? new StaticTransport() : new GameObject();
|
||||
//LOG_INFO("server", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
|
||||
@@ -124,38 +124,6 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<Gam
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHelper(CellCorpseSet const& cell_corpses, CellCoord& cell, CorpseMapType& m, uint32& count, Map* map)
|
||||
{
|
||||
if (cell_corpses.empty())
|
||||
return;
|
||||
|
||||
for (CellCorpseSet::const_iterator itr = cell_corpses.begin(); itr != cell_corpses.end(); ++itr)
|
||||
{
|
||||
if (itr->second != map->GetInstanceId())
|
||||
continue;
|
||||
|
||||
uint32 player_guid = itr->first;
|
||||
|
||||
Corpse* obj = sObjectAccessor->GetCorpseForPlayerGUID(player_guid);
|
||||
if (!obj)
|
||||
continue;
|
||||
|
||||
// TODO: this is a hack
|
||||
// corpse's map should be reset when the map is unloaded
|
||||
// but it may still exist when the grid is unloaded but map is not
|
||||
// in that case map == currMap
|
||||
obj->SetMap(map);
|
||||
|
||||
if (obj->IsInGrid())
|
||||
{
|
||||
obj->AddToWorld();
|
||||
continue;
|
||||
}
|
||||
|
||||
AddObjectHelper(cell, m, count, map, obj);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectGridLoader::Visit(GameObjectMapType& m)
|
||||
{
|
||||
CellCoord cellCoord = i_cell.GetCellCoord();
|
||||
@@ -170,12 +138,23 @@ void ObjectGridLoader::Visit(CreatureMapType& m)
|
||||
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
|
||||
}
|
||||
|
||||
void ObjectWorldLoader::Visit(CorpseMapType& m)
|
||||
void ObjectWorldLoader::Visit(CorpseMapType& /*m*/)
|
||||
{
|
||||
CellCoord cellCoord = i_cell.GetCellCoord();
|
||||
// corpses are always added to spawn mode 0 and they are spawned by their instance id
|
||||
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), 0, cellCoord.GetId());
|
||||
LoadHelper(cell_guids.corpses, cellCoord, m, i_corpses, i_map);
|
||||
if (std::unordered_set<Corpse*> const* corpses = i_map->GetCorpsesInCell(cellCoord.GetId()))
|
||||
{
|
||||
for (Corpse* corpse : *corpses)
|
||||
{
|
||||
corpse->AddToWorld();
|
||||
GridType& cell = i_grid.GetGridType(i_cell.CellX(), i_cell.CellY());
|
||||
if (corpse->IsWorldObject())
|
||||
cell.AddWorldObject(corpse);
|
||||
else
|
||||
cell.AddGridObject(corpse);
|
||||
|
||||
++i_corpses;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectGridLoader::LoadN(void)
|
||||
@@ -184,10 +163,10 @@ void ObjectGridLoader::LoadN(void)
|
||||
i_creatures = 0;
|
||||
i_corpses = 0;
|
||||
i_cell.data.Part.cell_y = 0;
|
||||
for (unsigned int x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
|
||||
for (uint32 x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
|
||||
{
|
||||
i_cell.data.Part.cell_x = x;
|
||||
for (unsigned int y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
|
||||
for (uint32 y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
|
||||
{
|
||||
i_cell.data.Part.cell_y = y;
|
||||
|
||||
@@ -202,7 +181,6 @@ void ObjectGridLoader::LoadN(void)
|
||||
ObjectWorldLoader worker(*this);
|
||||
TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer> visitor(worker);
|
||||
i_grid.VisitGrid(x, y, visitor);
|
||||
i_corpses += worker.i_corpses;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +218,7 @@ void ObjectGridCleaner::Visit(GridRefManager<T>& m)
|
||||
template void ObjectGridUnloader::Visit(CreatureMapType&);
|
||||
template void ObjectGridUnloader::Visit(GameObjectMapType&);
|
||||
template void ObjectGridUnloader::Visit(DynamicObjectMapType&);
|
||||
template void ObjectGridUnloader::Visit(CorpseMapType&);
|
||||
|
||||
template void ObjectGridCleaner::Visit(CreatureMapType&);
|
||||
template void ObjectGridCleaner::Visit<GameObject>(GameObjectMapType&);
|
||||
template void ObjectGridCleaner::Visit<DynamicObject>(DynamicObjectMapType&);
|
||||
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
class ObjectGridUnloader
|
||||
{
|
||||
public:
|
||||
void Visit(CorpseMapType&) { } // corpses are deleted with Map
|
||||
template<class T> void Visit(GridRefManager<T>& m);
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user