diff --git a/sql/migrations/20220107020332_world.sql b/sql/migrations/20220107020332_world.sql new file mode 100644 index 000000000..a7f1c7ab3 --- /dev/null +++ b/sql/migrations/20220107020332_world.sql @@ -0,0 +1,26 @@ +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`='20220107020332'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20220107020332'); +-- Add your query below. + + +-- Assign "Skip Missing Targets" flag to Shadowy Assassin's waypoints command. +UPDATE `generic_scripts` SET `data_flags` = `data_flags` | 16 WHERE `command`=60 && `id` BETWEEN 243517 AND 243526; + +-- Remove Move Random commands from Shadowy Assassin spawn script, and assign it as default movement. +UPDATE `creature_template` SET `movement_type`=1 WHERE `entry`=2434; +DELETE FROM `generic_scripts` WHERE `command`=20 && `id` BETWEEN 243513 AND 243526; +UPDATE `creature_movement_scripts` SET `dataint2`=0 WHERE `command`=10 && `id`=243501 && `dataint2` BETWEEN 243513 AND 243516; + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/Maps/Map.cpp b/src/game/Maps/Map.cpp index 12bd54311..315a75ec0 100644 --- a/src/game/Maps/Map.cpp +++ b/src/game/Maps/Map.cpp @@ -2487,6 +2487,10 @@ bool Map::FindScriptInitialTargets(WorldObject*& source, WorldObject*& target, S if (target && !target->IsInWorld()) target = nullptr; + if ((step.script->raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS) && + (!source && !step.sourceGuid.IsEmpty() || !target && !step.targetGuid.IsEmpty())) + return false; + return true; } @@ -2504,21 +2508,9 @@ bool Map::FindScriptFinalTargets(WorldObject*& source, WorldObject*& target, Scr { if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2))) { - switch (script.target_type) - { - case TARGET_T_NEAREST_CREATURE_WITH_ENTRY: - case TARGET_T_RANDOM_CREATURE_WITH_ENTRY: - case TARGET_T_CREATURE_WITH_GUID: - case TARGET_T_CREATURE_FROM_INSTANCE_DATA: - case TARGET_T_NEAREST_GAMEOBJECT_WITH_ENTRY: - case TARGET_T_RANDOM_GAMEOBJECT_WITH_ENTRY: - case TARGET_T_GAMEOBJECT_WITH_GUID: - case TARGET_T_GAMEOBJECT_FROM_INSTANCE_DATA: - { - sLog.outError("FindScriptTargets: Failed to find target for script with id %u (target_param1: %u), (target_param2: %u), (target_type: %u).", script.id, script.target_param1, script.target_param2, script.target_type); - return false; - } - } + if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS)) + sLog.outError("FindScriptTargets: Failed to find target for script with id %u (target_param1: %u), (target_param2: %u), (target_type: %u).", script.id, script.target_param1, script.target_param2, script.target_type); + return false; } } @@ -2574,8 +2566,11 @@ void Map::ScriptsProcess() if (scriptResultOk) scriptResultOk = (this->*(m_ScriptCommands[step.script->command]))(*step.script, source, target); + else + scriptResultOk = (step.script->raw.data[4] & SF_GENERAL_ABORT_ON_FAILURE) != 0; lock.lock(); + // Command returns true if we should abort script. if (scriptResultOk) TerminateScript(step); diff --git a/src/game/Maps/ScriptCommands.h b/src/game/Maps/ScriptCommands.h index 4f50774d2..c8ddf7ae7 100644 --- a/src/game/Maps/ScriptCommands.h +++ b/src/game/Maps/ScriptCommands.h @@ -500,12 +500,15 @@ enum eStartScriptForAllOptions enum eDataFlags { - SF_GENERAL_SWAP_INITIAL_TARGETS = 0x1, // Swaps the provided source and target, before buddy is checked. - SF_GENERAL_SWAP_FINAL_TARGETS = 0x2, // Swaps the local source and target, after buddy is assigned. - SF_GENERAL_TARGET_SELF = 0x4, // Replaces the provided target with the provided source. - SF_GENERAL_ABORT_ON_FAILURE = 0x8 // Terminates the script if the command fails. + SF_GENERAL_SWAP_INITIAL_TARGETS = 0x01, // Swaps the original source and target, before buddy is checked. + SF_GENERAL_SWAP_FINAL_TARGETS = 0x02, // Swaps the final source and target, after buddy is assigned. + SF_GENERAL_TARGET_SELF = 0x04, // Replaces the final target with the final source. + SF_GENERAL_ABORT_ON_FAILURE = 0x08, // Terminates the whole script if the command fails. + SF_GENERAL_SKIP_MISSING_TARGETS = 0x10, // Command is skipped if source or target is not found, without printing an error. }; +#define ALL_DB_SCRIPT_FLAGS (SF_GENERAL_SWAP_INITIAL_TARGETS | SF_GENERAL_SWAP_FINAL_TARGETS | SF_GENERAL_TARGET_SELF | SF_GENERAL_ABORT_ON_FAILURE | SF_GENERAL_SKIP_MISSING_TARGETS) + struct ScriptInfo { uint32 id; diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index 7389b49e6..b96ad9cf0 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -136,9 +136,15 @@ void ScriptMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) if (!CheckScriptTargets(tmp.target_type, tmp.target_param1, tmp.target_param2, tablename, tmp.id)) DisableScriptAction(tmp); + if (tmp.raw.data[4] != (tmp.raw.data[4] & ALL_DB_SCRIPT_FLAGS)) + { + sLog.outErrorDb("Table `%s` has unknown script flags (data_flags = %u) for script id %u", tablename, tmp.raw.data[4], tmp.id); + continue; + } + if (!tmp.target_type && (tmp.raw.data[4] & SF_GENERAL_SWAP_INITIAL_TARGETS) && (tmp.raw.data[4] & SF_GENERAL_SWAP_FINAL_TARGETS)) { - sLog.outErrorDb("Table `%s` has nonsensical flag combination (data_flags = %u) without a buddy for script id %u", tablename, tmp.moveTo.flags, tmp.id); + sLog.outErrorDb("Table `%s` has nonsensical flag combination (data_flags = %u) without a buddy for script id %u", tablename, tmp.raw.data[4], tmp.id); continue; }