Core/Entities: Fixed m_stringIds[0] invalidation when reloading creature_template with a gm command

(cherry picked from commit bec5bdb61b)
This commit is contained in:
Shauren
2024-04-10 20:27:57 +02:00
committed by Ovahlord
parent 32243eb1c1
commit 125b6d2ed7
5 changed files with 23 additions and 22 deletions
@@ -811,7 +811,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;
@@ -1158,7 +1158,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();
@@ -1978,7 +1978,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;
@@ -3494,7 +3494,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)
@@ -3502,12 +3502,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;
}
}