aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorModoX <moardox@gmail.com>2024-04-10 20:03:14 +0200
committerShauren <shauren.trinity@gmail.com>2024-10-05 18:00:07 +0200
commit5655aa4fd840ecaad73872566c5827e3446ed50e (patch)
treebbd0a5d799848f7bcb7b5977d06397724103e516
parentd98bb5f83c694e1571087ea2f6facdd302d84c5b (diff)
Core/Entities: Added possibility to inherit StringIds from other entities (#29908)
* also implicitly do so for personal summons (cherry picked from commit 88bbd27f8d007dca17bb0d244fcf7e753506734e)
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp9
-rw-r--r--src/server/game/Entities/Creature/Creature.h1
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp9
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h1
4 files changed, 20 insertions, 0 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index ee70ea61f90..79e97628aa9 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -2776,6 +2776,15 @@ uint32 Creature::GetScriptId() const
return ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(GetEntry()))->ScriptID;
}
+void Creature::InheritStringIds(Creature const* parent)
+{
+ // copy references to stringIds from template and spawn
+ m_stringIds = parent->m_stringIds;
+
+ // then copy script stringId, not just its reference
+ SetScriptStringId(std::string(parent->GetStringId(StringIdType::Script)));
+}
+
bool Creature::HasStringId(std::string_view id) const
{
return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end();
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index cff54558830..b2768a45643 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -198,6 +198,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
std::string const& GetAIName() const;
std::string GetScriptName() const;
uint32 GetScriptId() const;
+ void InheritStringIds(Creature const* parent);
bool HasStringId(std::string_view id) const;
void SetScriptStringId(std::string id);
std::array<std::string_view, 3> const& GetStringIds() const { return m_stringIds; }
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 02f25493186..2e2b11b2e62 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -2275,6 +2275,15 @@ uint32 GameObject::GetScriptId() const
return GetGOInfo()->ScriptId;
}
+void GameObject::InheritStringIds(GameObject const* parent)
+{
+ // copy references to stringIds from template and spawn
+ m_stringIds = parent->m_stringIds;
+
+ // then copy script stringId, not just its reference
+ SetScriptStringId(std::string(parent->GetStringId(StringIdType::Script)));
+}
+
bool GameObject::HasStringId(std::string_view id) const
{
return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end();
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 45601068bb4..7c412f01477 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -274,6 +274,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
uint32 GetScriptId() const;
GameObjectAI* AI() const { return m_AI; }
+ void InheritStringIds(GameObject const* parent);
bool HasStringId(std::string_view id) const;
void SetScriptStringId(std::string id);
std::array<std::string_view, 3> const& GetStringIds() const { return m_stringIds; }