mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 16:43:47 +00:00
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:
@@ -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())
|
||||
|
||||
@@ -136,6 +136,7 @@ typedef std::pair<DoorInfoMap::const_iterator, DoorInfoMap::const_iterator> Door
|
||||
typedef std::map<uint32 /*entry*/, MinionInfo> MinionInfoMap;
|
||||
typedef std::map<uint32 /*type*/, ObjectGuid /*guid*/> ObjectGuidMap;
|
||||
typedef std::map<uint32 /*entry*/, uint32 /*type*/> ObjectInfoMap;
|
||||
typedef std::map<ObjectGuid::LowType /*spawnId*/, uint8 /*state*/> ObjectStateMap;
|
||||
|
||||
class InstanceScript : public ZoneScript
|
||||
{
|
||||
@@ -265,6 +266,12 @@ public:
|
||||
// Allows executing code using all creatures registered in the instance script as minions
|
||||
void DoForAllMinions(uint32 id, std::function<void(Creature*)> exec);
|
||||
|
||||
//
|
||||
void StoreGameObjectState(ObjectGuid::LowType spawnId, uint8 state) { _objectStateMap[spawnId] = state; };
|
||||
[[nodiscard]] uint8 GetStoredGameObjectState(ObjectGuid::LowType spawnId) const;
|
||||
|
||||
void LoadInstanceSavedGameobjectStateData();
|
||||
|
||||
TaskScheduler scheduler;
|
||||
protected:
|
||||
void SetHeaders(std::string const& dataHeaders);
|
||||
@@ -311,6 +318,7 @@ private:
|
||||
ObjectInfoMap _creatureInfo;
|
||||
ObjectInfoMap _gameObjectInfo;
|
||||
ObjectGuidMap _objectGuids;
|
||||
ObjectStateMap _objectStateMap;
|
||||
uint32 completedEncounters; // completed encounter mask, bit indexes are DungeonEncounter.dbc boss numbers, used for packets
|
||||
std::unordered_set<uint32> _activatedAreaTriggers;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user