diff --git a/sql/migrations/20231215165730_world.sql b/sql/migrations/20231215165730_world.sql new file mode 100644 index 00000000000..06076bf62f0 --- /dev/null +++ b/sql/migrations/20231215165730_world.sql @@ -0,0 +1,45 @@ +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`='20231215165730'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20231215165730'); +-- Add your query below. + +-- 500: Distance Between Targets Is Equal Or Greater Than 8 Yards +INSERT INTO `conditions` (`condition_entry`, `type`, `value1`, `value2`, `value3`, `value4`, `flags`) VALUES (500, 38, 8, 1, 0, 0, 0); + +-- Removing unused creature spell lists for Venom Stalker +DELETE FROM `creature_spells` WHERE `entry`=159760; +UPDATE `creature_template` SET `spell_list_id`=0 WHERE `entry`=15976; + +-- Events list for Venom Stalker +DELETE FROM `creature_ai_events` WHERE `creature_id`=15976; +INSERT INTO `creature_ai_events` (`id`, `creature_id`, `condition_id`, `event_type`, `event_inverse_phase_mask`, `event_chance`, `event_flags`, `event_param1`, `event_param2`, `event_param3`, `event_param4`, `action1_script`, `action2_script`, `action3_script`, `comment`) VALUES (1597601, 15976, 0, 0, 0, 100, 1, 5000, 15000, 28000, 32000, 1597601, 0, 0, 'Venom Stalker - Cast Poison Charge'); +DELETE FROM `creature_ai_scripts` WHERE `id`=1597601; +INSERT INTO `creature_ai_scripts` (`id`, `delay`, `priority`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES +(1597601, 0, 0, 15, 28431, 0, 0, 0, 1, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 'Venom Stalker - Cast Poison Charge'); +UPDATE `creature_template` SET `ai_name`='EventAI' WHERE `entry`=15976; + +-- Removing unused creature spell lists for Necro Stalker +DELETE FROM `creature_spells` WHERE `entry`=164530; +UPDATE `creature_template` SET `spell_list_id`=0 WHERE `entry`=16453; + +-- Events list for Necro Stalker +DELETE FROM `creature_ai_events` WHERE `creature_id`=16453; +INSERT INTO `creature_ai_events` (`id`, `creature_id`, `condition_id`, `event_type`, `event_inverse_phase_mask`, `event_chance`, `event_flags`, `event_param1`, `event_param2`, `event_param3`, `event_param4`, `action1_script`, `action2_script`, `action3_script`, `comment`) VALUES (1645301, 16453, 0, 0, 0, 100, 1, 5000, 15000, 28000, 32000, 1645301, 0, 0, 'Necro Stalker - Cast Poison Charge'); +DELETE FROM `creature_ai_scripts` WHERE `id`=1645301; +INSERT INTO `creature_ai_scripts` (`id`, `delay`, `priority`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES +(1645301, 0, 0, 15, 28431, 0, 0, 0, 1, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 'Necro Stalker - Cast Poison Charge'); +UPDATE `creature_template` SET `ai_name`='EventAI' WHERE `entry`=16453; + + + +-- 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 54b719fb5f7..14d06485faf 100644 --- a/src/game/Maps/Map.cpp +++ b/src/game/Maps/Map.cpp @@ -2531,14 +2531,29 @@ bool Map::FindScriptFinalTargets(WorldObject*& source, WorldObject*& target, Scr // If we have a buddy lets find it. if (script.target_type) { - if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2))) + // Cast Spell scripts include spellinfo in target finding + if ((script.command == SCRIPT_COMMAND_CAST_SPELL)) { - if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS)) - sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "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; + SpellEntry const* pSpellInfo = sSpellMgr.GetSpellEntry(script.castSpell.spellId); + if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2, pSpellInfo))) + { + if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS)) + sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "FindScriptTargets: Failed to find target for Cast Spell script with id %u (spellId: %u), (target_param1: %u), (target_param2: %u), (target_type: %u).", script.id, script.castSpell.spellId, script.target_param1, script.target_param2, script.target_type); + return false; + } + } + else + { + if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2))) + { + if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS)) + sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "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; + } } } + // we swap target and source again if data_flags & 0x2 // this way we have all possible combinations with 3 targets if (script.raw.data[4] & SF_GENERAL_SWAP_FINAL_TARGETS) diff --git a/src/game/Maps/ScriptCommands.h b/src/game/Maps/ScriptCommands.h index 820fd62d8d9..34cec73a64e 100644 --- a/src/game/Maps/ScriptCommands.h +++ b/src/game/Maps/ScriptCommands.h @@ -1200,6 +1200,8 @@ enum ScriptTarget TARGET_T_RANDOM_GAMEOBJECT_WITH_ENTRY = 27, //Searches for random nearby gameobject with the given entry. //Param1 = gameobject_entry //Param2 = search_radius + TARGET_T_HOSTILE_FARTHEST = 28, //Farthest hostile on threat list. + //Param1 = select_flags TARGET_T_END }; diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index b726030c21a..88accbb9d44 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -1262,6 +1262,7 @@ bool ScriptMgr::CheckScriptTargets(uint32 targetType, uint32 targetParam1, uint3 case TARGET_T_HOSTILE_LAST_AGGRO: case TARGET_T_HOSTILE_RANDOM: case TARGET_T_HOSTILE_RANDOM_NOT_TOP: + case TARGET_T_HOSTILE_FARTHEST: { if (targetParam1& ~MAX_SELECT_FLAG_MASK) { @@ -2979,6 +2980,10 @@ WorldObject* GetTargetByType(WorldObject* pSource, WorldObject* pTarget, Map* pM if (Unit* pUnitSource = ToUnit(pSource)) return pUnitSource->FindNearestFriendlyPlayer(param1); break; + case TARGET_T_HOSTILE_FARTHEST: + if (Creature* pCreatureSource = ToCreature(pSource)) + return pCreatureSource->SelectAttackingTarget(ATTACKING_TARGET_FARTHEST, 0, pSpellEntry, param1 ? param1 : SELECT_FLAG_NO_TOTEM); + break; } return nullptr; }