Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target_type for target furthest enemy in spell casting AI #2352

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
45 changes: 45 additions & 0 deletions sql/migrations/20231215165730_world.sql
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 19 additions & 4 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/game/Maps/ScriptCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
5 changes: 5 additions & 0 deletions src/game/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Loading