Skip to content

Commit

Permalink
feat(Core/SmartScripts): SMART_EVENT_SUMMONED_UNIT_EVADE (azerothcore…
Browse files Browse the repository at this point in the history
…#18018)

* feat(Core/SmartScripts): SMART_EVENT_SUMMONED_UNIT_EVADE

* .
  • Loading branch information
avarishd authored Dec 15, 2023
1 parent 9df2c48 commit 03d06da
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/server/game/AI/CoreAI/GameObjectAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/server/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/CreatureAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/) {}

Expand Down
10 changes: 10 additions & 0 deletions src/server/game/AI/SmartScripts/SmartAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/server/game/AI/SmartScripts/SmartAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 03d06da

Please sign in to comment.