refactor(Core/GameObject): Move the GameObject state save handling to… (#18080)

* refactor(Core/GameObject): Move the GameObject state save handling to instance level

* Update GameObject.h

* remove leftover

* small improvements
This commit is contained in:
Andrew
2024-01-01 01:51:33 -03:00
committed by GitHub
parent a1212a52b0
commit a11434b24f
14 changed files with 100 additions and 192 deletions

View File

@@ -740,6 +740,26 @@ void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= nullptr*/, ui
instance->SendToPlayers(&data);
}
void InstanceScript::LoadInstanceSavedGameobjectStateData()
{
_objectStateMap.clear();
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SELECT_INSTANCE_SAVED_DATA);
stmt->SetData(0, instance->GetInstanceId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
{
Field* fields;
do
{
fields = result->Fetch();
StoreGameObjectState(fields[0].Get<uint32>(), fields[1].Get<uint8>());
} while (result->NextRow());
}
}
std::string InstanceScript::GetBossStateName(uint8 state)
{
// See enum EncounterState in InstanceScript.h
@@ -762,6 +782,18 @@ std::string InstanceScript::GetBossStateName(uint8 state)
}
}
uint8 InstanceScript::GetStoredGameObjectState(ObjectGuid::LowType spawnId) const
{
auto i = _objectStateMap.find(spawnId);
if (i != _objectStateMap.end())
{
return i->second;
}
return 3; // Any state higher than 2 to get the default state for the object we are loading.
}
bool InstanceHasScript(WorldObject const* obj, char const* scriptName)
{
if (InstanceMap* instance = obj->GetMap()->ToInstanceMap())