aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-07-30 13:55:34 +0200
committerShauren <shauren.trinity@gmail.com>2024-10-05 17:52:53 +0200
commit1f6a6d2c5b6ff2c72803edd1ed6c8c7284770526 (patch)
tree489164a31b1dcbe767c7175fae748a7df3d58ba1 /src
parentd019719289cb8266e581147ef2085bd2f43b2bd2 (diff)
Core/GameObjects: Added stringid to gameobjects
(cherry picked from commit 845f61e0a969891b14e1f182fadd29af347a1a3f)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp24
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h8
-rw-r--r--src/server/game/Entities/GameObject/GameObjectData.h1
-rw-r--r--src/server/game/Entities/Object/Object.cpp31
-rw-r--r--src/server/game/Entities/Object/Object.h20
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp10
-rw-r--r--src/server/game/Grids/Notifiers/GridNotifiers.h64
7 files changed, 148 insertions, 10 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index d893a357b85..c89c45911a8 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -417,6 +417,9 @@ bool GameObject::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* map, u
}
LastUsedScriptID = GetGOInfo()->ScriptId;
+
+ m_stringIds[0] = goinfo->StringId;
+
AIM_Initialize();
// Initialize loot duplicate count depending on raid difficulty
@@ -1142,6 +1145,8 @@ bool GameObject::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap
m_goData = data;
+ m_stringIds[1] = data->StringId;
+
if (addToMap && !GetMap()->AddToMap(this))
return false;
@@ -2270,6 +2275,25 @@ uint32 GameObject::GetScriptId() const
return GetGOInfo()->ScriptId;
}
+bool GameObject::HasStringId(std::string_view id) const
+{
+ return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end();
+}
+
+void GameObject::SetScriptStringId(std::string id)
+{
+ if (!id.empty())
+ {
+ m_scriptStringId.emplace(std::move(id));
+ m_stringIds[2] = *m_scriptStringId;
+ }
+ else
+ {
+ m_scriptStringId.reset();
+ m_stringIds[2] = {};
+ }
+}
+
// overwrite WorldObject function for proper name localization
std::string const & GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const
{
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index f45682405b2..882146faab9 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -270,10 +270,14 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
void SetRespawnCompatibilityMode(bool mode = true) { m_respawnCompatibilityMode = mode; }
bool GetRespawnCompatibilityMode() {return m_respawnCompatibilityMode; }
+ std::string const& GetAIName() const;
uint32 GetScriptId() const;
GameObjectAI* AI() const { return m_AI; }
- std::string const& GetAIName() const;
+ bool HasStringId(std::string_view id) const;
+ void SetScriptStringId(std::string id);
+ std::array<std::string_view, 3> const& GetStringIds() const { return m_stringIds; }
+
void SetDisplayId(uint32 displayid);
uint32 GetDisplayId() const { return GetUInt32Value(GAMEOBJECT_DISPLAYID); }
@@ -339,6 +343,8 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
GameObjectTemplateAddon const* m_goTemplateAddon;
GameObjectData const* m_goData;
GameObjectValue m_goValue;
+ std::array<std::string_view, 3> m_stringIds;
+ Optional<std::string> m_scriptStringId;
int64 m_packedRotation;
QuaternionData m_localRotation;
diff --git a/src/server/game/Entities/GameObject/GameObjectData.h b/src/server/game/Entities/GameObject/GameObjectData.h
index 40eda9ce862..a4e4a4bdce2 100644
--- a/src/server/game/Entities/GameObject/GameObjectData.h
+++ b/src/server/game/Entities/GameObject/GameObjectData.h
@@ -420,6 +420,7 @@ struct GameObjectTemplate
std::string AIName;
uint32 ScriptId;
+ std::string StringId;
WorldPacket QueryData[TOTAL_LOCALES];
// helpers
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 003e4f53cf1..74cfa6e9bb6 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -2148,6 +2148,19 @@ GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range, bool s
return go;
}
+GameObject* WorldObject::FindNearestGameObjectWithOptions(float range, FindGameObjectOptions const& options) const
+{
+ GameObject* go = nullptr;
+ Trinity::NearestCheckCustomizer checkCustomizer(*this, range);
+ Trinity::GameObjectWithOptionsInObjectRangeCheck checker(*this, checkCustomizer, options);
+ Trinity::GameObjectLastSearcher searcher(this, go, checker);
+ if (options.IgnorePhases)
+ searcher.i_phaseMask = PHASEMASK_ANYWHERE;
+
+ Cell::VisitGridObjects(this, searcher, range);
+ return go;
+}
+
GameObject* WorldObject::FindNearestUnspawnedGameObject(uint32 entry, float range) const
{
GameObject* go = nullptr;
@@ -3145,6 +3158,18 @@ void WorldObject::GetGameObjectListWithEntryInGrid(Container& gameObjectContaine
}
template <typename Container>
+void WorldObject::GetGameObjectListWithOptionsInGrid(Container& gameObjectContainer, float maxSearchRange, FindGameObjectOptions const& options) const
+{
+ Trinity::InRangeCheckCustomizer checkCustomizer(*this, maxSearchRange);
+ Trinity::GameObjectWithOptionsInObjectRangeCheck check(*this, checkCustomizer, options);
+ Trinity::GameObjectListSearcher searcher(this, gameObjectContainer, check);
+ if (options.IgnorePhases)
+ searcher.i_phaseMask = PHASEMASK_ANYWHERE;
+
+ Cell::VisitGridObjects(this, searcher, maxSearchRange);
+}
+
+template <typename Container>
void WorldObject::GetCreatureListWithEntryInGrid(Container& creatureContainer, uint32 entry, float maxSearchRange /*= 250.0f*/) const
{
Trinity::AllCreaturesOfEntryInRange check(this, entry, maxSearchRange);
@@ -3155,7 +3180,7 @@ void WorldObject::GetCreatureListWithEntryInGrid(Container& creatureContainer, u
template <typename Container>
void WorldObject::GetCreatureListWithOptionsInGrid(Container& creatureContainer, float maxSearchRange, FindCreatureOptions const& options) const
{
- Trinity::NoopCheckCustomizer checkCustomizer;
+ Trinity::InRangeCheckCustomizer checkCustomizer(*this, maxSearchRange);
Trinity::CreatureWithOptionsInObjectRangeCheck check(*this, checkCustomizer, options);
Trinity::CreatureListSearcher searcher(this, creatureContainer, check);
if (options.IgnorePhases)
@@ -3617,6 +3642,10 @@ template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::lis
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::deque<GameObject*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::vector<GameObject*>&, uint32, float) const;
+template TC_GAME_API void WorldObject::GetGameObjectListWithOptionsInGrid(std::list<GameObject*>&, float, FindGameObjectOptions const&) const;
+template TC_GAME_API void WorldObject::GetGameObjectListWithOptionsInGrid(std::deque<GameObject*>&, float, FindGameObjectOptions const&) const;
+template TC_GAME_API void WorldObject::GetGameObjectListWithOptionsInGrid(std::vector<GameObject*>&, float, FindGameObjectOptions const&) const;
+
template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::deque<Creature*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::vector<Creature*>&, uint32, float) const;
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index d489900eb16..da6aa84899b 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -341,6 +341,22 @@ struct FindCreatureOptions
FindCreatureOptions& operator=(FindCreatureOptions&&) = delete;
};
+struct FindGameObjectOptions
+{
+ Optional<uint32> GameObjectId;
+ Optional<std::string_view> StringId;
+
+ Optional<bool> IsSummon;
+ Optional<bool> IsSpawned;
+
+ bool IgnorePhases = false;
+ bool IgnoreNotOwnedPrivateObjects = true;
+ bool IgnorePrivateObjects = false;
+
+ Optional<ObjectGuid> OwnerGuid;
+ Optional<ObjectGuid> PrivateObjectOwnerGuid;
+};
+
class TC_GAME_API WorldObject : public Object, public WorldLocation
{
protected:
@@ -473,6 +489,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const;
Creature* FindNearestCreatureWithOptions(float range, FindCreatureOptions const& options) const;
GameObject* FindNearestGameObject(uint32 entry, float range, bool spawnedOnly = true) const;
+ GameObject* FindNearestGameObjectWithOptions(float range, FindGameObjectOptions const& options) const;
GameObject* FindNearestUnspawnedGameObject(uint32 entry, float range) const;
GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const;
Player* SelectNearestPlayer(float distance) const;
@@ -530,6 +547,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
void GetGameObjectListWithEntryInGrid(Container& gameObjectContainer, uint32 entry, float maxSearchRange = 250.0f) const;
template <typename Container>
+ void GetGameObjectListWithOptionsInGrid(Container& gameObjectContainer, float maxSearchRange, FindGameObjectOptions const& options) const;
+
+ template <typename Container>
void GetCreatureListWithEntryInGrid(Container& creatureContainer, uint32 entry, float maxSearchRange = 250.0f) const;
template <typename Container>
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index d89fd4c5894..a369d0dd5bb 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -2489,8 +2489,8 @@ void ObjectMgr::LoadGameObjects()
QueryResult result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation, "
// 7 8 9 10 11 12 13 14 15 16 17
"rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, eventEntry, poolSpawnId, "
- // 18
- "ScriptName "
+ // 18 19
+ "ScriptName, StringId "
"FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
"LEFT OUTER JOIN pool_members ON pool_members.type = 1 AND gameobject.guid = pool_members.spawnId");
@@ -2594,6 +2594,7 @@ void ObjectMgr::LoadGameObjects()
uint32 PoolId = fields[17].GetUInt32();
data.scriptId = GetScriptId(fields[18].GetString());
+ data.StringId = fields[19].GetString();
if (data.rotation.x < -1.0f || data.rotation.x > 1.0f)
{
@@ -7665,8 +7666,8 @@ void ObjectMgr::LoadGameObjectTemplate()
QueryResult result = WorldDatabase.Query("SELECT entry, type, displayId, name, IconName, castBarCaption, unk1, size, "
// 8 9 10 11 12 13 14 15 16 17 18 19 20
"Data0, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9, Data10, Data11, Data12, "
- // 21 22 23 24 25 26 27 28 29 30 31 32 33
- "Data13, Data14, Data15, Data16, Data17, Data18, Data19, Data20, Data21, Data22, Data23, AIName, ScriptName "
+ // 21 22 23 24 25 26 27 28 29 30 31 32 33 34
+ "Data13, Data14, Data15, Data16, Data17, Data18, Data19, Data20, Data21, Data22, Data23, AIName, ScriptName, StringId "
"FROM gameobject_template");
if (!result)
@@ -7697,6 +7698,7 @@ void ObjectMgr::LoadGameObjectTemplate()
got.AIName = fields[32].GetString();
got.ScriptId = GetScriptId(fields[33].GetString());
+ got.StringId = fields[34].GetString();
// Checks
if (!got.AIName.empty() && !sGameObjectAIRegistry->HasItem(got.AIName))
diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h
index 55f17abea86..d324ebc1290 100644
--- a/src/server/game/Grids/Notifiers/GridNotifiers.h
+++ b/src/server/game/Grids/Notifiers/GridNotifiers.h
@@ -583,12 +583,21 @@ namespace Trinity
// CHECKS && DO classes
// CHECK modifiers
- class NoopCheckCustomizer
+ class InRangeCheckCustomizer
{
public:
- bool Test(WorldObject const* /*o*/) const { return true; }
+ explicit InRangeCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
+
+ bool Test(WorldObject const* o) const
+ {
+ return i_obj.IsWithinDist(o, i_range);
+ }
void Update(WorldObject const* /*o*/) { }
+
+ private:
+ WorldObject const& i_obj;
+ float i_range;
};
class NearestCheckCustomizer
@@ -1387,14 +1396,14 @@ namespace Trinity
NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&) = delete;
};
- template <typename Customizer = NoopCheckCustomizer>
+ template <typename Customizer = InRangeCheckCustomizer>
class CreatureWithOptionsInObjectRangeCheck
{
public:
CreatureWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindCreatureOptions const& args)
: i_obj(obj), i_args(args), i_customizer(customizer) { }
- bool operator()(Creature* u) const
+ bool operator()(Creature const* u) const
{
if (u->getDeathState() == DEAD) // Despawned
return false;
@@ -1445,6 +1454,53 @@ namespace Trinity
Customizer& i_customizer;
};
+ template <typename Customizer = InRangeCheckCustomizer>
+ class GameObjectWithOptionsInObjectRangeCheck
+ {
+ public:
+ GameObjectWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindGameObjectOptions const& args)
+ : i_obj(obj), i_args(args), i_customizer(customizer) { }
+
+ bool operator()(GameObject const* go) const
+ {
+ if (i_args.IsSpawned.has_value() && i_args.IsSpawned != go->isSpawned()) // Despawned
+ return false;
+
+ if (go->GetGUID() == i_obj.GetGUID())
+ return false;
+
+ if (!i_customizer.Test(go))
+ return false;
+
+ if (i_args.GameObjectId && go->GetEntry() != i_args.GameObjectId)
+ return false;
+
+ if (i_args.StringId && !go->HasStringId(*i_args.StringId))
+ return false;
+
+ if (i_args.IsSummon.has_value() && (go->GetSpawnId() == 0) != i_args.IsSummon)
+ return false;
+
+ if ((i_args.OwnerGuid && go->GetOwnerGUID() != i_args.OwnerGuid)
+ || (i_args.PrivateObjectOwnerGuid && go->GetPrivateObjectOwner() != i_args.PrivateObjectOwnerGuid))
+ return false;
+
+ if (i_args.IgnorePrivateObjects && go->IsPrivateObject())
+ return false;
+
+ if (i_args.IgnoreNotOwnedPrivateObjects && !go->CheckPrivateObjectOwnerVisibility(&i_obj))
+ return false;
+
+ i_customizer.Update(go);
+ return true;
+ }
+
+ private:
+ WorldObject const& i_obj;
+ FindGameObjectOptions const& i_args;
+ Customizer& i_customizer;
+ };
+
class AnyPlayerInObjectRangeCheck
{
public: