diff options
author | ModoX <moardox@gmail.com> | 2024-04-10 20:03:14 +0200 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2024-05-28 16:40:42 +0200 |
commit | 32243eb1c19b6a8ccaafab0a154553a3e2cc21e4 (patch) | |
tree | 97e935d9ae02a08dce49a185c7b473c1fe63da3b | |
parent | 98506fa3ff3e5c743e9f4c705cf9f59e3b4a5747 (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.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 3 |
5 files changed, 23 insertions, 0 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index b0e92968e14..581f7eb0339 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -3020,6 +3020,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 e03ad96095d..aa71432267e 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -244,6 +244,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 cc0f76be458..6f9dc97d16b 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -3483,6 +3483,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 13b8afdd5ad..c194e44fa9d 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -378,6 +378,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; } diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index edd9206ff30..6746b49fd11 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2094,6 +2094,9 @@ TempSummon* WorldObject::SummonPersonalClone(Position const& pos, TempSummonType if (TempSummon* summon = map->SummonCreature(GetEntry(), pos, nullptr, despawnTime, privateObjectOwner, spellId, vehId, privateObjectOwner->GetGUID(), &smoothPhasingInfo)) { summon->SetTempSummonType(despawnType); + + if (Creature* thisCreature = ToCreature()) + summon->InheritStringIds(thisCreature); return summon; } } |