diff --git a/src/server/game/AI/CoreAI/GameObjectAI.h b/src/server/game/AI/CoreAI/GameObjectAI.h index 979f7ca45c4749..384fca1ec1e7db 100644 --- a/src/server/game/AI/CoreAI/GameObjectAI.h +++ b/src/server/game/AI/CoreAI/GameObjectAI.h @@ -68,10 +68,12 @@ class AC_GAME_API GameObjectAI virtual bool CanBeSeen(Player const* /*seer*/) { return true; } // Called when the gameobject summon successfully other creature - virtual void JustSummoned(Creature* /*summon*/) { } - virtual void SummonedCreatureDespawn(Creature* /*summon*/) { } + virtual void JustSummoned(Creature* /*summon*/) {} + virtual void SummonedCreatureDespawn(Creature* /*summon*/) {} - virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { } + virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) {} + + virtual void SummonedCreatureEvade(Creature* /*summon*/) {} }; class NullGameObjectAI : public GameObjectAI diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index e85a674d030c0b..bb014a03472869 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -21,6 +21,7 @@ #include "CreatureAIImpl.h" #include "CreatureGroups.h" #include "CreatureTextMgr.h" +#include "GameObjectAI.h" #include "Log.h" #include "MapReference.h" #include "Player.h" @@ -222,7 +223,7 @@ void CreatureAI::EnterEvadeMode(EvadeReason why) me->GetVehicleKit()->Reset(true); } - // despawn bosses at reset - only verified tbc/woltk bosses with this reset type - add bosses in last line respectively (dungeon/raid) and increase array limit + // despawn bosses at reset - only verified tbc/woltk bosses with this reset type CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(me->GetEntry()); if (cInfo && cInfo->HasFlagsExtra(CREATURE_FLAG_EXTRA_HARD_RESET)) { @@ -321,6 +322,21 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) formation->MemberEvaded(me); } + if (TempSummon* summon = me->ToTempSummon()) + { + if (WorldObject* summoner = summon->GetSummoner()) + { + if (summoner->ToCreature() && summoner->ToCreature()->IsAIEnabled) + { + summoner->ToCreature()->AI()->SummonedCreatureEvade(me); + } + else if (summoner->ToGameObject() && summoner->ToGameObject()->AI()) + { + summoner->ToGameObject()->AI()->SummonedCreatureEvade(me); + } + } + } + return true; } diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 977c29a62bbb53..94478d15e33c9b 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -137,6 +137,8 @@ class CreatureAI : public UnitAI virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) {} virtual void SummonedCreatureDespawnAll() {} + virtual void SummonedCreatureEvade(Creature* /*summon*/) {} + // Called when hit by a spell virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spell*/) {} diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 88a14a1a209263..c1210c8366e438 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -817,6 +817,11 @@ void SmartAI::SummonedCreatureDies(Creature* summon, Unit* /*killer*/) GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT_DIES, summon); } +void SmartAI::SummonedCreatureEvade(Creature* summon) +{ + GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT_EVADE, summon); +} + void SmartAI::AttackStart(Unit* who) { // xinef: dont allow charmed npcs to act on their own @@ -1136,6 +1141,11 @@ void SmartGameObjectAI::SummonedCreatureDies(Creature* summon, Unit* /*killer*/) GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT_DIES, summon); } +void SmartGameObjectAI::SummonedCreatureEvade(Creature* summon) +{ + GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT_EVADE, summon); +} + void SmartGameObjectAI::UpdateAI(uint32 diff) { GetScript()->OnUpdate(diff); diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index 93f942717366b6..5723822f5a5561 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -97,6 +97,9 @@ class SmartAI : public CreatureAI // Called when a summoned unit dies void SummonedCreatureDies(Creature* summon, Unit* killer) override; + // Called when a summoned unit evades + void SummonedCreatureEvade(Creature* summon) override; + // Tell creature to attack and follow the victim void AttackStart(Unit* who) override; @@ -283,6 +286,9 @@ class SmartGameObjectAI : public GameObjectAI // Called when a summoned unit dies void SummonedCreatureDies(Creature* summon, Unit* killer) override; + // Called when a summoned unit evades + void SummonedCreatureEvade(Creature* summon) override; + protected: SmartScript mScript; }; diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 25b2c8cb388033..41e3f9ce3940e7 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -4077,6 +4077,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui } case SMART_EVENT_SUMMONED_UNIT: case SMART_EVENT_SUMMONED_UNIT_DIES: + case SMART_EVENT_SUMMONED_UNIT_EVADE: { if (!IsCreature(unit)) return; diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index 85422ee251f7f8..2ce60090a10cb8 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -345,6 +345,7 @@ void SmartAIMgr::LoadSmartAIFromDB() case SMART_EVENT_INSTANCE_PLAYER_ENTER: case SMART_EVENT_TRANSPORT_ADDCREATURE: case SMART_EVENT_NEAR_PLAYERS: + case SMART_EVENT_SUMMONED_UNIT_EVADE: return true; default: return false; @@ -454,6 +455,7 @@ bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e) case SMART_TARGET_ROLE_SELECTION: case SMART_TARGET_LOOT_RECIPIENTS: case SMART_EVENT_SUMMONED_UNIT_DIES: + case SMART_EVENT_SUMMONED_UNIT_EVADE: case SMART_TARGET_PLAYER_RANGE: case SMART_TARGET_CLOSEST_GAMEOBJECT: case SMART_TARGET_SELF: @@ -571,6 +573,7 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e) case SMART_EVENT_NEAR_UNIT_NEGATION: return sizeof(SmartEvent::nearUnitNegation); case SMART_EVENT_AREA_CASTING: return sizeof(SmartEvent::minMaxRepeat); case SMART_EVENT_AREA_RANGE: return sizeof(SmartEvent::minMaxRepeat); + case SMART_EVENT_SUMMONED_UNIT_EVADE: return sizeof(SmartEvent::summoned); default: LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an event {} with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetEventType()); @@ -1060,6 +1063,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) case SMART_EVENT_SUMMON_DESPAWNED: case SMART_EVENT_SUMMONED_UNIT: case SMART_EVENT_SUMMONED_UNIT_DIES: + case SMART_EVENT_SUMMONED_UNIT_EVADE: if (e.event.summoned.creature && !IsCreatureValid(e, e.event.summoned.creature)) return false; diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index 56f3b894072ea3..a9530daed42a24 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -212,8 +212,9 @@ enum SMART_EVENT SMART_EVENT_NEAR_UNIT_NEGATION = 104, // type (0: creature 1: gob), entry, count, range, timer SMART_EVENT_AREA_CASTING = 105, // min, max, repeatMin, repeatMax, rangeMin, rangeMax SMART_EVENT_AREA_RANGE = 106, // min, max, repeatMin, repeatMax, rangeMin, rangeMax + SMART_EVENT_SUMMONED_UNIT_EVADE = 107, // CreatureId(0 all), CooldownMin, CooldownMax - SMART_EVENT_AC_END = 107 + SMART_EVENT_AC_END = 108 }; struct SmartEvent @@ -1840,7 +1841,8 @@ const uint32 SmartAIEventMask[SMART_EVENT_AC_END][2] = {SMART_EVENT_NEAR_UNIT, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT }, {SMART_EVENT_NEAR_UNIT_NEGATION, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT }, {SMART_EVENT_AREA_CASTING, SMART_SCRIPT_TYPE_MASK_CREATURE }, - {SMART_EVENT_AREA_RANGE, SMART_SCRIPT_TYPE_MASK_CREATURE } + {SMART_EVENT_AREA_RANGE, SMART_SCRIPT_TYPE_MASK_CREATURE }, + {SMART_EVENT_SUMMONED_UNIT_EVADE, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT }, }; enum SmartEventFlags