summaryrefslogtreecommitdiff
path: root/src/server/game/Globals/ObjectMgr.cpp
diff options
context:
space:
mode:
authorHanabi <54484196+hanabi5@users.noreply.github.com>2022-05-24 14:33:45 +0100
committerGitHub <noreply@github.com>2022-05-24 10:33:45 -0300
commita6a2ca8ef76716f5b58b4ed2ae53d0bde424775b (patch)
tree075e5df040e919a203fbe96711f3db6f6bd1ce0b /src/server/game/Globals/ObjectMgr.cpp
parent305a2689e965346dc7c12a87650fab08696b0a10 (diff)
feat(Core/GameObjects): Instance gameobject save data implementation (#11113)
* fix(Core): Save gameobject state on instances Currently, azerothcore doesn't save gameobject states on instances. Whenever there's a re-start or crash, the instance's gameobjects and their states aren't saved, producing un-wanted behaviours and blocking instances at times. Implemented CRUD for new table `instance_saved_data` that holds the states of gameobjects. - When worldserver launches and gameobjects are loaded, this will check if this object's state exists on the DB and sets the previous state. - On instance deletion (reset) these states are also removed based on the instance ID. - Whenever a gameobject state changes inside a dungeon or raid, we save on the database the set state. * Select query to synchronous and used FindMap() * loading gameobject states on create * reseting instance saved data * missing reset methods and on create state * database structure * Update src/server/game/Entities/GameObject/GameObject.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Entities/GameObject/GameObject.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Entities/GameObject/GameObject.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Entities/GameObject/GameObject.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Entities/Player/PlayerMisc.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Groups/Group.cpp Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * codestyle * table changes * table style * codestyle * table changes for columns * data sanitization * todo: - Finish loading db data into the containers - Using containers to find data - How to get data from ObjectMGR inside Gameobject? * loading on start up and db changes * Removing unused data structure * Uninitialised integer * Whitespace * clean-up and hooks to save states on memory * Codestyle MySQL deprecated backticks * i dont understand codefactor * build * Update data/sql/updates/pending_db_world/rev_1643395587559675400.sql Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update src/server/game/Globals/ObjectMgr.h Co-authored-by: Kargatum <dowlandtop@yandex.com> * review changes * unecessary removal * pushback instead of emplace * wrong database update * Update ObjectMgr.cpp * missing check * removing entry from the PR * missing removals * last delete * build * aha! Found the culprit for the sudden assert errors * type safety, save only important gameobjects * static cast to unsigned short * Update data/sql/updates/pending_db_characters/rev_1643629468629316100.sql Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * type changes * queries fix * fix build * enabling which gameobjects to save on the database * deadmines iron clad door * Adjustment to gameobject onj create state and instances: - Gnomeregan doors and Grubbis boss state - Deadmines missing doors - Stratholme gameobjects state saved * forgot emi blastfuse change to despawn * Leaving group logic * codestyle * fixing merge issues * prevent bad behaviour * brain meltdown * Update data/sql/updates/pending_db_characters/rev_1643629468629316100.sql * Update data/sql/updates/pending_db_world/rev_1649359139539727000.sql Co-authored-by: Claudiodfc <54484196+claudiodfc@users.noreply.github.com> Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Co-authored-by: Kargatum <dowlandtop@yandex.com> Co-authored-by: Skjalf <47818697+Nyeriah@users.noreply.github.com>
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 161f1d638a..32eda9fe72 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -9762,6 +9762,72 @@ uint32 ObjectMgr::GetQuestMoneyReward(uint8 level, uint32 questMoneyDifficulty)
return 0;
}
+void ObjectMgr::LoadInstanceSavedGameobjectStateData()
+{
+ uint32 oldMSTime = getMSTime();
+
+ CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SELECT_INSTANCE_SAVED_DATA);
+ PreparedQueryResult result = CharacterDatabase.Query(stmt);
+
+ if (!result)
+ {
+ // There's no gameobject with this GUID saved on the DB
+ LOG_INFO("sql.sql", ">> Loaded 0 Instance saved gameobject state data. DB table `instance_saved_go_state_data` is empty.");
+ return;
+ }
+
+ Field* fields;
+ uint32 count = 0;
+ do
+ {
+ fields = result->Fetch();
+ GameobjectInstanceSavedStateList.push_back({ fields[0].Get<uint32>(), fields[1].Get<uint32>(), fields[2].Get<unsigned short>() });
+ count++;
+ } while (result->NextRow());
+
+ LOG_INFO("server.loading", ">> Loaded {} instance saved gameobject state data in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
+ LOG_INFO("server.loading", " ");
+}
+
+uint8 ObjectMgr::GetInstanceSavedGameobjectState(uint32 id, uint32 guid)
+{
+ for (auto it = GameobjectInstanceSavedStateList.begin(); it != GameobjectInstanceSavedStateList.end(); it++)
+ {
+ if (it->m_guid == guid && it->m_instance == id)
+ {
+ return it->m_state;
+ }
+ }
+ return 3; // Any state higher than 2 to get the default state
+}
+
+bool ObjectMgr::FindInstanceSavedGameobjectState(uint32 id, uint32 guid)
+{
+ for (auto it = GameobjectInstanceSavedStateList.begin(); it != GameobjectInstanceSavedStateList.end(); it++)
+ {
+ if (it->m_guid == guid && it->m_instance == id)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void ObjectMgr::SetInstanceSavedGameobjectState(uint32 id, uint32 guid, uint8 state)
+{
+ for (auto it = GameobjectInstanceSavedStateList.begin(); it != GameobjectInstanceSavedStateList.end(); it++)
+ {
+ if (it->m_guid == guid && it->m_instance == id)
+ {
+ it->m_state = state;
+ }
+ }
+}
+void ObjectMgr::NewInstanceSavedGameobjectState(uint32 id, uint32 guid, uint8 state)
+{
+ GameobjectInstanceSavedStateList.push_back({ id, guid, state });
+}
+
void ObjectMgr::SendServerMail(Player* player, uint32 id, uint32 reqLevel, uint32 reqPlayTime, uint32 rewardMoneyA, uint32 rewardMoneyH, uint32 rewardItemA, uint32 rewardItemCountA, uint32 rewardItemH, uint32 rewardItemCountH, std::string subject, std::string body, uint8 active) const
{
if (active)