Skip to content

Commit e387833

Browse files
committed
Changes to ScriptTarget enum.
I don't like it being out of order.
1 parent ef7cc4a commit e387833

4 files changed

Lines changed: 113 additions & 49 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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`='20250319170825');
7+
IF v = 0 THEN
8+
INSERT INTO `migrations` VALUES ('20250319170825');
9+
-- Add your query below.
10+
11+
12+
-- Inserted 2 new target types after TARGET_T_HOSTILE_RANDOM_NOT_TOP (5).
13+
UPDATE `creature_ai_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
14+
UPDATE `creature_movement_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
15+
UPDATE `creature_spells_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
16+
UPDATE `event_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
17+
UPDATE `generic_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
18+
UPDATE `gossip_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
19+
UPDATE `gameobject_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
20+
UPDATE `spell_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
21+
UPDATE `quest_end_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
22+
UPDATE `quest_start_scripts` SET `target_type`=`target_type`+2 WHERE `target_type`>5;
23+
-- SCRIPT_COMMAND_TEMP_SUMMON_CREATURE (10)
24+
UPDATE `creature_ai_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
25+
UPDATE `creature_movement_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
26+
UPDATE `creature_spells_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
27+
UPDATE `event_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
28+
UPDATE `generic_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
29+
UPDATE `gossip_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
30+
UPDATE `gameobject_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
31+
UPDATE `spell_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
32+
UPDATE `quest_end_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
33+
UPDATE `quest_start_scripts` SET `dataint3`=`dataint3`+2 WHERE `dataint3`>5 && `command`=10;
34+
-- SCRIPT_COMMAND_MODIFY_THREAT (29)
35+
UPDATE `creature_ai_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
36+
UPDATE `creature_movement_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
37+
UPDATE `creature_spells_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
38+
UPDATE `event_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
39+
UPDATE `generic_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
40+
UPDATE `gossip_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
41+
UPDATE `gameobject_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
42+
UPDATE `spell_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
43+
UPDATE `quest_end_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
44+
UPDATE `quest_start_scripts` SET `datalong`=`datalong`+2 WHERE `datalong`>5 && `command`=29;
45+
-- Spell list targets.
46+
UPDATE `creature_spells` SET `castTarget_1`=`castTarget_1`+2 WHERE `castTarget_1`>5;
47+
UPDATE `creature_spells` SET `castTarget_2`=`castTarget_2`+2 WHERE `castTarget_2`>5;
48+
UPDATE `creature_spells` SET `castTarget_3`=`castTarget_3`+2 WHERE `castTarget_3`>5;
49+
UPDATE `creature_spells` SET `castTarget_4`=`castTarget_4`+2 WHERE `castTarget_4`>5;
50+
UPDATE `creature_spells` SET `castTarget_5`=`castTarget_5`+2 WHERE `castTarget_5`>5;
51+
UPDATE `creature_spells` SET `castTarget_6`=`castTarget_6`+2 WHERE `castTarget_6`>5;
52+
UPDATE `creature_spells` SET `castTarget_7`=`castTarget_7`+2 WHERE `castTarget_7`>5;
53+
UPDATE `creature_spells` SET `castTarget_8`=`castTarget_8`+2 WHERE `castTarget_8`>5;
54+
55+
-- Venom Stalker
56+
DELETE FROM `creature_ai_scripts` WHERE `id`=1597601;
57+
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
58+
(1597601, 0, 0, 15, 28431, 0, 0, 0, 1, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 'Venom Stalker - Cast Poison Charge');
59+
-- Necro Stalker
60+
DELETE FROM `creature_ai_scripts` WHERE `id`=1645301;
61+
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
62+
(1645301, 0, 0, 15, 28431, 0, 0, 0, 1, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 'Necro Stalker - Cast Poison Charge');
63+
64+
65+
-- End of migration.
66+
END IF;
67+
END??
68+
DELIMITER ;
69+
CALL add_migration();
70+
DROP PROCEDURE IF EXISTS add_migration;

src/game/Maps/Map.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,28 +2586,15 @@ bool Map::FindScriptFinalTargets(WorldObject*& source, WorldObject*& target, Scr
25862586
if (script.target_type)
25872587
{
25882588
// Cast Spell scripts include spellinfo in target finding
2589-
if ((script.command == SCRIPT_COMMAND_CAST_SPELL))
2589+
SpellEntry const* pSpellInfo = (script.command == SCRIPT_COMMAND_CAST_SPELL) ? sSpellMgr.GetSpellEntry(script.castSpell.spellId) : nullptr;
2590+
if (!(target = GetTargetByType(source, target, this, script.target_type, script.target_param1, script.target_param2, pSpellInfo)))
25902591
{
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-
}
2592+
if (!(script.raw.data[4] & SF_GENERAL_SKIP_MISSING_TARGETS))
2593+
sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "FindScriptTargets: Failed to find target for 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);
2594+
return false;
26072595
}
26082596
}
26092597

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

