mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 18:36:31 +01:00
Core/Misc: Add static versions of GetGUID and ToX methods to Object. The static versions return Empty/nullptr for null objects.
(cherry picked from commit b3ee407707)
This commit is contained in:
@@ -48,6 +48,7 @@ class Map;
|
||||
class Object;
|
||||
class Player;
|
||||
class Scenario;
|
||||
class SceneObject;
|
||||
class Spell;
|
||||
class SpellCastTargets;
|
||||
class SpellEffectInfo;
|
||||
@@ -151,6 +152,7 @@ class TC_GAME_API Object
|
||||
virtual void AddToWorld();
|
||||
virtual void RemoveFromWorld();
|
||||
|
||||
static ObjectGuid GetGUID(Object const* o) { return o ? o->GetGUID() : ObjectGuid::Empty; }
|
||||
ObjectGuid const& GetGUID() const { return m_guid; }
|
||||
uint32 GetEntry() const { return m_objectData->EntryID; }
|
||||
void SetEntry(uint32 entry) { SetUpdateFieldValue(m_values.ModifyValue(&Object::m_objectData).ModifyValue(&UF::ObjectData::EntryID), entry); }
|
||||
@@ -189,36 +191,58 @@ class TC_GAME_API Object
|
||||
void BuildFieldsUpdate(Player*, UpdateDataMapType &) const;
|
||||
|
||||
inline bool IsPlayer() const { return GetTypeId() == TYPEID_PLAYER; }
|
||||
static Player* ToPlayer(Object* o) { return o ? o->ToPlayer() : nullptr; }
|
||||
static Player const* ToPlayer(Object const* o) { return o ? o->ToPlayer() : nullptr; }
|
||||
Player* ToPlayer() { if (IsPlayer()) return reinterpret_cast<Player*>(this); else return nullptr; }
|
||||
Player const* ToPlayer() const { if (IsPlayer()) return reinterpret_cast<Player const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsCreature() const { return GetTypeId() == TYPEID_UNIT; }
|
||||
static Creature* ToCreature(Object* o) { return o ? o->ToCreature() : nullptr; }
|
||||
static Creature const* ToCreature(Object const* o) { return o ? o->ToCreature() : nullptr; }
|
||||
Creature* ToCreature() { if (IsCreature()) return reinterpret_cast<Creature*>(this); else return nullptr; }
|
||||
Creature const* ToCreature() const { if (IsCreature()) return reinterpret_cast<Creature const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsUnit() const { return isType(TYPEMASK_UNIT); }
|
||||
static Unit* ToUnit(Object* o) { return o ? o->ToUnit() : nullptr; }
|
||||
static Unit const* ToUnit(Object const* o) { return o ? o->ToUnit() : nullptr; }
|
||||
Unit* ToUnit() { if (IsUnit()) return reinterpret_cast<Unit*>(this); else return nullptr; }
|
||||
Unit const* ToUnit() const { if (IsUnit()) return reinterpret_cast<Unit const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsGameObject() const { return GetTypeId() == TYPEID_GAMEOBJECT; }
|
||||
static GameObject* ToGameObject(Object* o) { return o ? o->ToGameObject() : nullptr; }
|
||||
static GameObject const* ToGameObject(Object const* o) { return o ? o->ToGameObject() : nullptr; }
|
||||
GameObject* ToGameObject() { if (IsGameObject()) return reinterpret_cast<GameObject*>(this); else return nullptr; }
|
||||
GameObject const* ToGameObject() const { if (IsGameObject()) return reinterpret_cast<GameObject const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; }
|
||||
static Corpse* ToCorpse(Object* o) { return o ? o->ToCorpse() : nullptr; }
|
||||
static Corpse const* ToCorpse(Object const* o) { return o ? o->ToCorpse() : nullptr; }
|
||||
Corpse* ToCorpse() { if (IsCorpse()) return reinterpret_cast<Corpse*>(this); else return nullptr; }
|
||||
Corpse const* ToCorpse() const { if (IsCorpse()) return reinterpret_cast<Corpse const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsDynObject() const { return GetTypeId() == TYPEID_DYNAMICOBJECT; }
|
||||
static DynamicObject* ToDynObject(Object* o) { return o ? o->ToDynObject() : nullptr; }
|
||||
static DynamicObject const* ToDynObject(Object const* o) { return o ? o->ToDynObject() : nullptr; }
|
||||
DynamicObject* ToDynObject() { if (IsDynObject()) return reinterpret_cast<DynamicObject*>(this); else return nullptr; }
|
||||
DynamicObject const* ToDynObject() const { if (IsDynObject()) return reinterpret_cast<DynamicObject const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsAreaTrigger() const { return GetTypeId() == TYPEID_AREATRIGGER; }
|
||||
static AreaTrigger* ToAreaTrigger(Object* o) { return o ? o->ToAreaTrigger() : nullptr; }
|
||||
static AreaTrigger const* ToAreaTrigger(Object const* o) { return o ? o->ToAreaTrigger() : nullptr; }
|
||||
AreaTrigger* ToAreaTrigger() { if (IsAreaTrigger()) return reinterpret_cast<AreaTrigger*>(this); else return nullptr; }
|
||||
AreaTrigger const* ToAreaTrigger() const { if (IsAreaTrigger()) return reinterpret_cast<AreaTrigger const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsSceneObject() const { return GetTypeId() == TYPEID_SCENEOBJECT; }
|
||||
static SceneObject* ToSceneObject(Object* o) { return o ? o->ToSceneObject() : nullptr; }
|
||||
static SceneObject const* ToSceneObject(Object const* o) { return o ? o->ToSceneObject() : nullptr; }
|
||||
SceneObject* ToSceneObject() { if (IsSceneObject()) return reinterpret_cast<SceneObject*>(this); else return nullptr; }
|
||||
SceneObject const* ToSceneObject() const { if (IsSceneObject()) return reinterpret_cast<SceneObject const*>(this); else return nullptr; }
|
||||
|
||||
inline bool IsConversation() const { return GetTypeId() == TYPEID_CONVERSATION; }
|
||||
Conversation* ToConversation() { if (GetTypeId() == TYPEID_CONVERSATION) return reinterpret_cast<Conversation*>(this); else return nullptr; }
|
||||
Conversation const* ToConversation() const { if (GetTypeId() == TYPEID_CONVERSATION) return reinterpret_cast<Conversation const*>(this); else return nullptr; }
|
||||
static Conversation* ToConversation(Object* o) { return o ? o->ToConversation() : nullptr; }
|
||||
static Conversation const* ToConversation(Object const* o) { return o ? o->ToConversation() : nullptr; }
|
||||
Conversation* ToConversation() { if (IsConversation()) return reinterpret_cast<Conversation*>(this); else return nullptr; }
|
||||
Conversation const* ToConversation() const { if (IsConversation()) return reinterpret_cast<Conversation const*>(this); else return nullptr; }
|
||||
|
||||
UF::UpdateFieldHolder m_values;
|
||||
UF::UpdateField<UF::ObjectData, 0, TYPEID_OBJECT> m_objectData;
|
||||
|
||||
Reference in New Issue
Block a user