From 32243eb1c19b6a8ccaafab0a154553a3e2cc21e4 Mon Sep 17 00:00:00 2001 From: ModoX Date: Wed, 10 Apr 2024 20:03:14 +0200 Subject: Core/Entities: Added possibility to inherit StringIds from other entities (#29908) * also implicitly do so for personal summons (cherry picked from commit 88bbd27f8d007dca17bb0d244fcf7e753506734e) --- src/server/game/Entities/Creature/Creature.cpp | 9 +++++++++ src/server/game/Entities/Creature/Creature.h | 1 + src/server/game/Entities/GameObject/GameObject.cpp | 9 +++++++++ src/server/game/Entities/GameObject/GameObject.h | 1 + src/server/game/Entities/Object/Object.cpp | 3 +++ 5 files changed, 23 insertions(+) (limited to 'src') 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, 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 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 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 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; } } -- cgit v1.2.3