aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/GameObject
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-04-10 20:27:57 +0200
committerShauren <shauren.trinity@gmail.com>2024-04-10 20:27:57 +0200
commitbec5bdb61b1b78ae7f750019b9a187b489ebb496 (patch)
tree023e8d2eb7d13d09b02c1327a500c775dcfd6d6b /src/server/game/Entities/GameObject
parent88bbd27f8d007dca17bb0d244fcf7e753506734e (diff)
Core/Entities: Fixed m_stringIds[0] invalidation when reloading creature_template with a gm command
Diffstat (limited to 'src/server/game/Entities/GameObject')
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp12
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h5
2 files changed, 8 insertions, 9 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index f40c86eece6..eaa8c05f0dc 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -813,7 +813,7 @@ void SetControlZoneValue::Execute(GameObjectTypeBase& type) const
}
GameObject::GameObject() : WorldObject(false), MapObject(),
- m_model(nullptr), m_goValue(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0)
+ m_model(nullptr), m_goValue(), m_stringIds(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0)
{
m_objectType |= TYPEMASK_GAMEOBJECT;
m_objectTypeId = TYPEID_GAMEOBJECT;
@@ -1160,7 +1160,7 @@ bool GameObject::Create(uint32 entry, Map* map, Position const& pos, QuaternionD
LastUsedScriptID = GetGOInfo()->ScriptId;
- m_stringIds[AsUnderlyingType(StringIdType::Template)] = goInfo->StringId;
+ m_stringIds[AsUnderlyingType(StringIdType::Template)] = &goInfo->StringId;
AIM_Initialize();
@@ -1980,7 +1980,7 @@ bool GameObject::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap
m_goData = data;
- m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = data->StringId;
+ m_stringIds[AsUnderlyingType(StringIdType::Spawn)] = &data->StringId;
if (addToMap && !GetMap()->AddToMap(this))
return false;
@@ -3508,7 +3508,7 @@ void GameObject::InheritStringIds(GameObject const* parent)
bool GameObject::HasStringId(std::string_view id) const
{
- return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end();
+ return std::ranges::any_of(m_stringIds, [id](std::string const* stringId) { return stringId && *stringId == id; });
}
void GameObject::SetScriptStringId(std::string id)
@@ -3516,12 +3516,12 @@ void GameObject::SetScriptStringId(std::string id)
if (!id.empty())
{
m_scriptStringId.emplace(std::move(id));
- m_stringIds[AsUnderlyingType(StringIdType::Script)] = *m_scriptStringId;
+ m_stringIds[AsUnderlyingType(StringIdType::Script)] = &*m_scriptStringId;
}
else
{
m_scriptStringId.reset();
- m_stringIds[AsUnderlyingType(StringIdType::Script)] = {};
+ m_stringIds[AsUnderlyingType(StringIdType::Script)] = nullptr;
}
}
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index c194e44fa9d..86ebd9bb14d 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -381,8 +381,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
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; }
- std::string_view GetStringId(StringIdType type) const { return m_stringIds[size_t(type)]; }
+ std::string_view GetStringId(StringIdType type) const { return m_stringIds[size_t(type)] ? std::string_view(*m_stringIds[size_t(type)]) : std::string_view(); }
void SetDisplayId(uint32 displayid);
uint32 GetDisplayId() const { return m_gameObjectData->DisplayID; }
@@ -484,7 +483,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
GameObjectData const* m_goData;
std::unique_ptr<GameObjectTypeBase> m_goTypeImpl;
GameObjectValue m_goValue; // TODO: replace with m_goTypeImpl
- std::array<std::string_view, 3> m_stringIds;
+ std::array<std::string const*, 3> m_stringIds;
Optional<std::string> m_scriptStringId;
int64 m_packedRotation;