mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-18 19:35:42 +00:00
feat(Core/Instance): Implement helpers to easily save/retrieve persist… (#15113)
This commit is contained in:
@@ -351,6 +351,17 @@ bool InstanceScript::SetBossState(uint32 id, EncounterState state)
|
||||
return false;
|
||||
}
|
||||
|
||||
void InstanceScript::StorePersistentData(uint32 index, uint32 data)
|
||||
{
|
||||
if (index > persistentData.size())
|
||||
{
|
||||
LOG_ERROR("scripts", "InstanceScript::StorePersistentData() index larger than storage size. Index: {} Size: {} Data: {}.", index, persistentData.size(), data);
|
||||
return;
|
||||
}
|
||||
|
||||
persistentData[index] = data;
|
||||
}
|
||||
|
||||
void InstanceScript::Load(const char* data)
|
||||
{
|
||||
if (!data)
|
||||
@@ -366,6 +377,7 @@ void InstanceScript::Load(const char* data)
|
||||
if (ReadSaveDataHeaders(loadStream))
|
||||
{
|
||||
ReadSaveDataBossStates(loadStream);
|
||||
ReadSavePersistentData(loadStream);
|
||||
ReadSaveDataMore(loadStream);
|
||||
}
|
||||
else
|
||||
@@ -403,6 +415,14 @@ void InstanceScript::ReadSaveDataBossStates(std::istringstream& data)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::ReadSavePersistentData(std::istringstream& data)
|
||||
{
|
||||
for (uint32 i = 0; i < persistentData.size(); ++i)
|
||||
{
|
||||
data >> persistentData[i];
|
||||
}
|
||||
}
|
||||
|
||||
std::string InstanceScript::GetSaveData()
|
||||
{
|
||||
OUT_SAVE_INST_DATA;
|
||||
@@ -411,6 +431,7 @@ std::string InstanceScript::GetSaveData()
|
||||
|
||||
WriteSaveDataHeaders(saveStream);
|
||||
WriteSaveDataBossStates(saveStream);
|
||||
WritePersistentData(saveStream);
|
||||
WriteSaveDataMore(saveStream);
|
||||
|
||||
OUT_SAVE_INST_DATA_COMPLETE;
|
||||
@@ -434,6 +455,14 @@ void InstanceScript::WriteSaveDataBossStates(std::ostringstream& data)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::WritePersistentData(std::ostringstream& data)
|
||||
{
|
||||
for (auto const& entry : persistentData)
|
||||
{
|
||||
data << entry << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::DoUseDoorOrButton(ObjectGuid uiGuid, uint32 uiWithRestoreTime, bool bUseAlternativeState)
|
||||
{
|
||||
if (!uiGuid)
|
||||
|
||||
Reference in New Issue
Block a user