mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 21:26:23 +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)
|
||||
|
||||
@@ -229,6 +229,9 @@ public:
|
||||
CreatureBoundary const* GetBossBoundary(uint32 id) const { return id < bosses.size() ? &bosses[id].boundary : nullptr; }
|
||||
BossInfo const* GetBossInfo(uint32 id) const { return &bosses[id]; }
|
||||
|
||||
uint32 GetPersistentData(uint32 index) const { return index < persistentData.size() ? persistentData[index] : 0; };
|
||||
void StorePersistentData(uint32 index, uint32 data);
|
||||
|
||||
// Achievement criteria additional requirements check
|
||||
// NOTE: not use this if same can be checked existed requirement types from AchievementCriteriaRequirementType
|
||||
virtual bool CheckAchievementCriteriaMeet(uint32 /*criteria_id*/, Player const* /*source*/, Unit const* /*target*/ = nullptr, uint32 /*miscvalue1*/ = 0);
|
||||
@@ -257,6 +260,7 @@ public:
|
||||
protected:
|
||||
void SetHeaders(std::string const& dataHeaders);
|
||||
void SetBossNumber(uint32 number) { bosses.resize(number); }
|
||||
void SetPersistentDataCount(uint32 number) { persistentData.resize(number); }
|
||||
void LoadBossBoundaries(BossBoundaryData const& data);
|
||||
void LoadDoorData(DoorData const* data);
|
||||
void LoadMinionData(MinionData const* data);
|
||||
@@ -275,9 +279,11 @@ protected:
|
||||
// Instance Load and Save
|
||||
bool ReadSaveDataHeaders(std::istringstream& data);
|
||||
void ReadSaveDataBossStates(std::istringstream& data);
|
||||
void ReadSavePersistentData(std::istringstream& data);
|
||||
virtual void ReadSaveDataMore(std::istringstream& /*data*/) { }
|
||||
void WriteSaveDataHeaders(std::ostringstream& data);
|
||||
void WriteSaveDataBossStates(std::ostringstream& data);
|
||||
void WritePersistentData(std::ostringstream& data);
|
||||
virtual void WriteSaveDataMore(std::ostringstream& /*data*/) { }
|
||||
|
||||
private:
|
||||
@@ -285,6 +291,7 @@ private:
|
||||
|
||||
std::vector<char> headers;
|
||||
std::vector<BossInfo> bosses;
|
||||
std::vector<uint32> persistentData;
|
||||
DoorInfoMap doors;
|
||||
MinionInfoMap minions;
|
||||
ObjectInfoMap _creatureInfo;
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
{
|
||||
SetHeaders(DataHeader);
|
||||
SetBossNumber(MAX_ENCOUNTER);
|
||||
SetPersistentDataCount(MAX_DATA_INDEXES);
|
||||
LoadDoorData(doorData);
|
||||
|
||||
_passageEncounter = 0;
|
||||
@@ -149,7 +150,8 @@ public:
|
||||
DoSummonAction(creature, player);
|
||||
}
|
||||
}
|
||||
_passageEncounter++;
|
||||
|
||||
StorePersistentData(DATA_INDEX_PASSAGE_ENCOUNTER, _passageEncounter++);
|
||||
SaveToDB();
|
||||
}
|
||||
}
|
||||
@@ -186,16 +188,17 @@ public:
|
||||
if (Creature* creature = instance->GetCreature(_pathaleonGUID))
|
||||
creature->AI()->DoAction(1);
|
||||
}
|
||||
_passageEncounter++;
|
||||
|
||||
StorePersistentData(DATA_INDEX_PASSAGE_ENCOUNTER, _passageEncounter++);
|
||||
SaveToDB();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReadSaveDataMore(std::istringstream& data) override
|
||||
void ReadSaveDataMore(std::istringstream& /*data*/) override
|
||||
{
|
||||
data >> _passageEncounter;
|
||||
_passageEncounter = GetPersistentData(DATA_INDEX_PASSAGE_ENCOUNTER);
|
||||
|
||||
if (_passageEncounter == ENCOUNTER_PASSAGE_DONE)
|
||||
{
|
||||
@@ -203,11 +206,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void WriteSaveDataMore(std::ostringstream& data) override
|
||||
{
|
||||
data << _passageEncounter;
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectGuid _pathaleonGUID;
|
||||
uint32 _passageTimer;
|
||||
|
||||
@@ -70,6 +70,12 @@ enum SpellIds
|
||||
SPELL_TELEPORT_VISUAL = 35517
|
||||
};
|
||||
|
||||
enum DataIndex
|
||||
{
|
||||
DATA_INDEX_PASSAGE_ENCOUNTER = 0,
|
||||
MAX_DATA_INDEXES
|
||||
};
|
||||
|
||||
template <class AI, class T>
|
||||
inline AI* GetMechanarAI(T* obj)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user