src/game/Maps/ScriptCommands.h

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ enum eScriptCommand
144144
SCRIPT_COMMAND_STAND_STATE = 28, // source = Unit
145145
// datalong = stand_state (enum UnitStandStateType)
146146
SCRIPT_COMMAND_MODIFY_THREAT = 29, // source = Creature
147-
// datalong = eModifyThreatTargets
147+
// datalong = eModifyThreatTargets, ScriptTarget
148148
// x = percent
149149
SCRIPT_COMMAND_SEND_TAXI_PATH = 30, // source = Player
150150
// datalong = taxi_path_id
@@ -409,8 +409,8 @@ enum ePlaySoundFlags
409409
// Possible datalong values for SCRIPT_COMMAND_MODIFY_THREAT
410410
enum eModifyThreatTargets
411411
{
412-
// 0 to 5 from Target enum.
413-
SO_MODIFYTHREAT_ALL_ATTACKERS = 6
412+
// 0 to 7 from Target enum.
413+
SO_MODIFYTHREAT_ALL_ATTACKERS = 8
414414
};
415415

416416
// Possible datalong3 values for SCRIPT_COMMAND_TERMINATE_SCRIPT
@@ -1141,69 +1141,71 @@ enum ScriptTarget
11411141
//Param1 = select_flags
11421142
TARGET_T_HOSTILE_RANDOM_NOT_TOP = 5, //Any random target except top threat.
11431143
//Param1 = select_flags
1144+
TARGET_T_HOSTILE_NEAREST = 6, //Nearest hostile on threat list.
1145+
//Param1 = select_flags
1146+
TARGET_T_HOSTILE_FARTHEST = 7, //Farthest hostile on threat list.
1147+
//Param1 = select_flags
11441148

1145-
TARGET_T_OWNER_OR_SELF = 6, //Either self or owner if pet or controlled.
1146-
TARGET_T_OWNER = 7, //The owner of the source.
1149+
TARGET_T_OWNER_OR_SELF = 8, //Either self or owner if pet or controlled.
1150+
TARGET_T_OWNER = 9, //The owner of the source.
11471151

11481152

1149-
TARGET_T_NEAREST_CREATURE_WITH_ENTRY = 8, //Searches for closest nearby creature with the given entry.
1153+
TARGET_T_NEAREST_CREATURE_WITH_ENTRY = 10, //Searches for closest nearby creature with the given entry.
11501154
//Param1 = creature_entry
11511155
//Param2 = search_radius
11521156

1153-
TARGET_T_CREATURE_WITH_GUID = 9, //The creature with this database guid.
1157+
TARGET_T_CREATURE_WITH_GUID = 11, //The creature with this database guid.
11541158
//Param1 = db_guid
11551159

1156-
TARGET_T_CREATURE_FROM_INSTANCE_DATA = 10, //Find creature by guid stored in instance data.
1160+
TARGET_T_CREATURE_FROM_INSTANCE_DATA = 12, //Find creature by guid stored in instance data.
11571161
//Param1 = instance_data_field
11581162

1159-
TARGET_T_NEAREST_GAMEOBJECT_WITH_ENTRY = 11, //Searches for closest nearby gameobject with the given entry.
1163+
TARGET_T_NEAREST_GAMEOBJECT_WITH_ENTRY = 13, //Searches for closest nearby gameobject with the given entry.
11601164
//Param1 = gameobject_entry
11611165
//Param2 = search_radius
11621166

1163-
TARGET_T_GAMEOBJECT_WITH_GUID = 12, //The gameobject with this database guid.
1167+
TARGET_T_GAMEOBJECT_WITH_GUID = 14, //The gameobject with this database guid.
11641168
//Param1 = db_guid
11651169

1166-
TARGET_T_GAMEOBJECT_FROM_INSTANCE_DATA = 13, //Find gameobject by guid stored in instance data.
1170+
TARGET_T_GAMEOBJECT_FROM_INSTANCE_DATA = 15, //Find gameobject by guid stored in instance data.
11671171
//Param1 = instance_data_field
11681172

