From a3684c78efa93fec8f9c938b1c39d3f626257994 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sat, 23 Dec 2023 03:43:00 +0200 Subject: [PATCH] Fix quest script startup errors. --- sql/migrations/20231223014105_world.sql | 22 +++++++++++++++++ src/game/ScriptMgr.cpp | 32 +++++++++++++++++++++---- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 sql/migrations/20231223014105_world.sql diff --git a/sql/migrations/20231223014105_world.sql b/sql/migrations/20231223014105_world.sql new file mode 100644 index 00000000000..989ef96cbc7 --- /dev/null +++ b/sql/migrations/20231223014105_world.sql @@ -0,0 +1,22 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20231223014105'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20231223014105'); +-- Add your query below. + + +-- Remove unusued quest scripts. +DELETE FROM `quest_start_scripts` WHERE `id` IN (945, 3447); +DELETE FROM `quest_end_scripts` WHERE `id` IN (2952, 4603, 4604, 5058); + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index f47150ca8f0..b726030c21a 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -1419,11 +1419,23 @@ void ScriptMgr::LoadQuestEndScripts() { LoadScripts(sQuestEndScripts, "quest_end_scripts"); + std::set usedQuestCompleteScripts; + std::unique_ptr result(WorldDatabase.Query("SELECT DISTINCT `CompleteScript` FROM `quest_template`")); + if (result) + { + do + { + Field* fields = result->Fetch(); + uint32 scriptId = fields[0].GetUInt32(); + usedQuestCompleteScripts.insert(scriptId); + } while (result->NextRow()); + } + // check ids for (const auto& itr : sQuestEndScripts) { - if (!sObjectMgr.GetQuestTemplate(itr.first) && !sObjectMgr.IsExistingQuestId(itr.first)) - sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Table `quest_end_scripts` has not existing quest (Id: %u) as script id", itr.first); + if (usedQuestCompleteScripts.find(itr.first) == usedQuestCompleteScripts.end()) + sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Table `quest_end_scripts` has script (Id: %u) not referenced from anywhere", itr.first); } } @@ -1431,11 +1443,23 @@ void ScriptMgr::LoadQuestStartScripts() { LoadScripts(sQuestStartScripts, "quest_start_scripts"); + std::set usedQuestStartScripts; + std::unique_ptr result(WorldDatabase.Query("SELECT DISTINCT `StartScript` FROM `quest_template`")); + if (result) + { + do + { + Field* fields = result->Fetch(); + uint32 scriptId = fields[0].GetUInt32(); + usedQuestStartScripts.insert(scriptId); + } while (result->NextRow()); + } + // check ids for (const auto& itr : sQuestStartScripts) { - if (!sObjectMgr.GetQuestTemplate(itr.first) && !sObjectMgr.IsExistingQuestId(itr.first)) - sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Table `quest_start_scripts` has not existing quest (Id: %u) as script id", itr.first); + if (usedQuestStartScripts.find(itr.first) == usedQuestStartScripts.end()) + sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Table `quest_start_scripts` has script (Id: %u) not referenced from anywhere", itr.first); } }