mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
refactor(Core/InstanceScript): refactored load and save methods (#14977)
Co-authored-by: joschiwald <736792+joschiwald@users.noreply.github.com>
This commit is contained in:
@@ -134,6 +134,17 @@ void InstanceScript::LoadBossBoundaries(const BossBoundaryData& data)
|
||||
bosses[entry.bossId].boundary.push_back(entry.boundary);
|
||||
}
|
||||
|
||||
void InstanceScript::SetHeaders(std::string const& dataHeaders)
|
||||
{
|
||||
for (char header : dataHeaders)
|
||||
{
|
||||
if (isalpha(header))
|
||||
{
|
||||
headers.push_back(header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::LoadMinionData(const MinionData* data)
|
||||
{
|
||||
while (data->entry)
|
||||
@@ -340,30 +351,89 @@ bool InstanceScript::SetBossState(uint32 id, EncounterState state)
|
||||
return false;
|
||||
}
|
||||
|
||||
void InstanceScript::LoadBossState(const char* data)
|
||||
void InstanceScript::Load(const char* data)
|
||||
{
|
||||
if (!data)
|
||||
{
|
||||
OUT_LOAD_INST_DATA_FAIL;
|
||||
return;
|
||||
}
|
||||
|
||||
OUT_LOAD_INST_DATA(data);
|
||||
|
||||
std::istringstream loadStream(data);
|
||||
uint32 buff;
|
||||
|
||||
if (ReadSaveDataHeaders(loadStream))
|
||||
{
|
||||
ReadSaveDataBossStates(loadStream);
|
||||
ReadSaveDataMore(loadStream);
|
||||
}
|
||||
else
|
||||
OUT_LOAD_INST_DATA_FAIL;
|
||||
|
||||
OUT_LOAD_INST_DATA_COMPLETE;
|
||||
}
|
||||
|
||||
bool InstanceScript::ReadSaveDataHeaders(std::istringstream& data)
|
||||
{
|
||||
for (char header : headers)
|
||||
{
|
||||
char buff;
|
||||
data >> buff;
|
||||
|
||||
if (header != buff)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InstanceScript::ReadSaveDataBossStates(std::istringstream& data)
|
||||
{
|
||||
uint32 bossId = 0;
|
||||
for (std::vector<BossInfo>::iterator i = bosses.begin(); i != bosses.end(); ++i, ++bossId)
|
||||
{
|
||||
loadStream >> buff;
|
||||
uint32 buff;
|
||||
data >> buff;
|
||||
if (buff == IN_PROGRESS || buff == FAIL || buff == SPECIAL)
|
||||
buff = NOT_STARTED;
|
||||
|
||||
if (buff < TO_BE_DECIDED)
|
||||
SetBossState(bossId, (EncounterState)buff);
|
||||
SetBossState(bossId, EncounterState(buff));
|
||||
}
|
||||
}
|
||||
|
||||
std::string InstanceScript::GetBossSaveData()
|
||||
std::string InstanceScript::GetSaveData()
|
||||
{
|
||||
OUT_SAVE_INST_DATA;
|
||||
|
||||
std::ostringstream saveStream;
|
||||
for (std::vector<BossInfo>::iterator i = bosses.begin(); i != bosses.end(); ++i)
|
||||
saveStream << (uint32)i->state << ' ';
|
||||
|
||||
WriteSaveDataHeaders(saveStream);
|
||||
WriteSaveDataBossStates(saveStream);
|
||||
WriteSaveDataMore(saveStream);
|
||||
|
||||
OUT_SAVE_INST_DATA_COMPLETE;
|
||||
|
||||
return saveStream.str();
|
||||
}
|
||||
|
||||
void InstanceScript::WriteSaveDataHeaders(std::ostringstream& data)
|
||||
{
|
||||
for (char header : headers)
|
||||
{
|
||||
data << header << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::WriteSaveDataBossStates(std::ostringstream& data)
|
||||
{
|
||||
for (BossInfo const& bossInfo : bosses)
|
||||
{
|
||||
data << uint32(bossInfo.state) << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::DoUseDoorOrButton(ObjectGuid uiGuid, uint32 uiWithRestoreTime, bool bUseAlternativeState)
|
||||
{
|
||||
if (!uiGuid)
|
||||
|
||||
@@ -148,14 +148,14 @@ public:
|
||||
//On creation, NOT load.
|
||||
virtual void Initialize() {}
|
||||
|
||||
//On load
|
||||
virtual void Load(char const* data) { LoadBossState(data); }
|
||||
// On load
|
||||
virtual void Load(char const* data);
|
||||
|
||||
//Called when creature is Looted
|
||||
virtual void CreatureLooted(Creature* /*creature*/, LootType) {}
|
||||
|
||||
//When save is needed, this function generates the data
|
||||
virtual std::string GetSaveData() { return GetBossSaveData(); }
|
||||
// When save is needed, this function generates the data
|
||||
virtual std::string GetSaveData();
|
||||
|
||||
void SaveToDB();
|
||||
|
||||
@@ -255,6 +255,7 @@ public:
|
||||
// Allows to perform particular actions
|
||||
virtual void DoAction(int32 /*action*/) {}
|
||||
protected:
|
||||
void SetHeaders(std::string const& dataHeaders);
|
||||
void SetBossNumber(uint32 number) { bosses.resize(number); }
|
||||
void LoadBossBoundaries(BossBoundaryData const& data);
|
||||
void LoadDoorData(DoorData const* data);
|
||||
@@ -271,11 +272,18 @@ protected:
|
||||
void UpdateDoorState(GameObject* door);
|
||||
void UpdateMinionState(Creature* minion, EncounterState state);
|
||||
|
||||
void LoadBossState(char const* data);
|
||||
std::string GetBossSaveData();
|
||||
// Instance Load and Save
|
||||
bool ReadSaveDataHeaders(std::istringstream& data);
|
||||
void ReadSaveDataBossStates(std::istringstream& data);
|
||||
virtual void ReadSaveDataMore(std::istringstream& /*data*/) { }
|
||||
void WriteSaveDataHeaders(std::ostringstream& data);
|
||||
void WriteSaveDataBossStates(std::ostringstream& data);
|
||||
virtual void WriteSaveDataMore(std::ostringstream& /*data*/) { }
|
||||
|
||||
private:
|
||||
static void LoadObjectData(ObjectData const* creatureData, ObjectInfoMap& objectInfo);
|
||||
|
||||
std::vector<char> headers;
|
||||
std::vector<BossInfo> bosses;
|
||||
DoorInfoMap doors;
|
||||
MinionInfoMap minions;
|
||||
|
||||
Reference in New Issue
Block a user