Skip to content

Commit ef7cc4a

Browse files
Add target_type for target furthest enemy in spell casting AI (#2352)
1 parent 429ccdb commit ef7cc4a

4 files changed

Lines changed: 71 additions & 4 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
DROP PROCEDURE IF EXISTS add_migration;
2+
delimiter ??
3+
CREATE PROCEDURE `add_migration`()
4+
BEGIN
5+
DECLARE v INT DEFAULT 1;
6+
SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20231215165730');
7+
IF v=0 THEN
8+
INSERT INTO `migrations` VALUES ('20231215165730');
9+
-- Add your query below.
10+
11+
-- 500: Distance Between Targets Is Equal Or Greater Than 8 Yards
12+
INSERT INTO `conditions` (`condition_entry`, `type`, `value1`, `value2`, `value3`, `value4`, `flags`) VALUES (500, 38, 8, 1, 0, 0, 0);
13+
14+
-- Removing unused creature spell lists for Venom Stalker
15+
DELETE FROM `creature_spells` WHERE `entry`=159760;
16+
UPDATE `creature_template` SET `spell_list_id`=0 WHERE `entry`=15976;
17+
18+
-- Events list for Venom Stalker
19+
DELETE FROM `creature_ai_events` WHERE `creature_id`=15976;
20+
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');
21+
DELETE FROM `creature_ai_scripts` WHERE `id`=1597601;
22+
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
23+
(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');
24+
UPDATE `creature_template` SET `ai_name`='EventAI' WHERE `entry`=15976;
25+
26+
-- Removing unused creature spell lists for Necro Stalker
27+
DELETE FROM `creature_spells` WHERE `entry`=164530;
28+
UPDATE `creature_template` SET `spell_list_id`=0 WHERE `entry`=16453;
29+
30+
-- Events list for Necro Stalker
31+
DELETE FROM `creature_ai_events` WHERE `creature_id`=16453;
32+
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');
33+
DELETE FROM `creature_ai_scripts` WHERE `id`=1645301;
34+
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
35+
(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');
36+
UPDATE `creature_template` SET `ai_name`='EventAI' WHERE `entry`=16453;
37+
38+
39+
40+
-- End of migration.
41+
END IF;
42+
END??
43+
delimiter ;
44+
CALL add_migration();
45+
DROP PROCEDURE IF EXISTS add_migration;

src/game/Maps/Map.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,14 +2585,29 @@ bool Map::FindScriptFinalTargets(WorldObject*& source, WorldObject*& target, Scr
25852585
// If we have a buddy lets find it.
25862586
if (script.target_type)
25872587
{
2588-
if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2)))
2588+
// Cast Spell scripts include spellinfo in target finding
2589+
if ((script.command == SCRIPT_COMMAND_CAST_SPELL))
25892590
{
2590-
if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS))
2591-
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);
2592-
return false;
2591+
SpellEntry const* pSpellInfo = sSpellMgr.GetSpellEntry(script.castSpell.spellId);
2592+
if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2, pSpellInfo)))
2593+
{
2594+
if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS))
2595+
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);
2596+
return false;
2597+
}
2598+
}
2599+
else
2600+
{
2601+
if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2)))
2602+
{
2603+
if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS))
2604+
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);
2605+
return false;
2606+
}
25932607
}
25942608
}
25952609

2610+
25962611
// we swap target and source again if data_flags & 0x2
25972612
// this way we have all possible combinations with 3 targets
25982613
if (script.raw.data[4] & SF_GENERAL_SWAP_FINAL_TARGETS)

src/game/Maps/ScriptCommands.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ enum ScriptTarget
12021202
TARGET_T_RANDOM_GAMEOBJECT_WITH_ENTRY = 27, //Searches for random nearby gameobject with the given entry.
12031203
//Param1 = gameobject_entry
12041204
//Param2 = search_radius
1205+
TARGET_T_HOSTILE_FARTHEST = 28, //Farthest hostile on threat list.
1206+
//Param1 = select_flags
12051207
TARGET_T_END
12061208
};
12071209

src/game/ScriptMgr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ bool ScriptMgr::CheckScriptTargets(uint32 targetType, uint32 targetParam1, uint3
12601260
case TARGET_T_HOSTILE_LAST_AGGRO:
12611261
case TARGET_T_HOSTILE_RANDOM:
12621262
case TARGET_T_HOSTILE_RANDOM_NOT_TOP:
1263+
case TARGET_T_HOSTILE_FARTHEST:
12631264
{
12641265
if (targetParam1& ~MAX_SELECT_FLAG_MASK)
12651266
{
@@ -2977,6 +2978,10 @@ WorldObject* GetTargetByType(WorldObject* pSource, WorldObject* pTarget, Map* pM
29772978
if (Unit* pUnitSource = ToUnit(pSource))
29782979
return pUnitSource->FindNearestFriendlyPlayer(param1);
29792980
break;
2981+
case TARGET_T_HOSTILE_FARTHEST:
2982+
if (Creature* pCreatureSource = ToCreature(pSource))
2983+
return pCreatureSource->SelectAttackingTarget(ATTACKING_TARGET_FARTHEST, 0, pSpellEntry, param1 ? param1 : SELECT_FLAG_NO_TOTEM);
2984+
break;
29802985
}
29812986
return nullptr;
29822987
}

0 commit comments

Comments
 (0)