1169-
TARGET_T_FRIENDLY = 14, //Random friendly unit.
1173+
TARGET_T_FRIENDLY = 16, //Random friendly unit.
11701174
//Param1 = search_radius
11711175
//Param2 = (bool) exclude_target
1172-
TARGET_T_FRIENDLY_INJURED = 15, //Friendly unit missing the most health.
1176+
TARGET_T_FRIENDLY_INJURED = 17, //Friendly unit missing the most health.
11731177
//Param1 = search_radius
11741178
//Param2 = hp_percent
1175-
TARGET_T_FRIENDLY_INJURED_EXCEPT = 16, //Friendly unit missing the most health but not provided target.
1179+
TARGET_T_FRIENDLY_INJURED_EXCEPT = 18, //Friendly unit missing the most health but not provided target.
11761180
//Param1 = search_radius
11771181
//Param2 = hp_percent
1178-
TARGET_T_FRIENDLY_MISSING_BUFF = 17, //Friendly unit without aura.
1182+
TARGET_T_FRIENDLY_MISSING_BUFF = 19, //Friendly unit without aura.
11791183
//Param1 = search_radius
11801184
//Param2 = spell_id
1181-
TARGET_T_FRIENDLY_MISSING_BUFF_EXCEPT = 18, //Friendly unit without aura but not provided target.
1185+
TARGET_T_FRIENDLY_MISSING_BUFF_EXCEPT = 20, //Friendly unit without aura but not provided target.
11821186
//Param1 = search_radius
11831187
//Param2 = spell_id
1184-
TARGET_T_FRIENDLY_CC = 19, //Friendly unit under crowd control.
1188+
TARGET_T_FRIENDLY_CC = 21, //Friendly unit under crowd control.
11851189
//Param1 = search_radius
1186-
TARGET_T_MAP_EVENT_SOURCE = 20, //The source WorldObject of a scripted map event.
1190+
TARGET_T_MAP_EVENT_SOURCE = 22, //The source WorldObject of a scripted map event.
11871191
//Param1 = eventId
1188-
TARGET_T_MAP_EVENT_TARGET = 21, //The target WorldObject of a scripted map event.
1192+
TARGET_T_MAP_EVENT_TARGET = 23, //The target WorldObject of a scripted map event.
11891193
//Param1 = eventId
1190-
TARGET_T_MAP_EVENT_EXTRA_TARGET = 22, //An additional WorldObject target from a scripted map event.
1194+
TARGET_T_MAP_EVENT_EXTRA_TARGET = 24, //An additional WorldObject target from a scripted map event.
11911195
//Param1 = eventId
11921196
//Param2 = creature_entry or gameobject_entry
1193-
TARGET_T_NEAREST_PLAYER = 23, //Nearest player within range.
1197+
TARGET_T_NEAREST_PLAYER = 25, //Nearest player within range.
11941198
//Param1 = search-radius
1195-
TARGET_T_NEAREST_HOSTILE_PLAYER = 24, //Nearest hostile player within range.
1199+
TARGET_T_NEAREST_HOSTILE_PLAYER = 26, //Nearest hostile player within range.
11961200
//Param1 = search-radius
1197-
TARGET_T_NEAREST_FRIENDLY_PLAYER = 25, //Nearest friendly player within range.
1201+
TARGET_T_NEAREST_FRIENDLY_PLAYER = 27, //Nearest friendly player within range.
11981202
//Param1 = search-radius
1199-
TARGET_T_RANDOM_CREATURE_WITH_ENTRY = 26, //Searches for random nearby creature with the given entry. Not Self.
1203+
TARGET_T_RANDOM_CREATURE_WITH_ENTRY = 28, //Searches for random nearby creature with the given entry. Not Self.
12001204
//Param1 = creature_entry
12011205
//Param2 = search_radius
1202-
TARGET_T_RANDOM_GAMEOBJECT_WITH_ENTRY = 27, //Searches for random nearby gameobject with the given entry.
1206+
TARGET_T_RANDOM_GAMEOBJECT_WITH_ENTRY = 29, //Searches for random nearby gameobject with the given entry.
12031207
//Param1 = gameobject_entry
12041208
//Param2 = search_radius
1205-
TARGET_T_HOSTILE_FARTHEST = 28, //Farthest hostile on threat list.
1206-
//Param1 = select_flags
12071209
TARGET_T_END
12081210
};
12091211

src/game/ScriptMgr.cpp

Lines changed: 9 additions & 4 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_NEAREST:
12631264
case TARGET_T_HOSTILE_FARTHEST:
12641265
{
12651266
if (targetParam1& ~MAX_SELECT_FLAG_MASK)
@@ -2838,6 +2839,14 @@ WorldObject* GetTargetByType(WorldObject* pSource, WorldObject* pTarget, Map* pM
28382839
if (Creature* pCreatureSource = ToCreature(pSource))
28392840
return pCreatureSource->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1, pSpellEntry, param1 ? param1 : SELECT_FLAG_NO_TOTEM);
28402841
break;
2842+
case TARGET_T_HOSTILE_NEAREST:
2843+
if (Creature* pCreatureSource = ToCreature(pSource))
2844+
return pCreatureSource->SelectAttackingTarget(ATTACKING_TARGET_NEAREST, 0, pSpellEntry, param1 ? param1 : SELECT_FLAG_NO_TOTEM);
2845+
break;
2846+
case TARGET_T_HOSTILE_FARTHEST:
2847+
if (Creature* pCreatureSource = ToCreature(pSource))
2848+
return pCreatureSource->SelectAttackingTarget(ATTACKING_TARGET_FARTHEST, 0, pSpellEntry, param1 ? param1 : SELECT_FLAG_NO_TOTEM);
2849+
break;
28412850
case TARGET_T_OWNER_OR_SELF:
28422851
if (Unit* pUnitSource = ToUnit(pSource))
28432852
return pUnitSource->GetCharmerOrOwnerOrSelf();
@@ -2978,10 +2987,6 @@ WorldObject* GetTargetByType(WorldObject* pSource, WorldObject* pTarget, Map* pM
29782987
if (Unit* pUnitSource = ToUnit(pSource))
29792988
return pUnitSource->FindNearestFriendlyPlayer(param1);
29802989
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;
29852990
}
29862991
return nullptr;
29872992
}

0 commit comments

Comments
 (0)