AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SmartScript Class Reference

#include "SmartScript.h"

Public Types

typedef std::unordered_map< uint32, uint32CounterMap
 

Public Member Functions

 SmartScript ()
 
 ~SmartScript ()
 
void OnInitialize (WorldObject *obj, AreaTrigger const *at=nullptr)
 
void GetScript ()
 
void FillScript (SmartAIEventList e, WorldObject *obj, AreaTrigger const *at)
 
void ProcessEventsFor (SMART_EVENT e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
 
void ProcessEvent (SmartScriptHolder &e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
 
bool CheckTimer (SmartScriptHolder const &e) const
 
void UpdateTimer (SmartScriptHolder &e, uint32 const diff)
 
void ProcessAction (SmartScriptHolder &e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
 
void ProcessTimedAction (SmartScriptHolder &e, uint32 const &min, uint32 const &max, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
 
void GetTargets (ObjectVector &targets, SmartScriptHolder const &e, Unit *invoker=nullptr) const
 
void GetWorldObjectsInDist (ObjectVector &objects, float dist) const
 
void InstallTemplate (SmartScriptHolder const &e)
 
void AddEvent (SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask)
 
void SetPathId (uint32 id)
 
uint32 GetPathId () const
 
WorldObjectGetBaseObject () const
 
void OnUpdate (const uint32 diff)
 
void OnMoveInLineOfSight (Unit *who)
 
UnitDoSelectLowestHpFriendly (float range, uint32 MinHPDiff) const
 
UnitDoSelectLowestHpPercentFriendly (float range, uint32 minHpPct, uint32 maxHpPct) const
 
void DoFindFriendlyCC (std::vector< Creature * > &creatures, float range) const
 
void DoFindFriendlyMissingBuff (std::vector< Creature * > &creatures, float range, uint32 spellid) const
 
UnitDoFindClosestFriendlyInRange (float range, bool playerOnly) const
 
void StoreTargetList (ObjectVector const &targets, uint32 id)
 
bool IsSmart (Creature *c=nullptr)
 
bool IsSmartGO (GameObject *g=nullptr)
 
ObjectVector const * GetStoredTargetVector (uint32 id, WorldObject const &ref) const
 
void StoreCounter (uint32 id, uint32 value, uint32 reset, uint32 subtract)
 
uint32 GetCounterValue (uint32 id)
 
GameObjectFindGameObjectNear (WorldObject *searchObject, ObjectGuid::LowType guid) const
 
CreatureFindCreatureNear (WorldObject *searchObject, ObjectGuid::LowType guid) const
 
void OnReset ()
 
void ResetBaseObject ()
 
void SetScript9 (SmartScriptHolder &e, uint32 entry)
 
UnitGetLastInvoker (Unit *invoker=nullptr) const
 
void SetActualCombatDist (uint32 dist)
 
void RestoreMaxCombatDist ()
 
uint32 GetActualCombatDist () const
 
uint32 GetMaxCombatDist () const
 
void SetCasterActualDist (float dist)
 
void RestoreCasterMaxDist ()
 
Powers GetCasterPowerType () const
 
float GetCasterActualDist () const
 
float GetCasterMaxDist () const
 
bool AllowPhaseReset () const
 
void SetPhaseReset (bool allow)
 
void AddCreatureSummon (ObjectGuid const &guid)
 
void RemoveCreatureSummon (ObjectGuid const &guid)
 

Static Public Member Functions

static void RecalcTimer (SmartScriptHolder &e, uint32 min, uint32 max)
 
static void InitTimer (SmartScriptHolder &e)
 
static SmartScriptHolder CreateSmartEvent (SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask)
 
static bool IsUnit (WorldObject *obj)
 
static bool IsPlayer (WorldObject *obj)
 
static bool IsCreature (WorldObject *obj)
 
static bool IsCharmedCreature (WorldObject *obj)
 
static bool IsGameObject (WorldObject *obj)
 

Public Attributes

ObjectGuid mLastInvoker
 
CounterMap mCounterList
 

Private Member Functions

void IncPhase (uint32 p)
 
void DecPhase (uint32 p)
 
void SetPhase (uint32 p)
 
bool IsInPhase (uint32 p) const
 
void InstallEvents ()
 
void RemoveStoredEvent (uint32 id)
 
SmartScriptHolder FindLinkedEvent (uint32 link)
 

Private Attributes

SmartAIEventList mEvents
 
SmartAIEventList mInstallEvents
 
SmartAIEventList mTimedActionList
 
bool isProcessingTimedActionList
 
Creatureme
 
ObjectGuid meOrigGUID
 
GameObjectgo
 
ObjectGuid goOrigGUID
 
AreaTrigger const * trigger
 
SmartScriptType mScriptType
 
uint32 mEventPhase
 
std::unordered_map< int32, int32mStoredDecimals
 
uint32 mPathId
 
SmartAIEventStoredList mStoredEvents
 
std::list< uint32mRemIDs
 
uint32 mTextTimer
 
uint32 mLastTextID
 
uint32 mTalkerEntry
 
bool mUseTextTimer
 
uint32 mActualCombatDist
 
uint32 mMaxCombatDist
 
uint32 smartCasterActualDist
 
uint32 smartCasterMaxDist
 
Powers smartCasterPowerType
 
bool _allowPhaseReset
 
ObjectVectorMap _storedTargets
 
SMARTAI_TEMPLATE mTemplate
 
GuidUnorderedSet _summonList
 

Detailed Description

Member Typedef Documentation

◆ CounterMap

typedef std::unordered_map<uint32, uint32> SmartScript::CounterMap

Constructor & Destructor Documentation

◆ SmartScript()

SmartScript::SmartScript ( )
41{
42 go = nullptr;
43 me = nullptr;
44 trigger = nullptr;
45 mEventPhase = 0;
46 mPathId = 0;
47 mTextTimer = 0;
48 mLastTextID = 0;
49 mUseTextTimer = false;
50 mTalkerEntry = 0;
54
55 // Xinef: Fix Combat Movement
58
60 smartCasterMaxDist = 0.0f;
62
63 _allowPhaseReset = true;
64}
@ SMART_SCRIPT_TYPE_CREATURE
Definition: SmartScriptMgr.h:1617
@ SMARTAI_TEMPLATE_BASIC
Definition: SmartScriptMgr.h:1377
@ POWER_MANA
Definition: SharedDefines.h:241
uint32 mEventPhase
Definition: SmartScript.h:254
SMARTAI_TEMPLATE mTemplate
Definition: SmartScript.h:280
Creature * me
Definition: SmartScript.h:248
uint32 mPathId
Definition: SmartScript.h:257
SmartScriptType mScriptType
Definition: SmartScript.h:253
uint32 smartCasterActualDist
Definition: SmartScript.h:271
bool _allowPhaseReset
Definition: SmartScript.h:276
bool mUseTextTimer
Definition: SmartScript.h:264
uint32 mLastTextID
Definition: SmartScript.h:262
uint32 mTextTimer
Definition: SmartScript.h:261
GameObject * go
Definition: SmartScript.h:250
uint32 mMaxCombatDist
Definition: SmartScript.h:268
uint32 mActualCombatDist
Definition: SmartScript.h:267
AreaTrigger const * trigger
Definition: SmartScript.h:252
Powers smartCasterPowerType
Definition: SmartScript.h:273
uint32 mTalkerEntry
Definition: SmartScript.h:263
uint32 smartCasterMaxDist
Definition: SmartScript.h:272
bool isProcessingTimedActionList
Definition: SmartScript.h:247

References _allowPhaseReset, go, isProcessingTimedActionList, mActualCombatDist, me, mEventPhase, mLastTextID, mMaxCombatDist, mPathId, mScriptType, mTalkerEntry, mTemplate, mTextTimer, mUseTextTimer, POWER_MANA, SMART_SCRIPT_TYPE_CREATURE, SMARTAI_TEMPLATE_BASIC, smartCasterActualDist, smartCasterMaxDist, smartCasterPowerType, and trigger.

◆ ~SmartScript()

SmartScript::~SmartScript ( )
67{
68
69}

Member Function Documentation

◆ AddCreatureSummon()

void SmartScript::AddCreatureSummon ( ObjectGuid const &  guid)
4629{
4630 _summonList.insert(guid);
4631}
GuidUnorderedSet _summonList
Definition: SmartScript.h:313

References _summonList.

Referenced by SmartAI::JustSummoned().

◆ AddEvent()

void SmartScript::AddEvent ( SMART_EVENT  e,
uint32  event_flags,
uint32  event_param1,
uint32  event_param2,
uint32  event_param3,
uint32  event_param4,
uint32  event_param5,
SMART_ACTION  action,
uint32  action_param1,
uint32  action_param2,
uint32  action_param3,
uint32  action_param4,
uint32  action_param5,
uint32  action_param6,
SMARTAI_TARGETS  t,
uint32  target_param1,
uint32  target_param2,
uint32  target_param3,
uint32  target_param4,
uint32  phaseMask 
)
2802{
2803 mInstallEvents.push_back(CreateSmartEvent(e, event_flags, event_param1, event_param2, event_param3, event_param4, event_param5, action, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, t, target_param1, target_param2, target_param3, target_param4, phaseMask));
2804}
SmartAIEventList mInstallEvents
Definition: SmartScript.h:245
static SmartScriptHolder CreateSmartEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask)
Definition: SmartScript.cpp:2806

References CreateSmartEvent(), and mInstallEvents.

Referenced by InstallTemplate().

◆ AllowPhaseReset()

bool SmartScript::AllowPhaseReset ( ) const
inline
232{ return _allowPhaseReset; }

References _allowPhaseReset.

Referenced by OnReset().

◆ CheckTimer()

bool SmartScript::CheckTimer ( SmartScriptHolder const &  e) const
4191{
4192 return e.active;
4193}

References SmartScriptHolder::active.

◆ CreateSmartEvent()

SmartScriptHolder SmartScript::CreateSmartEvent ( SMART_EVENT  e,
uint32  event_flags,
uint32  event_param1,
uint32  event_param2,
uint32  event_param3,
uint32  event_param4,
uint32  event_param5,
SMART_ACTION  action,
uint32  action_param1,
uint32  action_param2,
uint32  action_param3,
uint32  action_param4,
uint32  action_param5,
uint32  action_param6,
SMARTAI_TARGETS  t,
uint32  target_param1,
uint32  target_param2,
uint32  target_param3,
uint32  target_param4,
uint32  phaseMask 
)
static
2807{
2808 SmartScriptHolder script;
2809 script.event.type = e;
2810 script.event.raw.param1 = event_param1;
2811 script.event.raw.param2 = event_param2;
2812 script.event.raw.param3 = event_param3;
2813 script.event.raw.param4 = event_param4;
2814 script.event.raw.param5 = event_param5;
2815 script.event.event_phase_mask = phaseMask;
2816 script.event.event_flags = event_flags;
2817 script.event.event_chance = 100;
2818
2819 script.action.type = action;
2820 script.action.raw.param1 = action_param1;
2821 script.action.raw.param2 = action_param2;
2822 script.action.raw.param3 = action_param3;
2823 script.action.raw.param4 = action_param4;
2824 script.action.raw.param5 = action_param5;
2825 script.action.raw.param6 = action_param6;
2826
2827 script.target.type = t;
2828 script.target.raw.param1 = target_param1;
2829 script.target.raw.param2 = target_param2;
2830 script.target.raw.param3 = target_param3;
2831 script.target.raw.param4 = target_param4;
2832
2834 InitTimer(script);
2835 return script;
2836}
static void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:4066
uint32 param1
Definition: SmartScriptMgr.h:498
uint32 event_flags
Definition: SmartScriptMgr.h:220
uint32 event_phase_mask
Definition: SmartScriptMgr.h:218
uint32 param2
Definition: SmartScriptMgr.h:499
struct SmartEvent::@30::@72 raw
uint32 param4
Definition: SmartScriptMgr.h:501
uint32 param3
Definition: SmartScriptMgr.h:500
uint32 event_chance
Definition: SmartScriptMgr.h:219
uint32 param5
Definition: SmartScriptMgr.h:502
SMART_EVENT type
Definition: SmartScriptMgr.h:217
uint32 param3
Definition: SmartScriptMgr.h:1020
uint32 param5
Definition: SmartScriptMgr.h:1022
uint32 param1
Definition: SmartScriptMgr.h:1018
SMART_ACTION type
Definition: SmartScriptMgr.h:712
uint32 param4
Definition: SmartScriptMgr.h:1021
struct SmartAction::@73::@180 raw
uint32 param6
Definition: SmartScriptMgr.h:1370
uint32 param2
Definition: SmartScriptMgr.h:1019
uint32 param4
Definition: SmartScriptMgr.h:1597
uint32 param1
Definition: SmartScriptMgr.h:1594
uint32 param3
Definition: SmartScriptMgr.h:1596
SMARTAI_TARGETS type
Definition: SmartScriptMgr.h:1448
struct SmartTarget::@181::@205 raw
uint32 param2
Definition: SmartScriptMgr.h:1595
Definition: SmartScriptMgr.h:1795
SmartAction action
Definition: SmartScriptMgr.h:1806
SmartScriptType source_type
Definition: SmartScriptMgr.h:1801
SmartEvent event
Definition: SmartScriptMgr.h:1805
SmartTarget target
Definition: SmartScriptMgr.h:1807

References SmartScriptHolder::action, SmartScriptHolder::event, SmartEvent::event_chance, SmartEvent::event_flags, SmartEvent::event_phase_mask, InitTimer(), SmartEvent::param1, SmartAction::param1, SmartTarget::param1, SmartEvent::param2, SmartAction::param2, SmartTarget::param2, SmartEvent::param3, SmartAction::param3, SmartTarget::param3, SmartEvent::param4, SmartAction::param4, SmartTarget::param4, SmartEvent::param5, SmartAction::param5, SmartAction::param6, SmartEvent::raw, SmartAction::raw, SmartTarget::raw, SMART_SCRIPT_TYPE_CREATURE, SmartScriptHolder::source_type, SmartScriptHolder::target, SmartEvent::type, SmartAction::type, and SmartTarget::type.

Referenced by AddEvent().

◆ DecPhase()

void SmartScript::DecPhase ( uint32  p)
private
4595{
4596 if (p >= mEventPhase)
4597 {
4598 SetPhase(0);
4599 }
4600 else
4601 {
4602 SetPhase(mEventPhase - p);
4603 }
4604}
void SetPhase(uint32 p)
Definition: SmartScript.cpp:4606

References mEventPhase, and SetPhase().

Referenced by ProcessAction().

◆ DoFindClosestFriendlyInRange()

Unit * SmartScript::DoFindClosestFriendlyInRange ( float  range,
bool  playerOnly 
) const
4500{
4501 if (!me)
4502 return nullptr;
4503
4504 Unit* unit = nullptr;
4505 Acore::AnyFriendlyNotSelfUnitInObjectRangeCheck u_check(me, me, range, playerOnly);
4507 Cell::VisitAllObjects(me, searcher, range);
4508 return unit;
4509}
Definition: Unit.h:1290
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:207
Definition: GridNotifiers.h:403

References me, and Cell::VisitAllObjects().

Referenced by GetTargets().

◆ DoFindFriendlyCC()

void SmartScript::DoFindFriendlyCC ( std::vector< Creature * > &  creatures,
float  range 
) const
4480{
4481 if (!me)
4482 return;
4483
4484 Acore::FriendlyCCedInRange u_check(me, range);
4486 Cell::VisitGridObjects(me, searcher, range);
4487}
creatures
Definition: boss_prince_malchezaar.cpp:49
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:179
Definition: GridNotifiers.h:470
Definition: GridNotifiers.h:815

References me, and Cell::VisitGridObjects().

Referenced by ProcessEvent().

◆ DoFindFriendlyMissingBuff()

void SmartScript::DoFindFriendlyMissingBuff ( std::vector< Creature * > &  creatures,
float  range,
uint32  spellid 
) const
4490{
4491 if (!me)
4492 return;
4493
4494 Acore::FriendlyMissingBuffInRange u_check(me, range, spellid);
4496 Cell::VisitGridObjects(me, searcher, range);
4497}
Definition: GridNotifiers.h:833

References me, and Cell::VisitGridObjects().

Referenced by ProcessEvent().

◆ DoSelectLowestHpFriendly()

Unit * SmartScript::DoSelectLowestHpFriendly ( float  range,
uint32  MinHPDiff 
) const
4453{
4454 if (!me)
4455 return nullptr;
4456
4457 Unit* unit = nullptr;
4458
4459 Acore::MostHPMissingInRange u_check(me, range, MinHPDiff);
4461 Cell::VisitGridObjects(me, searcher, range);
4462 return unit;
4463}
Definition: GridNotifiers.h:772

References me, and Cell::VisitGridObjects().

Referenced by ProcessEvent().

◆ DoSelectLowestHpPercentFriendly()

Unit * SmartScript::DoSelectLowestHpPercentFriendly ( float  range,
uint32  minHpPct,
uint32  maxHpPct 
) const
4466{
4467 if (!me)
4468 {
4469 return nullptr;
4470 }
4471
4472 Unit* unit = nullptr;
4473 Acore::MostHPPercentMissingInRange u_check(me, range, minHpPct, maxHpPct);
4475 Cell::VisitGridObjects(me, searcher, range);
4476 return unit;
4477}
Definition: GridNotifiers.h:791

References me, and Cell::VisitGridObjects().

Referenced by ProcessEvent().

◆ FillScript()

void SmartScript::FillScript ( SmartAIEventList  e,
WorldObject obj,
AreaTrigger const *  at 
)
4269{
4270 (void)at; // ensure that the variable is referenced even if extra logs are disabled in order to pass compiler checks
4271
4272 if (e.empty())
4273 {
4274 if (obj)
4275 LOG_DEBUG("sql.sql", "SmartScript: EventMap for Entry {} is empty but is using SmartScript.", obj->GetEntry());
4276
4277 if (at)
4278 LOG_DEBUG("sql.sql", "SmartScript: EventMap for AreaTrigger {} is empty but is using SmartScript.", at->entry);
4279 return;
4280 }
4281 for (SmartAIEventList::iterator i = e.begin(); i != e.end(); ++i)
4282 {
4283#ifndef ACORE_DEBUG
4284 if ((*i).event.event_flags & SMART_EVENT_FLAG_DEBUG_ONLY)
4285 continue;
4286#endif
4287
4288 if ((*i).event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_ALL)//if has instance flag add only if in it
4289 {
4290 if (obj && obj->GetMap()->IsDungeon())
4291 {
4292 if ((1 << (obj->GetMap()->GetSpawnMode() + 1)) & (*i).event.event_flags)
4293 {
4294 mEvents.push_back((*i));
4295 }
4296 }
4297 continue;
4298 }
4299 mEvents.push_back((*i));//NOTE: 'world(0)' events still get processed in ANY instance mode
4300 }
4301}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
@ SMART_EVENT_FLAG_DIFFICULTY_ALL
Definition: SmartScriptMgr.h:1778
@ SMART_EVENT_FLAG_DEBUG_ONLY
Definition: SmartScriptMgr.h:1774
SmartAIEventList mEvents
Definition: SmartScript.h:244
uint32 GetEntry() const
Definition: Object.h:109
Map * GetMap() const
Definition: Object.h:517
bool IsDungeon() const
Definition: Map.h:447
uint8 GetSpawnMode() const
Definition: Map.h:419

References AreaTrigger::entry, Object::GetEntry(), WorldObject::GetMap(), Map::GetSpawnMode(), Map::IsDungeon(), LOG_DEBUG, mEvents, SMART_EVENT_FLAG_DEBUG_ONLY, and SMART_EVENT_FLAG_DIFFICULTY_ALL.

Referenced by GetScript().

◆ FindCreatureNear()

Creature * SmartScript::FindCreatureNear ( WorldObject searchObject,
ObjectGuid::LowType  guid 
) const
inline
167 {
168 auto bounds = searchObject->GetMap()->GetCreatureBySpawnIdStore().equal_range(guid);
169 if (bounds.first == bounds.second)
170 return nullptr;
171
172 auto creatureItr = std::find_if(bounds.first, bounds.second, [](Map::CreatureBySpawnIdContainer::value_type const& pair)
173 {
174 return pair.second->IsAlive();
175 });
176
177 return creatureItr != bounds.second ? creatureItr->second : bounds.first->second;
178 }
CreatureBySpawnIdContainer & GetCreatureBySpawnIdStore()
Definition: Map.h:518

References Map::GetCreatureBySpawnIdStore(), and WorldObject::GetMap().

Referenced by GetTargets(), and ProcessEvent().

◆ FindGameObjectNear()

GameObject * SmartScript::FindGameObjectNear ( WorldObject searchObject,
ObjectGuid::LowType  guid 
) const
inline
158 {
159 auto bounds = searchObject->GetMap()->GetGameObjectBySpawnIdStore().equal_range(guid);
160 if (bounds.first == bounds.second)
161 return nullptr;
162
163 return bounds.first->second;
164 }
GameObjectBySpawnIdContainer & GetGameObjectBySpawnIdStore()
Definition: Map.h:521

References Map::GetGameObjectBySpawnIdStore(), and WorldObject::GetMap().

Referenced by GetTargets(), and ProcessEvent().

◆ FindLinkedEvent()

SmartScriptHolder SmartScript::FindLinkedEvent ( uint32  link)
inlineprivate
298 {
299 if (!mEvents.empty())
300 {
301 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
302 {
303 if (i->event_id == link)
304 {
305 return (*i);
306 }
307 }
308 }
310 return s;
311 }

References mEvents.

◆ GetActualCombatDist()

uint32 SmartScript::GetActualCombatDist ( ) const
inline
222{ return mActualCombatDist; }

References mActualCombatDist.

Referenced by SmartAI::AttackStart().

◆ GetBaseObject()

WorldObject * SmartScript::GetBaseObject ( ) const
inline
55 {
56 WorldObject* obj = nullptr;
57 if (me)
58 obj = me;
59 else if (go)
60 obj = go;
61 return obj;
62 }
Definition: Object.h:393

References go, and me.

Referenced by GetLastInvoker(), GetTargets(), GetWorldObjectsInDist(), InstallTemplate(), OnUpdate(), ProcessAction(), ProcessEvent(), ProcessEventsFor(), and ProcessTimedAction().

◆ GetCasterActualDist()

float SmartScript::GetCasterActualDist ( ) const
inline

◆ GetCasterMaxDist()

float SmartScript::GetCasterMaxDist ( ) const
inline
230{ return smartCasterMaxDist; }

References smartCasterMaxDist.

Referenced by ProcessAction().

◆ GetCasterPowerType()

Powers SmartScript::GetCasterPowerType ( ) const
inline
228{ return smartCasterPowerType; }

References smartCasterPowerType.

Referenced by ProcessAction().

◆ GetCounterValue()

uint32 SmartScript::GetCounterValue ( uint32  id)
inline
150 {
151 CounterMap::iterator itr = mCounterList.find(id);
152 if (itr != mCounterList.end())
153 return itr->second;
154 return 0;
155 }
CounterMap mCounterList
Definition: SmartScript.h:217

References mCounterList.

Referenced by ProcessEvent().

◆ GetLastInvoker()

Unit * SmartScript::GetLastInvoker ( Unit invoker = nullptr) const
4547{
4548 // Xinef: Look for invoker only on map of base object... Prevents multithreaded crashes
4549 if (GetBaseObject())
4551 // xinef: used for area triggers invoker cast
4552 else if (invoker)
4553 return ObjectAccessor::GetUnit(*invoker, mLastInvoker);
4554 return nullptr;
4555}
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:204
ObjectGuid mLastInvoker
Definition: SmartScript.h:215
WorldObject * GetBaseObject() const
Definition: SmartScript.h:54

References GetBaseObject(), ObjectAccessor::GetUnit(), and mLastInvoker.

Referenced by GetTargets(), ProcessAction(), and ProcessEvent().

◆ GetMaxCombatDist()

uint32 SmartScript::GetMaxCombatDist ( ) const
inline
223{ return mMaxCombatDist; }

References mMaxCombatDist.

Referenced by ProcessAction().

◆ GetPathId()

uint32 SmartScript::GetPathId ( ) const
inline
53{ return mPathId; }

References mPathId.

Referenced by ProcessEvent().

◆ GetScript()

void SmartScript::GetScript ( )
4304{
4306 if (me)
4307 {
4308 e = sSmartScriptMgr->GetScript(-((int32)me->GetSpawnId()), mScriptType);
4309 if (e.empty())
4310 e = sSmartScriptMgr->GetScript((int32)me->GetEntry(), mScriptType);
4311 FillScript(e, me, nullptr);
4312 }
4313 else if (go)
4314 {
4315 e = sSmartScriptMgr->GetScript(-((int32)go->GetSpawnId()), mScriptType);
4316 if (e.empty())
4317 e = sSmartScriptMgr->GetScript((int32)go->GetEntry(), mScriptType);
4318 FillScript(e, go, nullptr);
4319 }
4320 else if (trigger)
4321 {
4322 e = sSmartScriptMgr->GetScript((int32)trigger->entry, mScriptType);
4323 FillScript(e, nullptr, trigger);
4324 }
4325}
std::int32_t int32
Definition: Define.h:104
std::vector< SmartScriptHolder > SmartAIEventList
Definition: SmartScriptMgr.h:1882
#define sSmartScriptMgr
Definition: SmartScriptMgr.h:2056
void FillScript(SmartAIEventList e, WorldObject *obj, AreaTrigger const *at)
Definition: SmartScript.cpp:4268
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:67
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:146
uint32 entry
Definition: ObjectMgr.h:422

References AreaTrigger::entry, FillScript(), Object::GetEntry(), Creature::GetSpawnId(), GameObject::GetSpawnId(), go, me, mScriptType, sSmartScriptMgr, and trigger.

Referenced by OnInitialize().

◆ GetStoredTargetVector()

ObjectVector const * SmartScript::GetStoredTargetVector ( uint32  id,
WorldObject const &  ref 
) const
inline
116 {
117 auto itr = _storedTargets.find(id);
118 if (itr != _storedTargets.end())
119 return itr->second.GetObjectVector(ref);
120 return nullptr;
121 }
ObjectVectorMap _storedTargets
Definition: SmartScript.h:278

References _storedTargets.

Referenced by SmartAI::EndPath(), and GetTargets().

◆ GetTargets()

void SmartScript::GetTargets ( ObjectVector targets,
SmartScriptHolder const &  e,
Unit invoker = nullptr 
) const
2839{
2840 Unit* scriptTrigger = nullptr;
2841 if (invoker)
2842 scriptTrigger = invoker;
2843 else if (Unit* tempLastInvoker = GetLastInvoker())
2844 scriptTrigger = tempLastInvoker;
2845
2846 WorldObject* baseObject = GetBaseObject();
2847
2848 switch (e.GetTargetType())
2849 {
2850 case SMART_TARGET_SELF:
2851 if (baseObject)
2852 targets.push_back(baseObject);
2853 break;
2855 if (me)
2856 if (Unit* victim = me->GetVictim())
2857 targets.push_back(victim);
2858 break;
2860 if (me)
2861 {
2862 if (e.target.hostileRandom.powerType)
2863 {
2864 if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MaxThreat, 1, PowerUsersSelector(me, Powers(e.target.hostileRandom.powerType - 1), (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly)))
2865 targets.push_back(u);
2866 }
2867 else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MaxThreat, 1, (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
2868 targets.push_back(u);
2869 }
2870 break;
2872 if (me)
2873 {
2874 if (e.target.hostileRandom.powerType)
2875 {
2876 if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MinThreat, 0, PowerUsersSelector(me, Powers(e.target.hostileRandom.powerType - 1), (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly)))
2877 targets.push_back(u);
2878 }
2879 else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MinThreat, 0, (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
2880 targets.push_back(u);
2881 }
2882 break;
2884 if (me)
2885 {
2886 if (e.target.hostileRandom.powerType)
2887 {
2888 if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 0, PowerUsersSelector(me, Powers(e.target.hostileRandom.powerType - 1), (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly)))
2889 targets.push_back(u);
2890 }
2891 else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 0, (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
2892 targets.push_back(u);
2893 }
2894 break;
2896 if (me)
2897 {
2898 if (e.target.hostileRandom.powerType)
2899 {
2900 if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 1, PowerUsersSelector(me, Powers(e.target.hostileRandom.powerType - 1), (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly)))
2901 targets.push_back(u);
2902 }
2903 else if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::Random, 1, (float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
2904 targets.push_back(u);
2905 }
2906 break;
2908 if (me)
2909 {
2910 if (Unit* u = me->AI()->SelectTarget(SelectTargetMethod::MinDistance, 0, FarthestTargetSelector(me, e.target.farthest.maxDist, e.target.farthest.playerOnly, e.target.farthest.isInLos)))
2911 targets.push_back(u);
2912 }
2913 break;
2915 if (scriptTrigger)
2916 targets.push_back(scriptTrigger);
2917 break;
2919 if (scriptTrigger && scriptTrigger->GetVehicle() && scriptTrigger->GetVehicle()->GetBase())
2920 targets.push_back(scriptTrigger->GetVehicle()->GetBase());
2921 break;
2923 if (scriptTrigger)
2924 {
2925 if (Player* player = scriptTrigger->ToPlayer())
2926 {
2927 if (Group* group = player->GetGroup())
2928 {
2929 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
2930 if (Player* member = groupRef->GetSource())
2931 if (member->IsInMap(player))
2932 targets.push_back(member);
2933 }
2934 // We still add the player to the list if there is no group. If we do
2935 // this even if there is a group (thus the else-check), it will add the
2936 // same player to the list twice. We don't want that to happen.
2937 else
2938 targets.push_back(scriptTrigger);
2939 }
2940 }
2941 break;
2943 {
2944 WorldObject* ref = baseObject;
2945 if (!ref)
2946 ref = scriptTrigger;
2947
2948 if (!ref)
2949 {
2950 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_CREATURE_RANGE: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker",
2951 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
2952 break;
2953 }
2954
2955 ObjectVector units;
2956 GetWorldObjectsInDist(units, static_cast<float>(e.target.unitRange.maxDist));
2957
2958 for (WorldObject* unit : units)
2959 {
2960 if (!IsCreature(unit))
2961 continue;
2962
2963 if (me && me->GetGUID() == unit->GetGUID())
2964 continue;
2965
2966 // check alive state - 1 alive, 2 dead, 0 both
2967 if (uint32 state = e.target.unitRange.livingState)
2968 {
2969 if (unit->ToCreature()->IsAlive() && state == 2)
2970 continue;
2971 if (!unit->ToCreature()->IsAlive() && state == 1)
2972 continue;
2973 }
2974
2975 if (((e.target.unitRange.creature && unit->ToCreature()->GetEntry() == e.target.unitRange.creature) || !e.target.unitRange.creature) && ref->IsInRange(unit, (float)e.target.unitRange.minDist, (float)e.target.unitRange.maxDist))
2976 targets.push_back(unit);
2977 }
2978
2979 break;
2980 }
2982 {
2983 ObjectVector units;
2984 GetWorldObjectsInDist(units, static_cast<float>(e.target.unitDistance.dist));
2985
2986 for (WorldObject* unit : units)
2987 {
2988 if (!IsCreature(unit))
2989 continue;
2990
2991 if (me && me->GetGUID() == unit->GetGUID())
2992 continue;
2993
2994 // check alive state - 1 alive, 2 dead, 0 both
2995 if (uint32 state = e.target.unitDistance.livingState)
2996 {
2997 if (unit->ToCreature()->IsAlive() && state == 2)
2998 continue;
2999 if (!unit->ToCreature()->IsAlive() && state == 1)
3000 continue;
3001 }
3002
3003 if ((e.target.unitDistance.creature && unit->ToCreature()->GetEntry() == e.target.unitDistance.creature) || !e.target.unitDistance.creature)
3004 targets.push_back(unit);
3005 }
3006
3007 break;
3008 }
3010 {
3011 ObjectVector units;
3012 GetWorldObjectsInDist(units, static_cast<float>(e.target.goDistance.dist));
3013
3014 for (WorldObject* unit : units)
3015 {
3016 if (!IsGameObject(unit))
3017 continue;
3018
3019 if (go && go->GetGUID() == unit->GetGUID())
3020 continue;
3021
3022 if ((e.target.goDistance.entry && unit->ToGameObject()->GetEntry() == e.target.goDistance.entry) || !e.target.goDistance.entry)
3023 targets.push_back(unit);
3024 }
3025
3026 break;
3027 }
3029 {
3030
3031 WorldObject* ref = baseObject;
3032 if (!ref)
3033 ref = scriptTrigger;
3034
3035 if (!ref)
3036 {
3037 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_GAMEOBJECT_RANGE: Entry: {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3038 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3039 break;
3040 }
3041
3042 ObjectVector units;
3043 GetWorldObjectsInDist(units, static_cast<float>(e.target.goRange.maxDist));
3044
3045 for (WorldObject* unit : units)
3046 {
3047 if (!IsGameObject(unit))
3048 continue;
3049
3050 if (go && go->GetGUID() == unit->GetGUID())
3051 continue;
3052
3053 if (((e.target.goRange.entry && IsGameObject(unit) && unit->ToGameObject()->GetEntry() == e.target.goRange.entry) || !e.target.goRange.entry) && ref->IsInRange((unit), (float)e.target.goRange.minDist, (float)e.target.goRange.maxDist))
3054 targets.push_back(unit);
3055 }
3056
3057 break;
3058 }
3060 {
3061 if (!scriptTrigger && !baseObject)
3062 {
3063 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_CREATURE_GUID: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3064 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3065 break;
3066 }
3067
3068 Creature* target = FindCreatureNear(scriptTrigger ? scriptTrigger : GetBaseObject(), e.target.unitGUID.dbGuid);
3069 if (target && (!e.target.unitGUID.entry || target->GetEntry() == e.target.unitGUID.entry))
3070 targets.push_back(target);
3071 break;
3072 }
3074 {
3075 if (!scriptTrigger && !GetBaseObject())
3076 {
3077 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_GAMEOBJECT_GUID: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3078 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3079 break;
3080 }
3081
3082 GameObject* target = FindGameObjectNear(scriptTrigger ? scriptTrigger : GetBaseObject(), e.target.goGUID.dbGuid);
3083 if (target && (!e.target.goGUID.entry || target->GetEntry() == e.target.goGUID.entry))
3084 targets.push_back(target);
3085 break;
3086 }
3088 {
3089 ObjectVector units;
3090 GetWorldObjectsInDist(units, static_cast<float>(e.target.playerRange.maxDist));
3091
3092 if (!units.empty() && baseObject)
3093 for (WorldObject* unit : units)
3094 if (IsPlayer(unit) && baseObject->IsInRange(unit, float(e.target.playerRange.minDist), float(e.target.playerRange.maxDist)))
3095 targets.push_back(unit);
3096 break;
3097 }
3099 {
3100 ObjectVector units;
3101 GetWorldObjectsInDist(units, static_cast<float>(e.target.playerDistance.dist));
3102
3103 for (WorldObject* unit : units)
3104 if (IsPlayer(unit))
3105 targets.push_back(unit);
3106 break;
3107 }
3109 {
3110 WorldObject* ref = baseObject;
3111 if (!ref)
3112 ref = scriptTrigger;
3113
3114 if (!ref)
3115 {
3116 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_STORED: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3117 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3118 break;
3119 }
3120
3121 if (ObjectVector const* stored = GetStoredTargetVector(e.target.stored.id, *ref))
3122 targets.assign(stored->begin(), stored->end());
3123 break;
3124 }
3126 {
3127 WorldObject* ref = baseObject;
3128
3129 if (!ref)
3130 ref = scriptTrigger;
3131
3132 if (!ref)
3133 {
3134 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_CLOSEST_CREATURE: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3135 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3136 break;
3137 }
3138
3139 Creature* target = GetClosestCreatureWithEntry(ref, e.target.unitClosest.entry, (float)(e.target.unitClosest.dist ? e.target.unitClosest.dist : 100), !e.target.unitClosest.dead);
3140 if (target)
3141 targets.push_back(target);
3142 break;
3143 }
3145 {
3146 WorldObject* ref = baseObject;
3147
3148 if (!ref)
3149 ref = scriptTrigger;
3150
3151 if (!ref)
3152 {
3153 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_CLOSEST_GAMEOBJECT: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3154 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3155 break;
3156 }
3157
3158 GameObject* target = GetClosestGameObjectWithEntry(ref, e.target.goClosest.entry, (float)(e.target.goClosest.dist ? e.target.goClosest.dist : 100), e.target.goClosest.onlySpawned);
3159 if (target)
3160 targets.push_back(target);
3161 break;
3162 }
3164 {
3165 WorldObject* ref = baseObject;
3166
3167 if (!ref)
3168 ref = scriptTrigger;
3169
3170 if (!ref)
3171 {
3172 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_CLOSEST_PLAYER: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3173 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3174 break;
3175 }
3176
3177 if (Player* target = ref->SelectNearestPlayer((float)e.target.playerDistance.dist))
3178 targets.push_back(target);
3179 break;
3180 }
3182 /*
3183 * Owners/Summoners should be WorldObjects. This allows to have other objects
3184 * such as gameobjects to execute SmartScripts using this type of target.
3185 * Otherwise, only Units like creatures can summon other creatures.
3186 */
3187 {
3188 if (me)
3189 {
3191 {
3192 targets.push_back(owner);
3193 }
3194 else if (me->IsSummon() && me->ToTempSummon()->GetSummonerUnit())
3195 {
3196 targets.push_back(me->ToTempSummon()->GetSummonerUnit());
3197 }
3198 }
3199 else if (go)
3200 {
3202 {
3203 targets.push_back(owner);
3204 }
3205 }
3206
3207 // xinef: Get owner of owner
3208 if (e.target.owner.useCharmerOrOwner && !targets.empty())
3209 {
3210 if (WorldObject* owner = targets.front())
3211 {
3212 targets.clear();
3213
3214 if (owner->ToCreature())
3215 {
3216 if (Unit* base = ObjectAccessor::GetUnit(*owner, owner->ToCreature()->GetCharmerOrOwnerGUID()))
3217 {
3218 targets.push_back(base);
3219 }
3220 }
3221 else
3222 {
3223 if (Unit* base = ObjectAccessor::GetUnit(*owner, owner->ToGameObject()->GetOwnerGUID()))
3224 {
3225 targets.push_back(base);
3226 }
3227 }
3228 }
3229 }
3230 break;
3231 }
3233 {
3234 if (me)
3235 {
3237 for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
3238 if (Unit* temp = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
3239 // Xinef: added distance check
3240 if (e.target.threatList.maxDist == 0 || me->IsWithinCombatRange(temp, (float)e.target.threatList.maxDist))
3241 targets.push_back(temp);
3242 }
3243 break;
3244 }
3246 {
3247 if (me)
3248 if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist, e.target.closestAttackable.playerOnly))
3249 targets.push_back(target);
3250
3251 break;
3252 }
3254 {
3255 if (me)
3256 if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist, e.target.closestFriendly.playerOnly))
3257 targets.push_back(target);
3258
3259 break;
3260 }
3262 {
3263 ObjectVector units;
3264 GetWorldObjectsInDist(units, static_cast<float>(e.target.playerDistance.dist));
3265
3266 for (WorldObject* unit : units)
3267 if (IsPlayer(unit) && unit->ToPlayer()->IsAlive() && !unit->ToPlayer()->IsGameMaster())
3268 if (GetBaseObject()->IsInRange(unit, (float)e.target.playerWithAura.distMin, (float)e.target.playerWithAura.distMax))
3269 if (bool(e.target.playerWithAura.negation) != unit->ToPlayer()->HasAura(e.target.playerWithAura.spellId))
3270 targets.push_back(unit);
3271
3272 if (e.target.o > 0)
3273 Acore::Containers::RandomResize(targets, e.target.o);
3274
3275 break;
3276 }
3278 {
3279 ObjectVector units;
3280 GetWorldObjectsInDist(units, static_cast<float>(e.target.playerDistance.dist));
3281 // 1 = Tanks, 2 = Healer, 4 = Damage
3282 uint32 roleMask = e.target.roleSelection.roleMask;
3283 for (WorldObject* unit : units)
3284 if (Player* targetPlayer = unit->ToPlayer())
3285 if (targetPlayer->IsAlive() && !targetPlayer->IsGameMaster())
3286 {
3287 if (roleMask & SMART_TARGET_ROLE_FLAG_TANKS)
3288 {
3289 if (targetPlayer->HasTankSpec())
3290 {
3291 targets.push_back(unit);
3292 continue;
3293 }
3294 }
3295 if (roleMask & SMART_TARGET_ROLE_FLAG_HEALERS)
3296 {
3297 if (targetPlayer->HasHealSpec())
3298 {
3299 targets.push_back(unit);
3300 continue;
3301 }
3302 }
3303 if (roleMask & SMART_TARGET_ROLE_FLAG_DAMAGERS)
3304 {
3305 if (targetPlayer->HasCasterSpec() || targetPlayer->HasMeleeSpec())
3306 {
3307 targets.push_back(unit);
3308 continue;
3309 }
3310 }
3311 }
3312
3313 if (e.target.roleSelection.resize > 0)
3314 Acore::Containers::RandomResize(targets, e.target.roleSelection.resize);
3315
3316 break;
3317 }
3319 {
3320 if (me && me->IsVehicle())
3321 {
3322 if (Unit* target = me->GetVehicleKit()->GetPassenger(e.target.vehicle.seatMask))
3323 {
3324 targets.push_back(target);
3325 }
3326 }
3327 break;
3328 }
3330 {
3331 if (me)
3332 {
3333 if (Group* lootGroup = me->GetLootRecipientGroup())
3334 {
3335 for (GroupReference* it = lootGroup->GetFirstMember(); it != nullptr; it = it->next())
3336 {
3337 if (Player* recipient = it->GetSource())
3338 {
3339 targets.push_back(recipient);
3340 }
3341 }
3342 }
3343 else
3344 {
3345 if (Player* recipient = me->GetLootRecipient())
3346 {
3347 targets.push_back(recipient);
3348 }
3349 }
3350 }
3351 break;
3352 }
3354 {
3355 if (me)
3356 {
3357 for (ObjectGuid const& guid : _summonList)
3358 {
3359 if (!e.target.summonedCreatures.entry || guid.GetEntry() == e.target.summonedCreatures.entry)
3360 {
3361 if (Creature* creature = me->GetMap()->GetCreature(guid))
3362 {
3363 targets.push_back(creature);
3364 }
3365 }
3366 }
3367 }
3368 break;
3369 }
3371 {
3372 if (InstanceScript* instance = GetBaseObject()->GetInstanceScript())
3373 {
3374 if (e.target.instanceStorage.type == 1)
3375 {
3376 if (Creature* creature = instance->GetCreature(e.target.instanceStorage.index))
3377 {
3378 targets.push_back(creature);
3379 }
3380 }
3381 else if (e.target.instanceStorage.type == 2)
3382 {
3383 if (GameObject* go = instance->GetGameObject(e.target.instanceStorage.index))
3384 {
3385 targets.push_back(go);
3386 }
3387 }
3388 }
3389 else
3390 {
3391 LOG_ERROR("scripts.ai.sai", "SMART_TARGET_INSTANCE_STORAGE: Entry {} SourceType {} Event {} Action {} Target {} called outside an instance map.",
3392 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3393 }
3394
3395 break;
3396 }
3397 case SMART_TARGET_NONE:
3399 default:
3400 break;
3401 }
3402}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
Creature * GetClosestCreatureWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool alive)
Definition: ScriptedCreature.cpp:765
GameObject * GetClosestGameObjectWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool onlySpawned)
Definition: ScriptedCreature.cpp:770
@ SMART_TARGET_ROLE_FLAG_HEALERS
Definition: SmartScriptMgr.h:1611
@ SMART_TARGET_ROLE_FLAG_TANKS
Definition: SmartScriptMgr.h:1610
@ SMART_TARGET_ROLE_FLAG_DAMAGERS
Definition: SmartScriptMgr.h:1612
@ SMART_TARGET_LOOT_RECIPIENTS
Definition: SmartScriptMgr.h:1415
@ SMART_TARGET_CLOSEST_CREATURE
Definition: SmartScriptMgr.h:1407
@ SMART_TARGET_CREATURE_DISTANCE
Definition: SmartScriptMgr.h:1399
@ SMART_TARGET_HOSTILE_RANDOM_NOT_TOP
Definition: SmartScriptMgr.h:1394
@ SMART_TARGET_INVOKER_PARTY
Definition: SmartScriptMgr.h:1404
@ SMART_TARGET_CLOSEST_FRIENDLY
Definition: SmartScriptMgr.h:1414
@ SMART_TARGET_CLOSEST_GAMEOBJECT
Definition: SmartScriptMgr.h:1408
@ SMART_TARGET_VEHICLE_PASSENGER
Definition: SmartScriptMgr.h:1417
@ SMART_TARGET_GAMEOBJECT_RANGE
Definition: SmartScriptMgr.h:1401
@ SMART_TARGET_CREATURE_GUID
Definition: SmartScriptMgr.h:1398
@ SMART_TARGET_PLAYER_RANGE
Definition: SmartScriptMgr.h:1405
@ SMART_TARGET_SUMMONED_CREATURES
Definition: SmartScriptMgr.h:1428
@ SMART_TARGET_VICTIM
Definition: SmartScriptMgr.h:1390
@ SMART_TARGET_GAMEOBJECT_DISTANCE
Definition: SmartScriptMgr.h:1403
@ SMART_TARGET_CREATURE_RANGE
Definition: SmartScriptMgr.h:1397
@ SMART_TARGET_CLOSEST_PLAYER
Definition: SmartScriptMgr.h:1409
@ SMART_TARGET_HOSTILE_RANDOM
Definition: SmartScriptMgr.h:1393
@ SMART_TARGET_GAMEOBJECT_GUID
Definition: SmartScriptMgr.h:1402
@ SMART_TARGET_HOSTILE_SECOND_AGGRO
Definition: SmartScriptMgr.h:1391
@ SMART_TARGET_OWNER_OR_SUMMONER
Definition: SmartScriptMgr.h:1411
@ SMART_TARGET_SELF
Definition: SmartScriptMgr.h:1389
@ SMART_TARGET_PLAYER_WITH_AURA
Definition: SmartScriptMgr.h:1425
@ SMART_TARGET_ROLE_SELECTION
Definition: SmartScriptMgr.h:1427
@ SMART_TARGET_ACTION_INVOKER
Definition: SmartScriptMgr.h:1395
@ SMART_TARGET_POSITION
Definition: SmartScriptMgr.h:1396
@ SMART_TARGET_HOSTILE_LAST_AGGRO
Definition: SmartScriptMgr.h:1392
@ SMART_TARGET_ACTION_INVOKER_VEHICLE
Definition: SmartScriptMgr.h:1410
@ SMART_TARGET_INSTANCE_STORAGE
Definition: SmartScriptMgr.h:1429
@ SMART_TARGET_FARTHEST
Definition: SmartScriptMgr.h:1416
@ SMART_TARGET_THREAT_LIST
Definition: SmartScriptMgr.h:1412
@ SMART_TARGET_CLOSEST_ENEMY
Definition: SmartScriptMgr.h:1413
@ SMART_TARGET_NONE
Definition: SmartScriptMgr.h:1388
@ SMART_TARGET_PLAYER_DISTANCE
Definition: SmartScriptMgr.h:1406
@ SMART_TARGET_STORED
Definition: SmartScriptMgr.h:1400
std::vector< WorldObject * > ObjectVector
Definition: SmartScriptMgr.h:1823
Powers
Definition: SharedDefines.h:240
void RandomResize(C &container, std::size_t requestedSize)
Definition: Containers.h:81
WorldObject * GetWorldObject(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:120
Definition: UnitAI.h:124
Definition: UnitAI.h:154
Unit * SelectTarget(SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition: UnitAI.cpp:111
static bool IsPlayer(WorldObject *obj)
Definition: SmartScript.cpp:4562
Unit * GetLastInvoker(Unit *invoker=nullptr) const
Definition: SmartScript.cpp:4546
static bool IsCreature(WorldObject *obj)
Definition: SmartScript.cpp:4567
void GetWorldObjectsInDist(ObjectVector &objects, float dist) const
Definition: SmartScript.cpp:3404
Creature * FindCreatureNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:166
static bool IsGameObject(WorldObject *obj)
Definition: SmartScript.cpp:4583
ObjectVector const * GetStoredTargetVector(uint32 id, WorldObject const &ref) const
Definition: SmartScript.h:115
Unit * DoFindClosestFriendlyInRange(float range, bool playerOnly) const
Definition: SmartScript.cpp:4499
GameObject * FindGameObjectNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:157
std::list< HostileReference * > StorageType
Definition: ThreatMgr.h:148
ThreatContainer::StorageType const & GetThreatList() const
Definition: ThreatMgr.h:274
Definition: Creature.h:46
Player * GetLootRecipient() const
Definition: Creature.cpp:1278
Group * GetLootRecipientGroup() const
Definition: Creature.cpp:1285
Unit * SelectNearestTarget(float dist=0, bool playerOnly=false) const
Definition: Creature.cpp:2314
CreatureAI * AI() const
Definition: Creature.h:135
Unit * GetSummonerUnit() const
Definition: TemporarySummon.cpp:45
Definition: GameObject.h:122
ObjectGuid GetOwnerGUID() const
Definition: GameObject.h:175
Player * ToPlayer()
Definition: Object.h:195
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
Player * SelectNearestPlayer(float distance=0) const
Definition: Object.cpp:2436
bool IsInRange(WorldObject const *obj, float minRange, float maxRange, bool is3D=true) const
Definition: Object.cpp:1404
Definition: ObjectGuid.h:120
Definition: Player.h:1046
bool IsVehicle() const
Definition: Unit.h:1416
Vehicle * GetVehicle() const
Definition: Unit.h:2354
bool IsWithinCombatRange(Unit const *obj, float dist2compare) const
Definition: Unit.cpp:667
TempSummon * ToTempSummon()
Definition: Unit.h:2400
bool IsSummon() const
Definition: Unit.h:1410
Unit * GetVictim() const
Definition: Unit.h:1386
ThreatMgr & GetThreatMgr()
Definition: Unit.h:2145
Vehicle * GetVehicleKit() const
Definition: Unit.h:2353
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.h:1830
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:39
Unit * GetPassenger(int8 seatId) const
Definition: Vehicle.cpp:226
Definition: Group.h:168
Definition: GroupReference.h:27
GroupReference * next()
Definition: GroupReference.h:36
Definition: InstanceScript.h:140
Creature * GetCreature(ObjectGuid const guid)
Definition: Map.cpp:3293

References _summonList, Creature::AI(), SmartTarget::closestAttackable, SmartTarget::closestFriendly, SmartTarget::creature, SmartTarget::dbGuid, SmartTarget::dead, SmartTarget::dist, SmartTarget::distMax, SmartTarget::distMin, DoFindClosestFriendlyInRange(), SmartTarget::entry, SmartScriptHolder::entryOrGuid, SmartScriptHolder::event_id, SmartTarget::farthest, FindCreatureNear(), FindGameObjectNear(), SmartScriptHolder::GetActionType(), Vehicle::GetBase(), GetBaseObject(), Unit::GetCharmerOrOwnerGUID(), GetClosestCreatureWithEntry(), GetClosestGameObjectWithEntry(), Map::GetCreature(), Object::GetEntry(), Object::GetGUID(), GetLastInvoker(), Creature::GetLootRecipient(), Creature::GetLootRecipientGroup(), WorldObject::GetMap(), GameObject::GetOwnerGUID(), Vehicle::GetPassenger(), SmartScriptHolder::GetScriptType(), GetStoredTargetVector(), TempSummon::GetSummonerUnit(), SmartScriptHolder::GetTargetType(), ThreatMgr::GetThreatList(), Unit::GetThreatMgr(), ObjectAccessor::GetUnit(), Unit::GetVehicle(), Unit::GetVehicleKit(), Unit::GetVictim(), ObjectAccessor::GetWorldObject(), GetWorldObjectsInDist(), go, SmartTarget::goClosest, SmartTarget::goDistance, SmartTarget::goGUID, SmartTarget::goRange, SmartTarget::hostileRandom, SmartTarget::id, SmartTarget::index, SmartTarget::instanceStorage, IsCreature(), IsGameObject(), SmartTarget::isInLos, WorldObject::IsInRange(), IsPlayer(), Unit::IsSummon(), Unit::IsVehicle(), Unit::IsWithinCombatRange(), SmartTarget::livingState, LOG_ERROR, SmartTarget::maxDist, me, SmartTarget::minDist, SmartTarget::negation, GroupReference::next(), SmartTarget::o, SmartTarget::onlySpawned, SmartTarget::owner, SmartTarget::playerDistance, SmartTarget::playerOnly, SmartTarget::playerRange, SmartTarget::playerWithAura, SmartTarget::powerType, Acore::Containers::RandomResize(), SmartTarget::resize, SmartTarget::roleMask, SmartTarget::roleSelection, SmartTarget::seatMask, WorldObject::SelectNearestPlayer(), Creature::SelectNearestTarget(), UnitAI::SelectTarget(), SMART_TARGET_ACTION_INVOKER, SMART_TARGET_ACTION_INVOKER_VEHICLE, SMART_TARGET_CLOSEST_CREATURE, SMART_TARGET_CLOSEST_ENEMY, SMART_TARGET_CLOSEST_FRIENDLY, SMART_TARGET_CLOSEST_GAMEOBJECT, SMART_TARGET_CLOSEST_PLAYER, SMART_TARGET_CREATURE_DISTANCE, SMART_TARGET_CREATURE_GUID, SMART_TARGET_CREATURE_RANGE, SMART_TARGET_FARTHEST, SMART_TARGET_GAMEOBJECT_DISTANCE, SMART_TARGET_GAMEOBJECT_GUID, SMART_TARGET_GAMEOBJECT_RANGE, SMART_TARGET_HOSTILE_LAST_AGGRO, SMART_TARGET_HOSTILE_RANDOM, SMART_TARGET_HOSTILE_RANDOM_NOT_TOP, SMART_TARGET_HOSTILE_SECOND_AGGRO, SMART_TARGET_INSTANCE_STORAGE, SMART_TARGET_INVOKER_PARTY, SMART_TARGET_LOOT_RECIPIENTS, SMART_TARGET_NONE, SMART_TARGET_OWNER_OR_SUMMONER, SMART_TARGET_PLAYER_DISTANCE, SMART_TARGET_PLAYER_RANGE, SMART_TARGET_PLAYER_WITH_AURA, SMART_TARGET_POSITION, SMART_TARGET_ROLE_FLAG_DAMAGERS, SMART_TARGET_ROLE_FLAG_HEALERS, SMART_TARGET_ROLE_FLAG_TANKS, SMART_TARGET_ROLE_SELECTION, SMART_TARGET_SELF, SMART_TARGET_STORED, SMART_TARGET_SUMMONED_CREATURES, SMART_TARGET_THREAT_LIST, SMART_TARGET_VEHICLE_PASSENGER, SMART_TARGET_VICTIM, SmartTarget::spellId, SmartTarget::stored, SmartTarget::summonedCreatures, SmartScriptHolder::target, SmartTarget::threatList, Object::ToPlayer(), Unit::ToTempSummon(), SmartTarget::type, SmartTarget::unitClosest, SmartTarget::unitDistance, SmartTarget::unitGUID, SmartTarget::unitRange, SmartTarget::useCharmerOrOwner, and SmartTarget::vehicle.

Referenced by ProcessAction().

◆ GetWorldObjectsInDist()

void SmartScript::GetWorldObjectsInDist ( ObjectVector objects,
float  dist 
) const
3405{
3406 WorldObject* obj = GetBaseObject();
3407 if (!obj)
3408 return;
3409
3410 Acore::AllWorldObjectsInRange u_check(obj, dist);
3412 Cell::VisitAllObjects(obj, searcher, dist);
3413}
Definition: GridNotifiers.h:236
Definition: GridNotifiers.h:1582

References GetBaseObject(), and Cell::VisitAllObjects().

Referenced by GetTargets(), ProcessAction(), and ProcessEvent().

◆ IncPhase()

void SmartScript::IncPhase ( uint32  p)
private
4589{
4590 // protect phase from overflowing
4591 SetPhase(std::min<uint32>(SMART_EVENT_PHASE_12, mEventPhase + p));
4592}
@ SMART_EVENT_PHASE_12
Definition: SmartScriptMgr.h:76

References mEventPhase, SetPhase(), and SMART_EVENT_PHASE_12.

Referenced by ProcessAction().

◆ InitTimer()

void SmartScript::InitTimer ( SmartScriptHolder e)
static
4067{
4068 switch (e.GetEventType())
4069 {
4070 //set only events which have initial timers
4071 case SMART_EVENT_RANGE:
4072 // If onlyFireOnRepeat is true set to 2 before entering combat. Will be set back to 1 after entering combat to ignore initial firing.
4075 // make it predictable
4076 RecalcTimer(e, 500, 500);
4077 break;
4081 break;
4082 case SMART_EVENT_UPDATE:
4086 break;
4088 case SMART_EVENT_IC_LOS:
4089 // Xinef: cooldown should be processed AFTER action is done, not before...
4090 //RecalcTimer(e, e.event.los.cooldownMin, e.event.los.cooldownMax);
4091 //break;
4095 break;
4096 default:
4097 e.active = true;
4098 break;
4099 }
4100}
@ SMART_EVENT_IC_LOS
Definition: SmartScriptMgr.h:144
@ SMART_EVENT_NEAR_PLAYERS_NEGATION
Definition: SmartScriptMgr.h:210
@ SMART_EVENT_DISTANCE_GAMEOBJECT
Definition: SmartScriptMgr.h:194
@ SMART_EVENT_RANGE
Definition: SmartScriptMgr.h:127
@ SMART_EVENT_UPDATE_IC
Definition: SmartScriptMgr.h:118
@ SMART_EVENT_UPDATE
Definition: SmartScriptMgr.h:178
@ SMART_EVENT_UPDATE_OOC
Definition: SmartScriptMgr.h:119
@ SMART_EVENT_DISTANCE_CREATURE
Definition: SmartScriptMgr.h:193
@ SMART_EVENT_OOC_LOS
Definition: SmartScriptMgr.h:128
@ SMART_EVENT_NEAR_PLAYERS
Definition: SmartScriptMgr.h:209
static void RecalcTimer(SmartScriptHolder &e, uint32 min, uint32 max)
Definition: SmartScript.cpp:4101
struct SmartEvent::@30::@32 minMaxRepeat
struct SmartEvent::@30::@33 rangeRepeat
uint32 repeat
Definition: SmartScriptMgr.h:469
uint32 min
Definition: SmartScriptMgr.h:225
uint32 firstTimer
Definition: SmartScriptMgr.h:484
struct SmartEvent::@30::@70 nearPlayer
uint32 onlyFireOnRepeat
Definition: SmartScriptMgr.h:237
uint32 max
Definition: SmartScriptMgr.h:226
struct SmartEvent::@30::@68 distance
bool active
Definition: SmartScriptMgr.h:1816
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1811

References SmartScriptHolder::active, SmartEvent::distance, SmartScriptHolder::event, SmartEvent::firstTimer, SmartScriptHolder::GetEventType(), SmartEvent::max, SmartEvent::min, SmartEvent::minMaxRepeat, SmartEvent::nearPlayer, SmartEvent::onlyFireOnRepeat, SmartEvent::rangeRepeat, RecalcTimer(), SmartEvent::repeat, SMART_EVENT_DISTANCE_CREATURE, SMART_EVENT_DISTANCE_GAMEOBJECT, SMART_EVENT_IC_LOS, SMART_EVENT_NEAR_PLAYERS, SMART_EVENT_NEAR_PLAYERS_NEGATION, SMART_EVENT_OOC_LOS, SMART_EVENT_RANGE, SMART_EVENT_UPDATE, SMART_EVENT_UPDATE_IC, and SMART_EVENT_UPDATE_OOC.

Referenced by CreateSmartEvent(), OnInitialize(), OnReset(), and SetScript9().

◆ InstallEvents()

void SmartScript::InstallEvents ( )
private
4196{
4197 if (!mInstallEvents.empty())
4198 {
4199 for (SmartAIEventList::iterator i = mInstallEvents.begin(); i != mInstallEvents.end(); ++i)
4200 mEvents.push_back(*i);//must be before UpdateTimers
4201
4202 mInstallEvents.clear();
4203 }
4204}

References mEvents, and mInstallEvents.

Referenced by OnInitialize(), and OnUpdate().

◆ InstallTemplate()

void SmartScript::InstallTemplate ( SmartScriptHolder const &  e)
2728{
2729 if (!GetBaseObject())
2730 return;
2732 {
2733 LOG_ERROR("sql.sql", "SmartScript::InstallTemplate: Entry {} SourceType {} AI Template can not be set more then once, skipped.", e.entryOrGuid, e.GetScriptType());
2734 return;
2735 }
2736 mTemplate = (SMARTAI_TEMPLATE)e.action.installTtemplate.id;
2737 switch ((SMARTAI_TEMPLATE)e.action.installTtemplate.id)
2738 {
2740 {
2741 AddEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, e.action.installTtemplate.param2, e.action.installTtemplate.param3, 0, SMART_ACTION_CAST, e.action.installTtemplate.param1, e.target.raw.param1, 0, 0, 0, 0, SMART_TARGET_VICTIM, 0, 0, 0, 0, 1);
2742 AddEvent(SMART_EVENT_RANGE, 0, e.action.installTtemplate.param4, 300, 0, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 1);
2743 AddEvent(SMART_EVENT_RANGE, 0, 0, e.action.installTtemplate.param4 > 10 ? e.action.installTtemplate.param4 - 10 : 0, 0, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 1);
2744 AddEvent(SMART_EVENT_MANA_PCT, 0, e.action.installTtemplate.param5 - 15 > 100 ? 100 : e.action.installTtemplate.param5 + 15, 100, 1000, 1000, 0, SMART_ACTION_SET_EVENT_PHASE, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2745 AddEvent(SMART_EVENT_MANA_PCT, 0, 0, e.action.installTtemplate.param5, 1000, 1000, 0, SMART_ACTION_SET_EVENT_PHASE, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2746 AddEvent(SMART_EVENT_MANA_PCT, 0, 0, e.action.installTtemplate.param5, 1000, 1000, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2747 break;
2748 }
2750 {
2751 AddEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, e.action.installTtemplate.param2, e.action.installTtemplate.param3, 0, SMART_ACTION_CAST, e.action.installTtemplate.param1, e.target.raw.param1, 0, 0, 0, 0, SMART_TARGET_VICTIM, 0, 0, 0, 0, 0);
2752 AddEvent(SMART_EVENT_JUST_CREATED, 0, 0, 0, 0, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2753 break;
2754 }
2756 {
2757 if (!me)
2758 return;
2759 //store cage as id1
2760 AddEvent(SMART_EVENT_DATA_SET, 0, 0, 0, 0, 0, 0, SMART_ACTION_STORE_TARGET_LIST, 1, 0, 0, 0, 0, 0, SMART_TARGET_CLOSEST_GAMEOBJECT, e.action.installTtemplate.param1, 10, 0, 0, 0);
2761
2762 //reset(close) cage on hostage(me) respawn
2763 AddEvent(SMART_EVENT_UPDATE, SMART_EVENT_FLAG_NOT_REPEATABLE, 0, 0, 0, 0, 0, SMART_ACTION_RESET_GOBJECT, 0, 0, 0, 0, 0, 0, SMART_TARGET_GAMEOBJECT_DISTANCE, e.action.installTtemplate.param1, 5, 0, 0, 0);
2764
2765 AddEvent(SMART_EVENT_DATA_SET, 0, 0, 0, 0, 0, 0, SMART_ACTION_SET_RUN, e.action.installTtemplate.param3, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2766 AddEvent(SMART_EVENT_DATA_SET, 0, 0, 0, 0, 0, 0, SMART_ACTION_SET_EVENT_PHASE, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2767
2768 AddEvent(SMART_EVENT_UPDATE, SMART_EVENT_FLAG_NOT_REPEATABLE, 1000, 1000, 0, 0, 0, SMART_ACTION_MOVE_FORWARD, e.action.installTtemplate.param4, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 1);
2769 //phase 1: give quest credit on movepoint reached
2771 //phase 1: despawn after time on movepoint reached
2772 AddEvent(SMART_EVENT_MOVEMENTINFORM, 0, POINT_MOTION_TYPE, SMART_RANDOM_POINT, 0, 0, 0, SMART_ACTION_FORCE_DESPAWN, e.action.installTtemplate.param2, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 1);
2773
2774 if (sCreatureTextMgr->TextExist(me->GetEntry(), (uint8)e.action.installTtemplate.param5))
2775 AddEvent(SMART_EVENT_MOVEMENTINFORM, 0, POINT_MOTION_TYPE, SMART_RANDOM_POINT, 0, 0, 0, SMART_ACTION_TALK, e.action.installTtemplate.param5, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 1);
2776 break;
2777 }
2779 {
2780 if (!go)
2781 return;
2782 //store hostage as id1
2783 AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, 0, SMART_ACTION_STORE_TARGET_LIST, 1, 0, 0, 0, 0, 0, SMART_TARGET_CLOSEST_CREATURE, e.action.installTtemplate.param1, 10, 0, 0, 0);
2784 //store invoker as id2
2785 AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, 0, SMART_ACTION_STORE_TARGET_LIST, 2, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0, 0);
2786 //signal hostage
2787 AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, 0, SMART_ACTION_SET_DATA, 0, 0, 0, 0, 0, 0, SMART_TARGET_STORED, 1, 0, 0, 0, 0);
2788 //when hostage raeched end point, give credit to invoker
2789 if (e.action.installTtemplate.param2)
2790 AddEvent(SMART_EVENT_DATA_SET, 0, 0, 0, 0, 0, 0, SMART_ACTION_CALL_KILLEDMONSTER, e.action.installTtemplate.param1, 0, 0, 0, 0, 0, SMART_TARGET_STORED, 2, 0, 0, 0, 0);
2791 else
2792 AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, 0, SMART_ACTION_CALL_KILLEDMONSTER, e.action.installTtemplate.param1, 0, 0, 0, 0, 0, SMART_TARGET_STORED, 2, 0, 0, 0, 0);
2793 break;
2794 }
2796 default:
2797 return;
2798 }
2799}
std::uint8_t uint8
Definition: Define.h:110
SMARTAI_TEMPLATE
Definition: SmartScriptMgr.h:1376
@ SMARTAI_TEMPLATE_CAGED_GO_PART
Definition: SmartScriptMgr.h:1381
@ SMARTAI_TEMPLATE_CAGED_NPC_PART
Definition: SmartScriptMgr.h:1382
@ SMARTAI_TEMPLATE_CASTER
Definition: SmartScriptMgr.h:1378
@ SMARTAI_TEMPLATE_TURRET
Definition: SmartScriptMgr.h:1379
@ SMART_EVENT_FLAG_NOT_REPEATABLE
Definition: SmartScriptMgr.h:1767
@ SMART_ACTION_STORE_TARGET_LIST
Definition: SmartScriptMgr.h:589
@ SMART_ACTION_FORCE_DESPAWN
Definition: SmartScriptMgr.h:566
@ SMART_ACTION_CAST
Definition: SmartScriptMgr.h:536
@ SMART_ACTION_ALLOW_COMBAT_MOVEMENT
Definition: SmartScriptMgr.h:546
@ SMART_ACTION_MOVE_FORWARD
Definition: SmartScriptMgr.h:571
@ SMART_ACTION_CALL_KILLEDMONSTER
Definition: SmartScriptMgr.h:558
@ SMART_ACTION_TALK
Definition: SmartScriptMgr.h:526
@ SMART_ACTION_SET_DATA
Definition: SmartScriptMgr.h:570
@ SMART_ACTION_SET_RUN
Definition: SmartScriptMgr.h:584
@ SMART_ACTION_SET_EVENT_PHASE
Definition: SmartScriptMgr.h:547
@ SMART_ACTION_RESET_GOBJECT
Definition: SmartScriptMgr.h:557
@ SMART_EVENT_DATA_SET
Definition: SmartScriptMgr.h:156
@ SMART_EVENT_JUST_CREATED
Definition: SmartScriptMgr.h:181
@ SMART_EVENT_MOVEMENTINFORM
Definition: SmartScriptMgr.h:152
@ SMART_EVENT_MANA_PCT
Definition: SmartScriptMgr.h:121
@ SMART_EVENT_GO_STATE_CHANGED
Definition: SmartScriptMgr.h:188
@ SMART_RANDOM_POINT
Definition: SmartScriptMgr.h:58
@ POINT_MOTION_TYPE
Definition: MotionMaster.h:46
#define sCreatureTextMgr
Definition: CreatureTextMgr.h:119
void AddEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask)
Definition: SmartScript.cpp:2801

References SmartScriptHolder::action, AddEvent(), SmartScriptHolder::entryOrGuid, GetBaseObject(), Object::GetEntry(), SmartScriptHolder::GetScriptType(), go, SmartAction::id, SmartAction::installTtemplate, LOG_ERROR, me, mTemplate, SmartAction::param1, SmartTarget::param1, SmartAction::param2, SmartAction::param3, SmartAction::param4, SmartAction::param5, POINT_MOTION_TYPE, SmartTarget::raw, sCreatureTextMgr, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, SMART_ACTION_CALL_KILLEDMONSTER, SMART_ACTION_CAST, SMART_ACTION_FORCE_DESPAWN, SMART_ACTION_MOVE_FORWARD, SMART_ACTION_RESET_GOBJECT, SMART_ACTION_SET_DATA, SMART_ACTION_SET_EVENT_PHASE, SMART_ACTION_SET_RUN, SMART_ACTION_STORE_TARGET_LIST, SMART_ACTION_TALK, SMART_EVENT_DATA_SET, SMART_EVENT_FLAG_NOT_REPEATABLE, SMART_EVENT_GO_STATE_CHANGED, SMART_EVENT_JUST_CREATED, SMART_EVENT_MANA_PCT, SMART_EVENT_MOVEMENTINFORM, SMART_EVENT_RANGE, SMART_EVENT_UPDATE, SMART_EVENT_UPDATE_IC, SMART_RANDOM_POINT, SMART_TARGET_CLOSEST_CREATURE, SMART_TARGET_CLOSEST_GAMEOBJECT, SMART_TARGET_GAMEOBJECT_DISTANCE, SMART_TARGET_NONE, SMART_TARGET_STORED, SMART_TARGET_VICTIM, SMARTAI_TEMPLATE_BASIC, SMARTAI_TEMPLATE_CAGED_GO_PART, SMARTAI_TEMPLATE_CAGED_NPC_PART, SMARTAI_TEMPLATE_CASTER, SMARTAI_TEMPLATE_TURRET, and SmartScriptHolder::target.

Referenced by ProcessAction().

◆ IsCharmedCreature()

bool SmartScript::IsCharmedCreature ( WorldObject obj)
static
4573{
4574 if (!obj)
4575 return false;
4576
4577 if (Creature* creatureObj = obj->ToCreature())
4578 return creatureObj->IsCharmed();
4579
4580 return false;
4581}
Creature * ToCreature()
Definition: Object.h:197

References Object::ToCreature().

Referenced by ProcessEvent().

◆ IsCreature()

bool SmartScript::IsCreature ( WorldObject obj)
static
4568{
4569 return obj && obj->GetTypeId() == TYPEID_UNIT;
4570}
@ TYPEID_UNIT
Definition: ObjectGuid.h:37
TypeID GetTypeId() const
Definition: Object.h:121

References Object::GetTypeId(), and TYPEID_UNIT.

Referenced by GetTargets(), ProcessAction(), and ProcessEvent().

◆ IsGameObject()

bool SmartScript::IsGameObject ( WorldObject obj)
static
4584{
4585 return obj && obj->GetTypeId() == TYPEID_GAMEOBJECT;
4586}
@ TYPEID_GAMEOBJECT
Definition: ObjectGuid.h:39

References Object::GetTypeId(), and TYPEID_GAMEOBJECT.

Referenced by GetTargets(), and ProcessAction().

◆ IsInPhase()

bool SmartScript::IsInPhase ( uint32  p) const
private
4619{
4620 if (mEventPhase == 0)
4621 {
4622 return false;
4623 }
4624
4625 return ((1 << (mEventPhase - 1)) & p) != 0;
4626}

References mEventPhase.

Referenced by ProcessEvent(), and UpdateTimer().

◆ IsPlayer()

bool SmartScript::IsPlayer ( WorldObject obj)
static
4563{
4564 return obj && obj->GetTypeId() == TYPEID_PLAYER;
4565}
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38

References Object::GetTypeId(), and TYPEID_PLAYER.

Referenced by GetTargets(), SmartAI::IsEscortInvokerInRange(), and ProcessAction().

◆ IsSmart()

bool SmartScript::IsSmart ( Creature c = nullptr)
inline
87 {
88 bool smart = true;
89 if (c && c->GetAIName() != "SmartAI")
90 smart = false;
91
92 if (!me || me->GetAIName() != "SmartAI")
93 smart = false;
94
95 if (!smart)
96 LOG_ERROR("sql.sql", "SmartScript: Action target Creature(entry: {}) is not using SmartAI, action skipped to prevent crash.", c ? c->GetEntry() : (me ? me->GetEntry() : 0));
97
98 return smart;
99 }
std::string const & GetAIName() const
Definition: Creature.cpp:2937

References Creature::GetAIName(), Object::GetEntry(), LOG_ERROR, and me.

Referenced by ProcessAction().

◆ IsSmartGO()

bool SmartScript::IsSmartGO ( GameObject g = nullptr)
inline
102 {
103 bool smart = true;
104 if (g && g->GetAIName() != "SmartGameObjectAI")
105 smart = false;
106
107 if (!go || go->GetAIName() != "SmartGameObjectAI")
108 smart = false;
109 if (!smart)
110 LOG_ERROR("sql.sql", "SmartScript: Action target GameObject(entry: {}) is not using SmartGameObjectAI, action skipped to prevent crash.", g ? g->GetEntry() : (go ? go->GetEntry() : 0));
111
112 return smart;
113 }
std::string const & GetAIName() const
Definition: GameObject.cpp:100

References GameObject::GetAIName(), Object::GetEntry(), go, and LOG_ERROR.

◆ IsUnit()

bool SmartScript::IsUnit ( WorldObject obj)
static
4558{
4559 return obj && (obj->GetTypeId() == TYPEID_UNIT || obj->GetTypeId() == TYPEID_PLAYER);
4560}

References Object::GetTypeId(), TYPEID_PLAYER, and TYPEID_UNIT.

Referenced by ProcessAction(), and ProcessEvent().

◆ OnInitialize()

void SmartScript::OnInitialize ( WorldObject obj,
AreaTrigger const *  at = nullptr 
)
4328{
4329 if (obj)//handle object based scripts
4330 {
4331 switch (obj->GetTypeId())
4332 {
4333 case TYPEID_UNIT:
4335 me = obj->ToCreature();
4336 LOG_DEBUG("sql.sql", "SmartScript::OnInitialize: source is Creature {}", me->GetEntry());
4337 break;
4338 case TYPEID_GAMEOBJECT:
4340 go = obj->ToGameObject();
4341 LOG_DEBUG("sql.sql", "SmartScript::OnInitialize: source is GameObject {}", go->GetEntry());
4342 break;
4343 default:
4344 LOG_ERROR("scripts.ai.sai", "SmartScript::OnInitialize: Unhandled TypeID !WARNING!");
4345 return;
4346 }
4347 }
4348 else if (at)
4349 {
4351 trigger = at;
4352 LOG_DEBUG("sql.sql", "SmartScript::OnInitialize: source is AreaTrigger {}", trigger->entry);
4353 }
4354 else
4355 {
4356 LOG_ERROR("scripts.ai.sai", "SmartScript::OnInitialize: !WARNING! Initialized objects are nullptr.");
4357 return;
4358 }
4359
4360 GetScript();//load copy of script
4361
4362 uint32 maxDisableDist = 0;
4363 uint32 minEnableDist = 0;
4364 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
4365 {
4366 InitTimer((*i));//calculate timers for first time use
4367 if (i->GetEventType() == SMART_EVENT_RANGE && i->GetActionType() == SMART_ACTION_ALLOW_COMBAT_MOVEMENT)
4368 {
4369 if (i->action.combatMove.move == 1 && i->event.rangeRepeat.minRange > minEnableDist)
4370 minEnableDist = i->event.rangeRepeat.minRange;
4371 else if (i->action.combatMove.move == 0 && (i->event.rangeRepeat.maxRange < maxDisableDist || maxDisableDist == 0))
4372 maxDisableDist = i->event.rangeRepeat.maxRange;
4373 }
4374
4375 // Xinef: if smartcast combat move flag is present
4376 if (i->GetActionType() == SMART_ACTION_CAST && (i->action.cast.flags & SMARTCAST_COMBAT_MOVE))
4377 {
4378 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(i->action.cast.spell))
4379 {
4380 float maxRange = spellInfo->GetMaxRange(spellInfo->IsPositive());
4381 float minRange = spellInfo->GetMinRange(spellInfo->IsPositive());
4382
4383 if (maxRange > 0 && minRange <= maxRange)
4384 {
4385 smartCasterMaxDist = minRange + ((maxRange - minRange) * 0.65f);
4386 smartCasterPowerType = (Powers)spellInfo->PowerType;
4387 }
4388 }
4389 }
4390 }
4391 if (maxDisableDist > 0 && minEnableDist >= maxDisableDist)
4392 mMaxCombatDist = uint32(maxDisableDist + ((minEnableDist - maxDisableDist) / 2));
4393
4395 InstallEvents();
4397}
@ SMART_SCRIPT_TYPE_GAMEOBJECT
Definition: SmartScriptMgr.h:1618
@ SMART_SCRIPT_TYPE_AREATRIGGER
Definition: SmartScriptMgr.h:1619
@ SMART_EVENT_AI_INIT
Definition: SmartScriptMgr.h:155
@ SMARTCAST_COMBAT_MOVE
Definition: SmartScriptMgr.h:1790
#define sSpellMgr
Definition: SpellMgr.h:818
void ProcessEventsFor(SMART_EVENT e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition: SmartScript.cpp:95
void InstallEvents()
Definition: SmartScript.cpp:4195
void GetScript()
Definition: SmartScript.cpp:4303
GameObject * ToGameObject()
Definition: Object.h:202
Definition: SpellInfo.h:314

References AreaTrigger::entry, Object::GetEntry(), SpellInfo::GetMaxRange(), SpellInfo::GetMinRange(), GetScript(), Object::GetTypeId(), go, InitTimer(), InstallEvents(), SpellInfo::IsPositive(), LOG_DEBUG, LOG_ERROR, me, mEvents, mMaxCombatDist, mScriptType, SpellInfo::PowerType, ProcessEventsFor(), SMART_ACTION_ALLOW_COMBAT_MOVEMENT, SMART_ACTION_CAST, SMART_EVENT_AI_INIT, SMART_EVENT_JUST_CREATED, SMART_EVENT_RANGE, SMART_SCRIPT_TYPE_AREATRIGGER, SMART_SCRIPT_TYPE_CREATURE, SMART_SCRIPT_TYPE_GAMEOBJECT, SMARTCAST_COMBAT_MOVE, smartCasterMaxDist, smartCasterPowerType, sSpellMgr, Object::ToCreature(), Object::ToGameObject(), trigger, TYPEID_GAMEOBJECT, and TYPEID_UNIT.

Referenced by SmartAI::InitializeAI(), SmartGameObjectAI::InitializeAI(), and SmartTrigger::OnTrigger().

◆ OnMoveInLineOfSight()

void SmartScript::OnMoveInLineOfSight ( Unit who)
4400{
4401 if (!me)
4402 return;
4403
4405}
bool IsEngaged() const
Definition: Unit.h:1685

References Unit::IsEngaged(), me, ProcessEventsFor(), SMART_EVENT_IC_LOS, and SMART_EVENT_OOC_LOS.

Referenced by SmartAI::MoveInLineOfSight().

◆ OnReset()

void SmartScript::OnReset ( )
72{
73 // xinef: check if we allow phase reset
74 if (AllowPhaseReset())
75 SetPhase(0);
76
78 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
79 {
80 if (!((*i).event.event_flags & SMART_EVENT_FLAG_DONT_RESET))
81 {
82 InitTimer((*i));
83 (*i).runOnce = false;
84 }
85 }
88 mCounterList.clear();
89
90 // Xinef: Fix Combat Movement
93}
@ SMART_EVENT_FLAG_DONT_RESET
Definition: SmartScriptMgr.h:1775
@ SMART_EVENT_RESET
Definition: SmartScriptMgr.h:143
void RestoreCasterMaxDist()
Definition: SmartScript.h:227
bool AllowPhaseReset() const
Definition: SmartScript.h:232
void RestoreMaxCombatDist()
Definition: SmartScript.h:221
void ResetBaseObject()
Definition: SmartScript.h:181
void Clear()
Definition: ObjectGuid.h:140

References AllowPhaseReset(), ObjectGuid::Clear(), InitTimer(), mCounterList, mEvents, mLastInvoker, ProcessEventsFor(), ResetBaseObject(), RestoreCasterMaxDist(), RestoreMaxCombatDist(), SetPhase(), SMART_EVENT_FLAG_DONT_RESET, and SMART_EVENT_RESET.

Referenced by SmartAI::EnterEvadeMode(), SmartAI::JustReachedHome(), and SmartGameObjectAI::Reset().

◆ OnUpdate()

void SmartScript::OnUpdate ( const uint32  diff)
4207{
4209 return;
4210
4211 InstallEvents();//before UpdateTimers
4212
4213 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
4214 UpdateTimer(*i, diff);
4215
4216 if (!mStoredEvents.empty())
4217 {
4218 SmartAIEventStoredList::iterator i, icurr;
4219 for (i = mStoredEvents.begin(); i != mStoredEvents.end();)
4220 {
4221 icurr = i++;
4222 UpdateTimer(*icurr, diff);
4223 }
4224 }
4225
4226 bool needCleanup = true;
4227 if (!mTimedActionList.empty())
4228 {
4230 for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
4231 {
4232 if ((*i).enableTimed)
4233 {
4234 UpdateTimer(*i, diff);
4235 needCleanup = false;
4236 }
4237 }
4238
4240 }
4241 if (needCleanup)
4242 mTimedActionList.clear();
4243
4244 if (!mRemIDs.empty())
4245 {
4246 for (std::list<uint32>::const_iterator i = mRemIDs.begin(); i != mRemIDs.end(); ++i)
4248
4249 // xinef: clear list after cleaning...
4250 mRemIDs.clear();
4251 }
4252 if (mUseTextTimer && me)
4253 {
4254 if (mTextTimer < diff)
4255 {
4256 uint32 textID = mLastTextID;
4257 mLastTextID = 0;
4258 uint32 entry = mTalkerEntry;
4259 mTalkerEntry = 0;
4260 mTextTimer = 0;
4261 mUseTextTimer = false;
4262 ProcessEventsFor(SMART_EVENT_TEXT_OVER, nullptr, textID, entry);
4263 }
4264 else mTextTimer -= diff;
4265 }
4266}
@ SMART_EVENT_TEXT_OVER
Definition: SmartScriptMgr.h:170
void UpdateTimer(SmartScriptHolder &e, uint32 const diff)
Definition: SmartScript.cpp:4108
SmartAIEventStoredList mStoredEvents
Definition: SmartScript.h:258
std::list< uint32 > mRemIDs
Definition: SmartScript.h:259
SmartAIEventList mTimedActionList
Definition: SmartScript.h:246
void RemoveStoredEvent(uint32 id)
Definition: SmartScript.h:283

References GetBaseObject(), InstallEvents(), isProcessingTimedActionList, me, mEvents, mLastTextID, mRemIDs, mScriptType, mStoredEvents, mTalkerEntry, mTextTimer, mTimedActionList, mUseTextTimer, ProcessEventsFor(), RemoveStoredEvent(), SMART_EVENT_TEXT_OVER, SMART_SCRIPT_TYPE_CREATURE, SMART_SCRIPT_TYPE_GAMEOBJECT, and UpdateTimer().

Referenced by SmartAI::UpdateAI(), and SmartGameObjectAI::UpdateAI().

◆ ProcessAction()

void SmartScript::ProcessAction ( SmartScriptHolder e,
Unit unit = nullptr,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
SpellInfo const *  spell = nullptr,
GameObject gob = nullptr 
)
115{
116 //calc random
118 {
119 uint32 rnd = urand(1, 100);
120 if (e.event.event_chance <= rnd)
121 return;
122 }
123 e.runOnce = true;//used for repeat check
124
125 if (unit)
126 mLastInvoker = unit->GetGUID();
127
128 if (Unit* tempInvoker = GetLastInvoker())
129 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: Invoker: {} ({})", tempInvoker->GetName(), tempInvoker->GetGUID().ToString());
130
131 bool isControlled = e.action.moveToPos.controlled > 0;
132
133 ObjectVector targets;
134 GetTargets(targets, e, unit);
135
136 switch (e.GetActionType())
137 {
139 {
140 Creature* talker = e.target.type == 0 ? me : nullptr;
141 Unit* talkTarget = nullptr;
142
143 for (WorldObject* target : targets)
144 {
145 if (IsCreature((target)) && !target->ToCreature()->IsPet()) // Prevented sending text to pets.
146 {
148 {
149 talker = me;
150 talkTarget = target->ToCreature();
151 }
152 else
153 talker = target->ToCreature();
154 break;
155 }
156 else if (IsPlayer((target)))
157 {
158 talker = me; // xinef: added
159 talkTarget = target->ToPlayer();
160 break;
161 }
162 }
163
164 if (!talkTarget)
165 talkTarget = GetLastInvoker();
166
167 if (!talker)
168 break;
169
170 if (!sCreatureTextMgr->TextExist(talker->GetEntry(), uint8(e.action.talk.textGroupID)))
171 {
172 LOG_ERROR("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_TALK: EntryOrGuid {} SourceType {} EventType {} TargetType {} using non-existent Text id {} for talker {}, ignored.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetTargetType(), e.action.talk.textGroupID, talker->GetEntry());
173 break;
174 }
175
176 mTalkerEntry = talker->GetEntry();
179 mUseTextTimer = true;
180 sCreatureTextMgr->SendChat(talker, uint8(e.action.talk.textGroupID), talkTarget);
181 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_TALK: talker: {} ({}), textId: {}", talker->GetName(), talker->GetGUID().ToString(), mLastTextID);
182 break;
183 }
185 {
186 for (WorldObject* target : targets)
187 {
188 if (IsCreature(target))
189 sCreatureTextMgr->SendChat(target->ToCreature(), uint8(e.action.simpleTalk.textGroupID), IsPlayer(GetLastInvoker()) ? GetLastInvoker() : 0);
190 else if (IsPlayer(target) && me)
191 {
192 Unit* templastInvoker = GetLastInvoker();
193 sCreatureTextMgr->SendChat(me, uint8(e.action.simpleTalk.textGroupID), IsPlayer(templastInvoker) ? templastInvoker : 0, CHAT_MSG_ADDON, LANG_ADDON, TEXT_RANGE_NORMAL, 0, TEAM_NEUTRAL, false, target->ToPlayer());
194 }
195
196 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_SIMPLE_TALK: talker: {} ({}), textGroupId: {}",
197 target->GetName(), target->GetGUID().ToString(), uint8(e.action.simpleTalk.textGroupID));
198 }
199 break;
200 }
202 {
203 for (WorldObject* target : targets)
204 {
205 if (IsUnit(target))
206 {
207 target->ToUnit()->HandleEmoteCommand(e.action.emote.emote);
208 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_PLAY_EMOTE: target: {} ({}), emote: {}",
209 target->GetName(), target->GetGUID().ToString(), e.action.emote.emote);
210 }
211 }
212 break;
213 }
215 {
216 for (WorldObject* target : targets)
217 {
218 if (IsUnit(target))
219 {
220 if (e.action.sound.distance == 1)
221 target->PlayDistanceSound(e.action.sound.sound, e.action.sound.onlySelf ? target->ToPlayer() : nullptr);
222 else
223 target->PlayDirectSound(e.action.sound.sound, e.action.sound.onlySelf ? target->ToPlayer() : nullptr);
224 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_SOUND: target: {} ({}), sound: {}, onlyself: {}",
225 target->GetName(), target->GetGUID().ToString(), e.action.sound.sound, e.action.sound.onlySelf);
226 }
227 }
228 break;
229 }
231 {
232 uint32 sounds[4];
233 sounds[0] = e.action.randomSound.sound1;
234 sounds[1] = e.action.randomSound.sound2;
235 sounds[2] = e.action.randomSound.sound3;
236 sounds[3] = e.action.randomSound.sound4;
237 uint32 temp[4];
238 uint32 count = 0;
239 for (unsigned int sound : sounds)
240 {
241 if (sound)
242 {
243 temp[count] = sound;
244 ++count;
245 }
246 }
247
248 if (count == 0)
249 {
250 break;
251 }
252
253 for (WorldObject* target : targets)
254 {
255 if (IsUnit(target))
256 {
257 uint32 sound = temp[urand(0, count - 1)];
258 target->PlayDirectSound(sound, e.action.randomSound.onlySelf ? target->ToPlayer() : nullptr);
259 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_SOUND: target: {} ({}), sound: {}, onlyself: {}",
260 target->GetName(), target->GetGUID().ToString(), sound, e.action.randomSound.onlySelf);
261 }
262 }
263
264 break;
265 }
267 {
268 ObjectVector targets;
269
270 if (e.action.music.type > 0)
271 {
272 if (me && me->FindMap())
273 {
274 Map::PlayerList const& players = me->GetMap()->GetPlayers();
275
276 if (!players.IsEmpty())
277 {
278 for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
279 if (Player* player = i->GetSource())
280 {
281 if (player->GetZoneId() == me->GetZoneId())
282 {
283 if (e.action.music.type > 1)
284 {
285 if (player->GetAreaId() == me->GetAreaId())
286 targets.push_back(player);
287 }
288 else
289 targets.push_back(player);
290 }
291 }
292 }
293 }
294 }
295 else
296 GetTargets(targets, e);
297
298 if (!targets.empty())
299 {
300 for (WorldObject* target : targets)
301 {
302 if (IsUnit(target))
303 {
304 target->SendPlayMusic(e.action.music.sound, e.action.music.onlySelf > 0);
305 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_MUSIC: target: {} ({}), sound: {}, onlySelf: {}, type: {}",
306 target->GetName(), target->GetGUID().ToString(), e.action.music.sound, e.action.music.onlySelf, e.action.music.type);
307 }
308 }
309 }
310 break;
311 }
313 {
314 ObjectVector targets;
315
316 if (e.action.randomMusic.type > 0)
317 {
318 if (me && me->FindMap())
319 {
320 Map::PlayerList const& players = me->GetMap()->GetPlayers();
321
322 if (!players.IsEmpty())
323 {
324 for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
325 if (Player* player = i->GetSource())
326 {
327 if (player->GetZoneId() == me->GetZoneId())
328 {
329 if (e.action.randomMusic.type > 1)
330 {
331 if (player->GetAreaId() == me->GetAreaId())
332 targets.push_back(player);
333 }
334 else
335 targets.push_back(player);
336 }
337 }
338 }
339 }
340 }
341 else
342 GetTargets(targets, e);
343
344 if (targets.empty())
345 break;
346
347 uint32 sounds[4];
348 sounds[0] = e.action.randomMusic.sound1;
349 sounds[1] = e.action.randomMusic.sound2;
350 sounds[2] = e.action.randomMusic.sound3;
351 sounds[3] = e.action.randomMusic.sound4;
352 uint32 temp[4];
353 uint32 count = 0;
354 for (unsigned int sound : sounds)
355 {
356 if (sound)
357 {
358 temp[count] = sound;
359 ++count;
360 }
361 }
362
363 if (count == 0)
364 {
365 break;
366 }
367
368 for (WorldObject* target : targets)
369 {
370 if (IsUnit(target))
371 {
372 uint32 sound = temp[urand(0, count - 1)];
373 target->SendPlayMusic(sound, e.action.randomMusic.onlySelf > 0);
374 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_MUSIC: target: {} ({}), sound: {}, onlyself: {}, type: {}",
375 target->GetName(), target->GetGUID().ToString(), sound, e.action.randomMusic.onlySelf, e.action.randomMusic.type);
376 }
377 }
378
379 break;
380 }
382 {
383 for (WorldObject* target : targets)
384 {
385 if (IsCreature(target))
386 {
388 {
389 target->ToCreature()->SetFaction(e.action.faction.factionID);
390 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_FACTION: Creature entry {}, GuidLow {} set faction to {}",
391 target->GetEntry(), target->GetGUID().ToString(), e.action.faction.factionID);
392 }
393 else
394 {
395 if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(target->ToCreature()->GetEntry()))
396 {
397 if (target->ToCreature()->GetFaction() != ci->faction)
398 {
399 target->ToCreature()->SetFaction(ci->faction);
400 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_FACTION: Creature entry {}, GuidLow {} set faction to {}",
401 target->GetEntry(), target->GetGUID().ToString(), ci->faction);
402 }
403 }
404 }
405 }
406 }
407 break;
408 }
410 {
411 for (WorldObject* target : targets)
412 {
413 if (!IsCreature(target))
414 continue;
415
417 {
418 //set model based on entry from creature_template
420 {
421 if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(e.action.morphOrMount.creature))
422 {
423 uint32 displayId = ObjectMgr::ChooseDisplayId(ci);
424 target->ToCreature()->SetDisplayId(displayId);
425 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry {}, GuidLow {} set displayid to {}",
426 target->GetEntry(), target->GetGUID().ToString(), displayId);
427 }
428 }
429 //if no param1, then use value from param2 (modelId)
430 else
431 {
432 target->ToCreature()->SetDisplayId(e.action.morphOrMount.model);
433 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry {}, GuidLow {} set displayid to {}",
434 target->GetEntry(), target->GetGUID().ToString(), e.action.morphOrMount.model);
435 }
436 }
437 else
438 {
439 target->ToCreature()->DeMorph();
440 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry {}, GuidLow {} demorphs.",
441 target->GetEntry(), target->GetGUID().ToString());
442 }
443 }
444 break;
445 }
447 {
448 for (WorldObject* target : targets)
449 {
450 if (IsPlayer(target))
451 {
452 target->ToPlayer()->FailQuest(e.action.quest.quest);
453 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_FAIL_QUEST: Player guidLow {} fails quest {}",
454 target->GetGUID().ToString(), e.action.quest.quest);
455 }
456 }
457 break;
458 }
460 {
461 for (WorldObject* target : targets)
462 {
463 if (Player* player = target->ToPlayer())
464 {
465 if (Quest const* q = sObjectMgr->GetQuestTemplate(e.action.questOffer.questID))
466 {
467 if (me && e.action.questOffer.directAdd == 0)
468 {
469 if (player->CanTakeQuest(q, true))
470 {
471 if (WorldSession* session = player->GetSession())
472 {
473 PlayerMenu menu(session);
474 menu.SendQuestGiverQuestDetails(q, me->GetGUID(), true);
475 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_OFFER_QUEST: Player guidLow {} - offering quest {}",
476 player->GetGUID().ToString(), e.action.questOffer.questID);
477 }
478 }
479 }
480 else
481 {
482 player->AddQuestAndCheckCompletion(q, nullptr);
483 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_OFFER_QUEST: Player guidLow {} - quest {} added",
484 player->GetGUID().ToString(), e.action.questOffer.questID);
485 }
486 }
487 }
488 }
489 break;
490 }
492 {
493 for (WorldObject* target : targets)
494 {
495 if (!IsCreature(target))
496 continue;
497
498 target->ToCreature()->SetReactState(ReactStates(e.action.react.state));
499 }
500 break;
501 }
503 {
504 std::vector<uint32> emotes;
505 std::copy_if(e.action.randomEmote.emotes.begin(), e.action.randomEmote.emotes.end(),
506 std::back_inserter(emotes), [](uint32 emote) { return emote != 0; });
507
508 for (WorldObject* target : targets)
509 {
510 if (IsUnit(target))
511 {
513 target->ToUnit()->HandleEmoteCommand(emote);
514 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_EMOTE: Creature guidLow {} handle random emote {}",
515 target->GetGUID().ToString(), emote);
516 }
517 }
518 break;
519 }
521 {
522 if (!me)
523 break;
524
526 for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
527 {
528 if (Unit* target = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
529 {
531 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_ALL_PCT: Creature {} modify threat for unit {}, value {}",
532 me->GetGUID().ToString(), target->GetGUID().ToString(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
533 }
534 }
535 break;
536 }
538 {
539 if (!me)
540 break;
541
542 for (WorldObject* target : targets)
543 {
544 if (IsUnit(target))
545 {
547 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_SINGLE_PCT: Creature guidLow {} modify threat for unit {}, value %i",
548 me->GetGUID().ToString(), target->GetGUID().ToString(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
549 }
550 }
551 break;
552 }
554 {
555 for (WorldObject* target : targets)
556 {
557 // Special handling for vehicles
558 if (IsUnit(target))
559 if (Vehicle* vehicle = target->ToUnit()->GetVehicleKit())
560 for (auto & Seat : vehicle->Seats)
561 if (Player* player = ObjectAccessor::GetPlayer(*target, Seat.second.Passenger.Guid))
562 player->AreaExploredOrEventHappens(e.action.quest.quest);
563
564 if (IsPlayer(target))
565 {
566 target->ToPlayer()->AreaExploredOrEventHappens(e.action.quest.quest);
567
568 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS: Player guidLow {} credited quest {}",
569 target->GetGUID().ToString(), e.action.quest.quest);
570 }
571 }
572 break;
573 }
575 {
576 if (targets.empty())
577 break;
578
579 Unit* caster = me;
580 // Areatrigger Cast!
582 caster = unit->SummonTrigger(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetOrientation(), 5000);
583
584 if (e.action.cast.targetsLimit > 0 && targets.size() > e.action.cast.targetsLimit)
586
587 for (WorldObject* target : targets)
588 {
589 // may be nullptr
590 if (go)
591 {
592 go->CastSpell(target->ToUnit(), e.action.cast.spell);
593 }
594
595 if (!IsUnit(target))
596 continue;
597
598 if (caster && caster != me) // Areatrigger cast
599 {
600 caster->CastSpell(target->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
601 }
602 else if (me && (!(e.action.cast.flags & SMARTCAST_AURA_NOT_PRESENT) || !target->ToUnit()->HasAura(e.action.cast.spell)))
603 {
606
607 // Xinef: flag usable only if caster has max dist set
609 {
610 // Xinef: check mana case only and operate movement accordingly, LoS and range is checked in targetet movement generator
611 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(e.action.cast.spell);
612 int32 currentPower = me->GetPower(GetCasterPowerType());
613
614 if ((spellInfo && (currentPower < spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask()) || me->IsSpellProhibited(spellInfo->GetSchoolMask()))) || me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED))
615 {
617 CAST_AI(SmartAI, me->AI())->SetForcedCombatMove(0);
618 }
619 else if (GetCasterActualDist() == 0.0f && me->GetPowerPct(GetCasterPowerType()) > 30.0f)
620 {
622 CAST_AI(SmartAI, me->AI())->SetForcedCombatMove(GetCasterActualDist());
623 }
624 }
625
626 me->CastSpell(target->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
627 }
628 }
629
630 break;
631 }
633 {
634 Unit* tempLastInvoker = GetLastInvoker(unit); // xinef: can be used for area triggers cast
635 if (!tempLastInvoker)
636 break;
637
638 if (targets.empty())
639 break;
640
641 if (e.action.cast.targetsLimit > 0 && targets.size() > e.action.cast.targetsLimit)
643
644 for (WorldObject* target : targets)
645 {
646 if (!IsUnit(target))
647 continue;
648
649 if (!(e.action.cast.flags & SMARTCAST_AURA_NOT_PRESENT) || !target->ToUnit()->HasAura(e.action.cast.spell))
650 {
652 tempLastInvoker->InterruptNonMeleeSpells(false);
653
654 tempLastInvoker->CastSpell(target->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
655 }
656 }
657
658 break;
659 }
661 {
662 for (WorldObject* target : targets)
663 {
664 if (IsUnit(target))
665 {
666 target->ToUnit()->AddAura(e.action.cast.spell, target->ToUnit());
667 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ADD_AURA: Adding aura {} to unit {}",
668 e.action.cast.spell, target->GetGUID().ToString());
669 }
670 }
671 break;
672 }
674 {
675 for (WorldObject* target : targets)
676 {
677 if (IsGameObject(target))
678 {
679 GameObject* go = target->ToGameObject();
680
681 // Activate
683 {
685 }
686
688 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_ACTIVATE_GOBJECT. Gameobject {} activated", go->GetGUID().ToString());
689 }
690 }
691
692 break;
693 }
695 {
696 for (WorldObject* target : targets)
697 {
698 if (IsGameObject(target))
699 {
700 target->ToGameObject()->ResetDoorOrButton();
701 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RESET_GOBJECT. Gameobject {} (entry: {}) reset",
702 target->GetGUID().ToString(), target->GetEntry());
703 }
704 }
705 break;
706 }
708 {
709 for (WorldObject* target : targets)
710 {
711 if (IsUnit(target))
712 {
713 target->ToUnit()->SetUInt32Value(UNIT_NPC_EMOTESTATE, e.action.emote.emote);
714 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_EMOTE_STATE. Unit {} set emotestate to {}",
715 target->GetGUID().ToString(), e.action.emote.emote);
716 }
717 }
718 break;
719 }
721 {
722 for (WorldObject* target : targets)
723 {
724 if (IsUnit(target))
725 {
726 if (!e.action.unitFlag.type)
727 {
728 target->ToUnit()->SetFlag(UNIT_FIELD_FLAGS, e.action.unitFlag.flag);
729 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_UNIT_FLAG. Unit {} added flag {} to UNIT_FIELD_FLAGS",
730 target->GetGUID().ToString(), e.action.unitFlag.flag);
731 }
732 else
733 {
734 target->ToUnit()->SetFlag(UNIT_FIELD_FLAGS_2, e.action.unitFlag.flag);
735 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_UNIT_FLAG. Unit {} added flag {} to UNIT_FIELD_FLAGS_2",
736 target->GetGUID().ToString(), e.action.unitFlag.flag);
737 }
738 }
739 }
740 break;
741 }
743 {
744 for (WorldObject* target : targets)
745 {
746 if (IsUnit(target))
747 {
748 if (!e.action.unitFlag.type)
749 {
750 target->ToUnit()->RemoveFlag(UNIT_FIELD_FLAGS, e.action.unitFlag.flag);
751 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_REMOVE_UNIT_FLAG. Unit {} removed flag {} to UNIT_FIELD_FLAGS",
752 target->GetGUID().ToString(), e.action.unitFlag.flag);
753 }
754 else
755 {
756 target->ToUnit()->RemoveFlag(UNIT_FIELD_FLAGS_2, e.action.unitFlag.flag);
757 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_REMOVE_UNIT_FLAG. Unit {} removed flag {} to UNIT_FIELD_FLAGS_2",
758 target->GetGUID().ToString(), e.action.unitFlag.flag);
759 }
760 }
761 }
762 break;
763 }
765 {
766 if (!IsSmart())
767 break;
768
769 CAST_AI(SmartAI, me->AI())->SetAutoAttack(e.action.autoAttack.attack);
770 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_AUTO_ATTACK: Creature: {} bool on = {}",
772 break;
773 }
775 {
776 if (!IsSmart())
777 break;
778
779 // Xinef: Fix Combat Movement
780 bool move = e.action.combatMove.move;
781 if (move && GetMaxCombatDist() && e.GetEventType() == SMART_EVENT_MANA_PCT)
782 {
784 CAST_AI(SmartAI, me->AI())->SetForcedCombatMove(0);
785 }
786 else
787 CAST_AI(SmartAI, me->AI())->SetCombatMove(move);
788 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_ALLOW_COMBAT_MOVEMENT: Creature {} bool on = {}",
790 break;
791 }
793 {
794 if (!GetBaseObject())
795 break;
796
798 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_SET_EVENT_PHASE: Creature {} set event phase {}",
800 break;
801 }
803 {
804 if (!GetBaseObject())
805 break;
806
809 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_INC_EVENT_PHASE: Creature {} inc event phase by {}, "
810 "decrease by {}", GetBaseObject()->GetGUID().ToString(), e.action.incEventPhase.inc, e.action.incEventPhase.dec);
811 break;
812 }
814 {
815 if (!GetBaseObject())
816 break;
817
818 for (WorldObject* target : targets)
819 if (IsCreature(target))
820 if (target->ToCreature()->IsAIEnabled)
821 target->ToCreature()->AI()->EnterEvadeMode();
822
823 break;
824 }
826 {
827 // Xinef: do not allow to flee without control (stun, fear etc)
829 break;
830
832 if (e.action.flee.withEmote)
833 {
835 sCreatureTextMgr->SendChatPacket(me, builder, CHAT_MSG_MONSTER_EMOTE);
836 }
837 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_FLEE_FOR_ASSIST: Creature {} DoFleeToGetAssistance", me->GetGUID().ToString());
838 break;
839 }
841 {
842 if (!me)
843 break;
844
845 me->CombatStop(true);
846 break;
847 }
849 {
850 for (WorldObject* target : targets)
851 {
852 if (!IsUnit(target))
853 continue;
854
855 Unit* unitTarget = target->ToUnit();
856 // If invoker was pet or charm
857 Player* player = unitTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
858 if (player && GetBaseObject())
859 {
860 player->GroupEventHappens(e.action.quest.quest, GetBaseObject());
861 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_GROUPEVENTHAPPENS: Player {}, group credit for quest {}",
862 player->GetGUID().ToString(), e.action.quest.quest);
863 }
864
865 // Special handling for vehicles
866 if (Vehicle* vehicle = unitTarget->GetVehicleKit())
867 {
868 for (auto& Seat : vehicle->Seats)
869 {
870 if (Player* player = ObjectAccessor::GetPlayer(*unitTarget, Seat.second.Passenger.Guid))
871 {
872 player->GroupEventHappens(e.action.quest.quest, GetBaseObject());
873 }
874 }
875 }
876 }
877 break;
878 }
880 {
881 for (WorldObject* target : targets)
882 {
883 if (!IsUnit(target))
884 continue;
885
886 if (e.action.removeAura.spell)
887 {
889 {
890 if (Aura* aur = target->ToUnit()->GetAura(e.action.removeAura.spell))
891 aur->ModCharges(-static_cast<int32>(e.action.removeAura.charges), AURA_REMOVE_BY_EXPIRE);
892 }
893 else
894 target->ToUnit()->RemoveAurasDueToSpell(e.action.removeAura.spell);
895 }
896 else
897 target->ToUnit()->RemoveAllAuras();
898
899 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_REMOVEAURASFROMSPELL: Unit {}, spell {}",
900 target->GetGUID().ToString(), e.action.removeAura.spell);
901 }
902 break;
903 }
905 {
906 if (!IsSmart())
907 break;
908
909 if (targets.empty())
910 {
911 CAST_AI(SmartAI, me->AI())->StopFollow(false);
912 break;
913 }
914
915 for (WorldObject* target : targets)
916 {
917 if (IsUnit(target))
918 {
919 float angle = e.action.follow.angle > 6 ? (e.action.follow.angle * M_PI / 180.0f) : e.action.follow.angle;
920 CAST_AI(SmartAI, me->AI())->SetFollow(target->ToUnit(), float(e.action.follow.dist) + 0.1f, angle, e.action.follow.credit, e.action.follow.entry, e.action.follow.creditType, e.action.follow.aliveState);
921 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_FOLLOW: Creature {} following target {}",
922 me->GetGUID().ToString(), target->GetGUID().ToString());
923 break;
924 }
925 }
926 break;
927 }
929 {
930 if (!GetBaseObject())
931 break;
932
933 std::vector<uint32> phases;
934 std::copy_if(e.action.randomPhase.phases.begin(), e.action.randomPhase.phases.end(),
935 std::back_inserter(phases), [](uint32 phase) { return phase != 0; });
936
939 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_RANDOM_PHASE: Creature {} sets event phase to {}",
940 GetBaseObject()->GetGUID().ToString(), phase);
941 break;
942 }
944 {
945 if (!GetBaseObject())
946 break;
947
950 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_RANDOM_PHASE_RANGE: Creature {} sets event phase to {}",
951 GetBaseObject()->GetGUID().ToString(), phase);
952 break;
953 }
955 {
956 if (trigger && IsPlayer(unit))
957 {
959 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_CALL_KILLEDMONSTER: (trigger == true) Player {}, Killcredit: {}",
961 }
962 else if (e.target.type == SMART_TARGET_NONE || e.target.type == SMART_TARGET_SELF) // Loot recipient and his group members
963 {
964 if (!me)
965 break;
966
967 if (Player* player = me->GetLootRecipient())
968 {
970 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_CALL_KILLEDMONSTER: Player {}, Killcredit: {}",
972 }
973 }
974 else // Specific target type
975 {
976 for (WorldObject* target : targets)
977 {
978 if (!IsUnit(target))
979 continue;
980
982 if (!player)
983 continue;
984
986 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_CALL_KILLEDMONSTER: Player {}, Killcredit: {}",
987 target->GetGUID().ToString(), e.action.killedMonster.creature);
988 }
989 }
990 break;
991 }
993 {
994 WorldObject* obj = GetBaseObject();
995 if (!obj)
996 obj = unit;
997
998 if (!obj)
999 break;
1000
1001 InstanceScript* instance = obj->GetInstanceScript();
1002 if (!instance)
1003 {
1004 LOG_ERROR("scripts.ai.sai", "SmartScript: Event {} attempt to set instance data without instance script. EntryOrGuid {}", e.GetEventType(), e.entryOrGuid);
1005 break;
1006 }
1007
1008 switch (e.action.setInstanceData.type)
1009 {
1010 case 0:
1011 {
1013 LOG_DEBUG("scripts.ai.sai", "SmartScript::ProcessAction: SMART_ACTION_SET_INST_DATA: Field: {}, data: {}", e.action.setInstanceData.field, e.action.setInstanceData.data);
1014 } break;
1015 case 1:
1016 {
1018 LOG_DEBUG("scripts.ai.sai", "SmartScript::ProcessAction: SMART_ACTION_SET_INST_DATA: SetBossState BossId: {}, State: {} ({})", e.action.setInstanceData.field, e.action.setInstanceData.data, InstanceScript::GetBossStateName(e.action.setInstanceData.data));
1019 } break;
1020 default:
1021 {
1022 break;
1023 }
1024 }
1025 break;
1026 }
1028 {
1029 WorldObject* obj = GetBaseObject();
1030 if (!obj)
1031 obj = unit;
1032
1033 if (!obj)
1034 break;
1035
1036 InstanceScript* instance = obj->GetInstanceScript();
1037 if (!instance)
1038 {
1039 LOG_ERROR("sql.sql", "SmartScript: Event {} attempt to set instance data without instance script. EntryOrGuid {}", e.GetEventType(), e.entryOrGuid);
1040 break;
1041 }
1042
1043 if (targets.empty())
1044 break;
1045
1046 instance->SetGuidData(e.action.setInstanceData64.field, targets.front()->GetGUID());
1047 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_INST_DATA64: Field: {}, data: {}",
1048 e.action.setInstanceData64.field, targets.front()->GetGUID().ToString());
1049 break;
1050 }
1052 {
1053 for (WorldObject* target : targets)
1054 if (IsCreature(target))
1055 target->ToCreature()->UpdateEntry(e.action.updateTemplate.creature, target->ToCreature()->GetCreatureData(), e.action.updateTemplate.updateLevel != 0);
1056 break;
1057 }
1058 case SMART_ACTION_DIE:
1059 {
1060 if (me && !me->isDead())
1061 {
1062 me->KillSelf();
1063 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_DIE: Creature {}", me->GetGUID().ToString());
1064 }
1065 break;
1066 }
1068 {
1069 if (targets.empty())
1070 break;
1071
1072 if (!me->GetMap()->IsDungeon())
1073 {
1074 ObjectVector units;
1075 GetWorldObjectsInDist(units, static_cast<float>(e.target.unitRange.maxDist));
1076
1077 if (!units.empty() && GetBaseObject())
1078 for (WorldObject* unit : units)
1079 if (IsPlayer(unit) && !unit->ToPlayer()->isDead())
1080 {
1081 me->SetInCombatWith(unit->ToPlayer());
1082 unit->ToPlayer()->SetInCombatWith(me);
1083 me->AddThreat(unit->ToPlayer(), 0.0f);
1084 }
1085 }
1086 else
1087 {
1088 for (WorldObject* target : targets)
1089 {
1090 if (IsCreature(target))
1091 {
1092 target->ToCreature()->SetInCombatWithZone();
1093 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_IN_COMBAT_WITH_ZONE: Creature {}, target: {}",
1094 me->GetGUID().ToString(), target->GetGUID().ToString());
1095 }
1096 }
1097 }
1098
1099 break;
1100 }
1102 {
1103 for (WorldObject* target : targets)
1104 {
1105 if (IsCreature(target))
1106 {
1107 target->ToCreature()->CallForHelp(float(e.action.callHelp.range));
1109 {
1111 sCreatureTextMgr->SendChatPacket(target, builder, CHAT_MSG_MONSTER_EMOTE);
1112 }
1113 LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_FOR_HELP: Creature {}, target: {}",
1114 me->GetGUID().ToString(), target->GetGUID().ToString());
1115 }
1116 }
1117 break;
1118 }
1120 {
1121 if (me)
1122 {
1124 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: SMART_ACTION_SET_SHEATH: Creature {}, State: {}",
1126 }
1127 break;
1128 }
1130 {
1131 for (WorldObject* target : targets)
1132 {
1133 Milliseconds despawnDelay(e.action.forceDespawn.delay);
1134
1135 // Wait at least one world update tick before despawn, so it doesn't break linked actions.
1136 if (despawnDelay <= 0ms)
1137 {
1138 despawnDelay = 1ms;
1139 }
1140
1141 Seconds forceRespawnTimer(e.action.forceDespawn.forceRespawnTimer);
1142 if (Creature* creature = target->ToCreature())
1143 {
1144 creature->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
1145 }
1146 else if (GameObject* go = target->ToGameObject())
1147 {
1148 go->DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
1149 }
1150 }
1151
1152 break;
1153 }
1155 {
1156 for (WorldObject* target : targets)
1157 {
1158 if (IsUnit(target))
1159 target->ToUnit()->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
1160 else if (IsGameObject(target))
1161 target->ToGameObject()->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
1162 }
1163 break;
1164 }
1166 {
1167 for (WorldObject* target : targets)
1168 {
1169 if (!IsUnit(target))
1170 continue;
1171
1173 {
1174 if (e.action.morphOrMount.creature > 0)
1175 {
1176 if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(e.action.morphOrMount.creature))
1177 target->ToUnit()->Mount(ObjectMgr::ChooseDisplayId(cInfo));
1178 }
1179 else
1180 target->ToUnit()->Mount(e.action.morphOrMount.model);
1181 }
1182 else
1183 target->ToUnit()->Dismount();
1184 }
1185 break;
1186 }
1188 {
1189 for (WorldObject* target : targets)
1190 {
1191 if (IsCreature(target))
1192 {
1193 SmartAI* ai = CAST_AI(SmartAI, target->ToCreature()->AI());
1194 if (!ai)
1195 continue;
1196
1197 if (e.action.invincHP.percent)
1198 ai->SetInvincibilityHpLevel(target->ToCreature()->CountPctFromMaxHealth(e.action.invincHP.percent));
1199 else
1201 }
1202 }
1203 break;
1204 }
1206 {
1207 for (WorldObject* target : targets)
1208 {
1209 if (IsCreature(target))
1210 target->ToCreature()->AI()->SetData(e.action.setData.field, e.action.setData.data);
1211 else if (IsGameObject(target))
1212 target->ToGameObject()->AI()->SetData(e.action.setData.field, e.action.setData.data);
1213 }
1214 break;
1215 }
1217 {
1218 if (!me)
1219 break;
1220
1221 float x, y, z;
1222 me->GetClosePoint(x, y, z, me->GetObjectSize() / 3, (float)e.action.moveRandom.distance);
1224 break;
1225 }
1227 {
1228 if (!me)
1229 break;
1230
1232 break;
1233 }
1235 {
1236 for (WorldObject* target : targets)
1237 if (IsUnit(target))
1238 target->ToUnit()->SetVisible(!!e.action.visibility.state);
1239
1240 break;
1241 }
1243 {
1244 for (WorldObject* target : targets)
1245 target->setActive(!!e.action.setActive.state);
1246 break;
1247 }
1249 {
1250 if (!me)
1251 break;
1252
1253 if (targets.empty())
1254 break;
1255
1256 // attack random target
1257 if (Unit* target = Acore::Containers::SelectRandomContainerElement(targets)->ToUnit())
1258 me->AI()->AttackStart(target);
1259 break;
1260 }
1262 {
1263 for (WorldObject* target : targets)
1264 if (Unit* unitTarget = target->ToUnit())
1265 unitTarget->AttackStop();
1266 break;
1267 }
1269 {
1271 bool preferUnit = flags.HasFlag(SmartActionSummonCreatureFlags::PreferUnit);
1272 WorldObject* summoner = preferUnit ? unit : Coalesce<WorldObject>(GetBaseObject(), unit);
1273 if (!summoner)
1274 break;
1275
1276 bool personalSpawn = flags.HasFlag(SmartActionSummonCreatureFlags::PersonalSpawn);
1277
1279 {
1280 float range = (float)e.target.randomPoint.range;
1281 Position randomPoint;
1282 Position srcPos = { e.target.x, e.target.y, e.target.z, e.target.o };
1283 for (uint32 i = 0; i < e.target.randomPoint.amount; i++)
1284 {
1285 if (e.target.randomPoint.self > 0)
1286 randomPoint = me->GetRandomPoint(me->GetPosition(), range);
1287 else
1288 randomPoint = me->GetRandomPoint(srcPos, range);
1289 if (Creature* summon = summoner->SummonCreature(e.action.summonCreature.creature, randomPoint, (TempSummonType)e.action.summonCreature.type, e.action.summonCreature.duration, 0, nullptr, personalSpawn))
1290 {
1291 if (unit && e.action.summonCreature.attackInvoker)
1292 summon->AI()->AttackStart(unit);
1294 summon->AI()->AttackStart(me);
1295 }
1296 }
1297 break;
1298 }
1299
1300 float x, y, z, o;
1301 for (WorldObject* target : targets)
1302 {
1303 target->GetPosition(x, y, z, o);
1304 x += e.target.x;
1305 y += e.target.y;
1306 z += e.target.z;
1307 o += e.target.o;
1308 if (Creature* summon = summoner->SummonCreature(e.action.summonCreature.creature, x, y, z, o, (TempSummonType)e.action.summonCreature.type, e.action.summonCreature.duration, nullptr, personalSpawn))
1309 {
1310 if (e.action.summonCreature.attackInvoker == 2) // pussywizard: proper attackInvoker implementation
1311 summon->AI()->AttackStart(unit);
1313 summon->AI()->AttackStart(target->ToUnit());
1315 summon->AI()->AttackStart(me);
1316 }
1317 }
1318
1320 break;
1321
1323 {
1324 if (unit && e.action.summonCreature.attackInvoker)
1325 summon->AI()->AttackStart(unit);
1327 summon->AI()->AttackStart(me);
1328 }
1329 break;
1330 }
1332 {
1333 if (!GetBaseObject())
1334 break;
1335
1336 if (!targets.empty())
1337 {
1338 float x, y, z, o;
1339 for (WorldObject* target : targets)
1340 {
1341 // xinef: allow gameobjects to summon gameobjects!
1342 //if(!IsUnit((*itr)))
1343 // continue;
1344
1345 target->GetPosition(x, y, z, o);
1346 x += e.target.x;
1347 y += e.target.y;
1348 z += e.target.z;
1349 o += e.target.o;
1352 else
1353 target->SummonGameObject(e.action.summonGO.entry, GetBaseObject()->GetPositionX(), GetBaseObject()->GetPositionY(), GetBaseObject()->GetPositionZ(), GetBaseObject()->GetOrientation(), 0, 0, 0, 0, e.action.summonGO.despawnTime);
1354 }
1355 }
1356
1358 break;
1359
1361 break;
1362 }
1364 {
1365 for (WorldObject* target : targets)
1366 {
1367 if (!IsUnit(target))
1368 continue;
1369
1370 Unit::Kill(target->ToUnit(), target->ToUnit());
1371 }
1372
1373 break;
1374 }
1376 {
1377 InstallTemplate(e);
1378 break;
1379 }
1381 {
1382 for (WorldObject* target : targets)
1383 {
1384 if (!IsPlayer(target))
1385 continue;
1386
1387 target->ToPlayer()->AddItem(e.action.item.entry, e.action.item.count);
1388 }
1389 break;
1390 }
1392 {
1393 for (WorldObject* target : targets)
1394 {
1395 if (!IsPlayer(target))
1396 continue;
1397
1398 target->ToPlayer()->DestroyItemCount(e.action.item.entry, e.action.item.count, true);
1399 }
1400 break;
1401 }
1403 {
1405 break;
1406 }
1408 {
1409 for (WorldObject* target : targets)
1410 {
1411 if (IsPlayer(target))
1412 target->ToPlayer()->TeleportTo(e.action.teleport.mapID, e.target.x, e.target.y, e.target.z, e.target.o);
1413 else if (IsCreature(target))
1414 target->ToCreature()->NearTeleportTo(e.target.x, e.target.y, e.target.z, e.target.o);
1415 }
1416 break;
1417 }
1419 {
1420 if (!IsSmart())
1421 break;
1422
1423 CAST_AI(SmartAI, me->AI())->SetFly(e.action.setFly.fly);
1424 // Xinef: Set speed if any
1425 if (e.action.setFly.speed)
1426 me->SetSpeed(MOVE_RUN, float(e.action.setFly.speed / 100.0f), true);
1427
1428 // Xinef: this wil be executed only if state is different
1430 break;
1431 }
1433 {
1434 for (WorldObject* target : targets)
1435 {
1436 if (IsCreature(target))
1437 {
1438 if (IsSmart(target->ToCreature()))
1439 CAST_AI(SmartAI, target->ToCreature()->AI())->SetRun(e.action.setRun.run);
1440 else
1441 target->ToCreature()->SetWalk(e.action.setRun.run ? false : true); // Xinef: reversed
1442 }
1443 }
1444
1445 break;
1446 }
1448 {
1449 if (!IsSmart())
1450 break;
1451
1452 CAST_AI(SmartAI, me->AI())->SetSwim(e.action.setSwim.swim);
1453 break;
1454 }
1456 {
1457 if (!targets.empty())
1458 {
1459 for (WorldObject* target : targets)
1460 {
1461 if (IsCreature(target))
1462 {
1463 if (SmartAI* ai = CAST_AI(SmartAI, target->ToCreature()->AI()))
1465 else
1466 LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SET_COUNTER is not using SmartAI, skipping");
1467 }
1468 else if (IsGameObject(target))
1469 {
1470 if (SmartGameObjectAI* ai = CAST_AI(SmartGameObjectAI, target->ToGameObject()->AI()))
1472 else
1473 LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SET_COUNTER is not using SmartGameObjectAI, skipping");
1474 }
1475 }
1476 }
1477 else
1479 break;
1480 }
1482 {
1483 if (!IsSmart())
1484 break;
1485
1486 bool run = e.action.wpStart.run != 0;
1487 uint32 entry = e.action.wpStart.pathID;
1488 bool repeat = e.action.wpStart.repeat != 0;
1489
1490 for (WorldObject* target : targets)
1491 {
1492 if (IsPlayer(target))
1493 {
1495 break;
1496 }
1497 }
1498
1500 CAST_AI(SmartAI, me->AI())->StartPath(run, entry, repeat, unit);
1501
1502 uint32 quest = e.action.wpStart.quest;
1503 uint32 DespawnTime = e.action.wpStart.despawnTime;
1504 CAST_AI(SmartAI, me->AI())->mEscortQuestID = quest;
1505 CAST_AI(SmartAI, me->AI())->SetDespawnTime(DespawnTime);
1506 break;
1507 }
1509 {
1510 if (!IsSmart())
1511 break;
1512
1513 uint32 delay = e.action.wpPause.delay;
1514 CAST_AI(SmartAI, me->AI())->PausePath(delay, e.GetEventType() == SMART_EVENT_WAYPOINT_REACHED ? false : true);
1515 break;
1516 }
1518 {
1519 if (!IsSmart())
1520 break;
1521
1522 uint32 DespawnTime = e.action.wpStop.despawnTime;
1523 uint32 quest = e.action.wpStop.quest;
1524 bool fail = e.action.wpStop.fail;
1525 CAST_AI(SmartAI, me->AI())->StopPath(DespawnTime, quest, fail);
1526 break;
1527 }
1529 {
1530 if (!IsSmart())
1531 break;
1532
1533 CAST_AI(SmartAI, me->AI())->SetWPPauseTimer(0);
1534 break;
1535 }
1537 {
1538 if (!me)
1539 break;
1540
1541 if (e.action.orientation.random > 0)
1542 {
1543 float randomOri = frand(0.0f, 2 * M_PI);
1544 me->SetFacingTo(randomOri);
1546 me->SetOrientation(randomOri);
1547 break;
1548 }
1549
1551 {
1555 }
1556 else if (e.GetTargetType() == SMART_TARGET_POSITION)
1557 {
1558 me->SetFacingTo(e.target.o);
1561 }
1562 else if (!targets.empty())
1563 {
1564 me->SetFacingToObject(*targets.begin());
1566 me->SetInFront(*targets.begin());
1567 }
1568
1569 break;
1570 }
1572 {
1573 for (WorldObject* target : targets)
1574 {
1575 if (!IsPlayer(target))
1576 continue;
1577
1578 target->ToPlayer()->SendMovieStart(e.action.movie.entry);
1579 }
1580 break;
1581 }
1583 {
1584 if (!IsSmart())
1585 break;
1586
1587 WorldObject* target = nullptr;
1588
1590 {
1591 if (me)
1592 {
1593 float range = (float)e.target.randomPoint.range;
1594 Position srcPos = { e.target.x, e.target.y, e.target.z, e.target.o };
1595 Position randomPoint = me->GetRandomPoint(srcPos, range);
1598 randomPoint.m_positionX,
1599 randomPoint.m_positionY,
1600 randomPoint.m_positionZ,
1601 true,
1602 true,
1604 );
1605 }
1606
1607 break;
1608 }
1609
1610 /*if (e.GetTargetType() == SMART_TARGET_CREATURE_RANGE || e.GetTargetType() == SMART_TARGET_CREATURE_GUID ||
1611 e.GetTargetType() == SMART_TARGET_CREATURE_DISTANCE || e.GetTargetType() == SMART_TARGET_GAMEOBJECT_RANGE ||
1612 e.GetTargetType() == SMART_TARGET_GAMEOBJECT_GUID || e.GetTargetType() == SMART_TARGET_GAMEOBJECT_DISTANCE ||
1613 e.GetTargetType() == SMART_TARGET_CLOSEST_CREATURE || e.GetTargetType() == SMART_TARGET_CLOSEST_GAMEOBJECT ||
1614 e.GetTargetType() == SMART_TARGET_OWNER_OR_SUMMONER || e.GetTargetType() == SMART_TARGET_ACTION_INVOKER ||
1615 e.GetTargetType() == SMART_TARGET_CLOSEST_ENEMY || e.GetTargetType() == SMART_TARGET_CLOSEST_FRIENDLY ||
1616 e.GetTargetType() == SMART_TARGET_SELF || e.GetTargetType() == SMART_TARGET_STORED) // Xinef: bieda i rozpierdol TC)*/
1617 {
1618 // we want to move to random element
1619 if (!targets.empty())
1621 }
1622
1623 if (!target)
1624 {
1625 G3D::Vector3 dest(e.target.x, e.target.y, e.target.z);
1627 if (TransportBase* trans = me->GetDirectTransport())
1628 trans->CalculatePassengerPosition(dest.x, dest.y, dest.z);
1629
1630 me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, dest.x, dest.y, dest.z, true, true,
1632 }
1633 else // Xinef: we can use dest.x, dest.y, dest.z to make offset
1634 {
1635 float x, y, z;
1636 target->GetPosition(x, y, z);
1638 target->GetContactPoint(me, x, y, z, e.action.moveToPos.ContactDistance);
1639 me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, x + e.target.x, y + e.target.y, z + e.target.z, true, true, isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE);
1640 }
1641 break;
1642 }
1644 {
1645 for (WorldObject* target : targets)
1646 {
1647 if (IsCreature(target))
1648 {
1649 Creature* ctarget = target->ToCreature();
1650 ctarget->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, e.target.x, e.target.y, e.target.z, true, true, isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE);
1651 }
1652 }
1653
1654 break;
1655 }
1657 {
1658 for (WorldObject* target : targets)
1659 {
1660 if (IsCreature(target))
1661 target->ToCreature()->Respawn();
1662 else if (IsGameObject(target))
1663 {
1664 // do not modify respawndelay of already spawned gameobjects
1665 if (target->ToGameObject()->isSpawnedByDefault())
1666 target->ToGameObject()->Respawn();
1667 else
1669 }
1670 }
1671 break;
1672 }
1674 {
1675 for (WorldObject* target : targets)
1676 if (IsPlayer(target))
1678 break;
1679 }
1680 case SMART_ACTION_EQUIP:
1681 {
1682 for (WorldObject* target : targets)
1683 {
1684 if (Creature* npc = target->ToCreature())
1685 {
1686 std::array<uint32, MAX_EQUIPMENT_ITEMS> slot;
1687 if (int8 equipId = static_cast<int8>(e.action.equip.entry))
1688 {
1689 EquipmentInfo const* eInfo = sObjectMgr->GetEquipmentInfo(npc->GetEntry(), equipId);
1690 if (!eInfo)
1691 {
1692 LOG_ERROR("sql.sql", "SmartScript: SMART_ACTION_EQUIP uses non-existent equipment info id {} for creature {}", equipId, npc->GetEntry());
1693 break;
1694 }
1695
1696 npc->SetCurrentEquipmentId(equipId);
1697
1698 std::copy(std::begin(eInfo->ItemEntry), std::end(eInfo->ItemEntry), std::begin(slot));
1699 }
1700 else
1701 std::copy(std::begin(e.action.equip.slots), std::end(e.action.equip.slots), std::begin(slot));
1702
1703 for (uint32 i = 0; i < MAX_EQUIPMENT_ITEMS; ++i)
1704 if (!e.action.equip.mask || (e.action.equip.mask & (1 << i)))
1705 npc->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i, slot[i]);
1706 }
1707 }
1708 break;
1709 }
1711 {
1712 SmartEvent ne = SmartEvent();
1715 if (!ne.event_chance) ne.event_chance = 100;
1716
1721
1722 ne.event_flags = 0;
1725
1726 SmartAction ac = SmartAction();
1729
1731 ev.event = ne;
1732 ev.event_id = e.action.timeEvent.id;
1733 ev.target = e.target;
1734 ev.action = ac;
1735 InitTimer(ev);
1736 mStoredEvents.push_back(ev);
1737 break;
1738 }
1741
1742 // xinef: remove this event if not repeatable
1744 mRemIDs.push_back(e.action.timeEvent.id);
1745 break;
1747 mRemIDs.push_back(e.action.timeEvent.id);
1748 break;
1750 {
1751 for (WorldObject* target : targets)
1752 {
1753 if (IsCreature(target))
1754 {
1755 if (!meOrigGUID)
1757 if (!goOrigGUID)
1759 go = nullptr;
1760 me = target->ToCreature();
1761 break;
1762 }
1763 else if (IsGameObject(target))
1764 {
1765 if (!meOrigGUID)
1767 if (!goOrigGUID)
1769 go = target->ToGameObject();
1770 me = nullptr;
1771 break;
1772 }
1773 }
1774
1775 break;
1776 }
1779 break;
1781 OnReset();
1782 break;
1784 {
1785 if (!IsSmart())
1786 break;
1787
1788 float attackDistance = float(e.action.setRangedMovement.distance);
1789 float attackAngle = float(e.action.setRangedMovement.angle) / 180.0f * float(M_PI);
1790
1791 for (WorldObject* target : targets)
1792 if (Creature* creature = target->ToCreature())
1793 if (IsSmart(creature) && creature->GetVictim())
1794 if (CAST_AI(SmartAI, creature->AI())->CanCombatMove())
1795 creature->GetMotionMaster()->MoveChase(creature->GetVictim(), attackDistance, attackAngle);
1796
1797 break;
1798 }
1800 {
1802 {
1803 LOG_ERROR("sql.sql", "SmartScript: Entry {} SourceType {} Event {} Action {} is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1804 break;
1805 }
1806
1807 for (WorldObject* target : targets)
1808 {
1809 if (Creature* creature = target->ToCreature())
1810 {
1811 if (IsSmart(creature))
1812 CAST_AI(SmartAI, creature->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());
1813 }
1814 else if (GameObject* go = target->ToGameObject())
1815 {
1816 if (IsSmartGO(go))
1818 }
1819 }
1820 break;
1821 }
1823 {
1824 for (WorldObject* target : targets)
1825 if (IsCreature(target))
1827 break;
1828 }
1830 {
1831 for (WorldObject* target : targets)
1832 if (IsCreature(target))
1834 break;
1835 }
1837 {
1838 for (WorldObject* target : targets)
1839 if (IsCreature(target))
1841 break;
1842 }
1844 {
1845 if (targets.empty())
1846 break;
1847
1848 ObjectVector casters;
1850
1851 for (WorldObject* caster : casters)
1852 {
1853 if (!IsUnit(caster))
1854 continue;
1855
1856 Unit* casterUnit = caster->ToUnit();
1857
1858 bool interruptedSpell = false;
1859
1860 for (WorldObject* target : targets)
1861 {
1862 if (!IsUnit(target))
1863 continue;
1864
1866 {
1867 if (!interruptedSpell && e.action.crossCast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
1868 {
1869 casterUnit->InterruptNonMeleeSpells(false);
1870 interruptedSpell = true;
1871 }
1872
1873 casterUnit->CastSpell(target->ToUnit(), e.action.crossCast.spell, (e.action.crossCast.flags & SMARTCAST_TRIGGERED) != 0);
1874 }
1875 else
1876 LOG_DEBUG("scripts.ai", "Spell {} not cast because it has flag SMARTCAST_AURA_NOT_PRESENT and the target ({}) already has the aura", e.action.crossCast.spell, target->GetGUID().ToString());
1877 }
1878 }
1879 break;
1880 }
1882 {
1883 std::vector<uint32> actionLists;
1885 std::back_inserter(actionLists), [](uint32 actionList) { return actionList != 0; });
1886
1889 {
1890 LOG_ERROR("sql.sql", "SmartScript: Entry {} SourceType {} Event {} Action {} is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1891 break;
1892 }
1893
1894 for (WorldObject* target : targets)
1895 {
1896 if (Creature* creature = target->ToCreature())
1897 {
1898 if (IsSmart(creature))
1899 CAST_AI(SmartAI, creature->AI())->SetScript9(e, id, GetLastInvoker());
1900 }
1901 else if (GameObject* go = target->ToGameObject())
1902 {
1903 if (IsSmartGO(go))
1904 CAST_AI(SmartGameObjectAI, go->AI())->SetScript9(e, id, GetLastInvoker());
1905 }
1906 }
1907 break;
1908 }
1910 {
1913 {
1914 LOG_ERROR("sql.sql", "SmartScript: Entry {} SourceType {} Event {} Action {} is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1915 break;
1916 }
1917
1918 for (WorldObject* target : targets)
1919 {
1920 if (Creature* creature = target->ToCreature())
1921 {
1922 if (IsSmart(creature))
1923 CAST_AI(SmartAI, creature->AI())->SetScript9(e, id, GetLastInvoker());
1924 }
1925 else if (GameObject* go = target->ToGameObject())
1926 {
1927 if (IsSmartGO(go))
1928 CAST_AI(SmartGameObjectAI, go->AI())->SetScript9(e, id, GetLastInvoker());
1929 }
1930 }
1931 break;
1932 }
1934 {
1935 for (WorldObject* target : targets)
1936 if (IsPlayer(target))
1938 break;
1939 }
1941 {
1942 bool foundTarget = false;
1943
1944 for (WorldObject* target : targets)
1945 {
1946 if (IsCreature((target)))
1947 {
1948 foundTarget = true;
1949
1952 else
1953 target->ToCreature()->GetMotionMaster()->MoveIdle();
1954 }
1955 }
1956
1957 if (!foundTarget && me && IsCreature(me) && me->IsAlive())
1958 {
1961 else
1963 }
1964 break;
1965 }
1967 {
1968 for (WorldObject* target : targets)
1969 if (IsUnit(target))
1971 break;
1972 }
1974 {
1975 for (WorldObject* target : targets)
1976 if (IsUnit(target))
1978 break;
1979 }
1981 {
1982 for (WorldObject* target : targets)
1983 if (IsUnit(target))
1985 break;
1986 }
1988 {
1989 for (WorldObject* target : targets)
1990 if (IsGameObject(target))
1992 break;
1993 }
1995 {
1996 for (WorldObject* target : targets)
1997 if (IsUnit(target))
1999 break;
2000 }
2002 {
2003 for (WorldObject* target : targets)
2004 if (IsUnit(target))
2006 break;
2007 }
2009 {
2010 for (WorldObject* target : targets)
2011 if (IsUnit(target))
2013 break;
2014 }
2016 {
2018 {
2019 if (me)
2020 {
2021 float range = (float)e.target.randomPoint.range;
2022 Position srcPos = { e.target.x, e.target.y, e.target.z, e.target.o };
2023 Position randomPoint = me->GetRandomPoint(srcPos, range);
2024 me->GetMotionMaster()->MoveJump(randomPoint, (float)e.action.jump.speedxy, (float)e.action.jump.speedz);
2025 }
2026
2027 break;
2028 }
2029
2030 if (targets.empty())
2031 break;
2032
2033 // xinef: my implementation
2034 if (e.action.jump.selfJump)
2035 {
2037 if (me)
2038 me->GetMotionMaster()->MoveJump(target->GetPositionX() + e.target.x, target->GetPositionY() + e.target.y, target->GetPositionZ() + e.target.z, (float)e.action.jump.speedxy, (float)e.action.jump.speedz);
2039 }
2040 else
2041 {
2042 for (WorldObject* target : targets)
2043 if (WorldObject* obj = (target))
2044 {
2045 if (Creature* creature = obj->ToCreature())
2046 creature->GetMotionMaster()->MoveJump(e.target.x, e.target.y, e.target.z, (float)e.action.jump.speedxy, (float)e.action.jump.speedz);
2047 }
2048 }
2049
2050 break;
2051 }
2053 {
2054 for (WorldObject* target : targets)
2055 if (IsGameObject(target))
2057 break;
2058 }
2060 {
2061 for (WorldObject* target : targets)
2062 if (IsGameObject(target))
2064 break;
2065 }
2067 {
2068 WorldObject* ref = GetBaseObject();
2069
2070 if (!ref)
2071 ref = unit;
2072
2073 if (!ref)
2074 break;
2075
2076 ObjectVector const* storedTargets = GetStoredTargetVector(e.action.sendTargetToTarget.id, *ref);
2077 if (!storedTargets)
2078 break;
2079
2080 for (WorldObject* target : targets)
2081 {
2082 if (IsCreature(target))
2083 {
2084 if (SmartAI* ai = CAST_AI(SmartAI, target->ToCreature()->AI()))
2085 ai->GetScript()->StoreTargetList(ObjectVector(*storedTargets), e.action.sendTargetToTarget.id); // store a copy of target list
2086 else
2087 LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SEND_TARGET_TO_TARGET is not using SmartAI, skipping");
2088 }
2089 else if (IsGameObject(target))
2090 {
2092 ai->GetScript()->StoreTargetList(ObjectVector(*storedTargets), e.action.sendTargetToTarget.id); // store a copy of target list
2093 else
2094 LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SEND_TARGET_TO_TARGET is not using SmartGameObjectAI, skipping");
2095 }
2096 }
2097 break;
2098 }
2100 {
2101 if (!GetBaseObject())
2102 break;
2103
2104 LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_SEND_GOSSIP_MENU: gossipMenuId {}, gossipNpcTextId {}",
2106
2107 for (WorldObject* target : targets)
2108 if (Player* player = target->ToPlayer())
2109 {
2112 else
2113 ClearGossipMenuFor(player);
2114
2116 }
2117
2118 break;
2119 }
2121 {
2122 if (!targets.empty())
2123 {
2124 float x, y, z, o;
2125 for (WorldObject* target : targets)
2126 if (IsCreature(target))
2127 {
2129 {
2130 target->ToCreature()->GetRespawnPosition(x, y, z, &o);
2131 target->ToCreature()->SetHomePosition(x, y, z, o);
2132 }
2133 else
2134 target->ToCreature()->SetHomePosition(target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation());
2135 }
2136 }
2137 else if (me && e.GetTargetType() == SMART_TARGET_POSITION)
2138 {
2140 {
2141 float x, y, z, o;
2142 me->GetRespawnPosition(x, y, z, &o);
2143 me->SetHomePosition(x, y, z, o);
2144 }
2145 else
2147 }
2148 break;
2149 }
2151 {
2152 for (WorldObject* target : targets)
2153 if (IsCreature(target))
2155
2156 break;
2157 }
2159 {
2160 for (WorldObject* target : targets)
2161 if (IsCreature(target))
2163 break;
2164 }
2166 {
2167 for (WorldObject* target : targets)
2168 if (IsGameObject(target))
2170 break;
2171 }
2173 {
2174 for (WorldObject* target : targets)
2175 if (IsGameObject(target))
2177 break;
2178 }
2180 {
2181 for (WorldObject* target : targets)
2182 if (IsGameObject(target))
2184 break;
2185 }
2187 {
2188 std::list<TempSummon*> summonList;
2190
2191 for (std::list<TempSummon*>::const_iterator itr = summonList.begin(); itr != summonList.end(); ++itr)
2192 {
2193 if (unit && e.action.creatureGroup.attackInvoker)
2194 (*itr)->AI()->AttackStart(unit);
2196 (*itr)->AI()->AttackStart(me);
2197 }
2198
2199 break;
2200 }
2202 {
2203 for (WorldObject* target : targets)
2204 if (IsUnit(target))
2206 break;
2207 }
2209 {
2210 for (WorldObject* target : targets)
2211 if (IsUnit(target))
2213 break;
2214 }
2216 {
2217 for (WorldObject* target : targets)
2218 if (IsUnit(target))
2220 break;
2221 }
2223 {
2224 uint32 eventId = e.action.gameEventStop.id;
2225 if (!sGameEventMgr->IsActiveEvent(eventId))
2226 {
2227 LOG_ERROR("scripts.ai.sai", "SmartScript::ProcessAction: At case SMART_ACTION_GAME_EVENT_STOP, inactive event (id: {})", eventId);
2228 break;
2229 }
2230 sGameEventMgr->StopEvent(eventId, true);
2231 break;
2232 }
2234 {
2235 uint32 eventId = e.action.gameEventStart.id;
2236 if (sGameEventMgr->IsActiveEvent(eventId))
2237 {
2238 LOG_ERROR("scripts.ai.sai", "SmartScript::ProcessAction: At case SMART_ACTION_GAME_EVENT_START, already activated event (id: {})", eventId);
2239 break;
2240 }
2241 sGameEventMgr->StartEvent(eventId, true);
2242 break;
2243 }
2245 {
2246 std::vector<uint32> waypoints;
2247 std::copy_if(e.action.closestWaypointFromList.wps.begin(), e.action.closestWaypointFromList.wps.end(),
2248 std::back_inserter(waypoints), [](uint32 wp) { return wp != 0; });
2249
2250 float distanceToClosest = std::numeric_limits<float>::max();
2251 WayPoint* closestWp = nullptr;
2252
2253 for (WorldObject* target : targets)
2254 {
2255 if (Creature* creature = target->ToCreature())
2256 {
2257 if (IsSmart(creature))
2258 {
2259 for (uint32 wp : waypoints)
2260 {
2261 WPPath* path = sSmartWaypointMgr->GetPath(wp);
2262 if (!path || path->empty())
2263 continue;
2264
2265 auto itrWp = path->find(0);
2266 if (itrWp != path->end())
2267 {
2268 if (WayPoint* wp = itrWp->second)
2269 {
2270 float distToThisPath = creature->GetDistance(wp->x, wp->y, wp->z);
2271 if (distToThisPath < distanceToClosest)
2272 {
2273 distanceToClosest = distToThisPath;
2274 closestWp = wp;
2275 }
2276 }
2277 }
2278 }
2279
2280 if (closestWp)
2281 CAST_AI(SmartAI, creature->AI())->StartPath(false, closestWp->id, true);
2282 }
2283 }
2284 }
2285 break;
2286 }
2288 {
2289 for (WorldObject* target : targets)
2290 if (IsGameObject(target))
2292
2293 break;
2294 }
2296 {
2297 for (WorldObject* target : targets)
2298 if (IsUnit(target))
2299 target->ToUnit()->ExitVehicle();
2300
2301 break;
2302 }
2304 {
2305 for (WorldObject* target : targets)
2306 if (IsUnit(target))
2307 {
2309 target->ToUnit()->SendMovementFlagUpdate();
2310 }
2311
2312 break;
2313 }
2315 {
2316 for (WorldObject* target : targets)
2317 if (IsCreature(target))
2319
2320 break;
2321 }
2323 {
2326 else
2328
2331 break;
2332 }
2334 {
2335 for (WorldObject* const target : targets)
2336 if (IsCreature(target))
2338 break;
2339 }
2340 case SMART_ACTION_FLEE:
2341 {
2342 for (WorldObject* const target : targets)
2343 if (IsCreature(target))
2345 break;
2346 }
2348 {
2349 for (WorldObject* const target : targets)
2350 if (IsUnit(target))
2351 me->AddThreat(target->ToUnit(), float(e.action.threatPCT.threatINC) - float(e.action.threatPCT.threatDEC));
2352 break;
2353 }
2355 {
2356 for (WorldObject* const target : targets)
2357 if (IsCreature(target))
2359 break;
2360 }
2362 {
2365 break;
2366 }
2368 {
2369 for (WorldObject* target : targets)
2370 if (IsUnit(target))
2371 target->ToUnit()->SetHover(e.action.setHover.state);
2372 break;
2373 }
2375 {
2376 for (WorldObject* target : targets)
2377 if (IsUnit(target))
2379
2380 break;
2381 }
2383 {
2384 for (WorldObject* target : targets)
2385 if (IsUnit(target))
2387 break;
2388 }
2389 case SMART_ACTION_FALL:
2390 {
2391 for (WorldObject* target : targets)
2392 if (IsUnit(target))
2393 target->ToUnit()->GetMotionMaster()->MoveFall();
2394
2395 break;
2396 }
2398 {
2400 break;
2401 }
2403 {
2404 for (WorldObject* const target : targets)
2405 if (IsUnit(target))
2406 target->ToUnit()->RemoveAllGameObjects();
2407 break;
2408 }
2410 {
2411 for (WorldObject* const target : targets)
2412 {
2413 if (IsUnit(target))
2414 {
2416 target->ToUnit()->StopMoving();
2418 target->ToUnit()->GetMotionMaster()->MovementExpired();
2419 }
2420 }
2421 break;
2422 }
2424 {
2425 for (WorldObject* target : targets)
2426 if (IsUnit(target))
2428
2429 break;
2430 }
2432 {
2433 for (WorldObject* target : targets)
2434 if (IsUnit(target))
2435 if (Player* player = target->ToUnit()->GetCharmerOrOwnerPlayerOrPlayerItself())
2436 {
2438 break;
2439 }
2440
2441 break;
2442 }
2444 {
2445 if (me && me->FindMap())
2446 me->FindMap()->LoadGrid(e.target.x, e.target.y);
2447 break;
2448 }
2450 {
2451 char const* text = sObjectMgr->GetAcoreString(e.action.playerTalk.textId, DEFAULT_LOCALE);
2452
2453 if (!targets.empty())
2454 for (WorldObject* target : targets)
2455 if (IsPlayer(target))
2456 !e.action.playerTalk.flag ? target->ToPlayer()->Say(text, LANG_UNIVERSAL) : target->ToPlayer()->Yell(text, LANG_UNIVERSAL);
2457
2458 break;
2459 }
2461 {
2462 if (!me)
2463 break;
2464
2465 for (WorldObject* target : targets)
2466 {
2467 if (IsUnit(target))
2468 {
2471
2473 {
2474 // If cast flag SMARTCAST_COMBAT_MOVE is set combat movement will not be allowed
2475 // unless target is outside spell range, out of mana, or LOS.
2476
2477 bool _allowMove = false;
2478 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(e.action.castCustom.spell); // AssertSpellInfo?
2479 int32 mana = me->GetPower(POWER_MANA);
2480
2481 if (me->GetDistance(target->ToUnit()) > spellInfo->GetMaxRange(true) ||
2482 me->GetDistance(target->ToUnit()) < spellInfo->GetMinRange(true) ||
2483 !me->IsWithinLOSInMap(target->ToUnit()) ||
2484 mana < spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask()))
2485 _allowMove = true;
2486
2487 CAST_AI(SmartAI, me->AI())->SetCombatMove(_allowMove);
2488 }
2489
2491 {
2492 CustomSpellValues values;
2493 if (e.action.castCustom.bp1)
2495 if (e.action.castCustom.bp2)
2497 if (e.action.castCustom.bp3)
2500 }
2501 }
2502 }
2503 break;
2504 }
2506 {
2507 if (!me)
2508 break;
2509
2510 if (targets.empty())
2511 break;
2512
2514
2515 float a = static_cast<float>(e.action.summonVortex.a);
2516 float k = static_cast<float>(e.action.summonVortex.k) / 1000.0f;
2517 float r_max = static_cast<float>(e.action.summonVortex.r_max);
2518 float delta_phi = M_PI * static_cast<float>(e.action.summonVortex.phi_delta) / 180.0f;
2519
2520 // r(phi) = a * e ^ (k * phi)
2521 // r(phi + delta_phi) = a * e ^ (k * (phi + delta_phi))
2522 // r(phi + delta_phi) = a * e ^ (k * phi) * e ^ (k * delta_phi)
2523 // r(phi + delta_phi) = r(phi) * e ^ (k * delta_phi)
2524 float factor = std::exp(k * delta_phi);
2525
2526 // r(0) = a * e ^ (k * 0) = a * e ^ 0 = a * 1 = a
2527 float summonRadius = a;
2528
2529 for (WorldObject* target : targets)
2530 {
2531 // Offset by orientation, should not count into radius calculation,
2532 // but is needed for vortex direction (polar coordinates)
2533 float phi = target->GetOrientation();
2534
2535 do
2536 {
2537 Position summonPosition(*target);
2538 summonPosition.RelocatePolarOffset(phi, summonRadius);
2539
2541
2542 phi += delta_phi;
2543 summonRadius *= factor;
2544 } while (summonRadius <= r_max);
2545 }
2546
2547 break;
2548 }
2550 {
2551 if (!me)
2552 break;
2553
2555
2556 float distInARow = static_cast<float>(e.action.coneSummon.distanceBetweenSummons);
2557 float coneAngle = static_cast<float>(e.action.coneSummon.coneAngle) * M_PI / 180.0f;
2558
2559 for (uint32 radius = 0; radius <= e.action.coneSummon.coneLength; radius += e.action.coneSummon.distanceBetweenRings)
2560 {
2561 float deltaAngle = 0.0f;
2562 if (radius > 0)
2563 deltaAngle = distInARow / radius;
2564
2565 uint32 count = 1;
2566 if (deltaAngle > 0)
2567 count += coneAngle / deltaAngle;
2568
2569 float currentAngle = -static_cast<float>(count) * deltaAngle / 2.0f;
2570
2572 currentAngle += G3D::fuzzyGt(e.target.o, 0.0f) ? (e.target.o - me->GetOrientation()) : 0.0f;
2573 else if (!targets.empty())
2574 {
2575 currentAngle += (me->GetAngle(targets.front()) - me->GetOrientation());
2576 }
2577
2578 for (uint32 index = 0; index < count; ++index)
2579 {
2580 Position spawnPosition(*me);
2581 spawnPosition.RelocatePolarOffset(currentAngle, radius);
2582 currentAngle += deltaAngle;
2583
2585 }
2586 }
2587
2588 break;
2589 }
2591 {
2592 for (WorldObject* target : targets)
2593 {
2594 if (Player* playerTarget = target->ToPlayer())
2595 {
2596 playerTarget->RemoveArenaSpellCooldowns();
2597 playerTarget->RemoveAurasDueToSpell(57724); // Spell Shaman Debuff - Sated (Heroism)
2598 playerTarget->RemoveAurasDueToSpell(57723); // Spell Shaman Debuff - Exhaustion (Bloodlust)
2599 playerTarget->RemoveAurasDueToSpell(2825); // Bloodlust
2600 playerTarget->RemoveAurasDueToSpell(32182); // Heroism
2601 }
2602 }
2603
2604 break;
2605 }
2607 {
2610 {
2611 if (targets.empty())
2612 break;
2613
2614 for (WorldObject* objTarget : targets)
2615 {
2616 if (Creature const* unitTarget = objTarget->ToCreature())
2617 {
2618 if (unitTarget->IsAIEnabled)
2619 {
2620 unitTarget->AI()->DoAction(actionId);
2621 }
2622 }
2623 else if (GameObject const* gobjTarget = objTarget->ToGameObject())
2624 {
2625 gobjTarget->AI()->DoAction(actionId);
2626 }
2627 }
2628
2629 }
2630 else
2631 {
2632 InstanceScript* instanceScript = nullptr;
2633 if (WorldObject* baseObj = GetBaseObject())
2634 {
2635 instanceScript = baseObj->GetInstanceScript();
2636 }
2637 // Action is triggered by AreaTrigger
2638 else if (trigger && IsPlayer(unit))
2639 {
2640 instanceScript = unit->GetInstanceScript();
2641 }
2642
2643 if (instanceScript)
2644 {
2645 instanceScript->DoAction(actionId);
2646 }
2647 }
2648 break;
2649 }
2651 {
2652 if (!IsSmart())
2653 break;
2654
2655 CAST_AI(SmartAI, me->AI())->SetEvadeDisabled(e.action.disableEvade.disable != 0);
2656 break;
2657 }
2659 {
2660 for (WorldObject* const target : targets)
2661 {
2662 if (IsCreature(target))
2664 }
2665 break;
2666 }
2668 {
2669 for (WorldObject* target : targets)
2670 if (Unit* targetUnit = target->ToUnit())
2671 targetUnit->SetHealth(targetUnit->CountPctFromMaxHealth(e.action.setHealthPct.percent));
2672 break;
2673 }
2675 {
2676 uint32 speedInteger = e.action.movementSpeed.speedInteger;
2677 uint32 speedFraction = e.action.movementSpeed.speedFraction;
2678 float speed = float(speedInteger) + float(speedFraction) / std::pow(10, std::floor(std::log10(float(speedFraction ? speedFraction : 1)) + 1));
2679
2680 for (WorldObject* target : targets)
2681 if (IsCreature(target))
2683
2684 break;
2685 }
2687 {
2688 for (WorldObject* target : targets)
2689 {
2690 if (!IsPlayer(target))
2691 continue;
2692
2694 }
2695 break;
2696 }
2697 default:
2698 LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Unhandled Action type {}", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
2699 break;
2700 }
2701
2702 if (e.link && e.link != e.event_id)
2703 {
2705 if (linked.GetActionType() && linked.GetEventType() == SMART_EVENT_LINK)
2706 ProcessEvent(linked, unit, var0, var1, bvar, spell, gob);
2707 else
2708 LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Link Event {} not found or invalid, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.link);
2709 }
2710}
#define DEFAULT_LOCALE
Definition: Common.h:88
std::int8_t int8
Definition: Define.h:106
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:27
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:30
float frand(float min, float max)
Definition: Random.cpp:57
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
#define CAST_AI(a, b)
Definition: ScriptedCreature.h:28
void SendGossipMenuFor(Player *player, uint32 npcTextID, ObjectGuid const guid)
Definition: ScriptedGossip.cpp:45
void ClearGossipMenuFor(Player *player)
Definition: ScriptedGossip.cpp:22
SMARTAI_TARGETS
Definition: SmartScriptMgr.h:1387
@ SMART_TARGET_RANDOM_POINT
Definition: SmartScriptMgr.h:1426
#define sSmartWaypointMgr
Definition: SmartScriptMgr.h:2057
SMART_ACTION
Definition: SmartScriptMgr.h:524
@ SMART_ACTION_REMOVE_TIMED_EVENT
Definition: SmartScriptMgr.h:599
@ SMART_ACTION_NONE
Definition: SmartScriptMgr.h:525
@ SMART_ACTION_SET_GO_FLAG
Definition: SmartScriptMgr.h:629
@ SMART_ACTION_WP_RESUME
Definition: SmartScriptMgr.h:590
@ SMART_ACTION_UPDATE_TEMPLATE
Definition: SmartScriptMgr.h:561
@ SMART_ACTION_SET_HEALTH_REGEN
Definition: SmartScriptMgr.h:627
@ SMART_ACTION_ACTIVATE_GOBJECT
Definition: SmartScriptMgr.h:534
@ SMART_ACTION_GAME_EVENT_START
Definition: SmartScriptMgr.h:637
@ SMART_ACTION_CALL_RANDOM_RANGE_TIMED_ACTIONLIST
Definition: SmartScriptMgr.h:613
@ SMART_ACTION_REMOVE_UNIT_FIELD_BYTES_1
Definition: SmartScriptMgr.h:616
@ SMART_ACTION_SET_INST_DATA64
Definition: SmartScriptMgr.h:560
@ SMART_ACTION_SET_FACTION
Definition: SmartScriptMgr.h:527
@ SMART_ACTION_THREAT_SINGLE_PCT
Definition: SmartScriptMgr.h:538
@ SMART_ACTION_OFFER_QUEST
Definition: SmartScriptMgr.h:532
@ SMART_ACTION_REMOVE_ALL_GAMEOBJECTS
Definition: SmartScriptMgr.h:651
@ SMART_ACTION_RISE_UP
Definition: SmartScriptMgr.h:639
@ SMART_ACTION_SET_INGAME_PHASE_MASK
Definition: SmartScriptMgr.h:569
@ SMART_ACTION_SET_UNIT_FIELD_BYTES_1
Definition: SmartScriptMgr.h:615
@ SMART_ACTION_CLOSE_GOSSIP
Definition: SmartScriptMgr.h:597
@ SMART_ACTION_DISABLE_EVADE
Definition: SmartScriptMgr.h:642
@ SMART_ACTION_CONE_SUMMON
Definition: SmartScriptMgr.h:689
@ SMART_ACTION_ADD_GO_FLAG
Definition: SmartScriptMgr.h:630
@ SMART_ACTION_ADD_DYNAMIC_FLAG
Definition: SmartScriptMgr.h:620
@ SMART_ACTION_KILL_UNIT
Definition: SmartScriptMgr.h:576
@ SMART_ACTION_LOAD_EQUIPMENT
Definition: SmartScriptMgr.h:649
@ SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS
Definition: SmartScriptMgr.h:540
@ SMART_ACTION_ATTACK_START
Definition: SmartScriptMgr.h:574
@ SMART_ACTION_SET_UNIT_FLAG
Definition: SmartScriptMgr.h:543
@ SMART_ACTION_NO_ENVIRONMENT_UPDATE
Definition: SmartScriptMgr.h:682
@ SMART_ACTION_CALL_GROUPEVENTHAPPENS
Definition: SmartScriptMgr.h:551
@ SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL
Definition: SmartScriptMgr.h:568
@ SMART_ACTION_INVOKER_CAST
Definition: SmartScriptMgr.h:610
@ SMART_ACTION_JUMP_TO_POS
Definition: SmartScriptMgr.h:622
@ SMART_ACTION_CALL_RANDOM_TIMED_ACTIONLIST
Definition: SmartScriptMgr.h:612
@ SMART_ACTION_SEND_GOSSIP_MENU
Definition: SmartScriptMgr.h:623
@ SMART_ACTION_SET_COUNTER
Definition: SmartScriptMgr.h:588
@ SMART_ACTION_FLEE_FOR_ASSIST
Definition: SmartScriptMgr.h:550
@ SMART_ACTION_EQUIP
Definition: SmartScriptMgr.h:596
@ SMART_ACTION_SET_ROOT
Definition: SmartScriptMgr.h:628
@ SMART_ACTION_ATTACK_STOP
Definition: SmartScriptMgr.h:694
@ SMART_ACTION_SUMMON_GO
Definition: SmartScriptMgr.h:575
@ SMART_ACTION_SET_HOVER
Definition: SmartScriptMgr.h:676
@ SMART_ACTION_WP_PAUSE
Definition: SmartScriptMgr.h:579
@ SMART_ACTION_SIMPLE_TALK
Definition: SmartScriptMgr.h:609
@ SMART_ACTION_STOP_MOTION
Definition: SmartScriptMgr.h:681
@ SMART_ACTION_VORTEX_SUMMON
Definition: SmartScriptMgr.h:691
@ SMART_ACTION_MUSIC
Definition: SmartScriptMgr.h:685
@ SMART_ACTION_SET_UNIT_MOVEMENT_FLAGS
Definition: SmartScriptMgr.h:673
@ SMART_ACTION_ADD_AURA
Definition: SmartScriptMgr.h:600
@ SMART_ACTION_THREAT_ALL_PCT
Definition: SmartScriptMgr.h:539
@ SMART_ACTION_RESPAWN_TARGET
Definition: SmartScriptMgr.h:595
@ SMART_ACTION_SOUND
Definition: SmartScriptMgr.h:529
@ SMART_ACTION_MOVE_TO_POS_TARGET
Definition: SmartScriptMgr.h:670
@ SMART_ACTION_SET_MOVEMENT_SPEED
Definition: SmartScriptMgr.h:661
@ SMART_ACTION_PLAY_CINEMATIC
Definition: SmartScriptMgr.h:660
@ SMART_ACTION_SET_GO_STATE
Definition: SmartScriptMgr.h:671
@ SMART_ACTION_ADD_NPC_FLAG
Definition: SmartScriptMgr.h:607
@ SMART_ACTION_EVADE
Definition: SmartScriptMgr.h:549
@ SMART_ACTION_FAIL_QUEST
Definition: SmartScriptMgr.h:531
@ SMART_ACTION_INTERRUPT_SPELL
Definition: SmartScriptMgr.h:617
@ SMART_ACTION_ADD_POWER
Definition: SmartScriptMgr.h:634
@ SMART_ACTION_REMOVE_DYNAMIC_FLAG
Definition: SmartScriptMgr.h:621
@ SMART_ACTION_RANDOM_SOUND
Definition: SmartScriptMgr.h:640
@ SMART_ACTION_RANDOM_MUSIC
Definition: SmartScriptMgr.h:686
@ SMART_ACTION_SET_COMBAT_DISTANCE
Definition: SmartScriptMgr.h:674
@ SMART_ACTION_SET_POWER
Definition: SmartScriptMgr.h:633
@ SMART_ACTION_SEND_TARGET_TO_TARGET
Definition: SmartScriptMgr.h:625
@ SMART_ACTION_REMOVE_POWER
Definition: SmartScriptMgr.h:635
@ SMART_ACTION_ADD_IMMUNITY
Definition: SmartScriptMgr.h:677
@ SMART_ACTION_SET_DYNAMIC_FLAG
Definition: SmartScriptMgr.h:619
@ SMART_ACTION_FALL
Definition: SmartScriptMgr.h:679
@ SMART_ACTION_GO_SET_GO_STATE
Definition: SmartScriptMgr.h:643
@ SMART_ACTION_CUSTOM_CAST
Definition: SmartScriptMgr.h:688
@ SMART_ACTION_REMOVE_ITEM
Definition: SmartScriptMgr.h:582
@ SMART_ACTION_SEND_GO_CUSTOM_ANIM
Definition: SmartScriptMgr.h:618
@ SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL
Definition: SmartScriptMgr.h:528
@ SMART_ACTION_REMOVE_UNIT_FLAG
Definition: SmartScriptMgr.h:544
@ SMART_ACTION_RANDOM_PHASE
Definition: SmartScriptMgr.h:555
@ SMART_ACTION_SET_EMOTE_STATE
Definition: SmartScriptMgr.h:542
@ SMART_ACTION_CROSS_CAST
Definition: SmartScriptMgr.h:611
@ SMART_ACTION_WP_STOP
Definition: SmartScriptMgr.h:580
@ SMART_ACTION_GAME_EVENT_STOP
Definition: SmartScriptMgr.h:636
@ SMART_ACTION_CALL_SCRIPT_RESET
Definition: SmartScriptMgr.h:603
@ SMART_ACTION_CU_ENCOUNTER_START
Definition: SmartScriptMgr.h:692
@ SMART_ACTION_WP_START
Definition: SmartScriptMgr.h:578
@ SMART_ACTION_COMBAT_STOP
Definition: SmartScriptMgr.h:552
@ SMART_ACTION_EXIT_VEHICLE
Definition: SmartScriptMgr.h:672
@ SMART_ACTION_SET_HEALTH_PCT
Definition: SmartScriptMgr.h:663
@ SMART_ACTION_AUTO_ATTACK
Definition: SmartScriptMgr.h:545
@ SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL
Definition: SmartScriptMgr.h:567
@ SMART_ACTION_SET_VISIBILITY
Definition: SmartScriptMgr.h:572
@ SMART_ACTION_RANDOM_PHASE_RANGE
Definition: SmartScriptMgr.h:556
@ SMART_ACTION_GO_SET_LOOT_STATE
Definition: SmartScriptMgr.h:624
@ SMART_ACTION_PLAYER_TALK
Definition: SmartScriptMgr.h:690
@ SMART_ACTION_SET_SWIM
Definition: SmartScriptMgr.h:586
@ SMART_ACTION_SET_SIGHT_DIST
Definition: SmartScriptMgr.h:646
@ SMART_ACTION_SET_INST_DATA
Definition: SmartScriptMgr.h:559
@ SMART_ACTION_REMOVE_GO_FLAG
Definition: SmartScriptMgr.h:631
@ SMART_ACTION_LOAD_GRID
Definition: SmartScriptMgr.h:684
@ SMART_ACTION_CALL_FOR_HELP
Definition: SmartScriptMgr.h:564
@ SMART_ACTION_ADD_THREAT
Definition: SmartScriptMgr.h:648
@ SMART_ACTION_TELEPORT
Definition: SmartScriptMgr.h:587
@ SMART_ACTION_PLAYMOVIE
Definition: SmartScriptMgr.h:593
@ SMART_ACTION_TRIGGER_RANDOM_TIMED_EVENT
Definition: SmartScriptMgr.h:650
@ SMART_ACTION_FOLLOW
Definition: SmartScriptMgr.h:554
@ SMART_ACTION_PLAY_EMOTE
Definition: SmartScriptMgr.h:530
@ SMART_ACTION_SET_CORPSE_DELAY
Definition: SmartScriptMgr.h:641
@ SMART_ACTION_SET_SHEATH
Definition: SmartScriptMgr.h:565
@ SMART_ACTION_SET_ORIENTATION
Definition: SmartScriptMgr.h:591
@ SMART_ACTION_SET_NPC_FLAG
Definition: SmartScriptMgr.h:606
@ SMART_ACTION_MOVE_TO_POS
Definition: SmartScriptMgr.h:594
@ SMART_ACTION_RANDOM_EMOTE
Definition: SmartScriptMgr.h:535
@ SMART_ACTION_INC_EVENT_PHASE
Definition: SmartScriptMgr.h:548
@ SMART_ACTION_CREATE_TIMED_EVENT
Definition: SmartScriptMgr.h:592
@ SMART_ACTION_SET_EVENT_FLAG_RESET
Definition: SmartScriptMgr.h:680
@ SMART_ACTION_DIE
Definition: SmartScriptMgr.h:562
@ SMART_ACTION_RESET_SCRIPT_BASE_OBJECT
Definition: SmartScriptMgr.h:602
@ SMART_ACTION_REMOVE_NPC_FLAG
Definition: SmartScriptMgr.h:608
@ SMART_ACTION_SET_FLY
Definition: SmartScriptMgr.h:585
@ SMART_ACTION_INSTALL_AI_TEMPLATE
Definition: SmartScriptMgr.h:583
@ SMART_ACTION_SUMMON_CREATURE
Definition: SmartScriptMgr.h:537
@ SMART_ACTION_CALL_TIMED_ACTIONLIST
Definition: SmartScriptMgr.h:605
@ SMART_ACTION_SET_IN_COMBAT_WITH_ZONE
Definition: SmartScriptMgr.h:563
@ SMART_ACTION_DO_ACTION
Definition: SmartScriptMgr.h:693
@ SMART_ACTION_SET_HOME_POS
Definition: SmartScriptMgr.h:626
@ SMART_ACTION_ADD_ITEM
Definition: SmartScriptMgr.h:581
@ SMART_ACTION_SET_ACTIVE
Definition: SmartScriptMgr.h:573
@ SMART_ACTION_SET_RANGED_MOVEMENT
Definition: SmartScriptMgr.h:604
@ SMART_ACTION_ACTIVATE_TAXI
Definition: SmartScriptMgr.h:577
@ SMART_ACTION_START_CLOSEST_WAYPOINT
Definition: SmartScriptMgr.h:638
@ SMART_ACTION_SET_CASTER_COMBAT_DIST
Definition: SmartScriptMgr.h:675
@ SMART_ACTION_SUMMON_CREATURE_GROUP
Definition: SmartScriptMgr.h:632
@ SMART_ACTION_REMOVE_IMMUNITY
Definition: SmartScriptMgr.h:678
@ SMART_ACTION_SET_REACT_STATE
Definition: SmartScriptMgr.h:533
@ SMART_ACTION_RANDOM_MOVE
Definition: SmartScriptMgr.h:614
@ SMART_ACTION_OVERRIDE_SCRIPT_BASE_OBJECT
Definition: SmartScriptMgr.h:601
@ SMART_ACTION_TRIGGER_TIMED_EVENT
Definition: SmartScriptMgr.h:598
@ SMART_ACTION_REMOVEAURASFROMSPELL
Definition: SmartScriptMgr.h:553
@ SMART_ACTION_FLEE
Definition: SmartScriptMgr.h:647
@ SMART_ACTION_ZONE_UNDER_ATTACK
Definition: SmartScriptMgr.h:683
SMART_EVENT
Definition: SmartScriptMgr.h:117
@ SMART_EVENT_TIMED_EVENT_TRIGGERED
Definition: SmartScriptMgr.h:177
@ SMART_EVENT_LINK
Definition: SmartScriptMgr.h:179
@ SMART_EVENT_WAYPOINT_REACHED
Definition: SmartScriptMgr.h:158
SmartActionSummonCreatureFlags
Definition: SmartScriptMgr.h:700
@ SMART_ESCORT_TARGETS
Definition: SmartScriptMgr.h:59
std::unordered_map< uint32, WayPoint * > WPPath
Definition: SmartScriptMgr.h:1821
@ SMARTCAST_TRIGGERED
Definition: SmartScriptMgr.h:1785
@ SMARTCAST_INTERRUPT_PREVIOUS
Definition: SmartScriptMgr.h:1784
@ SMARTCAST_AURA_NOT_PRESENT
Definition: SmartScriptMgr.h:1789
npc
Definition: BattlegroundSA.h:75
#define MAX_EQUIPMENT_ITEMS
Definition: CreatureData.h:39
LootState
Definition: GameObject.h:111
@ GO_READY
Definition: GameObject.h:113
GOState
Definition: GameObjectData.h:689
TempSummonType
Definition: Object.h:41
@ TEMPSUMMON_TIMED_DESPAWN
Definition: Object.h:44
@ TEMPSUMMON_CORPSE_DESPAWN
Definition: Object.h:46
@ UNIT_NPC_FLAGS
Definition: UpdateFields.h:139
@ UNIT_FIELD_FLAGS_2
Definition: UpdateFields.h:118
@ UNIT_VIRTUAL_ITEM_SLOT_ID
Definition: UpdateFields.h:116
@ UNIT_FIELD_FLAGS
Definition: UpdateFields.h:117
@ UNIT_NPC_EMOTESTATE
Definition: UpdateFields.h:140
@ UNIT_FIELD_BYTES_1
Definition: UpdateFields.h:131
@ UNIT_DYNAMIC_FLAGS
Definition: UpdateFields.h:136
@ GAMEOBJECT_FLAGS
Definition: UpdateFields.h:399
@ MOVEMENTFLAG_ONTRANSPORT
Definition: Unit.h:561
ReactStates
Definition: Unit.h:1022
SheathState
Definition: Unit.h:125
@ UNIT_STATE_LOST_CONTROL
Definition: Unit.h:366
@ UNIT_STATE_ROOT
Definition: Unit.h:335
@ UNIT_STATE_NO_ENVIRONMENT_UPD
Definition: Unit.h:353
UnitMoveType
Definition: Unit.h:377
@ MOVE_RUN
Definition: Unit.h:379
@ UNIT_FLAG_SILENCED
Definition: Unit.h:461
#define sGameEventMgr
Definition: GameEventMgr.h:186
#define sObjectMgr
Definition: ObjectMgr.h:1640
EncounterState
Definition: InstanceScript.h:55
@ BROADCAST_TEXT_CALL_FOR_HELP
Definition: Language.h:24
@ BROADCAST_TEXT_FLEE_FOR_ASSIST
Definition: Language.h:25
@ MOTION_SLOT_CONTROLLED
Definition: MotionMaster.h:63
@ MOTION_SLOT_ACTIVE
Definition: MotionMaster.h:62
@ CHASE_MOTION_TYPE
Definition: MotionMaster.h:43
@ AURA_REMOVE_BY_EXPIRE
Definition: SpellAuraDefines.h:395
@ SPELLVALUE_BASE_POINT1
Definition: SpellDefines.h:115
@ SPELLVALUE_BASE_POINT2
Definition: SpellDefines.h:116
@ SPELLVALUE_BASE_POINT0
Definition: SpellDefines.h:114
@ TRIGGERED_FULL_MASK
Will return SPELL_FAILED_DONT_REPORT in CheckCast functions.
Definition: SpellDefines.h:148
@ TRIGGERED_NONE
Definition: SpellDefines.h:131
@ TEXT_RANGE_NORMAL
Definition: CreatureTextMgr.h:30
phase
Definition: boss_skadi.cpp:102
@ GAMEOBJECT_TYPE_DOOR
Definition: SharedDefines.h:1532
@ CHAT_MSG_MONSTER_EMOTE
Definition: SharedDefines.h:3140
@ CHAT_MSG_ADDON
Definition: SharedDefines.h:3123
@ LANG_UNIVERSAL
Definition: SharedDefines.h:707
@ LANG_ADDON
Definition: SharedDefines.h:725
@ TEAM_NEUTRAL
Definition: SharedDefines.h:734
std::string ToString(Type &&val, Params &&... params)
Definition: StringConvert.h:250
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition: Containers.h:135
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:225
bool IsEmpty() const
Definition: LinkedList.h:97
Definition: LinkedList.h:139
Definition: EnumFlag.h:54
virtual void AttackStart(Unit *)
Definition: UnitAI.cpp:28
Definition: SmartAI.h:45
SmartScript * GetScript()
Definition: SmartAI.h:73
void SetInvincibilityHpLevel(uint32 level)
Definition: SmartAI.h:181
Definition: SmartAI.h:253
void IncPhase(uint32 p)
Definition: SmartScript.cpp:4588
void SetActualCombatDist(uint32 dist)
Definition: SmartScript.h:220
bool IsSmart(Creature *c=nullptr)
Definition: SmartScript.h:86
bool IsSmartGO(GameObject *g=nullptr)
Definition: SmartScript.h:101
void ProcessEvent(SmartScriptHolder &e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition: SmartScript.cpp:3415
void StoreTargetList(ObjectVector const &targets, uint32 id)
Definition: SmartScript.h:79
SmartScriptHolder FindLinkedEvent(uint32 link)
Definition: SmartScript.h:297
static bool IsUnit(WorldObject *obj)
Definition: SmartScript.cpp:4557
float GetCasterActualDist() const
Definition: SmartScript.h:229
void StoreCounter(uint32 id, uint32 value, uint32 reset, uint32 subtract)
Definition: SmartScript.h:123
float GetCasterMaxDist() const
Definition: SmartScript.h:230
void SetPhaseReset(bool allow)
Definition: SmartScript.h:233
void GetTargets(ObjectVector &targets, SmartScriptHolder const &e, Unit *invoker=nullptr) const
Definition: SmartScript.cpp:2838
uint32 GetMaxCombatDist() const
Definition: SmartScript.h:223
void SetCasterActualDist(float dist)
Definition: SmartScript.h:226
void OnReset()
Definition: SmartScript.cpp:71
void InstallTemplate(SmartScriptHolder const &e)
Definition: SmartScript.cpp:2727
ObjectGuid goOrigGUID
Definition: SmartScript.h:251
Powers GetCasterPowerType() const
Definition: SmartScript.h:228
void DecPhase(uint32 p)
Definition: SmartScript.cpp:4594
ObjectGuid meOrigGUID
Definition: SmartScript.h:249
Definition: SmartScriptMgr.h:33
uint32 id
Definition: SmartScriptMgr.h:44
Definition: SmartScriptMgr.h:216
uint32 repeatMin
Definition: SmartScriptMgr.h:227
uint32 repeatMax
Definition: SmartScriptMgr.h:228
Definition: SmartScriptMgr.h:711
struct SmartAction::@73::@119 wpStart
struct SmartAction::@73::@110 forceDespawn
struct SmartAction::@73::@179 cinematic
uint32 targetParam2
Definition: SmartScriptMgr.h:813
std::array< uint32, SMART_ACTION_PARAM_COUNT > emotes
Definition: SmartScriptMgr.h:797
struct SmartAction::@73::@92 summonCreature
struct SmartAction::@73::@116 setActive
struct SmartAction::@73::@163 setHomePos
uint32 repeatMax
Definition: SmartScriptMgr.h:1066
uint32 phaseMin
Definition: SmartScriptMgr.h:898
uint32 targetsLimit
Definition: SmartScriptMgr.h:804
struct SmartAction::@73::@155 creatureGroup
SAIBool transport
Definition: SmartScriptMgr.h:1160
uint32 newPower
Definition: SmartScriptMgr.h:1217
SAIBool reset
Definition: SmartScriptMgr.h:1051
std::array< uint32, SMART_ACTION_PARAM_COUNT > actionLists
Definition: SmartScriptMgr.h:1114
uint32 delay
Definition: SmartScriptMgr.h:938
uint32 random
Definition: SmartScriptMgr.h:1283
uint32 quickChange
Definition: SmartScriptMgr.h:1282
struct SmartAction::@73::@100 removeAura
SAIBool root
Definition: SmartScriptMgr.h:1194
uint32 dist
Definition: SmartScriptMgr.h:883
uint32 group
Definition: SmartScriptMgr.h:1209
SAIBool disable
Definition: SmartScriptMgr.h:1336
struct SmartAction::@73::@148 setGoLootState
struct SmartAction::@73::@146 moveToPos
uint32 spell
Definition: SmartScriptMgr.h:802
struct SmartAction::@73::@178 setHealthPct
std::array< uint32, SMART_ACTION_PARAM_COUNT > wps
Definition: SmartScriptMgr.h:1232
struct SmartAction::@73::@112 ingamePhaseMask
uint32 minHP
Definition: SmartScriptMgr.h:944
SAIBool force
Definition: SmartScriptMgr.h:1259
struct SmartAction::@73::@165 randomTimedEvent
uint32 flags
Definition: SmartScriptMgr.h:803
uint32 distanceBetweenSummons
Definition: SmartScriptMgr.h:1297
uint32 data
Definition: SmartScriptMgr.h:910
uint32 powerType
Definition: SmartScriptMgr.h:1216
SAIBool regenHealth
Definition: SmartScriptMgr.h:1189
uint32 entry
Definition: SmartScriptMgr.h:885
struct SmartAction::@73::@170 coneSummon
uint32 quest
Definition: SmartScriptMgr.h:781
uint32 bp1
Definition: SmartScriptMgr.h:1312
uint32 distance
Definition: SmartScriptMgr.h:744
struct SmartAction::@73::@102 randomPhase
uint32 min
Definition: SmartScriptMgr.h:1063
struct SmartAction::@73::@129 storeTargets
struct SmartAction::@73::@150 setRangedMovement
SAIBool withDelayed
Definition: SmartScriptMgr.h:1125
SAIBool withInstant
Definition: SmartScriptMgr.h:1127
uint32 subtract
Definition: SmartScriptMgr.h:1052
struct SmartAction::@73::@151 setHealthRegen
struct SmartAction::@73::@104 killedMonster
uint32 a
Definition: SmartScriptMgr.h:1321
struct SmartAction::@73::@173 summonVortex
uint32 percent
Definition: SmartScriptMgr.h:945
uint32 dec
Definition: SmartScriptMgr.h:867
struct SmartAction::@73::@89 crossCast
struct SmartAction::@73::@176 corpseDelay
uint32 summonEntry
Definition: SmartScriptMgr.h:1294
struct SmartAction::@73::@169 stopMotion
struct SmartAction::@73::@131 movie
uint32 instanceTarget
Definition: SmartScriptMgr.h:1331
uint32 credit
Definition: SmartScriptMgr.h:886
uint32 controlled
Definition: SmartScriptMgr.h:1161
uint32 alternative
Definition: SmartScriptMgr.h:819
uint32 targetParam1
Definition: SmartScriptMgr.h:812
uint32 mapID
Definition: SmartScriptMgr.h:1044
uint32 stopMovement
Definition: SmartScriptMgr.h:1288
struct SmartAction::@73::@103 randomPhaseRange
uint32 charges
Definition: SmartScriptMgr.h:878
struct SmartAction::@73::@98 incEventPhase
uint32 model
Definition: SmartScriptMgr.h:737
struct SmartAction::@73::@122 item
struct SmartAction::@73::@137 timedActionList
struct SmartAction::@73::@147 sendGossipMenu
struct SmartAction::@73::@171 playerTalk
struct SmartAction::@73::@174 doAction
struct SmartAction::@73::@168 orientation
uint32 duration
Definition: SmartScriptMgr.h:719
struct SmartAction::@73::@111 invincHP
SAIBool attackInvoker
Definition: SmartScriptMgr.h:832
SAIBool useTalkTarget
Definition: SmartScriptMgr.h:720
SAIBool run
Definition: SmartScriptMgr.h:989
struct SmartAction::@73::@125 setFly
uint32 value
Definition: SmartScriptMgr.h:1050
uint32 movementExpired
Definition: SmartScriptMgr.h:1289
struct SmartAction::@73::@109 setSheath
struct SmartAction::@73::@106 setInstanceData64
uint32 targetParam3
Definition: SmartScriptMgr.h:814
SAIBool swim
Definition: SmartScriptMgr.h:1039
uint32 sound2
Definition: SmartScriptMgr.h:750
struct SmartAction::@73::@136 delunitByte
uint32 spawnPos
Definition: SmartScriptMgr.h:1253
struct SmartAction::@73::@138 randTimedActionList
uint32 creature
Definition: SmartScriptMgr.h:736
struct SmartAction::@73::@164 loadEquipment
struct SmartAction::@73::@132 equip
struct SmartAction::@73::@97 setEventPhase
struct SmartAction::@73::@115 visibility
struct SmartAction::@73::@157 gameEventStop
struct SmartAction::@73::@86 react
struct SmartAction::@73::@113 setData
struct SmartAction::@73::@126 setSwim
uint32 angle
Definition: SmartScriptMgr.h:884
uint32 field
Definition: SmartScriptMgr.h:909
struct SmartAction::@73::@90 activateObject
uint32 range
Definition: SmartScriptMgr.h:824
struct SmartAction::@73::@158 gameEventStart
uint32 flag
Definition: SmartScriptMgr.h:1084
struct SmartAction::@73::@96 combatMove
struct SmartAction::@73::@142 jump
struct SmartAction::@73::@177 movementSpeed
struct SmartAction::@73::@141 sendGoCustomAnim
uint32 sound3
Definition: SmartScriptMgr.h:751
uint32 targetsummon
Definition: SmartScriptMgr.h:978
struct SmartAction::@73::@156 power
uint32 chance
Definition: SmartScriptMgr.h:1067
struct SmartAction::@73::@144 flee
uint32 state
Definition: SmartScriptMgr.h:792
uint32 byte1
Definition: SmartScriptMgr.h:1095
uint32 sound1
Definition: SmartScriptMgr.h:749
struct SmartAction::@73::@121 wpStop
SAIBool updateLevel
Definition: SmartScriptMgr.h:922
struct SmartAction::@73::@114 moveRandom
uint32 forceRespawnTimer
Definition: SmartScriptMgr.h:939
uint32 speed
Definition: SmartScriptMgr.h:1033
struct SmartAction::@73::@82 randomMusic
uint32 sound4
Definition: SmartScriptMgr.h:752
uint32 targetType
Definition: SmartScriptMgr.h:811
struct SmartAction::@73::@80 randomSound
struct SmartAction::@73::@120 wpPause
struct SmartAction::@73::@175 disableEvade
uint32 aliveState
Definition: SmartScriptMgr.h:888
struct SmartAction::@73::@161 sightDistance
SAIBool onlySelf
Definition: SmartScriptMgr.h:743
uint32 attackScriptOwner
Definition: SmartScriptMgr.h:833
uint32 speedxy
Definition: SmartScriptMgr.h:1137
struct SmartAction::@73::@118 taxi
uint32 pointId
Definition: SmartScriptMgr.h:1159
SAIBool attack
Definition: SmartScriptMgr.h:851
uint32 repeatMin
Definition: SmartScriptMgr.h:1065
uint32 anim
Definition: SmartScriptMgr.h:1132
struct SmartAction::@73::@152 setRoot
SAIBool fly
Definition: SmartScriptMgr.h:1032
uint32 textGroupID
Definition: SmartScriptMgr.h:718
std::array< uint32, SMART_ACTION_PARAM_COUNT > phases
Definition: SmartScriptMgr.h:893
uint32 spell_id
Definition: SmartScriptMgr.h:1126
struct SmartAction::@73::@153 goFlag
uint32 textId
Definition: SmartScriptMgr.h:1304
uint32 gossipMenuId
Definition: SmartScriptMgr.h:1167
struct SmartAction::@73::@172 castCustom
uint32 speedz
Definition: SmartScriptMgr.h:1138
struct SmartAction::@73::@154 goState
SAIBool repeat
Definition: SmartScriptMgr.h:991
uint32 gossipNpcTextId
Definition: SmartScriptMgr.h:1168
struct SmartAction::@73::@88 cast
uint32 mask
Definition: SmartScriptMgr.h:950
struct SmartAction::@73::@162 casterDistance
uint32 phi_delta
Definition: SmartScriptMgr.h:1324
uint32 count
Definition: SmartScriptMgr.h:1012
uint32 inc
Definition: SmartScriptMgr.h:866
struct SmartAction::@73::@101 follow
uint32 phaseMax
Definition: SmartScriptMgr.h:899
uint32 timer
Definition: SmartScriptMgr.h:1341
uint32 ContactDistance
Definition: SmartScriptMgr.h:1162
struct SmartAction::@73::@128 setCounter
uint32 k
Definition: SmartScriptMgr.h:1322
uint32 distanceBetweenRings
Definition: SmartScriptMgr.h:1296
uint32 coneLength
Definition: SmartScriptMgr.h:1298
struct SmartAction::@73::@75 talk
uint32 counterId
Definition: SmartScriptMgr.h:1049
struct SmartAction::@73::@166 setHover
SAIBool withEmote
Definition: SmartScriptMgr.h:928
uint32 max
Definition: SmartScriptMgr.h:1064
uint32 selfJump
Definition: SmartScriptMgr.h:1139
uint32 maxId
Definition: SmartScriptMgr.h:1265
struct SmartAction::@73::@95 autoAttack
uint32 r_max
Definition: SmartScriptMgr.h:1323
struct SmartAction::@73::@127 teleport
uint32 speedFraction
Definition: SmartScriptMgr.h:1348
struct SmartAction::@73::@78 morphOrMount
struct SmartAction::@73::@108 callHelp
SAIBool fail
Definition: SmartScriptMgr.h:1006
struct SmartAction::@73::@85 questOffer
SAIBool directAdd
Definition: SmartScriptMgr.h:787
uint32 bp2
Definition: SmartScriptMgr.h:1313
uint32 disableGravity
Definition: SmartScriptMgr.h:1034
uint32 sound
Definition: SmartScriptMgr.h:742
uint32 threatINC
Definition: SmartScriptMgr.h:839
struct SmartAction::@73::@124 setRun
uint32 coneAngle
Definition: SmartScriptMgr.h:1299
uint32 summonDuration
Definition: SmartScriptMgr.h:1295
struct SmartAction::@73::@167 immunity
uint32 threatDEC
Definition: SmartScriptMgr.h:840
struct SmartAction::@73::@87 randomEmote
struct SmartAction::@73::@159 closestWaypointFromList
uint32 reactState
Definition: SmartScriptMgr.h:994
struct SmartAction::@73::@93 threatPCT
struct SmartAction::@73::@130 timeEvent
uint32 speedInteger
Definition: SmartScriptMgr.h:1347
struct SmartAction::@73::@105 setInstanceData
struct SmartAction::@73::@145 RespawnTarget
struct SmartAction::@73::@160 combatDistance
uint32 actionId
Definition: SmartScriptMgr.h:1329
uint32 despawnTime
Definition: SmartScriptMgr.h:977
struct SmartAction::@73::@149 sendTargetToTarget
uint32 goRespawnTime
Definition: SmartScriptMgr.h:1154
uint32 factionID
Definition: SmartScriptMgr.h:731
struct SmartAction::@73::@77 faction
struct SmartAction::@73::@107 updateTemplate
SAIBool move
Definition: SmartScriptMgr.h:856
struct SmartAction::@73::@140 interruptSpellCasting
struct SmartAction::@73::@143 movementFlag
struct SmartAction::@73::@117 summonGO
std::array< uint32, MAX_EQUIPMENT_ITEMS > slots
Definition: SmartScriptMgr.h:1079
struct SmartAction::@73::@133 unitFlag
uint32 movementType
Definition: SmartScriptMgr.h:1346
uint32 questID
Definition: SmartScriptMgr.h:786
uint32 bp3
Definition: SmartScriptMgr.h:1314
uint32 pathID
Definition: SmartScriptMgr.h:990
uint32 emote
Definition: SmartScriptMgr.h:776
struct SmartAction::@73::@76 simpleTalk
uint32 id
Definition: SmartScriptMgr.h:984
uint32 minId
Definition: SmartScriptMgr.h:1264
uint32 phase
Definition: SmartScriptMgr.h:861
struct SmartAction::@73::@135 setunitByte
uint32 sheath
Definition: SmartScriptMgr.h:933
struct SmartAction::@73::@81 music
uint32 isNegative
Definition: SmartScriptMgr.h:1330
uint32 creditType
Definition: SmartScriptMgr.h:887
struct SmartTarget::@181::@185 unitRange
float o
Definition: SmartScriptMgr.h:1449
uint32 maxDist
Definition: SmartScriptMgr.h:1455
uint32 range
Definition: SmartScriptMgr.h:1574
float x
Definition: SmartScriptMgr.h:1449
uint32 self
Definition: SmartScriptMgr.h:1576
uint32 amount
Definition: SmartScriptMgr.h:1575
struct SmartTarget::@181::@202 randomPoint
float y
Definition: SmartScriptMgr.h:1449
float z
Definition: SmartScriptMgr.h:1449
bool runOnce
Definition: SmartScriptMgr.h:1817
uint32 link
Definition: SmartScriptMgr.h:1803
uint32 event_id
Definition: SmartScriptMgr.h:1802
int32 entryOrGuid
Definition: SmartScriptMgr.h:1800
uint32 GetScriptType() const
Definition: SmartScriptMgr.h:1810
uint32 GetTargetType() const
Definition: SmartScriptMgr.h:1813
uint32 GetActionType() const
Definition: SmartScriptMgr.h:1812
void ModifyThreatByPercent(Unit *victim, int32 percent)
Definition: ThreatMgr.cpp:509
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:328
void Respawn(bool force=false)
Definition: Creature.cpp:2005
void GetRespawnPosition(float &x, float &y, float &z, float *ori=nullptr, float *dist=nullptr) const
Definition: Creature.cpp:2844
bool SetDisableGravity(bool disable, bool packetOnly=false, bool updateAnimationTier=true) override
Definition: Creature.cpp:3092
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:330
void LoadEquipment(int8 id=1, bool force=false)
Definition: Creature.cpp:1777
void SendZoneUnderAttackMessage(Player *attacker)
Send a message to LocalDefense channel for players opposition team in the zone.
Definition: Creature.cpp:2716
void SetRegeneratingHealth(bool c)
Definition: Creature.h:310
void GetTransportHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:335
void SetReactState(ReactStates st)
Definition: Creature.h:89
float m_SightDistance
Definition: Creature.h:363
void DoFleeToGetAssistance()
Definition: Creature.cpp:1031
float m_CombatDistance
Definition: Creature.h:363
void SetCorpseDelay(uint32 delay)
Definition: Creature.h:72
bool IsSpellProhibited(SpellSchoolMask idSchoolMask) const
Definition: Creature.cpp:2740
Definition: CreatureData.h:176
Definition: CreatureData.h:349
uint32 ItemEntry[MAX_EQUIPMENT_ITEMS]
Definition: CreatureData.h:350
Definition: GossipDef.h:258
void SendCloseGossip()
Definition: GossipDef.cpp:240
void SetGoState(GOState state)
Definition: GameObject.cpp:2467
void UseDoorOrButton(uint32 time_to_restore=0, bool alternative=false, Unit *user=nullptr)
Definition: GameObject.cpp:1427
bool isSpawnedByDefault() const
Definition: GameObject.h:197
void SetLootState(LootState s, Unit *unit=nullptr)
Definition: GameObject.cpp:2432
GameObjectAI * AI() const
Definition: GameObject.h:310
void SetRespawnTime(int32 respawn)
Definition: GameObject.cpp:1301
GameobjectTypes GetGoType() const
Definition: GameObject.h:205
void Respawn()
Definition: GameObject.cpp:1316
void SendCustomAnim(uint32 anim)
Definition: GameObject.cpp:2138
void DespawnOrUnsummon(Milliseconds delay=0ms, Seconds forcedRespawnTime=0s)
Definition: GameObject.cpp:930
void CastSpell(Unit *target, uint32 spell)
Definition: GameObject.cpp:2073
void SetFlag(uint16 index, uint32 newFlag)
Definition: Object.cpp:845
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition: Object.cpp:860
void RemoveByteFlag(uint16 index, uint8 offset, uint8 newFlag)
Definition: Object.cpp:930
bool HasFlag(uint16 index, uint32 flag) const
Definition: Object.cpp:889
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:650
Unit * ToUnit()
Definition: Object.h:200
void SetByteFlag(uint16 index, uint8 offset, uint8 newFlag)
Definition: Object.cpp:911
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition: Object.cpp:2318
Map * FindMap() const
Definition: Object.h:518
InstanceScript * GetInstanceScript() const
Definition: Object.cpp:1192
bool IsWithinLOSInMap(WorldObject const *obj, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, Optional< float > collisionHeight={ }, Optional< float > combatReach={ }) const
Definition: Object.cpp:1347
bool GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0, WorldObject const *forWho=nullptr, bool force=false) const
Definition: Object.cpp:2662
std::string const & GetName() const
Definition: Object.h:446
void GetContactPoint(WorldObject const *obj, float &x, float &y, float &z, float distance2d=CONTACT_DISTANCE) const
Definition: Object.cpp:2705
float GetDistance(WorldObject const *obj) const
Definition: Object.cpp:1245
uint32 GetAreaId() const
Definition: Object.cpp:3083
uint32 GetZoneId() const
Definition: Object.cpp:3075
float GetObjectSize() const
Definition: Object.cpp:2734
GameObject * SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime, bool checkTransport=true, GOSummonType summonType=GO_SUMMON_TIMED_OR_CORPSE_DESPAWN)
Definition: Object.cpp:2332
void GetRandomPoint(const Position &srcPos, float distance, float &rand_x, float &rand_y, float &rand_z) const
Definition: Object.cpp:1502
void SummonCreatureGroup(uint8 group, std::list< TempSummon * > *list=nullptr)
Definition: Object.cpp:2395
Creature * SummonTrigger(float x, float y, float z, float ang, uint32 dur, bool setLevel=false, CreatureAI *(*GetAI)(Creature *)=nullptr)
Definition: Object.cpp:2367
static ObjectGuid const Empty
Definition: ObjectGuid.h:122
std::string ToString() const
Definition: ObjectGuid.cpp:47
Definition: Position.h:28
float m_positionZ
Definition: Position.h:58
float m_positionX
Definition: Position.h:56
float GetPositionZ() const
Definition: Position.h:119
float m_positionY
Definition: Position.h:57
float GetOrientation() const
Definition: Position.h:120
void SetOrientation(float orientation)
Definition: Position.h:112
float GetPositionX() const
Definition: Position.h:117
void GetPosition(float &x, float &y) const
Definition: Position.h:122
float GetPositionY() const
Definition: Position.h:118
float GetAngle(const Position *pos) const
Definition: Position.cpp:77
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition: PlayerQuest.cpp:1802
bool ActivateTaxiPathTo(std::vector< uint32 > const &nodes, Creature *npc=nullptr, uint32 spellid=1)
Definition: Player.cpp:10128
void SendCinematicStart(uint32 CinematicSequenceId) const
Definition: Player.cpp:5599
void Yell(std::string_view text, Language language, WorldObject const *=nullptr) override
Handles yelled message in regular chat based on declared language and in config pre-defined Range.
Definition: Player.cpp:9250
void Say(std::string_view text, Language language, WorldObject const *=nullptr) override
Handles said message in regular chat based on declared language and in config pre-defined Range.
Definition: Player.cpp:9230
void PrepareGossipMenu(WorldObject *source, uint32 menuId=0, bool showQuests=false)
Definition: PlayerGossip.cpp:31
PlayerMenu * PlayerTalkClass
Definition: Player.h:2188
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition: Player.cpp:12627
uint8 getGender() const
Definition: Unit.h:1428
void SetFacingTo(float ori)
Definition: Unit.cpp:20782
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10401
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:14318
void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply, SpellImmuneBlockType blockType=SPELL_BLOCK_TYPE_ALL)
Definition: Unit.cpp:13300
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true, bool bySelf=false)
Definition: Unit.cpp:4069
void RemoveAllGameObjects()
Definition: Unit.cpp:6175
void AddThreat(Unit *victim, float fThreat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
Definition: Unit.cpp:14548
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition: Unit.cpp:10576
static void Kill(Unit *killer, Unit *victim, bool durabilityLoss=true, WeaponAttackType attackType=BASE_ATTACK, SpellInfo const *spellProto=nullptr, Spell const *spell=nullptr)
Definition: Unit.cpp:17862
void SetPower(Powers power, uint32 val, bool withPowerUpdate=true, bool fromRegenerate=false)
Definition: Unit.cpp:15458
MotionMaster * GetMotionMaster()
Definition: Unit.h:2262
void SetUnitMovementFlags(uint32 f)
Definition: Unit.h:2276
SpellCastResult CastCustomSpell(Unit *victim, uint32 spellId, int32 const *bp0, int32 const *bp1, int32 const *bp2, bool triggered, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:1226
void SetInCombatWith(Unit *enemy, uint32 duration=0)
Definition: Unit.cpp:13492
void SetFacingToObject(WorldObject *object)
Definition: Unit.cpp:20792
bool IsAlive() const
Definition: Unit.h:1808
void StopMoving()
Definition: Unit.cpp:16824
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition: Unit.cpp:5610
void AddUnitState(uint32 f)
Definition: Unit.h:1397
virtual void SetSheath(SheathState sheathed)
Definition: Unit.h:1492
void SetControlled(bool apply, UnitState state, Unit *source=nullptr, bool isFear=false)
Definition: Unit.cpp:18192
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:2274
uint32 GetMaxPower(Powers power) const
Definition: Unit.h:1462
TransportBase * GetDirectTransport() const
Returns the transport this unit is on directly (if on vehicle and transport, return vehicle)
Definition: Unit.cpp:18935
void SendMovementFlagUpdate(bool self=false)
Definition: Unit.cpp:16878
virtual bool SetHover(bool enable, bool packetOnly=false, bool updateAnimationTier=true)
Definition: Unit.cpp:20918
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:1169
void SetSpeed(UnitMoveType mtype, float rate, bool forced=false)
Definition: Unit.cpp:14323
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:18924
bool IsAIEnabled
Definition: Unit.h:2350
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1398
float GetPowerPct(Powers power) const
Definition: Unit.h:1451
uint32 GetPower(Powers power) const
Definition: Unit.h:1461
void KillSelf(bool durabilityLoss=true, WeaponAttackType attackType=BASE_ATTACK, SpellInfo const *spellProto=nullptr, Spell const *spell=nullptr)
Definition: Unit.h:1551
void SetInFront(WorldObject const *target)
Definition: Unit.cpp:20776
bool AttackStop()
Definition: Unit.cpp:10368
bool isDead() const
Definition: Unit.h:1810
void ExitVehicle(Position const *exitPosition=nullptr)
Definition: Unit.cpp:19896
Definition: Vehicle.h:30
Definition: VehicleDefines.h:107
static uint32 ChooseDisplayId(CreatureTemplate const *cinfo, CreatureData const *data=nullptr)
Definition: ObjectMgr.cpp:1717
virtual bool SetBossState(uint32 id, EncounterState state)
Definition: InstanceScript.cpp:317
virtual void DoAction(int32)
Definition: InstanceScript.h:262
static std::string GetBossStateName(uint8 state)
Definition: InstanceScript.cpp:701
void LoadGrid(float x, float y)
Definition: Map.cpp:494
PlayerList const & GetPlayers() const
Definition: Map.h:484
Definition: MapRefMgr.h:26
iterator begin()
Definition: MapRefMgr.h:36
iterator end()
Definition: MapRefMgr.h:37
virtual void SetData(uint32, uint32)
Definition: ZoneScript.h:53
virtual void SetGuidData(uint32, ObjectGuid)
Definition: ZoneScript.h:46
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Definition: MotionMaster.cpp:299
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:817
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:178
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition: MotionMaster.h:210
void MoveJump(Position const &pos, float speedXY, float speedZ, uint32 id=0)
Definition: MotionMaster.h:225
void MoveIdle()
Definition: MotionMaster.cpp:231
void MoveFall(uint32 id=0, bool addFlagForNPC=false)
Definition: MotionMaster.cpp:545
void MoveFleeing(Unit *enemy, uint32 time=0)
Definition: MotionMaster.cpp:657
void MoveRandom(float wanderDistance=0.0f)
Definition: MotionMaster.cpp:238
Definition: QuestDef.h:207
Player session in the World.
Definition: WorldSession.h:330
Definition: SpellAuras.h:87
Definition: SpellDefines.h:162
void AddSpellMod(SpellValueMod mod, int32 value)
Definition: SpellDefines.h:164
float GetMinRange(bool positive=false) const
Definition: SpellInfo.cpp:2297
SpellSchoolMask GetSchoolMask() const
Definition: SpellInfo.cpp:1972
float GetMaxRange(bool positive=false, Unit *caster=nullptr, Spell *spell=nullptr) const
Definition: SpellInfo.cpp:2306
Definition: ChatTextBuilder.h:31

References SmartScriptHolder::action, SmartAction::activateObject, Unit::AddThreat(), Creature::AI(), SmartAction::aliveState, SmartAction::alternative, SmartTarget::amount, SmartAction::angle, SmartAction::attack, SmartAction::attackInvoker, SmartAction::attackScriptOwner, UnitAI::AttackStart(), AURA_REMOVE_BY_EXPIRE, SmartAction::autoAttack, MapRefMgr::begin(), BROADCAST_TEXT_CALL_FOR_HELP, BROADCAST_TEXT_FLEE_FOR_ASSIST, SmartAction::callHelp, SmartAction::cast, CAST_AI, Unit::CastSpell(), GameObject::CastSpell(), SmartAction::charges, CHAT_MSG_ADDON, CHAT_MSG_MONSTER_EMOTE, ObjectMgr::ChooseDisplayId(), SmartAction::combatMove, Unit::CombatStop(), SmartAction::ContactDistance, SmartAction::controlled, SmartAction::count, SmartAction::counterId, SmartAction::creature, SmartAction::credit, SmartAction::creditType, SmartAction::data, SmartAction::dec, DecPhase(), SmartAction::delay, GameObject::DespawnOrUnsummon(), SmartAction::despawnTime, SmartAction::directAdd, SmartAction::disableGravity, SmartAction::dist, SmartAction::distance, Creature::DoFleeToGetAssistance(), SmartAction::duration, SmartAction::emote, SmartAction::emotes, MapRefMgr::end(), SmartAction::entry, SmartScriptHolder::entryOrGuid, SmartScriptHolder::event, SmartEvent::event_chance, SmartAction::faction, SmartAction::factionID, SmartAction::fail, SmartAction::field, WorldObject::FindMap(), SmartAction::flag, SmartAction::flags, SmartAction::flee, SmartAction::fly, SmartAction::follow, SmartAction::forceDespawn, SmartAction::forceRespawnTimer, frand(), GAMEOBJECT_TYPE_DOOR, SmartScriptHolder::GetActionType(), WorldObject::GetAreaId(), GetBaseObject(), InstanceScript::GetBossStateName(), GetCasterActualDist(), GetCasterMaxDist(), GetCasterPowerType(), Unit::GetCharmerOrOwnerPlayerOrPlayerItself(), WorldObject::GetClosePoint(), Unit::GetDirectTransport(), Object::GetEntry(), SmartScriptHolder::GetEventType(), Unit::getGender(), GameObject::GetGoType(), Object::GetGUID(), Creature::GetHomePosition(), WorldObject::GetInstanceScript(), GetLastInvoker(), Creature::GetLootRecipient(), WorldObject::GetMap(), GetMaxCombatDist(), Unit::GetMaxPower(), Unit::GetMotionMaster(), WorldObject::GetName(), WorldObject::GetObjectSize(), Position::GetOrientation(), ObjectAccessor::GetPlayer(), Map::GetPlayers(), Position::GetPosition(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), Unit::GetPower(), Unit::GetPowerPct(), WorldObject::GetRandomPoint(), SpellInfo::GetSchoolMask(), SmartScriptHolder::GetScriptType(), Unit::GetSpeed(), GetTargets(), SmartScriptHolder::GetTargetType(), ThreatMgr::GetThreatList(), Unit::GetThreatMgr(), Unit::GetTransGUID(), Creature::GetTransportHomePosition(), ObjectAccessor::GetUnit(), Unit::GetVehicleKit(), GetWorldObjectsInDist(), WorldObject::GetZoneId(), go, GO_READY, Player::GroupEventHappens(), EnumFlag< T >::HasFlag(), Object::HasFlag(), Unit::HasUnitMovementFlag(), Unit::HasUnitState(), SmartAction::id, SmartAction::inc, SmartAction::incEventPhase, IncPhase(), SmartAction::ingamePhaseMask, InstallTemplate(), Unit::InterruptNonMeleeSpells(), SmartAction::invincHP, IsCreature(), Unit::isDead(), Map::IsDungeon(), LinkedListHead::IsEmpty(), IsGameObject(), IsPlayer(), IsSmart(), Creature::IsSpellProhibited(), IsUnit(), SmartAction::item, Unit::Kill(), SmartAction::killedMonster, Unit::KillSelf(), LANG_ADDON, LANG_UNIVERSAL, LOG_DEBUG, LOG_ERROR, Position::m_positionX, Position::m_positionY, Position::m_positionZ, SmartAction::mapID, SmartAction::mask, SmartTarget::maxDist, me, SmartAction::minHP, mLastInvoker, mLastTextID, SmartAction::model, ThreatMgr::ModifyThreatByPercent(), SmartAction::morphOrMount, MOTION_SLOT_ACTIVE, MOTION_SLOT_CONTROLLED, SmartAction::move, MOVE_RUN, MOVEMENTFLAG_ONTRANSPORT, MotionMaster::MovePoint(), SmartAction::moveRandom, SmartAction::moveToPos, SmartAction::movie, mTalkerEntry, mTextTimer, mUseTextTimer, SmartAction::music, SmartTarget::o, SmartAction::onlySelf, SmartAction::orientation, SmartAction::pathID, SmartAction::percent, SmartAction::phase, SmartAction::phaseMax, SmartAction::phaseMin, SmartAction::phases, SmartAction::pointId, SmartAction::quest, SmartAction::questID, SmartAction::questOffer, SmartAction::quickChange, SmartAction::random, SmartAction::randomEmote, SmartAction::randomMusic, SmartAction::randomPhase, SmartAction::randomPhaseRange, SmartTarget::randomPoint, Acore::Containers::RandomResize(), SmartAction::randomSound, SmartAction::range, SmartTarget::range, SmartAction::react, SmartAction::reactState, SmartAction::removeAura, SmartAction::repeat, SmartAction::reset, RestoreCasterMaxDist(), Player::RewardPlayerAndGroupAtEvent(), SmartAction::run, SmartScriptHolder::runOnce, sCreatureTextMgr, Acore::Containers::SelectRandomContainerElement(), SmartTarget::self, PlayerMenu::SendQuestGiverQuestDetails(), SmartAction::setActive, SetActualCombatDist(), InstanceScript::SetBossState(), SetCasterActualDist(), SmartAction::setCounter, SmartAction::setData, ZoneScript::SetData(), Creature::SetDisableGravity(), SmartAction::setEventPhase, Unit::SetFacingTo(), Unit::SetFacingToObject(), SmartAction::setFly, ZoneScript::SetGuidData(), Unit::SetInCombatWith(), Unit::SetInFront(), SmartAction::setInstanceData, SmartAction::setInstanceData64, SmartAI::SetInvincibilityHpLevel(), GameObject::SetLootState(), Position::SetOrientation(), SetPhase(), Creature::SetReactState(), SmartAction::setRun, SmartAction::setSheath, Unit::SetSheath(), Unit::SetSpeed(), SmartAction::setSwim, SmartAction::sheath, SmartAction::simpleTalk, SMART_ACTION_ACTIVATE_GOBJECT, SMART_ACTION_ADD_AURA, SMART_ACTION_ADD_ITEM, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, SMART_ACTION_ATTACK_START, SMART_ACTION_ATTACK_STOP, SMART_ACTION_AUTO_ATTACK, SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS, SMART_ACTION_CALL_FOR_HELP, SMART_ACTION_CALL_GROUPEVENTHAPPENS, SMART_ACTION_CALL_KILLEDMONSTER, SMART_ACTION_CAST, SMART_ACTION_COMBAT_STOP, SMART_ACTION_DIE, SMART_ACTION_EVADE, SMART_ACTION_FAIL_QUEST, SMART_ACTION_FLEE_FOR_ASSIST, SMART_ACTION_FOLLOW, SMART_ACTION_FORCE_DESPAWN, SMART_ACTION_INC_EVENT_PHASE, SMART_ACTION_INSTALL_AI_TEMPLATE, SMART_ACTION_INVOKER_CAST, SMART_ACTION_KILL_UNIT, SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL, SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL, SMART_ACTION_MOVE_FORWARD, SMART_ACTION_MOVE_TO_POS, SMART_ACTION_MUSIC, SMART_ACTION_OFFER_QUEST, SMART_ACTION_PLAY_EMOTE, SMART_ACTION_PLAYMOVIE, SMART_ACTION_RANDOM_EMOTE, SMART_ACTION_RANDOM_MUSIC, SMART_ACTION_RANDOM_PHASE, SMART_ACTION_RANDOM_PHASE_RANGE, SMART_ACTION_RANDOM_SOUND, SMART_ACTION_REMOVE_ITEM, SMART_ACTION_REMOVE_UNIT_FLAG, SMART_ACTION_REMOVEAURASFROMSPELL, SMART_ACTION_RESET_GOBJECT, SMART_ACTION_RISE_UP, SMART_ACTION_SET_ACTIVE, SMART_ACTION_SET_COUNTER, SMART_ACTION_SET_DATA, SMART_ACTION_SET_EMOTE_STATE, SMART_ACTION_SET_EVENT_PHASE, SMART_ACTION_SET_FACTION, SMART_ACTION_SET_FLY, SMART_ACTION_SET_IN_COMBAT_WITH_ZONE, SMART_ACTION_SET_INGAME_PHASE_MASK, SMART_ACTION_SET_INST_DATA, SMART_ACTION_SET_INST_DATA64, SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL, SMART_ACTION_SET_ORIENTATION, SMART_ACTION_SET_REACT_STATE, SMART_ACTION_SET_RUN, SMART_ACTION_SET_SHEATH, SMART_ACTION_SET_SWIM, SMART_ACTION_SET_UNIT_FLAG, SMART_ACTION_SET_VISIBILITY, SMART_ACTION_SIMPLE_TALK, SMART_ACTION_SOUND, SMART_ACTION_STORE_TARGET_LIST, SMART_ACTION_SUMMON_CREATURE, SMART_ACTION_SUMMON_GO, SMART_ACTION_TALK, SMART_ACTION_TELEPORT, SMART_ACTION_THREAT_ALL_PCT, SMART_ACTION_THREAT_SINGLE_PCT, SMART_ACTION_UPDATE_TEMPLATE, SMART_ACTION_WP_PAUSE, SMART_ACTION_WP_RESUME, SMART_ACTION_WP_START, SMART_ACTION_WP_STOP, SMART_ESCORT_TARGETS, SMART_EVENT_LINK, SMART_EVENT_MANA_PCT, SMART_EVENT_WAYPOINT_REACHED, SMART_RANDOM_POINT, SMART_SCRIPT_TYPE_AREATRIGGER, SMART_TARGET_NONE, SMART_TARGET_POSITION, SMART_TARGET_RANDOM_POINT, SMART_TARGET_SELF, SMARTCAST_AURA_NOT_PRESENT, SMARTCAST_COMBAT_MOVE, SMARTCAST_INTERRUPT_PREVIOUS, SMARTCAST_TRIGGERED, sObjectMgr, SmartAction::sound, SmartAction::sound1, SmartAction::sound2, SmartAction::sound3, SmartAction::sound4, SmartAction::speed, SmartAction::spell, sSpellMgr, SmartAction::state, StoreCounter(), StoreTargetList(), SmartAction::storeTargets, SmartAction::subtract, SmartAction::summonCreature, WorldObject::SummonCreature(), WorldObject::SummonGameObject(), SmartAction::summonGO, WorldObject::SummonTrigger(), SmartAction::swim, SmartAction::talk, SmartScriptHolder::target, SmartAction::targetsLimit, SmartAction::targetsummon, TEAM_NEUTRAL, SmartAction::teleport, TEXT_RANGE_NORMAL, SmartAction::textGroupID, SmartAction::threatDEC, SmartAction::threatINC, SmartAction::threatPCT, Object::ToCreature(), Object::ToGameObject(), Object::ToPlayer(), ObjectGuid::ToString(), Object::ToUnit(), SmartAction::transport, trigger, SmartAction::type, SmartTarget::type, UNIT_FIELD_FLAGS, UNIT_FIELD_FLAGS_2, UNIT_FLAG_SILENCED, UNIT_NPC_EMOTESTATE, UNIT_STATE_LOST_CONTROL, SmartAction::unitFlag, SmartTarget::unitRange, SmartAction::updateLevel, SmartAction::updateTemplate, urand(), GameObject::UseDoorOrButton(), SmartAction::useTalkTarget, SmartAction::value, SmartAction::visibility, SmartAction::withEmote, SmartAction::wpPause, SmartAction::wpStart, SmartAction::wpStop, SmartTarget::x, SmartTarget::y, and SmartTarget::z.

Referenced by ProcessEvent(), and ProcessTimedAction().

◆ ProcessEvent()

void SmartScript::ProcessEvent ( SmartScriptHolder e,
Unit unit = nullptr,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
SpellInfo const *  spell = nullptr,
GameObject gob = nullptr 
)
3416{
3417 if (!e.active && e.GetEventType() != SMART_EVENT_LINK)
3418 return;
3419
3421 return;
3422
3424 return;
3425
3426 switch (e.GetEventType())
3427 {
3428 case SMART_EVENT_LINK://special handling
3429 ProcessAction(e, unit, var0, var1, bvar, spell, gob);
3430 break;
3431 //called from Update tick
3432 case SMART_EVENT_UPDATE:
3434 break;
3436 if (me && me->IsEngaged())
3437 return;
3439 break;
3441 if (!me || !me->IsEngaged())
3442 return;
3444 break;
3446 {
3447 if (!me || !me->IsEngaged() || !me->GetMaxHealth())
3448 return;
3449 uint32 perc = (uint32)me->GetHealthPct();
3450 if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
3451 return;
3453 break;
3454 }
3456 {
3457 if (!me || !me->IsEngaged() || !me->GetVictim() || !me->GetVictim()->GetMaxHealth())
3458 return;
3459 uint32 perc = (uint32)me->GetVictim()->GetHealthPct();
3460 if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
3461 return;
3463 break;
3464 }
3466 {
3467 if (!me || !me->IsEngaged() || !me->GetMaxPower(POWER_MANA))
3468 return;
3470 if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
3471 return;
3473 break;
3474 }
3476 {
3477 if (!me || !me->IsEngaged() || !me->GetVictim() || !me->GetVictim()->GetMaxPower(POWER_MANA))
3478 return;
3480 if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
3481 return;
3483 break;
3484 }
3485 case SMART_EVENT_RANGE:
3486 {
3487 if (!me || !me->IsEngaged() || !me->GetVictim())
3488 return;
3489
3491 {
3493 {
3496 }
3497 else
3499 }
3500 else
3501 RecalcTimer(e, 500, 500); // make it predictable
3502
3503 break;
3504 }
3506 {
3507 if (!me || !me->IsEngaged())
3508 return;
3509
3510 Unit* victim = me->GetVictim();
3511
3512 if (!victim || !victim->IsNonMeleeSpellCast(false, false, true))
3513 return;
3514
3515 if (e.event.targetCasting.spellId > 0)
3516 if (Spell* currSpell = victim->GetCurrentSpell(CURRENT_GENERIC_SPELL))
3517 if (currSpell->m_spellInfo->Id != e.event.targetCasting.spellId)
3518 return;
3519
3521 break;
3522 }
3524 {
3525 if (!me || !me->IsEngaged())
3526 return;
3527
3529 if (!target || !target->IsInCombat())
3530 {
3531 // Xinef: if there are at least two same npcs, they will perform the same action immediately even if this is useless...
3532 RecalcTimer(e, 1000, 3000);
3533 return;
3534 }
3536 break;
3537 }
3539 {
3540 if (!me || !me->IsEngaged())
3541 return;
3542
3543 std::vector<Creature*> creatures;
3545 if (creatures.empty())
3546 {
3547 // Xinef: if there are at least two same npcs, they will perform the same action immediately even if this is useless...
3548 RecalcTimer(e, 1000, 3000);
3549 return;
3550 }
3552 break;
3553 }
3555 {
3557 {
3558 return;
3559 }
3560
3561 std::vector<Creature*> creatures;
3563
3564 if (creatures.empty())
3565 return;
3566
3568 break;
3569 }
3571 {
3572 if (!me)
3573 return;
3574 uint32 count = me->GetAuraCount(e.event.aura.spell);
3575 if ((!e.event.aura.count && !count) || (e.event.aura.count && count >= e.event.aura.count))
3577 break;
3578 }
3580 {
3581 if (!me || !me->GetVictim())
3582 return;
3584 if (count < e.event.aura.count)
3585 return;
3587 break;
3588 }
3590 {
3591 if (bvar == (e.event.charm.onRemove != 1))
3592 ProcessAction(e, unit, var0, var1, bvar, spell, gob);
3593 break;
3594 }
3595 //no params
3596 case SMART_EVENT_AGGRO:
3597 case SMART_EVENT_DEATH:
3598 case SMART_EVENT_EVADE:
3611 case SMART_EVENT_RESET:
3615 ProcessAction(e, unit, var0, var1, bvar, spell, gob);
3616 break;
3617
3619 switch (e.event.gossipHello.filter)
3620 {
3621 case 0:
3622 // no filter set, always execute action
3623 break;
3624 case 1:
3625 // GossipHello only filter set, skip action if reportUse
3626 if (var0)
3627 {
3628 return;
3629 }
3630 break;
3631 case 2:
3632 // reportUse only filter set, skip action if GossipHello
3633 if (!var0)
3634 {
3635 return;
3636 }
3637 break;
3638 default:
3639 // Ignore any other value
3640 break;
3641 }
3642
3643 ProcessAction(e, unit, var0, var1, bvar, spell, gob);
3644 break;
3646 {
3647 if (!me)
3648 return;
3649
3650 if (Unit* victim = me->GetVictim())
3651 {
3652 if (!victim->HasInArc(static_cast<float>(M_PI), me))
3654 }
3655 break;
3656 }
3658 if (e.event.emote.emote == var0)
3659 {
3660 ProcessAction(e, unit);
3661 RecalcTimer(e, e.event.emote.cooldownMin, e.event.emote.cooldownMax);
3662 }
3663 break;
3664 case SMART_EVENT_KILL:
3665 {
3666 if (!me || !unit)
3667 return;
3668 if (e.event.kill.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
3669 return;
3670 if (e.event.kill.creature && unit->GetEntry() != e.event.kill.creature)
3671 return;
3673 ProcessAction(e, unit);
3674 break;
3675 }
3678 {
3679 if (!spell)
3680 return;
3681 if ((!e.event.spellHit.spell || spell->Id == e.event.spellHit.spell) &&
3682 (!e.event.spellHit.school || (spell->SchoolMask & e.event.spellHit.school)))
3683 {
3685 ProcessAction(e, unit, 0, 0, bvar, spell);
3686 }
3687 break;
3688 }
3690 {
3691 if (!me || me->IsEngaged())
3692 return;
3693 //can trigger if closer than fMaxAllowedRange
3694 float range = (float)e.event.los.maxDist;
3695
3696 //if range is ok and we are actually in LOS
3697 if (me->IsWithinDistInMap(unit, range) && me->IsWithinLOSInMap(unit))
3698 {
3700 //if friendly event&&who is not hostile OR hostile event&&who is hostile
3701 if ((hostilityMode == SmartEvent::LOSHostilityMode::Any) ||
3702 (hostilityMode == SmartEvent::LOSHostilityMode::NotHostile && !me->IsHostileTo(unit)) ||
3703 (hostilityMode == SmartEvent::LOSHostilityMode::Hostile && me->IsHostileTo(unit)))
3704 {
3705 if (e.event.los.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
3706 return;
3708 ProcessAction(e, unit);
3709 }
3710 }
3711 break;
3712 }
3713 case SMART_EVENT_IC_LOS:
3714 {
3715 if (!me || !me->IsEngaged())
3716 return;
3717 //can trigger if closer than fMaxAllowedRange
3718 float range = (float)e.event.los.maxDist;
3719
3720 //if range is ok and we are actually in LOS
3721 if (me->IsWithinDistInMap(unit, range) && me->IsWithinLOSInMap(unit))
3722 {
3724 //if friendly event&&who is not hostile OR hostile event&&who is hostile
3725 if ((hostilityMode == SmartEvent::LOSHostilityMode::Any) ||
3726 (hostilityMode == SmartEvent::LOSHostilityMode::NotHostile && !me->IsHostileTo(unit)) ||
3727 (hostilityMode == SmartEvent::LOSHostilityMode::Hostile && me->IsHostileTo(unit)))
3728 {
3729 if (e.event.los.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
3730 return;
3732 ProcessAction(e, unit);
3733 }
3734 }
3735 break;
3736 }
3738 {
3739 if (!GetBaseObject())
3740 return;
3742 return;
3744 return;
3745 ProcessAction(e);
3746 break;
3747 }
3750 {
3751 if (!IsCreature(unit))
3752 return;
3753 if (e.event.summoned.creature && unit->GetEntry() != e.event.summoned.creature)
3754 return;
3756 ProcessAction(e, unit);
3757 break;
3758 }
3762 {
3763 if (var0 > e.event.minMaxRepeat.max || var0 < e.event.minMaxRepeat.min)
3764 return;
3766 ProcessAction(e, unit);
3767 break;
3768 }
3770 {
3771 if ((e.event.movementInform.type && var0 != e.event.movementInform.type) || (e.event.movementInform.id && var1 != e.event.movementInform.id))
3772 return;
3773 ProcessAction(e, unit, var0, var1);
3774 break;
3775 }
3778 {
3779 if (e.event.waypoint.pathID && var0 != e.event.waypoint.pathID)
3780 return;
3781 ProcessAction(e, unit, var0);
3782 break;
3783 }
3789 {
3790 if (!me || (e.event.waypoint.pointID && var0 != e.event.waypoint.pointID) || (e.event.waypoint.pathID && GetPathId() != e.event.waypoint.pathID))
3791 return;
3792 ProcessAction(e, unit);
3793 break;
3794 }
3796 {
3797 if (e.event.summoned.creature && e.event.summoned.creature != var0)
3798 return;
3800 ProcessAction(e, unit, var0);
3801 break;
3802 }
3804 {
3806 return;
3808 ProcessAction(e, unit, var0);
3809 break;
3810 }
3813 {
3814 if (e.event.quest.quest && var0 != e.event.quest.quest)
3815 return;
3816 RecalcTimer(e, e.event.quest.cooldownMin, e.event.quest.cooldownMax);
3817 ProcessAction(e, unit, var0);
3818 break;
3819 }
3821 {
3823 return;
3824 ProcessAction(e, unit, var0);
3825 break;
3826 }
3828 {
3829 if (e.event.areatrigger.id && var0 != e.event.areatrigger.id)
3830 return;
3831 ProcessAction(e, unit, var0);
3832 break;
3833 }
3835 {
3837 return;
3838 ProcessAction(e, unit, var0);
3839 break;
3840 }
3842 {
3843 if (e.event.dataSet.id != var0 || e.event.dataSet.value != var1)
3844 return;
3846 ProcessAction(e, unit, var0, var1);
3847 break;
3848 }
3851 {
3852 if (!unit)
3853 return;
3855 ProcessAction(e, unit);
3856 break;
3857 }
3859 {
3860 if (e.event.timedEvent.id == var0)
3861 ProcessAction(e, unit);
3862 break;
3863 }
3865 {
3866 LOG_DEBUG("sql.sql", "SmartScript: Gossip Select: menu {} action {}", var0, var1); //little help for scripters
3867 if (e.event.gossip.sender != var0 || e.event.gossip.action != var1)
3868 return;
3869 ProcessAction(e, unit, var0, var1);
3870 break;
3871 }
3873 {
3875 {
3876 return;
3877 }
3878
3880 break;
3881 }
3884 {
3885 if (e.event.gameEvent.gameEventId != var0)
3886 return;
3887 ProcessAction(e, nullptr, var0);
3888 break;
3889 }
3891 {
3892 if (e.event.goStateChanged.state != var0)
3893 return;
3894 ProcessAction(e, unit, var0, var1);
3895 break;
3896 }
3898 {
3899 if (e.event.eventInform.eventId != var0)
3900 return;
3901 ProcessAction(e, nullptr, var0);
3902 break;
3903 }
3905 {
3906 if (e.event.doAction.eventId != var0)
3907 return;
3908 ProcessAction(e, unit, var0);
3909 break;
3910 }
3912 {
3913 if (!me || !me->IsEngaged())
3914 return;
3915
3916 ObjectVector targets;
3917 switch (e.GetTargetType())
3918 {
3926 {
3927 if (targets.empty())
3928 return;
3929 for (WorldObject* target : targets)
3930 {
3931 if (IsUnit(target) && me->IsFriendlyTo(target->ToUnit()) && target->ToUnit()->IsAlive() && target->ToUnit()->IsInCombat())
3932 {
3933 uint32 healthPct = uint32(target->ToUnit()->GetHealthPct());
3934 if (healthPct > e.event.friendlyHealthPct.maxHpPct || healthPct < e.event.friendlyHealthPct.minHpPct)
3935 {
3936 continue;
3937 }
3938
3939 target = target->ToUnit();
3940 break;
3941 }
3942 }
3943
3944 break;
3945 }
3946 case SMART_TARGET_SELF:
3949 break;
3950 default:
3951 return;
3952 }
3953
3954 if (targets.empty())
3955 return;
3956
3958 break;
3959 }
3961 {
3962 if (!me)
3963 return;
3964
3965 WorldObject* creature = nullptr;
3966
3967 if (e.event.distance.guid != 0)
3968 {
3969 creature = FindCreatureNear(me, e.event.distance.guid);
3970
3971 if (!creature)
3972 return;
3973
3974 if (!me->IsInRange(creature, 0, (float)e.event.distance.dist))
3975 return;
3976 }
3977 else if (e.event.distance.entry != 0)
3978 {
3979 std::list<Creature*> list;
3981
3982 if (!list.empty())
3983 creature = list.front();
3984 }
3985
3986 if (creature)
3988
3989 break;
3990 }
3992 {
3993 if (!me)
3994 return;
3995
3996 WorldObject* gameobject = nullptr;
3997
3998 if (e.event.distance.guid != 0)
3999 {
4000 gameobject = FindGameObjectNear(me, e.event.distance.guid);
4001
4002 if (!gameobject)
4003 return;
4004
4005 if (!me->IsInRange(gameobject, 0, (float)e.event.distance.dist))
4006 return;
4007 }
4008 else if (e.event.distance.entry != 0)
4009 {
4010 std::list<GameObject*> list;
4012
4013 if (!list.empty())
4014 gameobject = list.front();
4015 }
4016
4017 if (gameobject)
4019
4020 break;
4021 }
4023 if (e.event.counter.id != var0 || GetCounterValue(e.event.counter.id) != e.event.counter.value)
4024 return;
4025
4027 break;
4029 {
4030 ObjectVector units;
4031 GetWorldObjectsInDist(units, static_cast<float>(e.event.nearPlayer.radius));
4032
4033 if (!units.empty())
4034 {
4035 if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
4036 return;
4037
4038 if (units.size() >= e.event.nearPlayer.minCount)
4039 ProcessAction(e, unit);
4040 }
4042 break;
4043 }
4045 {
4046 ObjectVector units;
4047 GetWorldObjectsInDist(units, static_cast<float>(e.event.nearPlayerNegation.radius));
4048
4049 if (!units.empty())
4050 {
4051 if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
4052 return;
4053
4054 if (units.size() < e.event.nearPlayerNegation.minCount)
4055 ProcessAction(e, unit);
4056 }
4058 break;
4059 }
4060 default:
4061 LOG_ERROR("sql.sql", "SmartScript::ProcessEvent: Unhandled Event type {}", e.GetEventType());
4062 break;
4063 }
4064}
@ SMART_EVENT_FLAG_WHILE_CHARMED
Definition: SmartScriptMgr.h:1776
@ SMART_SCRIPT_RESPAWN_CONDITION_AREA
Definition: SmartScriptMgr.h:519
@ SMART_SCRIPT_RESPAWN_CONDITION_MAP
Definition: SmartScriptMgr.h:518
@ SMART_EVENT_EVADE
Definition: SmartScriptMgr.h:125
@ SMART_EVENT_ACTION_DONE
Definition: SmartScriptMgr.h:190
@ SMART_EVENT_SUMMON_DESPAWNED
Definition: SmartScriptMgr.h:153
@ SMART_EVENT_SPELLHIT
Definition: SmartScriptMgr.h:126
@ SMART_EVENT_RECEIVE_EMOTE
Definition: SmartScriptMgr.h:140
@ SMART_EVENT_FRIENDLY_HEALTH_PCT
Definition: SmartScriptMgr.h:192
@ SMART_EVENT_QUEST_FAIL
Definition: SmartScriptMgr.h:169
@ SMART_EVENT_RECEIVE_HEAL
Definition: SmartScriptMgr.h:171
@ SMART_EVENT_CHARMED_TARGET
Definition: SmartScriptMgr.h:148
@ SMART_EVENT_TARGET_MANA_PCT
Definition: SmartScriptMgr.h:136
@ SMART_EVENT_QUEST_COMPLETION
Definition: SmartScriptMgr.h:167
@ SMART_EVENT_HEALTH_PCT
Definition: SmartScriptMgr.h:120
@ SMART_EVENT_EVENT_PHASE_CHANGE
Definition: SmartScriptMgr.h:184
@ SMART_EVENT_AREATRIGGER_ONTRIGGER
Definition: SmartScriptMgr.h:164
@ SMART_EVENT_ON_SPELLCLICK
Definition: SmartScriptMgr.h:191
@ SMART_EVENT_PASSENGER_REMOVED
Definition: SmartScriptMgr.h:146
@ SMART_EVENT_INSTANCE_PLAYER_ENTER
Definition: SmartScriptMgr.h:163
@ SMART_EVENT_WAYPOINT_PAUSED
Definition: SmartScriptMgr.h:173
@ SMART_EVENT_REACHED_HOME
Definition: SmartScriptMgr.h:139
@ SMART_EVENT_TRANSPORT_ADDCREATURE
Definition: SmartScriptMgr.h:160
@ SMART_EVENT_REWARD_QUEST
Definition: SmartScriptMgr.h:138
@ SMART_EVENT_GO_EVENT_INFORM
Definition: SmartScriptMgr.h:189
@ SMART_EVENT_JUST_SUMMONED
Definition: SmartScriptMgr.h:172
@ SMART_EVENT_CHARMED
Definition: SmartScriptMgr.h:147
@ SMART_EVENT_WAYPOINT_START
Definition: SmartScriptMgr.h:157
@ SMART_EVENT_SPELLHIT_TARGET
Definition: SmartScriptMgr.h:149
@ SMART_EVENT_GAME_EVENT_START
Definition: SmartScriptMgr.h:186
@ SMART_EVENT_KILL
Definition: SmartScriptMgr.h:123
@ SMART_EVENT_TRANSPORT_REMOVE_PLAYER
Definition: SmartScriptMgr.h:161
@ SMART_EVENT_GOSSIP_HELLO
Definition: SmartScriptMgr.h:182
@ SMART_EVENT_GOSSIP_SELECT
Definition: SmartScriptMgr.h:180
@ SMART_EVENT_CORPSE_REMOVED
Definition: SmartScriptMgr.h:154
@ SMART_EVENT_PASSENGER_BOARDED
Definition: SmartScriptMgr.h:145
@ SMART_EVENT_TRANSPORT_ADDPLAYER
Definition: SmartScriptMgr.h:159
@ SMART_EVENT_WAYPOINT_ENDED
Definition: SmartScriptMgr.h:176
@ SMART_EVENT_IS_BEHIND_TARGET
Definition: SmartScriptMgr.h:185
@ SMART_EVENT_ACCEPTED_QUEST
Definition: SmartScriptMgr.h:137
@ SMART_EVENT_COUNTER_SET
Definition: SmartScriptMgr.h:195
@ SMART_EVENT_FRIENDLY_MISSING_BUFF
Definition: SmartScriptMgr.h:134
@ SMART_EVENT_WAYPOINT_RESUMED
Definition: SmartScriptMgr.h:174
@ SMART_EVENT_TARGET_BUFFED
Definition: SmartScriptMgr.h:142
@ SMART_EVENT_RESPAWN
Definition: SmartScriptMgr.h:129
@ SMART_EVENT_QUEST_ACCEPTED
Definition: SmartScriptMgr.h:165
@ SMART_EVENT_FRIENDLY_HEALTH
Definition: SmartScriptMgr.h:132
@ SMART_EVENT_QUEST_REWARDED
Definition: SmartScriptMgr.h:168
@ SMART_EVENT_DEATH
Definition: SmartScriptMgr.h:124
@ SMART_EVENT_TRANSPORT_RELOCATE
Definition: SmartScriptMgr.h:162
@ SMART_EVENT_GAME_EVENT_END
Definition: SmartScriptMgr.h:187
@ SMART_EVENT_DAMAGED
Definition: SmartScriptMgr.h:150
@ SMART_EVENT_FOLLOW_COMPLETED
Definition: SmartScriptMgr.h:183
@ SMART_EVENT_QUEST_OBJ_COMPLETION
Definition: SmartScriptMgr.h:166
@ SMART_EVENT_WAYPOINT_STOPPED
Definition: SmartScriptMgr.h:175
@ SMART_EVENT_SUMMONED_UNIT_DIES
Definition: SmartScriptMgr.h:202
@ SMART_EVENT_FRIENDLY_IS_CC
Definition: SmartScriptMgr.h:133
@ SMART_EVENT_AGGRO
Definition: SmartScriptMgr.h:122
@ SMART_EVENT_TARGET_HEALTH_PCT
Definition: SmartScriptMgr.h:130
@ SMART_EVENT_VICTIM_CASTING
Definition: SmartScriptMgr.h:131
@ SMART_EVENT_DAMAGED_TARGET
Definition: SmartScriptMgr.h:151
@ SMART_EVENT_HAS_AURA
Definition: SmartScriptMgr.h:141
@ SMART_EVENT_SUMMONED_UNIT
Definition: SmartScriptMgr.h:135
@ CURRENT_GENERIC_SPELL
Definition: Unit.h:979
uint32 GetCounterValue(uint32 id)
Definition: SmartScript.h:149
void DoFindFriendlyMissingBuff(std::vector< Creature * > &creatures, float range, uint32 spellid) const
Definition: SmartScript.cpp:4489
void DoFindFriendlyCC(std::vector< Creature * > &creatures, float range) const
Definition: SmartScript.cpp:4479
void ProcessAction(SmartScriptHolder &e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition: SmartScript.cpp:114
static bool IsCharmedCreature(WorldObject *obj)
Definition: SmartScript.cpp:4572
uint32 GetPathId() const
Definition: SmartScript.h:53
Unit * DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const
Definition: SmartScript.cpp:4452
bool IsInPhase(uint32 p) const
Definition: SmartScript.cpp:4618
Unit * DoSelectLowestHpPercentFriendly(float range, uint32 minHpPct, uint32 maxHpPct) const
Definition: SmartScript.cpp:4465
void ProcessTimedAction(SmartScriptHolder &e, uint32 const &min, uint32 const &max, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition: SmartScript.cpp:2712
uint32 map
Definition: SmartScriptMgr.h:271
struct SmartEvent::@30::@59 gossip
struct SmartEvent::@30::@34 kill
struct SmartEvent::@30::@57 timedEvent
uint32 checkTimer
Definition: SmartScriptMgr.h:485
struct SmartEvent::@30::@56 textOver
struct SmartEvent::@30::@40 friendlyHealth
uint32 entry
Definition: SmartScriptMgr.h:467
struct SmartEvent::@30::@67 friendlyHealthPct
uint32 id
Definition: SmartScriptMgr.h:357
LOSHostilityMode
Definition: SmartScriptMgr.h:507
uint32 cooldownMax
Definition: SmartScriptMgr.h:243
struct SmartEvent::@30::@52 transportAddCreature
struct SmartEvent::@30::@47 charm
struct SmartEvent::@30::@54 instancePlayerEnter
uint32 pointID
Definition: SmartScriptMgr.h:370
uint32 radius
Definition: SmartScriptMgr.h:291
uint32 maxDist
Definition: SmartScriptMgr.h:262
struct SmartEvent::@30::@36 los
uint32 sender
Definition: SmartScriptMgr.h:414
uint32 school
Definition: SmartScriptMgr.h:251
uint32 eventId
Definition: SmartScriptMgr.h:447
struct SmartEvent::@30::@42 missingBuff
struct SmartEvent::@30::@63 gameEvent
struct SmartEvent::@30::@55 areatrigger
uint32 guid
Definition: SmartScriptMgr.h:466
uint32 dist
Definition: SmartScriptMgr.h:468
uint32 spellId
Definition: SmartScriptMgr.h:285
struct SmartEvent::@30::@64 goStateChanged
uint32 emote
Definition: SmartScriptMgr.h:328
struct SmartEvent::@30::@39 targetCasting
struct SmartEvent::@30::@43 summoned
struct SmartEvent::@30::@41 friendlyCC
uint32 filter
Definition: SmartScriptMgr.h:409
uint32 hostilityMode
Hostility mode of the event. 0: hostile, 1: not hostile, 2: any.
Definition: SmartScriptMgr.h:261
uint32 hpDeficit
Definition: SmartScriptMgr.h:290
uint32 area
Definition: SmartScriptMgr.h:272
uint32 count
Definition: SmartScriptMgr.h:336
uint32 onlyInCombat
Definition: SmartScriptMgr.h:309
struct SmartEvent::@30::@49 movementInform
struct SmartEvent::@30::@66 doAction
uint32 value
Definition: SmartScriptMgr.h:363
uint32 pathID
Definition: SmartScriptMgr.h:371
SAIBool playerOnly
Definition: SmartScriptMgr.h:244
uint32 creatureEntry
Definition: SmartScriptMgr.h:399
struct SmartEvent::@30::@37 respawn
uint32 action
Definition: SmartScriptMgr.h:415
struct SmartEvent::@30::@71 nearPlayerNegation
struct SmartEvent::@30::@50 dataSet
uint32 spell
Definition: SmartScriptMgr.h:250
struct SmartEvent::@30::@58 gossipHello
struct SmartEvent::@30::@61 eventPhaseChange
uint32 gameEventId
Definition: SmartScriptMgr.h:437
uint32 textGroupID
Definition: SmartScriptMgr.h:398
struct SmartEvent::@30::@35 spellHit
uint32 cooldownMin
Definition: SmartScriptMgr.h:242
uint32 onRemove
Definition: SmartScriptMgr.h:343
uint32 quest
Definition: SmartScriptMgr.h:321
struct SmartEvent::@30::@46 aura
uint32 state
Definition: SmartScriptMgr.h:442
uint32 minHpPct
Definition: SmartScriptMgr.h:457
uint32 maxRange
Definition: SmartScriptMgr.h:234
struct SmartEvent::@30::@38 minMax
struct SmartEvent::@30::@69 counter
struct SmartEvent::@30::@62 behindTarget
struct SmartEvent::@30::@51 waypoint
uint32 maxHpPct
Definition: SmartScriptMgr.h:458
uint32 team
Definition: SmartScriptMgr.h:386
uint32 minRange
Definition: SmartScriptMgr.h:233
uint32 minCount
Definition: SmartScriptMgr.h:482
struct SmartEvent::@30::@65 eventInform
uint32 creature
Definition: SmartScriptMgr.h:245
uint32 phasemask
Definition: SmartScriptMgr.h:426
void GetGameObjectListWithEntryInGrid(std::list< GameObject * > &lList, uint32 uiEntry, float fMaxSearchRange) const
Definition: Object.cpp:2456
void GetCreatureListWithEntryInGrid(std::list< Creature * > &lList, uint32 uiEntry, float fMaxSearchRange) const
Definition: Object.cpp:2463
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition: Object.cpp:1321
bool HasInArc(float arcangle, const Position *pos, float targetRadius=0.0f) const
Definition: Position.cpp:140
float GetHealthPct() const
Definition: Unit.h:1448
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true) const
Definition: Unit.cpp:4039
uint32 GetMaxHealth() const
Definition: Unit.h:1441
uint32 GetAuraCount(uint32 spellId) const
Definition: Unit.cpp:5594
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:10214
bool IsHostileTo(Unit const *unit) const
Definition: Unit.cpp:10209
bool IsInCombat() const
Definition: Unit.h:1688
Spell * GetCurrentSpell(CurrentSpellTypes spellType) const
Definition: Unit.h:2061
Definition: Spell.h:284

References SmartEvent::action, SmartScriptHolder::active, SmartEvent::Any, SmartEvent::area, SmartEvent::areatrigger, SmartEvent::aura, SmartEvent::behindTarget, SmartEvent::charm, SmartEvent::checkTimer, SmartEvent::cooldownMax, SmartEvent::cooldownMin, SmartEvent::count, SmartEvent::counter, SmartEvent::creature, SmartEvent::creatureEntry, CURRENT_GENERIC_SPELL, SmartEvent::dataSet, SmartEvent::dist, SmartEvent::distance, SmartEvent::doAction, DoFindFriendlyCC(), DoFindFriendlyMissingBuff(), DoSelectLowestHpFriendly(), DoSelectLowestHpPercentFriendly(), SmartEvent::emote, SmartEvent::entry, SmartScriptHolder::event, SmartEvent::event_flags, SmartEvent::event_phase_mask, SmartEvent::eventId, SmartEvent::eventInform, SmartEvent::eventPhaseChange, SmartEvent::filter, FindCreatureNear(), FindGameObjectNear(), SmartEvent::friendlyCC, SmartEvent::friendlyHealth, SmartEvent::friendlyHealthPct, SmartEvent::gameEvent, SmartEvent::gameEventId, Unit::GetAuraCount(), GetBaseObject(), GetCounterValue(), WorldObject::GetCreatureListWithEntryInGrid(), Unit::GetCurrentSpell(), Object::GetEntry(), SmartScriptHolder::GetEventType(), WorldObject::GetGameObjectListWithEntryInGrid(), Unit::GetHealthPct(), GetLastInvoker(), Unit::GetMaxHealth(), Unit::GetMaxPower(), GetPathId(), Unit::GetPowerPct(), SmartScriptHolder::GetTargetType(), Object::GetTypeId(), Unit::GetVictim(), GetWorldObjectsInDist(), SmartEvent::gossip, SmartEvent::gossipHello, SmartEvent::goStateChanged, SmartEvent::guid, SmartEvent::Hostile, SmartEvent::hostilityMode, SmartEvent::hpDeficit, SmartEvent::id, SpellInfo::Id, SmartEvent::instancePlayerEnter, IsCharmedCreature(), IsCreature(), Unit::IsEngaged(), Unit::IsFriendlyTo(), Unit::IsHostileTo(), Unit::IsInCombat(), IsInPhase(), WorldObject::IsInRange(), Unit::IsNonMeleeSpellCast(), IsUnit(), WorldObject::IsWithinDistInMap(), WorldObject::IsWithinLOSInMap(), SmartEvent::kill, LOG_DEBUG, LOG_ERROR, SmartEvent::los, SmartEvent::map, SmartEvent::max, SmartEvent::maxDist, SmartEvent::maxHpPct, SmartEvent::maxRange, me, SmartEvent::min, SmartEvent::minCount, SmartEvent::minHpPct, SmartEvent::minMax, SmartEvent::minMaxRepeat, SmartEvent::minRange, SmartEvent::missingBuff, SmartEvent::movementInform, SmartEvent::nearPlayer, SmartEvent::nearPlayerNegation, SmartEvent::NotHostile, SmartEvent::onlyFireOnRepeat, SmartEvent::onlyInCombat, SmartEvent::onRemove, SmartEvent::pathID, SmartEvent::phasemask, SmartEvent::playerOnly, SmartEvent::pointID, POWER_MANA, ProcessAction(), ProcessTimedAction(), SmartEvent::quest, SmartEvent::radius, SmartEvent::rangeRepeat, RecalcTimer(), SmartEvent::repeat, SmartEvent::repeatMax, SmartEvent::repeatMin, SmartEvent::respawn, SmartScriptHolder::runOnce, SmartEvent::school, SpellInfo::SchoolMask, Acore::Containers::SelectRandomContainerElement(), SmartEvent::sender, SMART_EVENT_ACCEPTED_QUEST, SMART_EVENT_ACTION_DONE, SMART_EVENT_AGGRO, SMART_EVENT_AI_INIT, SMART_EVENT_AREATRIGGER_ONTRIGGER, SMART_EVENT_CHARMED, SMART_EVENT_CHARMED_TARGET, SMART_EVENT_CORPSE_REMOVED, SMART_EVENT_COUNTER_SET, SMART_EVENT_DAMAGED, SMART_EVENT_DAMAGED_TARGET, SMART_EVENT_DATA_SET, SMART_EVENT_DEATH, SMART_EVENT_DISTANCE_CREATURE, SMART_EVENT_DISTANCE_GAMEOBJECT, SMART_EVENT_EVADE, SMART_EVENT_EVENT_PHASE_CHANGE, SMART_EVENT_FLAG_NOT_REPEATABLE, SMART_EVENT_FLAG_WHILE_CHARMED, SMART_EVENT_FOLLOW_COMPLETED, SMART_EVENT_FRIENDLY_HEALTH, SMART_EVENT_FRIENDLY_HEALTH_PCT, SMART_EVENT_FRIENDLY_IS_CC, SMART_EVENT_FRIENDLY_MISSING_BUFF, SMART_EVENT_GAME_EVENT_END, SMART_EVENT_GAME_EVENT_START, SMART_EVENT_GO_EVENT_INFORM, SMART_EVENT_GO_STATE_CHANGED, SMART_EVENT_GOSSIP_HELLO, SMART_EVENT_GOSSIP_SELECT, SMART_EVENT_HAS_AURA, SMART_EVENT_HEALTH_PCT, SMART_EVENT_IC_LOS, SMART_EVENT_INSTANCE_PLAYER_ENTER, SMART_EVENT_IS_BEHIND_TARGET, SMART_EVENT_JUST_CREATED, SMART_EVENT_JUST_SUMMONED, SMART_EVENT_KILL, SMART_EVENT_LINK, SMART_EVENT_MANA_PCT, SMART_EVENT_MOVEMENTINFORM, SMART_EVENT_NEAR_PLAYERS, SMART_EVENT_NEAR_PLAYERS_NEGATION, SMART_EVENT_ON_SPELLCLICK, SMART_EVENT_OOC_LOS, SMART_EVENT_PASSENGER_BOARDED, SMART_EVENT_PASSENGER_REMOVED, SMART_EVENT_QUEST_ACCEPTED, SMART_EVENT_QUEST_COMPLETION, SMART_EVENT_QUEST_FAIL, SMART_EVENT_QUEST_OBJ_COMPLETION, SMART_EVENT_QUEST_REWARDED, SMART_EVENT_RANGE, SMART_EVENT_REACHED_HOME, SMART_EVENT_RECEIVE_EMOTE, SMART_EVENT_RECEIVE_HEAL, SMART_EVENT_RESET, SMART_EVENT_RESPAWN, SMART_EVENT_REWARD_QUEST, SMART_EVENT_SPELLHIT, SMART_EVENT_SPELLHIT_TARGET, SMART_EVENT_SUMMON_DESPAWNED, SMART_EVENT_SUMMONED_UNIT, SMART_EVENT_SUMMONED_UNIT_DIES, SMART_EVENT_TARGET_BUFFED, SMART_EVENT_TARGET_HEALTH_PCT, SMART_EVENT_TARGET_MANA_PCT, SMART_EVENT_TEXT_OVER, SMART_EVENT_TIMED_EVENT_TRIGGERED, SMART_EVENT_TRANSPORT_ADDCREATURE, SMART_EVENT_TRANSPORT_ADDPLAYER, SMART_EVENT_TRANSPORT_RELOCATE, SMART_EVENT_TRANSPORT_REMOVE_PLAYER, SMART_EVENT_UPDATE, SMART_EVENT_UPDATE_IC, SMART_EVENT_UPDATE_OOC, SMART_EVENT_VICTIM_CASTING, SMART_EVENT_WAYPOINT_ENDED, SMART_EVENT_WAYPOINT_PAUSED, SMART_EVENT_WAYPOINT_REACHED, SMART_EVENT_WAYPOINT_RESUMED, SMART_EVENT_WAYPOINT_START, SMART_EVENT_WAYPOINT_STOPPED, SMART_SCRIPT_RESPAWN_CONDITION_AREA, SMART_SCRIPT_RESPAWN_CONDITION_MAP, SMART_TARGET_ACTION_INVOKER, SMART_TARGET_CLOSEST_CREATURE, SMART_TARGET_CLOSEST_PLAYER, SMART_TARGET_CREATURE_DISTANCE, SMART_TARGET_CREATURE_GUID, SMART_TARGET_CREATURE_RANGE, SMART_TARGET_PLAYER_DISTANCE, SMART_TARGET_PLAYER_RANGE, SMART_TARGET_SELF, SmartEvent::spell, SmartEvent::spellHit, SmartEvent::spellId, SmartEvent::state, SmartEvent::summoned, SmartEvent::targetCasting, SmartEvent::team, SmartEvent::textGroupID, SmartEvent::textOver, SmartEvent::timedEvent, SmartEvent::transportAddCreature, SmartEvent::type, TYPEID_PLAYER, SmartEvent::value, and SmartEvent::waypoint.

Referenced by ProcessEventsFor(), and UpdateTimer().

◆ ProcessEventsFor()

void SmartScript::ProcessEventsFor ( SMART_EVENT  e,
Unit unit = nullptr,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
SpellInfo const *  spell = nullptr,
GameObject gob = nullptr 
)
96{
97 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
98 {
99 SMART_EVENT eventType = SMART_EVENT((*i).GetEventType());
100 if (eventType == SMART_EVENT_LINK)//special handling
101 continue;
102
103 if (eventType == e)
104 {
105 ConditionList conds = sConditionMgr->GetConditionsForSmartEvent((*i).entryOrGuid, (*i).event_id, (*i).source_type);
106 ConditionSourceInfo info = ConditionSourceInfo(unit, GetBaseObject(), me ? me->GetVictim() : nullptr);
107
108 if (sConditionMgr->IsObjectMeetToConditions(info, conds))
109 ProcessEvent(*i, unit, var0, var1, bvar, spell, gob);
110 }
111 }
112}
#define sConditionMgr
Definition: ConditionMgr.h:289
std::list< Condition * > ConditionList
Definition: ConditionMgr.h:236
Definition: ConditionMgr.h:181

References GetBaseObject(), Unit::GetVictim(), me, mEvents, ProcessEvent(), sConditionMgr, and SMART_EVENT_LINK.

Referenced by SmartAI::CorpseRemoved(), SmartAI::DamageDealt(), SmartAI::DamageTaken(), SmartGameObjectAI::Destroyed(), SmartAI::DoAction(), SmartAI::EndPath(), SmartAI::EnterEvadeMode(), SmartGameObjectAI::EventInform(), SmartGameObjectAI::GossipHello(), SmartGameObjectAI::GossipSelect(), SmartAI::HealReceived(), SmartAI::InitializeAI(), SmartGameObjectAI::InitializeAI(), SmartAI::IsSummonedBy(), SmartAI::JustDied(), SmartAI::JustEngagedWith(), SmartAI::JustReachedHome(), SmartAI::JustRespawned(), SmartAI::JustSummoned(), SmartGameObjectAI::JustSummoned(), SmartAI::KilledUnit(), SmartAI::MovementInform(), SmartAI::MovepointReached(), SmartAI::OnCharmed(), SmartGameObjectAI::OnGameEvent(), OnInitialize(), OnMoveInLineOfSight(), OnReset(), SmartAI::OnSpellClick(), SmartGameObjectAI::OnStateChanged(), SmartTrigger::OnTrigger(), OnUpdate(), SmartAI::PassengerBoarded(), SmartAI::PausePath(), SmartGameObjectAI::QuestAccept(), SmartGameObjectAI::QuestReward(), SmartAI::ReceiveEmote(), SmartGameObjectAI::Reset(), SmartAI::SetData(), SmartGameObjectAI::SetData(), SetPhase(), SmartAI::sGossipHello(), SmartAI::sGossipSelect(), SmartAI::sOnGameEvent(), SmartAI::SpellHit(), SmartGameObjectAI::SpellHit(), SmartAI::SpellHitTarget(), SmartAI::sQuestAccept(), SmartAI::sQuestReward(), SmartAI::StartPath(), SmartAI::StopFollow(), SmartAI::StopPath(), StoreCounter(), SmartAI::SummonedCreatureDespawn(), SmartGameObjectAI::SummonedCreatureDespawn(), SmartAI::SummonedCreatureDies(), SmartGameObjectAI::SummonedCreatureDies(), and SmartAI::UpdatePath().

◆ ProcessTimedAction()

void SmartScript::ProcessTimedAction ( SmartScriptHolder e,
uint32 const &  min,
uint32 const &  max,
Unit unit = nullptr,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
SpellInfo const *  spell = nullptr,
GameObject gob = nullptr 
)
2713{
2714 // xinef: extended by selfs victim
2715 ConditionList const conds = sConditionMgr->GetConditionsForSmartEvent(e.entryOrGuid, e.event_id, e.source_type);
2716 ConditionSourceInfo info = ConditionSourceInfo(unit, GetBaseObject(), me ? me->GetVictim() : nullptr);
2717
2718 if (sConditionMgr->IsObjectMeetToConditions(info, conds))
2719 {
2720 ProcessAction(e, unit, var0, var1, bvar, spell, gob);
2721 RecalcTimer(e, min, max);
2722 }
2723 else
2724 RecalcTimer(e, 5000, 5000);
2725}

References SmartScriptHolder::entryOrGuid, SmartScriptHolder::event_id, GetBaseObject(), Unit::GetVictim(), me, ProcessAction(), RecalcTimer(), sConditionMgr, and SmartScriptHolder::source_type.

Referenced by ProcessEvent().

◆ RecalcTimer()

void SmartScript::RecalcTimer ( SmartScriptHolder e,
uint32  min,
uint32  max 
)
static
4102{
4103 // min/max was checked at loading!
4104 e.timer = urand(uint32(min), uint32(max));
4105 e.active = e.timer ? false : true;
4106}
uint32 timer
Definition: SmartScriptMgr.h:1815

References SmartScriptHolder::active, SmartScriptHolder::timer, and urand().

Referenced by InitTimer(), ProcessEvent(), and ProcessTimedAction().

◆ RemoveCreatureSummon()

void SmartScript::RemoveCreatureSummon ( ObjectGuid const &  guid)
4634{
4635 _summonList.erase(guid);
4636}

References _summonList.

Referenced by SmartAI::SummonedCreatureDespawn().

◆ RemoveStoredEvent()

void SmartScript::RemoveStoredEvent ( uint32  id)
inlineprivate
284 {
285 if (!mStoredEvents.empty())
286 {
287 for (SmartAIEventStoredList::iterator i = mStoredEvents.begin(); i != mStoredEvents.end(); ++i)
288 {
289 if (i->event_id == id)
290 {
291 mStoredEvents.erase(i);
292 return;
293 }
294 }
295 }
296 }

References mStoredEvents.

Referenced by OnUpdate().

◆ ResetBaseObject()

void SmartScript::ResetBaseObject ( )
inline
182 {
183 WorldObject* lookupRoot = me;
184 if (!lookupRoot)
185 lookupRoot = go;
186
187 if (lookupRoot)
188 {
189 if (meOrigGUID)
190 {
191 if (Creature* m = ObjectAccessor::GetCreature(*lookupRoot, meOrigGUID))
192 {
193 me = m;
194 go = nullptr;
195 }
196 }
197
198 if (goOrigGUID)
199 {
201 {
202 me = nullptr;
203 go = o;
204 }
205 }
206 }
207
210 }
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:189
Creature * GetCreature(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:215

References ObjectGuid::Clear(), ObjectAccessor::GetCreature(), ObjectAccessor::GetGameObject(), go, goOrigGUID, me, and meOrigGUID.

Referenced by OnReset().

◆ RestoreCasterMaxDist()

void SmartScript::RestoreCasterMaxDist ( )
inline

◆ RestoreMaxCombatDist()

void SmartScript::RestoreMaxCombatDist ( )
inline

References mActualCombatDist, and mMaxCombatDist.

Referenced by OnReset().

◆ SetActualCombatDist()

void SmartScript::SetActualCombatDist ( uint32  dist)
inline
220{ mActualCombatDist = dist; }

References mActualCombatDist.

Referenced by ProcessAction().

◆ SetCasterActualDist()

void SmartScript::SetCasterActualDist ( float  dist)
inline
226{ smartCasterActualDist = dist; }

References smartCasterActualDist.

Referenced by ProcessAction().

◆ SetPathId()

void SmartScript::SetPathId ( uint32  id)
inline
52{ mPathId = id; }

References mPathId.

Referenced by SmartAI::EndPath(), and SmartAI::LoadPath().

◆ SetPhase()

void SmartScript::SetPhase ( uint32  p)
private
4607{
4608 uint32 oldPhase = mEventPhase;
4609
4610 mEventPhase = p;
4611
4612 if (oldPhase != mEventPhase)
4613 {
4615 }
4616}

References mEventPhase, ProcessEventsFor(), and SMART_EVENT_EVENT_PHASE_CHANGE.

Referenced by DecPhase(), IncPhase(), OnReset(), and ProcessAction().

◆ SetPhaseReset()

void SmartScript::SetPhaseReset ( bool  allow)
inline
233{ _allowPhaseReset = allow; }

References _allowPhaseReset.

◆ SetScript9()

void SmartScript::SetScript9 ( SmartScriptHolder e,
uint32  entry 
)
4512{
4513 //do NOT clear mTimedActionList if it's being iterated because it will invalidate the iterator and delete
4514 // any SmartScriptHolder contained like the "e" parameter passed to this function
4516 {
4517 LOG_ERROR("scripts.ai.sai", "Entry {} SourceType {} Event {} Action {} is trying to overwrite timed action list from a timed action, this is not allowed!.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
4518 return;
4519 }
4520
4521 // Do NOT allow to start a new actionlist if a previous one is already running, unless explicitly allowed. We need to always finish the current actionlist
4523 {
4524 return;
4525 }
4526
4527 mTimedActionList.clear();
4529 if (mTimedActionList.empty())
4530 return;
4531 for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
4532 {
4533 i->enableTimed = i == mTimedActionList.begin();//enable processing only for the first action
4534
4535 if (e.action.timedActionList.timerType == 0)
4536 i->event.type = SMART_EVENT_UPDATE_OOC;
4537 else if (e.action.timedActionList.timerType == 1)
4538 i->event.type = SMART_EVENT_UPDATE_IC;
4539 else if (e.action.timedActionList.timerType > 1)
4540 i->event.type = SMART_EVENT_UPDATE;
4541
4542 InitTimer((*i));
4543 }
4544}
@ SMART_SCRIPT_TYPE_TIMED_ACTIONLIST
Definition: SmartScriptMgr.h:1626
SAIBool allowOverride
Definition: SmartScriptMgr.h:1109
uint32 timerType
Definition: SmartScriptMgr.h:1108

References SmartScriptHolder::action, SmartAction::allowOverride, SmartScriptHolder::entryOrGuid, SmartScriptHolder::GetActionType(), SmartScriptHolder::GetEventType(), SmartScriptHolder::GetScriptType(), InitTimer(), isProcessingTimedActionList, LOG_ERROR, mTimedActionList, SMART_EVENT_UPDATE, SMART_EVENT_UPDATE_IC, SMART_EVENT_UPDATE_OOC, SMART_SCRIPT_TYPE_TIMED_ACTIONLIST, sSmartScriptMgr, SmartAction::timedActionList, and SmartAction::timerType.

Referenced by SmartAI::SetScript9(), and SmartGameObjectAI::SetScript9().

◆ StoreCounter()

void SmartScript::StoreCounter ( uint32  id,
uint32  value,
uint32  reset,
uint32  subtract 
)
inline
124 {
125 CounterMap::iterator itr = mCounterList.find(id);
126 if (itr != mCounterList.end())
127 {
128 if (!reset && !subtract)
129 {
130 itr->second += value;
131 }
132 else if (subtract)
133 {
134 itr->second -= value;
135 }
136 else
137 {
138 itr->second = value;
139 }
140 }
141 else
142 {
143 mCounterList.insert(std::make_pair(id, value));
144 }
145
147 }

References mCounterList, ProcessEventsFor(), and SMART_EVENT_COUNTER_SET.

Referenced by ProcessAction().

◆ StoreTargetList()

void SmartScript::StoreTargetList ( ObjectVector const &  targets,
uint32  id 
)
inline
80 {
81 // insert or replace
82 _storedTargets.erase(id);
83 _storedTargets.emplace(id, ObjectGuidVector(targets));
84 }
Definition: SmartScriptMgr.h:1826

References _storedTargets.

Referenced by ProcessAction().

◆ UpdateTimer()

void SmartScript::UpdateTimer ( SmartScriptHolder e,
uint32 const  diff 
)
4109{
4110 if (e.GetEventType() == SMART_EVENT_LINK)
4111 return;
4112
4114 return;
4115
4116 if (e.GetEventType() == SMART_EVENT_UPDATE_IC && (!me || !me->IsEngaged()))
4117 return;
4118
4119 if (e.GetEventType() == SMART_EVENT_UPDATE_OOC && (me && me->IsEngaged()))//can be used with me=nullptr (go script)
4120 return;
4121
4122 if (e.timer < diff)
4123 {
4124 // delay spell cast event if another spell is being casted
4126 {
4128 {
4130 {
4131 e.timer = 1;
4132 return;
4133 }
4134 }
4135 }
4136
4137 // Delay flee for assist event if casting
4139 {
4140 e.timer = 1;
4141 return;
4142 }
4143
4144 e.active = true;//activate events with cooldown
4145 switch (e.GetEventType())//process ONLY timed events
4146 {
4149 case SMART_EVENT_UPDATE:
4156 case SMART_EVENT_RANGE:
4167 {
4168 ProcessEvent(e);
4170 {
4171 e.enableTimed = false;//disable event if it is in an ActionList and was processed once
4172 for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
4173 {
4174 //find the first event which is not the current one and enable it
4175 if (i->event_id > e.event_id)
4176 {
4177 i->enableTimed = true;
4178 break;
4179 }
4180 }
4181 }
4182 break;
4183 }
4184 }
4185 }
4186 else
4187 e.timer -= diff;
4188}
@ UNIT_STATE_CASTING
Definition: Unit.h:340
bool enableTimed
Definition: SmartScriptMgr.h:1818

References SmartScriptHolder::action, SmartScriptHolder::active, SmartAction::cast, SmartScriptHolder::enableTimed, SmartScriptHolder::event, SmartScriptHolder::event_id, SmartEvent::event_phase_mask, SmartAction::flags, SmartScriptHolder::GetActionType(), SmartScriptHolder::GetEventType(), SmartScriptHolder::GetScriptType(), Unit::HasUnitState(), Unit::IsEngaged(), IsInPhase(), me, mTimedActionList, ProcessEvent(), SMART_ACTION_CAST, SMART_ACTION_FLEE_FOR_ASSIST, SMART_EVENT_DISTANCE_CREATURE, SMART_EVENT_DISTANCE_GAMEOBJECT, SMART_EVENT_FRIENDLY_HEALTH, SMART_EVENT_FRIENDLY_HEALTH_PCT, SMART_EVENT_FRIENDLY_IS_CC, SMART_EVENT_FRIENDLY_MISSING_BUFF, SMART_EVENT_HAS_AURA, SMART_EVENT_HEALTH_PCT, SMART_EVENT_IS_BEHIND_TARGET, SMART_EVENT_LINK, SMART_EVENT_MANA_PCT, SMART_EVENT_NEAR_PLAYERS, SMART_EVENT_NEAR_PLAYERS_NEGATION, SMART_EVENT_RANGE, SMART_EVENT_TARGET_BUFFED, SMART_EVENT_TARGET_HEALTH_PCT, SMART_EVENT_TARGET_MANA_PCT, SMART_EVENT_UPDATE, SMART_EVENT_UPDATE_IC, SMART_EVENT_UPDATE_OOC, SMART_EVENT_VICTIM_CASTING, SMART_SCRIPT_TYPE_TIMED_ACTIONLIST, SMARTCAST_INTERRUPT_PREVIOUS, SMARTCAST_TRIGGERED, SmartScriptHolder::timer, and UNIT_STATE_CASTING.

Referenced by OnUpdate().

Member Data Documentation

◆ _allowPhaseReset

bool SmartScript::_allowPhaseReset
private

◆ _storedTargets

ObjectVectorMap SmartScript::_storedTargets
private

◆ _summonList

GuidUnorderedSet SmartScript::_summonList
private

◆ go

◆ goOrigGUID

ObjectGuid SmartScript::goOrigGUID
private

Referenced by ResetBaseObject().

◆ isProcessingTimedActionList

bool SmartScript::isProcessingTimedActionList
private

Referenced by OnUpdate(), SetScript9(), and SmartScript().

◆ mActualCombatDist

uint32 SmartScript::mActualCombatDist
private

◆ mCounterList

CounterMap SmartScript::mCounterList

◆ me

◆ meOrigGUID

ObjectGuid SmartScript::meOrigGUID
private

Referenced by ResetBaseObject().

◆ mEventPhase

uint32 SmartScript::mEventPhase
private

◆ mEvents

◆ mInstallEvents

SmartAIEventList SmartScript::mInstallEvents
private

Referenced by AddEvent(), and InstallEvents().

◆ mLastInvoker

◆ mLastTextID

uint32 SmartScript::mLastTextID
private

◆ mMaxCombatDist

uint32 SmartScript::mMaxCombatDist
private

◆ mPathId

uint32 SmartScript::mPathId
private

Referenced by GetPathId(), SetPathId(), and SmartScript().

◆ mRemIDs

std::list<uint32> SmartScript::mRemIDs
private

Referenced by OnUpdate().

◆ mScriptType

SmartScriptType SmartScript::mScriptType
private

◆ mStoredDecimals

std::unordered_map<int32, int32> SmartScript::mStoredDecimals
private

◆ mStoredEvents

SmartAIEventStoredList SmartScript::mStoredEvents
private

Referenced by OnUpdate(), and RemoveStoredEvent().

◆ mTalkerEntry

uint32 SmartScript::mTalkerEntry
private

◆ mTemplate

SMARTAI_TEMPLATE SmartScript::mTemplate
private

Referenced by InstallTemplate(), and SmartScript().

◆ mTextTimer

uint32 SmartScript::mTextTimer
private

◆ mTimedActionList

SmartAIEventList SmartScript::mTimedActionList
private

Referenced by OnUpdate(), SetScript9(), and UpdateTimer().

◆ mUseTextTimer

bool SmartScript::mUseTextTimer
private

◆ smartCasterActualDist

uint32 SmartScript::smartCasterActualDist
private

◆ smartCasterMaxDist

uint32 SmartScript::smartCasterMaxDist
private

◆ smartCasterPowerType

Powers SmartScript::smartCasterPowerType
private

◆ trigger

AreaTrigger const* SmartScript::trigger
private