From 178c13ec720584e6385e88b27ff0436dc94809d6 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 25 Oct 2020 16:01:57 +0100 Subject: [PATCH] SmartAI/SpellCasts * fixed getting spell casts per NPC * fixed spell usage for NPCs when used by Timed Actionlists * added 'used by (smart) areatrigger' to SpellDetailPage * fixed forgotten rename from SmartAI overhaul --- includes/defines.php | 5 ++++- pages/npc.php | 29 ++++++++++++++++++++++++++++- pages/spell.php | 39 +++++++++++++++++++++++++++------------ 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/includes/defines.php b/includes/defines.php index 87e52fa3..4f5234a6 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -1536,6 +1536,9 @@ define('SAI_ACTION_PLAY_SPELL_VISUAL_KIT', 137); // spellVisualKit define('SAI_ACTION_OVERRIDE_LIGHT', 138); // zoneId, areaLightId, overrideLightID, transitionMilliseconds define('SAI_ACTION_OVERRIDE_WEATHER', 139); // zoneId, weatherId, intensity +define('SAI_ACTION_ALL_SPELLCASTS', [SAI_ACTION_CAST, SAI_ACTION_ADD_AURA, SAI_ACTION_INVOKER_CAST, SAI_ACTION_SELF_CAST, SAI_ACTION_CROSS_CAST]); +define('SAI_ACTION_ALL_TIMED_ACTION_LISTS', [SAI_ACTION_CALL_TIMED_ACTIONLIST, SAI_ACTION_CALL_RANDOM_TIMED_ACTIONLIST, SAI_ACTION_CALL_RANDOM_RANGE_TIMED_ACTIONLIST]); + define('SAI_CAST_FLAG_INTERRUPT_PREV', 0x01); define('SAI_CAST_FLAG_TRIGGERED', 0x02); // define('SAI_CAST_FORCE_CAST', 0x04); // Forces cast even if creature is out of mana or out of range @@ -1587,7 +1590,7 @@ define('SAI_TARGET_CLOSEST_ENEMY', 25); // Any attackable t define('SAI_TARGET_CLOSEST_FRIENDLY', 26); // Any friendly unit (creature, player or pet) within maxDist define('SAI_TARGET_LOOT_RECIPIENTS', 27); // All tagging players define('SAI_TARGET_FARTHEST', 28); // Farthest unit on the threat list -define('SAI_TARGET_VEHICLE_ACCESSORY', 29); // Vehicle can target unit in given seat +define('SAI_TARGET_VEHICLE_PASSENGER', 29); // Vehicle can target unit in given seat define('SAI_TARGET_CLOSEST_UNSPAWNED_GO', 30); // entry(0any), maxDist define('SAI_TEMPLATE_BASIC', 0); // diff --git a/pages/npc.php b/pages/npc.php index 0dc94546..0abd9826 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -365,7 +365,34 @@ class NpcPage extends GenericPage // tab: abilities / tab_controlledabilities (dep: VehicleId) // SMART_SCRIPT_TYPE_CREATURE = 0; SMART_ACTION_CAST = 11; SMART_ACTION_ADD_AURA = 75; SMART_ACTION_INVOKER_CAST = 85; SMART_ACTION_CROSS_CAST = 86 - $smartSpells = DB::World()->selectCol('SELECT action_param1 FROM smart_scripts WHERE source_type = 0 AND action_type IN (11, 75, 85, 86) AND entryOrGUID = ?d', $this->typeId); + $smartScripts = DB::World()->select('SELECT action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6 FROM smart_scripts WHERE source_type = ?d AND action_type IN (?a) AND entryOrGUID = ?d', SAI_SRC_TYPE_CREATURE, array_merge(SAI_ACTION_ALL_SPELLCASTS, SAI_ACTION_ALL_TIMED_ACTION_LISTS), $this->typeId); + $smartSpells = []; + $smartTALs = []; + foreach ($smartScripts as $s) + { + if (in_array($s['action_type'], SAI_ACTION_ALL_SPELLCASTS)) + $smartSpells[] = $s['action_param1']; + else if ($s['action_type'] == SAI_ACTION_CALL_TIMED_ACTIONLIST) + $smartTALs[] = $s['action_param1']; + else if ($s['action_type'] == SAI_ACTION_CALL_RANDOM_TIMED_ACTIONLIST) + { + for ($i = 1; $i < 7; $i++) + if ($s['action_param'.$i]) + $smartTALs[] = $s['action_param'.$i]; + } + else if ($s['action_type'] == SAI_ACTION_CALL_RANDOM_RANGE_TIMED_ACTIONLIST) + { + for ($i = $s['action_param1']; $i <= $s['action_param2']; $i++) + $smartTALs[] = $i; + } + else + var_dump($s); + } + + if ($smartTALs) + if ($_ = DB::World()->selectCol('SELECT action_param1 FROM smart_scripts WHERE source_type = ?d AND action_type IN (?a) AND entryOrGUID IN (?a)', SAI_SRC_TYPE_ACTIONLIST, SAI_ACTION_ALL_SPELLCASTS, $smartTALs)) + $smartSpells = array_merge($smartSpells, $_); + $tplSpells = []; $conditions = ['OR']; diff --git a/pages/spell.php b/pages/spell.php index ba594b04..0ab08030 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -632,6 +632,23 @@ class SpellPage extends GenericPage $this->extendGlobalData($ubObjects->getJSGlobals()); } + // tab: used by - areatrigger + if (User::isInGroup(U_GROUP_EMPLOYEE)) + { + if ($_ = $this->ubSmartScript(TYPE_AREATRIGGER)) + { + $ubTriggers = new AreaTriggerList(array(['id', $_])); + if (!$ubTriggers->error) + { + $this->lvTabs[] = ['areatrigger', array( + 'data' => array_values($ubTriggers->getListviewData()), + 'id' => 'used-by-areatrigger', + 'name' => '$LANG.tab_usedby' + ), 'areatrigger']; + } + } + } + // tab: criteria of $conditions = array( ['ac.type', [ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, @@ -2226,30 +2243,28 @@ class SpellPage extends GenericPage { $src = -1; if ($type == TYPE_OBJECT) - $src = 1; + $src = SAI_SRC_TYPE_OBJECT; else if ($type == TYPE_NPC) - $src = 0; + $src = SAI_SRC_TYPE_CREATURE; + else if ($type == TYPE_AREATRIGGER) + $src = SAI_SRC_TYPE_AREATRIGGER; else return []; - /* - SMART_SCRIPT_TYPE_CREATURE = 0 => SMART_ACTION_CAST = 11; SMART_ACTION_ADD_AURA = 75; SMART_ACTION_INVOKER_CAST = 85; SMART_ACTION_CROSS_CAST = 86 - SMART_SCRIPT_TYPE_TIMED_ACTIONLIST = 9 => SMART_ACTION_CALL_TIMED_ACTIONLIST = 80; SMART_ACTION_CALL_RANDOM_TIMED_ACTIONLIST = 87; SMART_ACTION_CALL_RANDOM_RANGE_TIMED_ACTIONLIST = 88 - */ - $ids = []; - if ($smartS = DB::World()->selectCol('SELECT entryOrGUID AS ARRAY_KEY, source_type FROM smart_scripts WHERE entryorguid > 0 AND source_type IN (?d, 9) AND action_type IN (11, 75, 85, 86) AND action_param1 = ?d', $src, $this->typeId)) + if ($smartS = DB::World()->select('SELECT entryOrGUID, source_type FROM smart_scripts WHERE entryOrGUID > 0 AND source_type IN (?a) AND action_type IN (?a) AND action_param1 = ?d', [$src, SAI_SRC_TYPE_ACTIONLIST], SAI_ACTION_ALL_SPELLCASTS, $this->typeId)) { // filter for timed action list - if ($tal = array_filter($smartS, function($x) {return $x == 9;})) + if ($tal = array_filter($smartS, function($x) {return $x['source_type'] == SAI_SRC_TYPE_ACTIONLIST;})) { - if ($talIds = DB::World()->selectCol('SELECT entryOrGUID FROM smart_scripts WHERE entryorguid > 0 AND source_type = ?d AND action_type IN (80, 87, 88) AND (action_param1 IN (?a) OR action_param2 IN (?a) OR action_param3 IN (?a) OR action_param4 IN (?a) OR action_param5 IN (?a) OR action_param6 IN (?a))', $type, array_keys($tal), array_keys($tal), array_keys($tal), array_keys($tal), array_keys($tal), array_keys($tal))) - $ids[] = ['id', $talIds]; + $talIds = array_column($tal, 'entryOrGUID'); + if ($_ = DB::World()->selectCol('SELECT entryOrGUID FROM smart_scripts WHERE entryOrGUID > 0 AND source_type = ?d AND action_type IN (?a) AND (action_param1 IN (?a) OR action_param2 IN (?a) OR action_param3 IN (?a) OR action_param4 IN (?a) OR action_param5 IN (?a) OR action_param6 IN (?a))', $src, SAI_ACTION_ALL_TIMED_ACTION_LISTS, $talIds, $talIds, $talIds, $talIds, $talIds, $talIds)) + $ids = $_; $smartS = array_diff($smartS, $tal); } if ($smartS); - $ids = array_merge($ids, $smartS); + $ids = array_merge($ids, array_column($smartS, 'entryOrGUID')); } return $ids;