TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SmartScript Class Reference

#include <SmartScript.h>

Public Types

typedef std::unordered_map
< uint32, uint32
CounterMap
 

Public Member Functions

 SmartScript ()
 
 ~SmartScript ()
 
void OnInitialize (WorldObject *obj, AreaTriggerEntry const *at=NULL)
 
void GetScript ()
 
void FillScript (SmartAIEventList e, WorldObject *obj, AreaTriggerEntry const *at)
 
void ProcessEventsFor (SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
 
void ProcessEvent (SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
 
bool CheckTimer (SmartScriptHolder const &e) const
 
void RecalcTimer (SmartScriptHolder &e, uint32 min, uint32 max)
 
void UpdateTimer (SmartScriptHolder &e, uint32 const diff)
 
void InitTimer (SmartScriptHolder &e)
 
void ProcessAction (SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
 
void ProcessTimedAction (SmartScriptHolder &e, uint32 const &min, uint32 const &max, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
 
ObjectListGetTargets (SmartScriptHolder const &e, Unit *invoker=NULL)
 
ObjectListGetWorldObjectsInDist (float dist)
 
void InstallTemplate (SmartScriptHolder const &e)
 
SmartScriptHolder CreateEvent (SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, 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 phaseMask=0)
 
void AddEvent (SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, 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 phaseMask=0)
 
void SetPathId (uint32 id)
 
uint32 GetPathId () const
 
WorldObjectGetBaseObject ()
 
bool IsUnit (WorldObject *obj)
 
bool IsPlayer (WorldObject *obj)
 
bool IsCreature (WorldObject *obj)
 
bool IsGameObject (WorldObject *obj)
 
void OnUpdate (const uint32 diff)
 
void OnMoveInLineOfSight (Unit *who)
 
UnitDoSelectLowestHpFriendly (float range, uint32 MinHPDiff)
 
void DoFindFriendlyCC (std::list< Creature * > &_list, float range)
 
void DoFindFriendlyMissingBuff (std::list< Creature * > &list, float range, uint32 spellid)
 
UnitDoFindClosestFriendlyInRange (float range, bool playerOnly)
 
void StoreTargetList (ObjectList *targets, uint32 id)
 
bool IsSmart (Creature *c=NULL)
 
bool IsSmartGO (GameObject *g=NULL)
 
ObjectListGetTargetList (uint32 id)
 
void StoreCounter (uint32 id, uint32 value, uint32 reset)
 
uint32 GetCounterId (uint32 id)
 
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 ()
 

Public Attributes

ObjectListMapmTargetStorage
 
ObjectGuid mLastInvoker
 
CounterMap mCounterList
 

Private Member Functions

void IncPhase (int32 p=1)
 
void DecPhase (int32 p=1)
 
bool IsInPhase (uint32 p) const
 
void SetPhase (uint32 p=0)
 
void InstallEvents ()
 
void RemoveStoredEvent (uint32 id)
 

Private Attributes

SmartAIEventList mEvents
 
SmartAIEventList mInstallEvents
 
SmartAIEventList mTimedActionList
 
bool isProcessingTimedActionList
 
Creatureme
 
ObjectGuid meOrigGUID
 
GameObjectgo
 
ObjectGuid goOrigGUID
 
AreaTriggerEntry consttrigger
 
SmartScriptType mScriptType
 
uint32 mEventPhase
 
uint32 mPathId
 
SmartAIEventList mStoredEvents
 
std::list< uint32mRemIDs
 
uint32 mTextTimer
 
uint32 mLastTextID
 
uint32 mTalkerEntry
 
bool mUseTextTimer
 
SMARTAI_TEMPLATE mTemplate
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

SmartScript::SmartScript ( )
41 {
42  go = NULL;
43  me = NULL;
44  trigger = NULL;
45  mEventPhase = 0;
46  mPathId = 0;
48  mTextTimer = 0;
49  mLastTextID = 0;
50  mUseTextTimer = false;
51  mTalkerEntry = 0;
55 }
uint32 mLastTextID
Definition: SmartScript.h:277
uint32 mEventPhase
Definition: SmartScript.h:270
Definition: SmartScriptMgr.h:1062
ObjectListMap * mTargetStorage
Definition: SmartScript.h:201
SmartScriptType mScriptType
Definition: SmartScript.h:269
AreaTriggerEntry const * trigger
Definition: SmartScript.h:268
bool isProcessingTimedActionList
Definition: SmartScript.h:263
uint32 mTextTimer
Definition: SmartScript.h:276
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: SmartScriptMgr.h:1210
SMARTAI_TEMPLATE mTemplate
Definition: SmartScript.h:281
std::unordered_map< uint32, ObjectGuidList * > ObjectListMap
Definition: SmartScriptMgr.h:1443
GameObject * go
Definition: SmartScript.h:266
uint32 mTalkerEntry
Definition: SmartScript.h:278
uint32 mPathId
Definition: SmartScript.h:272
Creature * me
Definition: SmartScript.h:264
bool mUseTextTimer
Definition: SmartScript.h:279
SmartScript::~SmartScript ( )
58 {
59  for (ObjectListMap::iterator itr = mTargetStorage->begin(); itr != mTargetStorage->end(); ++itr)
60  delete itr->second;
61 
62  delete mTargetStorage;
63  mCounterList.clear();
64 }
CounterMap mCounterList
Definition: SmartScript.h:238
ObjectListMap * mTargetStorage
Definition: SmartScript.h:201

Member Function Documentation

void SmartScript::AddEvent ( SMART_EVENT  e,
uint32  event_flags,
uint32  event_param1,
uint32  event_param2,
uint32  event_param3,
uint32  event_param4,
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  phaseMask = 0 
)
2463 {
2464  mInstallEvents.push_back(CreateEvent(e, event_flags, event_param1, event_param2, event_param3, event_param4, action, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, t, target_param1, target_param2, target_param3, phaseMask));
2465 }
SmartScriptHolder CreateEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, 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 phaseMask=0)
Definition: SmartScript.cpp:2467
SmartAIEventList mInstallEvents
Definition: SmartScript.h:261

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SmartScript::CheckTimer ( SmartScriptHolder const e) const
3426 {
3427  return e.active;
3428 }
SmartScriptHolder SmartScript::CreateEvent ( SMART_EVENT  e,
uint32  event_flags,
uint32  event_param1,
uint32  event_param2,
uint32  event_param3,
uint32  event_param4,
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  phaseMask = 0 
)
2468 {
2469  SmartScriptHolder script;
2470  script.event.type = e;
2471  script.event.raw.param1 = event_param1;
2472  script.event.raw.param2 = event_param2;
2473  script.event.raw.param3 = event_param3;
2474  script.event.raw.param4 = event_param4;
2475  script.event.event_phase_mask = phaseMask;
2476  script.event.event_flags = event_flags;
2477  script.event.event_chance = 100;
2478 
2479  script.action.type = action;
2480  script.action.raw.param1 = action_param1;
2481  script.action.raw.param2 = action_param2;
2482  script.action.raw.param3 = action_param3;
2483  script.action.raw.param4 = action_param4;
2484  script.action.raw.param5 = action_param5;
2485  script.action.raw.param6 = action_param6;
2486 
2487  script.target.type = t;
2488  script.target.raw.param1 = target_param1;
2489  script.target.raw.param2 = target_param2;
2490  script.target.raw.param3 = target_param3;
2491 
2493  InitTimer(script);
2494  return script;
2495 }
uint32 event_phase_mask
Definition: SmartScriptMgr.h:189
SmartEvent event
Definition: SmartScriptMgr.h:1372
SMARTAI_TARGETS type
Definition: SmartScriptMgr.h:1117
void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:3326
struct SmartTarget::@194::@209 raw
struct SmartAction::@114::@193 raw
uint32 event_flags
Definition: SmartScriptMgr.h:191
SmartTarget target
Definition: SmartScriptMgr.h:1374
Definition: SmartScriptMgr.h:1210
struct SmartEvent::@77::@113 raw
SMART_EVENT type
Definition: SmartScriptMgr.h:188
SmartAction action
Definition: SmartScriptMgr.h:1373
SmartScriptType source_type
Definition: SmartScriptMgr.h:1368
uint32 event_chance
Definition: SmartScriptMgr.h:190
Definition: SmartScriptMgr.h:1361
SMART_ACTION type
Definition: SmartScriptMgr.h:561

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::DecPhase ( int32  p = 1)
inlineprivate
250  {
251  if (mEventPhase > (uint32)p)
252  mEventPhase -= (uint32)p;
253  else
254  mEventPhase = 0;
255  }
uint32 mEventPhase
Definition: SmartScript.h:270
uint32_t uint32
Definition: Define.h:150
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

Unit * SmartScript::DoFindClosestFriendlyInRange ( float  range,
bool  playerOnly 
)
3691 {
3692  if (!me)
3693  return NULL;
3694 
3695  Unit* unit = NULL;
3696  Trinity::AnyFriendlyUnitInObjectRangeCheck u_check(me, me, range, playerOnly);
3698  me->VisitNearbyObject(range, searcher);
3699  return unit;
3700 }
Definition: GridNotifiers.h:840
arena_t NULL
Definition: jemalloc_internal.h:624
void VisitNearbyObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:587
Definition: GridNotifiers.h:393
Creature * me
Definition: SmartScript.h:264
Definition: Unit.h:1305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::DoFindFriendlyCC ( std::list< Creature * > &  _list,
float  range 
)
3657 {
3658  if (!me)
3659  return;
3660 
3662  Cell cell(p);
3663  cell.SetNoCreate();
3664 
3665  Trinity::FriendlyCCedInRange u_check(me, range);
3667 
3669 
3670  cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range);
3671 }
Definition: TypeContainerVisitor.h:32
Map * GetMap() const
Definition: Object.h:543
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
Definition: TypeContainer.h:86
float GetPositionY() const
Definition: Position.h:105
Definition: GridNotifiers.h:459
Definition: GridNotifiers.h:760
Definition: Cell.h:49
float GetPositionX() const
Definition: Position.h:104
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::DoFindFriendlyMissingBuff ( std::list< Creature * > &  list,
float  range,
uint32  spellid 
)
3674 {
3675  if (!me)
3676  return;
3677 
3679  Cell cell(p);
3680  cell.SetNoCreate();
3681 
3682  Trinity::FriendlyMissingBuffInRange u_check(me, range, spellid);
3684 
3686 
3687  cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range);
3688 }
Definition: TypeContainerVisitor.h:32
Map * GetMap() const
Definition: Object.h:543
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
Definition: TypeContainer.h:86
Definition: GridNotifiers.h:778
float GetPositionY() const
Definition: Position.h:105
Definition: GridNotifiers.h:459
Definition: Cell.h:49
float GetPositionX() const
Definition: Position.h:104
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Unit * SmartScript::DoSelectLowestHpFriendly ( float  range,
uint32  MinHPDiff 
)
3637 {
3638  if (!me)
3639  return NULL;
3640 
3642  Cell cell(p);
3643  cell.SetNoCreate();
3644 
3645  Unit* unit = NULL;
3646 
3647  Trinity::MostHPMissingInRange u_check(me, range, MinHPDiff);
3649 
3651 
3652  cell.Visit(p, grid_unit_searcher, *me->GetMap(), *me, range);
3653  return unit;
3654 }
Definition: TypeContainerVisitor.h:32
Map * GetMap() const
Definition: Object.h:543
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: GridNotifiers.h:741
Definition: TypeContainer.h:86
float GetPositionY() const
Definition: Position.h:105
Definition: GridNotifiers.h:393
Definition: Cell.h:49
float GetPositionX() const
Definition: Position.h:104
Creature * me
Definition: SmartScript.h:264
Definition: Unit.h:1305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::FillScript ( SmartAIEventList  e,
WorldObject obj,
AreaTriggerEntry const at 
)
3496 {
3497  if (e.empty())
3498  {
3499  if (obj)
3500  TC_LOG_DEBUG("scripts.ai", "SmartScript: EventMap for Entry %u is empty but is using SmartScript.", obj->GetEntry());
3501  if (at)
3502  TC_LOG_DEBUG("scripts.ai", "SmartScript: EventMap for AreaTrigger %u is empty but is using SmartScript.", at->ID);
3503  return;
3504  }
3505  for (SmartAIEventList::iterator i = e.begin(); i != e.end(); ++i)
3506  {
3507  #ifndef TRINITY_DEBUG
3508  if ((*i).event.event_flags & SMART_EVENT_FLAG_DEBUG_ONLY)
3509  continue;
3510  #endif
3511 
3512  if ((*i).event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_ALL)//if has instance flag add only if in it
3513  {
3514  if (obj && obj->GetMap()->IsDungeon())
3515  {
3516  if ((1 << (obj->GetMap()->GetSpawnMode()+1)) & (*i).event.event_flags)
3517  {
3518  mEvents.push_back((*i));
3519  }
3520  }
3521  continue;
3522  }
3523  mEvents.push_back((*i));//NOTE: 'world(0)' events still get processed in ANY instance mode
3524  }
3525  if (mEvents.empty() && obj)
3526  TC_LOG_ERROR("sql.sql", "SmartScript: Entry %u has events but no events added to list because of instance flags.", obj->GetEntry());
3527  if (mEvents.empty() && at)
3528  TC_LOG_ERROR("sql.sql", "SmartScript: AreaTrigger %u has events but no events added to list because of instance flags. NOTE: triggers can not handle any instance flags.", at->ID);
3529 }
uint8 GetSpawnMode() const
Definition: Map.h:369
Map * GetMap() const
Definition: Object.h:543
bool IsDungeon() const
Definition: Map.h:395
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: SmartScriptMgr.h:1345
Definition: SmartScriptMgr.h:1342
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
SmartAIEventList mEvents
Definition: SmartScript.h:260

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Creature* SmartScript::FindCreatureNear ( WorldObject searchObject,
ObjectGuid::LowType  guid 
) const
inline
188  {
189  auto bounds = searchObject->GetMap()->GetCreatureBySpawnIdStore().equal_range(guid);
190  if (bounds.first == bounds.second)
191  return nullptr;
192 
193  auto creatureItr = std::find_if(bounds.first, bounds.second, [](Map::CreatureBySpawnIdContainer::value_type const& pair)
194  {
195  return pair.second->IsAlive();
196  });
197 
198  return creatureItr != bounds.second ? creatureItr->second : bounds.first->second;
199  }
Map * GetMap() const
Definition: Object.h:543
CreatureBySpawnIdContainer & GetCreatureBySpawnIdStore()
Definition: Map.h:469

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GameObject* SmartScript::FindGameObjectNear ( WorldObject searchObject,
ObjectGuid::LowType  guid 
) const
inline
179  {
180  auto bounds = searchObject->GetMap()->GetGameObjectBySpawnIdStore().equal_range(guid);
181  if (bounds.first == bounds.second)
182  return nullptr;
183 
184  return bounds.first->second;
185  }
Map * GetMap() const
Definition: Object.h:543
GameObjectBySpawnIdContainer & GetGameObjectBySpawnIdStore()
Definition: Map.h:472

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WorldObject* SmartScript::GetBaseObject ( )
inline
57  {
58  WorldObject* obj = NULL;
59  if (me)
60  obj = me;
61  else if (go)
62  obj = go;
63  return obj;
64  }
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Object.h:423
GameObject * go
Definition: SmartScript.h:266
Creature * me
Definition: SmartScript.h:264

+ Here is the caller graph for this function:

uint32 SmartScript::GetCounterId ( uint32  id)
inline
163  {
164  CounterMap::iterator itr = mCounterList.find(id);
165  if (itr != mCounterList.end())
166  return itr->first;
167  return 0;
168  }
CounterMap mCounterList
Definition: SmartScript.h:238

+ Here is the caller graph for this function:

uint32 SmartScript::GetCounterValue ( uint32  id)
inline
171  {
172  CounterMap::iterator itr = mCounterList.find(id);
173  if (itr != mCounterList.end())
174  return itr->second;
175  return 0;
176  }
CounterMap mCounterList
Definition: SmartScript.h:238

+ Here is the caller graph for this function:

Unit * SmartScript::GetLastInvoker ( )
3732 {
3733  WorldObject* lookupRoot = me;
3734  if (!lookupRoot)
3735  lookupRoot = go;
3736 
3737  if (lookupRoot)
3738  return ObjectAccessor::GetUnit(*lookupRoot, mLastInvoker);
3739 
3741 }
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
Definition: Object.h:423
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
ObjectGuid mLastInvoker
Definition: SmartScript.h:236
GameObject * go
Definition: SmartScript.h:266
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 SmartScript::GetPathId ( ) const
inline
55 { return mPathId; }
uint32 mPathId
Definition: SmartScript.h:272

+ Here is the caller graph for this function:

void SmartScript::GetScript ( )
3532 {
3533  SmartAIEventList e;
3534  if (me)
3535  {
3536  e = sSmartScriptMgr->GetScript(-((int32)me->GetSpawnId()), mScriptType);
3537  if (e.empty())
3538  e = sSmartScriptMgr->GetScript((int32)me->GetEntry(), mScriptType);
3539  FillScript(e, me, NULL);
3540  }
3541  else if (go)
3542  {
3543  e = sSmartScriptMgr->GetScript(-((int32)go->GetSpawnId()), mScriptType);
3544  if (e.empty())
3545  e = sSmartScriptMgr->GetScript((int32)go->GetEntry(), mScriptType);
3546  FillScript(e, go, NULL);
3547  }
3548  else if (trigger)
3549  {
3550  e = sSmartScriptMgr->GetScript((int32)trigger->ID, mScriptType);
3551  FillScript(e, NULL, trigger);
3552  }
3553 }
void FillScript(SmartAIEventList e, WorldObject *obj, AreaTriggerEntry const *at)
Definition: SmartScript.cpp:3495
std::vector< SmartScriptHolder > SmartAIEventList
Definition: SmartScriptMgr.h:1468
SmartScriptType mScriptType
Definition: SmartScript.h:269
AreaTriggerEntry const * trigger
Definition: SmartScript.h:268
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 ID
Definition: DBCStructure.h:76
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:902
int32_t int32
Definition: Define.h:146
GameObject * go
Definition: SmartScript.h:266
uint32 GetEntry() const
Definition: Object.h:107
Creature * me
Definition: SmartScript.h:264
#define sSmartScriptMgr
Definition: SmartScriptMgr.h:1669

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectList* SmartScript::GetTargetList ( uint32  id)
inline
141  {
142  ObjectListMap::iterator itr = mTargetStorage->find(id);
143  if (itr != mTargetStorage->end())
144  return (*itr).second->GetObjectList();
145  return NULL;
146  }
ObjectListMap * mTargetStorage
Definition: SmartScript.h:201
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

ObjectList * SmartScript::GetTargets ( SmartScriptHolder const e,
Unit invoker = NULL 
)
2498 {
2499  Unit* scriptTrigger = NULL;
2500  if (invoker)
2501  scriptTrigger = invoker;
2502  else if (Unit* tempLastInvoker = GetLastInvoker())
2503  scriptTrigger = tempLastInvoker;
2504 
2505  WorldObject* baseObject = GetBaseObject();
2506 
2507  ObjectList* l = new ObjectList();
2508  switch (e.GetTargetType())
2509  {
2510  case SMART_TARGET_SELF:
2511  if (baseObject)
2512  l->push_back(baseObject);
2513  break;
2514  case SMART_TARGET_VICTIM:
2515  if (me)
2516  if (Unit* victim = me->GetVictim())
2517  l->push_back(victim);
2518  break;
2520  if (me)
2521  if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_TOPAGGRO, 1))
2522  l->push_back(u);
2523  break;
2525  if (me)
2526  if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_BOTTOMAGGRO, 0))
2527  l->push_back(u);
2528  break;
2530  if (me)
2531  if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0))
2532  l->push_back(u);
2533  break;
2535  if (me)
2536  if (Unit* u = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1))
2537  l->push_back(u);
2538  break;
2540  if (scriptTrigger)
2541  l->push_back(scriptTrigger);
2542  break;
2544  if (scriptTrigger && scriptTrigger->GetVehicle() && scriptTrigger->GetVehicle()->GetBase())
2545  l->push_back(scriptTrigger->GetVehicle()->GetBase());
2546  break;
2548  if (scriptTrigger)
2549  {
2550  if (Player* player = scriptTrigger->ToPlayer())
2551  {
2552  if (Group* group = player->GetGroup())
2553  {
2554  for (GroupReference* groupRef = group->GetFirstMember(); groupRef != NULL; groupRef = groupRef->next())
2555  if (Player* member = groupRef->GetSource())
2556  l->push_back(member);
2557  }
2558  // We still add the player to the list if there is no group. If we do
2559  // this even if there is a group (thus the else-check), it will add the
2560  // same player to the list twice. We don't want that to happen.
2561  else
2562  l->push_back(scriptTrigger);
2563  }
2564  }
2565  break;
2567  {
2568  // will always return a valid pointer, even if empty list
2569  ObjectList* units = GetWorldObjectsInDist((float)e.target.unitRange.maxDist);
2570  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2571  {
2572  if (!IsCreature(*itr))
2573  continue;
2574 
2575  if (me && me->GetGUID() == (*itr)->GetGUID())
2576  continue;
2577 
2578  if ((!e.target.unitRange.creature || (*itr)->ToCreature()->GetEntry() == e.target.unitRange.creature) && baseObject->IsInRange(*itr, float(e.target.unitRange.minDist), float(e.target.unitRange.maxDist)))
2579  l->push_back(*itr);
2580  }
2581 
2582  delete units;
2583  break;
2584  }
2586  {
2587  // will always return a valid pointer, even if empty list
2588  ObjectList* units = GetWorldObjectsInDist((float)e.target.unitDistance.dist);
2589  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2590  {
2591  if (!IsCreature(*itr))
2592  continue;
2593 
2594  if (me && me->GetGUID() == (*itr)->GetGUID())
2595  continue;
2596 
2597  if (!e.target.unitDistance.creature || (*itr)->ToCreature()->GetEntry() == e.target.unitDistance.creature)
2598  l->push_back(*itr);
2599  }
2600 
2601  delete units;
2602  break;
2603  }
2605  {
2606  // will always return a valid pointer, even if empty list
2607  ObjectList* units = GetWorldObjectsInDist((float)e.target.goDistance.dist);
2608  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2609  {
2610  if (!IsGameObject(*itr))
2611  continue;
2612 
2613  if (go && go->GetGUID() == (*itr)->GetGUID())
2614  continue;
2615 
2616  if (!e.target.goDistance.entry || (*itr)->ToGameObject()->GetEntry() == e.target.goDistance.entry)
2617  l->push_back(*itr);
2618  }
2619 
2620  delete units;
2621  break;
2622  }
2624  {
2625  // will always return a valid pointer, even if empty list
2626  ObjectList* units = GetWorldObjectsInDist((float)e.target.goRange.maxDist);
2627  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2628  {
2629  if (!IsGameObject(*itr))
2630  continue;
2631 
2632  if (go && go->GetGUID() == (*itr)->GetGUID())
2633  continue;
2634 
2635  if ((!e.target.goRange.entry && (*itr)->ToGameObject()->GetEntry() == e.target.goRange.entry) && baseObject->IsInRange(*itr, float(e.target.goRange.minDist), float(e.target.goRange.maxDist)))
2636  l->push_back(*itr);
2637  }
2638 
2639  delete units;
2640  break;
2641  }
2643  {
2644  if (!scriptTrigger && !baseObject)
2645  {
2646  TC_LOG_ERROR("sql.sql", "SMART_TARGET_CREATURE_GUID can not be used without invoker");
2647  break;
2648  }
2649 
2650  if (Creature* target = FindCreatureNear(scriptTrigger ? scriptTrigger : baseObject, e.target.unitGUID.dbGuid))
2651  if (!e.target.unitGUID.entry || target->GetEntry() == e.target.unitGUID.entry)
2652  l->push_back(target);
2653  break;
2654  }
2656  {
2657  if (!scriptTrigger && !baseObject)
2658  {
2659  TC_LOG_ERROR("sql.sql", "SMART_TARGET_GAMEOBJECT_GUID can not be used without invoker");
2660  break;
2661  }
2662 
2663  if (GameObject* target = FindGameObjectNear(scriptTrigger ? scriptTrigger : baseObject, e.target.goGUID.dbGuid))
2664  if (!e.target.goGUID.entry || target->GetEntry() == e.target.goGUID.entry)
2665  l->push_back(target);
2666  break;
2667  }
2669  {
2670  // will always return a valid pointer, even if empty list
2671  ObjectList* units = GetWorldObjectsInDist((float)e.target.playerRange.maxDist);
2672  if (!units->empty() && baseObject)
2673  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2674  if (IsPlayer(*itr) && baseObject->IsInRange(*itr, (float)e.target.playerRange.minDist, (float)e.target.playerRange.maxDist))
2675  l->push_back(*itr);
2676 
2677  delete units;
2678  break;
2679  }
2681  {
2682  // will always return a valid pointer, even if empty list
2683  ObjectList* units = GetWorldObjectsInDist((float)e.target.playerDistance.dist);
2684  for (ObjectList::const_iterator itr = units->begin(); itr != units->end(); ++itr)
2685  if (IsPlayer(*itr))
2686  l->push_back(*itr);
2687 
2688  delete units;
2689  break;
2690  }
2691  case SMART_TARGET_STORED:
2692  {
2693  ObjectListMap::iterator itr = mTargetStorage->find(e.target.stored.id);
2694  if (itr != mTargetStorage->end())
2695  {
2696  ObjectList* objectList = itr->second->GetObjectList();
2697  l->assign(objectList->begin(), objectList->end());
2698  }
2699 
2700  return l;
2701  }
2703  {
2704  if (Creature* target = GetClosestCreatureWithEntry(baseObject, e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100), !e.target.closest.dead))
2705  l->push_back(target);
2706  break;
2707  }
2709  {
2710  if (GameObject* target = GetClosestGameObjectWithEntry(baseObject, e.target.closest.entry, float(e.target.closest.dist ? e.target.closest.dist : 100)))
2711  l->push_back(target);
2712  break;
2713  }
2715  {
2716  if (me)
2717  if (Player* target = me->SelectNearestPlayer(float(e.target.playerDistance.dist)))
2718  l->push_back(target);
2719  break;
2720  }
2722  {
2723  if (me)
2724  {
2725  ObjectGuid charmerOrOwnerGuid = me->GetCharmerOrOwnerGUID();
2726 
2727  if (!charmerOrOwnerGuid)
2728  charmerOrOwnerGuid = me->GetCreatorGUID();
2729 
2730  if (Unit* owner = ObjectAccessor::GetUnit(*me, charmerOrOwnerGuid))
2731  l->push_back(owner);
2732  }
2733  break;
2734  }
2736  {
2737  if (me)
2738  {
2740  for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
2741  if (Unit* temp = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
2742  l->push_back(temp);
2743  }
2744  break;
2745  }
2747  {
2748  if (me)
2749  if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist, e.target.closestAttackable.playerOnly != 0))
2750  l->push_back(target);
2751  break;
2752  }
2754  {
2755  if (me)
2756  if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist, e.target.closestFriendly.playerOnly != 0))
2757  l->push_back(target);
2758  break;
2759  }
2760  case SMART_TARGET_POSITION:
2761  case SMART_TARGET_NONE:
2762  default:
2763  break;
2764  }
2765 
2766  if (l->empty())
2767  {
2768  delete l;
2769  l = NULL;
2770  }
2771 
2772  return l;
2773 }
Definition: SmartScriptMgr.h:1086
Definition: SmartScriptMgr.h:1099
Definition: UnitAI.h:36
Definition: SmartScriptMgr.h:1081
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
Definition: SmartScriptMgr.h:1085
TC_GAME_API Creature * GetClosestCreatureWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool alive)
Definition: ScriptedCreature.cpp:611
Definition: SmartScriptMgr.h:1098
ObjectListMap * mTargetStorage
Definition: SmartScript.h:201
Unit * SelectNearestTarget(float dist=0, bool playerOnly=false) const
Definition: Creature.cpp:1944
Definition: SmartScriptMgr.h:1082
arena_t NULL
Definition: jemalloc_internal.h:624
ThreatContainer::StorageType const & getThreatList() const
Definition: ThreatManager.h:263
Player * SelectNearestPlayer(float distance=0) const
Definition: Creature.cpp:1998
Definition: Object.h:423
Definition: Creature.h:467
Definition: SmartScriptMgr.h:1084
Definition: SmartScriptMgr.h:1079
Definition: SmartScriptMgr.h:1095
bool IsPlayer(WorldObject *obj)
Definition: SmartScript.h:71
Player * ToPlayer()
Definition: Object.h:191
Definition: UnitAI.h:37
Definition: SmartScriptMgr.h:1078
std::list< WorldObject * > ObjectList
Definition: SmartScriptMgr.h:1391
Definition: SmartScriptMgr.h:1096
Definition: SmartScriptMgr.h:1074
Definition: UnitAI.h:35
Definition: SmartScriptMgr.h:1087
Unit * GetVictim() const
Definition: Unit.h:1379
CreatureAI * AI() const
Definition: Creature.h:525
Unit * SelectTarget(SelectAggroTarget targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, int32 aura=0)
Definition: UnitAI.cpp:91
Definition: GameObject.h:880
bool IsGameObject(WorldObject *obj)
Definition: SmartScript.h:81
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.cpp:12677
GameObject * go
Definition: SmartScript.h:266
Definition: SmartScriptMgr.h:1080
Definition: SmartScriptMgr.h:1089
Unit * GetLastInvoker()
Definition: SmartScript.cpp:3731
GameObject * FindGameObjectNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:178
Definition: SmartScriptMgr.h:1088
ObjectList * GetWorldObjectsInDist(float dist)
Definition: SmartScript.cpp:2775
Definition: SmartScriptMgr.h:1091
bool IsInRange(WorldObject const *obj, float minRange, float maxRange, bool is3D=true) const
Definition: Object.cpp:1703
Definition: SmartScriptMgr.h:1093
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Vehicle * GetVehicle() const
Definition: Unit.h:2166
ObjectGuid GetCreatorGUID() const
Definition: Unit.h:1700
std::list< HostileReference * > StorageType
Definition: ThreatManager.h:149
Definition: SmartScriptMgr.h:1097
Definition: SmartScriptMgr.h:1073
Definition: SmartScriptMgr.h:1094
ThreatManager & getThreatManager()
Definition: Unit.h:1998
Definition: SmartScriptMgr.h:1090
Definition: SmartScriptMgr.h:1092
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: ObjectGuid.h:189
Definition: SmartScriptMgr.h:1075
Definition: SmartScriptMgr.h:1083
Creature * FindCreatureNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:187
Definition: SmartScriptMgr.h:1076
bool IsCreature(WorldObject *obj)
Definition: SmartScript.h:76
Creature * me
Definition: SmartScript.h:264
Definition: Unit.h:1305
TC_GAME_API GameObject * GetClosestGameObjectWithEntry(WorldObject *source, uint32 entry, float maxSearchRange)
Definition: ScriptedCreature.cpp:616
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49
Definition: Group.h:191
Definition: GroupReference.h:27
Definition: SmartScriptMgr.h:1077
Unit * DoFindClosestFriendlyInRange(float range, bool playerOnly)
Definition: SmartScript.cpp:3690

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectList * SmartScript::GetWorldObjectsInDist ( float  dist)
2776 {
2777  ObjectList* targets = new ObjectList();
2778  WorldObject* obj = GetBaseObject();
2779  if (obj)
2780  {
2781  Trinity::AllWorldObjectsInRange u_check(obj, dist);
2783  obj->VisitNearbyObject(dist, searcher);
2784  }
2785  return targets;
2786 }
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
Definition: Object.h:423
void VisitNearbyObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:587
std::list< WorldObject * > ObjectList
Definition: SmartScriptMgr.h:1391
Definition: GridNotifiers.h:218
Definition: GridNotifiers.h:1317

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::IncPhase ( int32  p = 1)
inlineprivate
242  {
243  if (p >= 0)
244  mEventPhase += (uint32)p;
245  else
246  DecPhase(abs(p));
247  }
G3D::Matrix abs(const G3D::Matrix &M)
Definition: Matrix.h:632
uint32 mEventPhase
Definition: SmartScript.h:270
void DecPhase(int32 p=1)
Definition: SmartScript.h:249
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::InitTimer ( SmartScriptHolder e)
3327 {
3328  switch (e.GetEventType())
3329  {
3330  //set only events which have initial timers
3331  case SMART_EVENT_UPDATE:
3332  case SMART_EVENT_UPDATE_IC:
3334  RecalcTimer(e, e.event.minMaxRepeat.min, e.event.minMaxRepeat.max);
3335  break;
3338  RecalcTimer(e, e.event.distance.repeat, e.event.distance.repeat);
3339  break;
3340  default:
3341  e.active = true;
3342  break;
3343  }
3344 }
Definition: SmartScriptMgr.h:179
SmartEvent event
Definition: SmartScriptMgr.h:1372
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1377
Definition: SmartScriptMgr.h:180
bool active
Definition: SmartScriptMgr.h:1382
struct SmartEvent::@77::@79 minMaxRepeat
void RecalcTimer(SmartScriptHolder &e, uint32 min, uint32 max)
Definition: SmartScript.cpp:3345
Definition: SmartScriptMgr.h:164
Definition: SmartScriptMgr.h:105
Definition: SmartScriptMgr.h:104
struct SmartEvent::@77::@111 distance

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::InstallEvents ( )
private
3431 {
3432  if (!mInstallEvents.empty())
3433  {
3434  for (SmartAIEventList::iterator i = mInstallEvents.begin(); i != mInstallEvents.end(); ++i)
3435  mEvents.push_back(*i);//must be before UpdateTimers
3436 
3437  mInstallEvents.clear();
3438  }
3439 }
SmartAIEventList mEvents
Definition: SmartScript.h:260
SmartAIEventList mInstallEvents
Definition: SmartScript.h:261

+ Here is the caller graph for this function:

void SmartScript::InstallTemplate ( SmartScriptHolder const e)
2389 {
2390  if (!GetBaseObject())
2391  return;
2392  if (mTemplate)
2393  {
2394  TC_LOG_ERROR("sql.sql", "SmartScript::InstallTemplate: Entry " SI64FMTD " SourceType %u AI Template can not be set more then once, skipped.", e.entryOrGuid, e.GetScriptType());
2395  return;
2396  }
2397  mTemplate = (SMARTAI_TEMPLATE)e.action.installTtemplate.id;
2398  switch ((SMARTAI_TEMPLATE)e.action.installTtemplate.id)
2399  {
2401  {
2402  AddEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, e.action.installTtemplate.param2, e.action.installTtemplate.param3, SMART_ACTION_CAST, e.action.installTtemplate.param1, e.target.raw.param1, 0, 0, 0, 0, SMART_TARGET_VICTIM, 0, 0, 0, 1);
2403  AddEvent(SMART_EVENT_RANGE, 0, e.action.installTtemplate.param4, 300, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 1);
2404  AddEvent(SMART_EVENT_RANGE, 0, 0, e.action.installTtemplate.param4>10?e.action.installTtemplate.param4-10:0, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 1);
2405  AddEvent(SMART_EVENT_MANA_PCT, 0, e.action.installTtemplate.param5-15>100?100:e.action.installTtemplate.param5+15, 100, 1000, 1000, SMART_ACTION_SET_EVENT_PHASE, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2406  AddEvent(SMART_EVENT_MANA_PCT, 0, 0, e.action.installTtemplate.param5, 1000, 1000, SMART_ACTION_SET_EVENT_PHASE, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2407  AddEvent(SMART_EVENT_MANA_PCT, 0, 0, e.action.installTtemplate.param5, 1000, 1000, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2408  break;
2409  }
2411  {
2412  AddEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, e.action.installTtemplate.param2, e.action.installTtemplate.param3, SMART_ACTION_CAST, e.action.installTtemplate.param1, e.target.raw.param1, 0, 0, 0, 0, SMART_TARGET_VICTIM, 0, 0, 0, 0);
2413  AddEvent(SMART_EVENT_JUST_CREATED, 0, 0, 0, 0, 0, SMART_ACTION_ALLOW_COMBAT_MOVEMENT, 0, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2414  break;
2415  }
2417  {
2418  if (!me)
2419  return;
2420  //store cage as id1
2421  AddEvent(SMART_EVENT_DATA_SET, 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);
2422 
2423  //reset(close) cage on hostage(me) respawn
2424  AddEvent(SMART_EVENT_UPDATE, SMART_EVENT_FLAG_NOT_REPEATABLE, 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);
2425 
2426  AddEvent(SMART_EVENT_DATA_SET, 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);
2427  AddEvent(SMART_EVENT_DATA_SET, 0, 0, 0, 0, 0, SMART_ACTION_SET_EVENT_PHASE, 1, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2428 
2429  AddEvent(SMART_EVENT_UPDATE, SMART_EVENT_FLAG_NOT_REPEATABLE, 1000, 1000, 0, 0, SMART_ACTION_MOVE_FORWARD, e.action.installTtemplate.param4, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 1);
2430  //phase 1: give quest credit on movepoint reached
2432  //phase 1: despawn after time on movepoint reached
2433  AddEvent(SMART_EVENT_MOVEMENTINFORM, 0, POINT_MOTION_TYPE, SMART_RANDOM_POINT, 0, 0, SMART_ACTION_FORCE_DESPAWN, e.action.installTtemplate.param2, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 1);
2434 
2435  if (sCreatureTextMgr->TextExist(me->GetEntry(), (uint8)e.action.installTtemplate.param5))
2436  AddEvent(SMART_EVENT_MOVEMENTINFORM, 0, POINT_MOTION_TYPE, SMART_RANDOM_POINT, 0, 0, SMART_ACTION_TALK, e.action.installTtemplate.param5, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 1);
2437  break;
2438  }
2440  {
2441  if (!go)
2442  return;
2443  //store hostage as id1
2444  AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 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);
2445  //store invoker as id2
2446  AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, SMART_ACTION_STORE_TARGET_LIST, 2, 0, 0, 0, 0, 0, SMART_TARGET_NONE, 0, 0, 0, 0);
2447  //signal hostage
2448  AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, SMART_ACTION_SET_DATA, 0, 0, 0, 0, 0, 0, SMART_TARGET_STORED, 1, 0, 0, 0);
2449  //when hostage raeched end point, give credit to invoker
2450  if (e.action.installTtemplate.param2)
2451  AddEvent(SMART_EVENT_DATA_SET, 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);
2452  else
2453  AddEvent(SMART_EVENT_GO_STATE_CHANGED, 0, 2, 0, 0, 0, SMART_ACTION_CALL_KILLEDMONSTER, e.action.installTtemplate.param1, 0, 0, 0, 0, 0, SMART_TARGET_STORED, 2, 0, 0, 0);
2454  break;
2455  }
2457  default:
2458  return;
2459  }
2460 }
Definition: SmartScriptMgr.h:1066
Definition: SmartScriptMgr.h:53
Definition: SmartScriptMgr.h:174
void AddEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, 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 phaseMask=0)
Definition: SmartScript.cpp:2462
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
Definition: SmartScriptMgr.h:503
Definition: SmartScriptMgr.h:480
Definition: SmartScriptMgr.h:461
Definition: SmartScriptMgr.h:1062
Definition: SmartScriptMgr.h:1085
Definition: SmartScriptMgr.h:460
Definition: SmartScriptMgr.h:498
Definition: SmartScriptMgr.h:1335
Definition: SmartScriptMgr.h:485
SMARTAI_TEMPLATE
Definition: SmartScriptMgr.h:1060
Definition: SmartScriptMgr.h:1064
Definition: SmartScriptMgr.h:138
Definition: SmartScriptMgr.h:440
Definition: SmartScriptMgr.h:1067
Definition: SmartScriptMgr.h:142
Definition: SmartScriptMgr.h:472
Definition: SmartScriptMgr.h:167
Definition: SmartScriptMgr.h:450
Definition: SmartScriptMgr.h:471
SMARTAI_TEMPLATE mTemplate
Definition: SmartScript.h:281
#define SI64FMTD
Definition: Define.h:140
Definition: SmartScriptMgr.h:107
#define sCreatureTextMgr
Definition: CreatureTextMgr.h:113
Definition: SmartScriptMgr.h:113
Definition: SmartScriptMgr.h:164
GameObject * go
Definition: SmartScript.h:266
Definition: SmartScriptMgr.h:1088
uint8_t uint8
Definition: g3dmath.h:164
Definition: SmartScriptMgr.h:1093
Definition: SmartScriptMgr.h:1073
Definition: SmartScriptMgr.h:1063
Definition: SmartScriptMgr.h:104
Definition: SmartScriptMgr.h:1092
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: SmartScriptMgr.h:1075
Definition: SmartScriptMgr.h:484
Creature * me
Definition: SmartScript.h:264
Definition: MotionMaster.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SmartScript::IsCreature ( WorldObject obj)
inline
77  {
78  return obj && obj->GetTypeId() == TYPEID_UNIT;
79  }
Definition: ObjectGuid.h:32
TypeID GetTypeId() const
Definition: Object.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SmartScript::IsGameObject ( WorldObject obj)
inline
82  {
83  return obj && obj->GetTypeId() == TYPEID_GAMEOBJECT;
84  }
TypeID GetTypeId() const
Definition: Object.h:113
Definition: ObjectGuid.h:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SmartScript::IsInPhase ( uint32  p) const
inlineprivate
257 { return ((1 << (mEventPhase - 1)) & p) != 0; }
uint32 mEventPhase
Definition: SmartScript.h:270

+ Here is the caller graph for this function:

bool SmartScript::IsPlayer ( WorldObject obj)
inline
72  {
73  return obj && obj->GetTypeId() == TYPEID_PLAYER;
74  }
TypeID GetTypeId() const
Definition: Object.h:113
Definition: ObjectGuid.h:33

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SmartScript::IsSmart ( Creature c = NULL)
inline
112  {
113  bool smart = true;
114  if (c && c->GetAIName() != "SmartAI")
115  smart = false;
116 
117  if (!me || me->GetAIName() != "SmartAI")
118  smart = false;
119 
120  if (!smart)
121  TC_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: " UI64FMTD " Entry: %u) is not using SmartAI, action called by Creature (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(c ? c->GetSpawnId() : UI64LIT(0)), c ? c->GetEntry() : 0, uint64(me ? me->GetSpawnId() : UI64LIT(0)), me ? me->GetEntry() : 0);
122 
123  return smart;
124  }
#define UI64LIT(N)
Definition: Define.h:138
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
uint64_t uint64
Definition: g3dmath.h:170
#define UI64FMTD
Definition: Define.h:137
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Creature * me
Definition: SmartScript.h:264
std::string GetAIName() const
Definition: Creature.cpp:2417

+ Here is the caller graph for this function:

bool SmartScript::IsSmartGO ( GameObject g = NULL)
inline
127  {
128  bool smart = true;
129  if (g && g->GetAIName() != "SmartGameObjectAI")
130  smart = false;
131 
132  if (!go || go->GetAIName() != "SmartGameObjectAI")
133  smart = false;
134  if (!smart)
135  TC_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: " UI64FMTD " Entry: %u) is not using SmartGameObjectAI, action called by GameObject (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(g ? g->GetSpawnId() : UI64LIT(0)), g ? g->GetEntry() : 0, uint64(go ? go->GetSpawnId() : UI64LIT(0)), go ? go->GetEntry() : 0);
136 
137  return smart;
138  }
#define UI64LIT(N)
Definition: Define.h:138
uint64_t uint64
Definition: g3dmath.h:170
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:902
std::string GetAIName() const
Definition: GameObject.cpp:90
#define UI64FMTD
Definition: Define.h:137
GameObject * go
Definition: SmartScript.h:266
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the caller graph for this function:

bool SmartScript::IsUnit ( WorldObject obj)
inline
67  {
68  return obj && (obj->GetTypeId() == TYPEID_UNIT || obj->GetTypeId() == TYPEID_PLAYER);
69  }
Definition: ObjectGuid.h:32
TypeID GetTypeId() const
Definition: Object.h:113
Definition: ObjectGuid.h:33

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::OnInitialize ( WorldObject obj,
AreaTriggerEntry const at = NULL 
)
3556 {
3557  if (obj)//handle object based scripts
3558  {
3559  switch (obj->GetTypeId())
3560  {
3561  case TYPEID_UNIT:
3563  me = obj->ToCreature();
3564  TC_LOG_DEBUG("scripts.ai", "SmartScript::OnInitialize: source is Creature %u", me->GetEntry());
3565  break;
3566  case TYPEID_GAMEOBJECT:
3568  go = obj->ToGameObject();
3569  TC_LOG_DEBUG("scripts.ai", "SmartScript::OnInitialize: source is GameObject %u", go->GetEntry());
3570  break;
3571  default:
3572  TC_LOG_ERROR("misc", "SmartScript::OnInitialize: Unhandled TypeID !WARNING!");
3573  return;
3574  }
3575  } else if (at)
3576  {
3578  trigger = at;
3579  TC_LOG_DEBUG("scripts.ai", "SmartScript::OnInitialize: source is AreaTrigger %u", trigger->ID);
3580  }
3581  else
3582  {
3583  TC_LOG_ERROR("misc", "SmartScript::OnInitialize: !WARNING! Initialized objects are NULL.");
3584  return;
3585  }
3586 
3587  GetScript();//load copy of script
3588 
3589  for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
3590  InitTimer((*i));//calculate timers for first time use
3591 
3593  InstallEvents();
3595 }
Definition: SmartScriptMgr.h:1212
SmartScriptType mScriptType
Definition: SmartScript.h:269
AreaTriggerEntry const * trigger
Definition: SmartScript.h:268
Definition: ObjectGuid.h:32
Definition: SmartScriptMgr.h:141
void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:3326
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 ID
Definition: DBCStructure.h:76
GameObject * ToGameObject()
Definition: Object.h:200
TypeID GetTypeId() const
Definition: Object.h:113
void InstallEvents()
Definition: SmartScript.cpp:3430
Definition: SmartScriptMgr.h:167
void GetScript()
Definition: SmartScript.cpp:3531
Definition: SmartScriptMgr.h:1210
Definition: ObjectGuid.h:34
GameObject * go
Definition: SmartScript.h:266
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
Creature * ToCreature()
Definition: Object.h:194
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
SmartAIEventList mEvents
Definition: SmartScript.h:260
Definition: SmartScriptMgr.h:1211
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::OnMoveInLineOfSight ( Unit who)
3598 {
3599  if (!me)
3600  return;
3601 
3603 }
bool IsInCombat() const
Definition: Unit.h:1584
Definition: SmartScriptMgr.h:114
Definition: SmartScriptMgr.h:130
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::OnReset ( )
67 {
68  SetPhase(0);
70  for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
71  {
72  if (!((*i).event.event_flags & SMART_EVENT_FLAG_DONT_RESET))
73  {
74  InitTimer((*i));
75  (*i).runOnce = false;
76  }
77  }
80  mCounterList.clear();
81 }
void ResetBaseObject()
Definition: SmartScript.h:204
CounterMap mCounterList
Definition: SmartScript.h:238
Definition: SmartScriptMgr.h:1343
void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:3326
ObjectGuid mLastInvoker
Definition: SmartScript.h:236
void Clear()
Definition: ObjectGuid.h:215
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
void SetPhase(uint32 p=0)
Definition: SmartScript.h:258
SmartAIEventList mEvents
Definition: SmartScript.h:260
Definition: SmartScriptMgr.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::OnUpdate ( const uint32  diff)
3442 {
3444  return;
3445 
3446  InstallEvents();//before UpdateTimers
3447 
3448  for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
3449  UpdateTimer(*i, diff);
3450 
3451  if (!mStoredEvents.empty())
3452  for (SmartAIEventList::iterator i = mStoredEvents.begin(); i != mStoredEvents.end(); ++i)
3453  UpdateTimer(*i, diff);
3454 
3455  bool needCleanup = true;
3456  if (!mTimedActionList.empty())
3457  {
3459  for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
3460  {
3461  if ((*i).enableTimed)
3462  {
3463  UpdateTimer(*i, diff);
3464  needCleanup = false;
3465  }
3466  }
3467 
3469  }
3470  if (needCleanup)
3471  mTimedActionList.clear();
3472 
3473  if (!mRemIDs.empty())
3474  {
3475  for (std::list<uint32>::iterator i = mRemIDs.begin(); i != mRemIDs.end(); ++i)
3476  {
3477  RemoveStoredEvent((*i));
3478  }
3479  }
3480  if (mUseTextTimer && me)
3481  {
3482  if (mTextTimer < diff)
3483  {
3484  uint32 textID = mLastTextID;
3485  mLastTextID = 0;
3486  uint32 entry = mTalkerEntry;
3487  mTalkerEntry = 0;
3488  mTextTimer = 0;
3489  mUseTextTimer = false;
3490  ProcessEventsFor(SMART_EVENT_TEXT_OVER, NULL, textID, entry);
3491  } else mTextTimer -= diff;
3492  }
3493 }
uint32 mLastTextID
Definition: SmartScript.h:277
SmartAIEventList mTimedActionList
Definition: SmartScript.h:262
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
SmartAIEventList mStoredEvents
Definition: SmartScript.h:273
SmartScriptType mScriptType
Definition: SmartScript.h:269
bool isProcessingTimedActionList
Definition: SmartScript.h:263
uint32 mTextTimer
Definition: SmartScript.h:276
arena_t NULL
Definition: jemalloc_internal.h:624
void InstallEvents()
Definition: SmartScript.cpp:3430
Definition: SmartScriptMgr.h:1210
uint32_t uint32
Definition: Define.h:150
void RemoveStoredEvent(uint32 id)
Definition: SmartScript.h:284
void UpdateTimer(SmartScriptHolder &e, uint32 const diff)
Definition: SmartScript.cpp:3352
uint32 mTalkerEntry
Definition: SmartScript.h:278
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
SmartAIEventList mEvents
Definition: SmartScript.h:260
Definition: SmartScriptMgr.h:1211
Creature * me
Definition: SmartScript.h:264
bool mUseTextTimer
Definition: SmartScript.h:279
std::list< uint32 > mRemIDs
Definition: SmartScript.h:274
Definition: SmartScriptMgr.h:156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::ProcessAction ( SmartScriptHolder e,
Unit unit = NULL,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
const SpellInfo spell = NULL,
GameObject gob = NULL 
)
Todo:
Resume path when reached jump location
98 {
99  //calc random
101  {
102  uint32 rnd = urand(0, 100);
103  if (e.event.event_chance <= rnd)
104  return;
105  }
106  e.runOnce = true;//used for repeat check
107 
108  if (unit)
109  mLastInvoker = unit->GetGUID();
110 
111  if (Unit* tempInvoker = GetLastInvoker())
112  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: Invoker: %s (%s)", tempInvoker->GetName().c_str(), tempInvoker->GetGUID().ToString().c_str());
113 
114  switch (e.GetActionType())
115  {
116  case SMART_ACTION_TALK:
117  {
118  ObjectList* targets = GetTargets(e, unit);
119  Creature* talker = me;
120  Player* targetPlayer = NULL;
121  Unit* talkTarget = NULL;
122 
123  if (targets)
124  {
125  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
126  {
127  if (IsCreature(*itr) && !(*itr)->ToCreature()->IsPet()) // Prevented sending text to pets.
128  {
129  if (e.action.talk.useTalkTarget)
130  talkTarget = (*itr)->ToCreature();
131  else
132  talker = (*itr)->ToCreature();
133  break;
134  }
135  else if (IsPlayer(*itr))
136  {
137  targetPlayer = (*itr)->ToPlayer();
138  break;
139  }
140  }
141 
142  delete targets;
143  }
144 
145  if (!talker)
146  break;
147 
148  mTalkerEntry = talker->GetEntry();
149  mLastTextID = e.action.talk.textGroupID;
150  mTextTimer = e.action.talk.duration;
151 
152  if (IsPlayer(GetLastInvoker())) // used for $vars in texts and whisper target
153  talkTarget = GetLastInvoker();
154  else if (targetPlayer)
155  talkTarget = targetPlayer;
156 
157  mUseTextTimer = true;
158  sCreatureTextMgr->SendChat(talker, uint8(e.action.talk.textGroupID), talkTarget);
159  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_TALK: talker: %s (%s), textGuid: %s",
160  talker->GetName().c_str(), talker->GetGUID().ToString().c_str(), talkTarget ? talkTarget->GetGUID().ToString().c_str() : "Empty");
161  break;
162  }
164  {
165  ObjectList* targets = GetTargets(e, unit);
166  if (targets)
167  {
168  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
169  {
170  if (IsCreature(*itr))
171  sCreatureTextMgr->SendChat((*itr)->ToCreature(), uint8(e.action.talk.textGroupID), IsPlayer(GetLastInvoker()) ? GetLastInvoker() : 0);
172  else if (IsPlayer(*itr) && me)
173  {
174  Unit* templastInvoker = GetLastInvoker();
175  sCreatureTextMgr->SendChat(me, uint8(e.action.talk.textGroupID), IsPlayer(templastInvoker) ? templastInvoker : 0, CHAT_MSG_ADDON, LANG_ADDON, TEXT_RANGE_NORMAL, 0, TEAM_OTHER, false, (*itr)->ToPlayer());
176  }
177  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SIMPLE_TALK: talker: %s (%s), textGroupId: %u",
178  (*itr)->GetName().c_str(), (*itr)->GetGUID().ToString().c_str(), uint8(e.action.talk.textGroupID));
179  }
180 
181  delete targets;
182  }
183  break;
184  }
186  {
187  ObjectList* targets = GetTargets(e, unit);
188  if (targets)
189  {
190  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
191  {
192  if (IsUnit(*itr))
193  {
194  (*itr)->ToUnit()->HandleEmoteCommand(e.action.emote.emote);
195  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_PLAY_EMOTE: target: %s (%s), emote: %u",
196  (*itr)->GetName().c_str(), (*itr)->GetGUID().ToString().c_str(), e.action.emote.emote);
197  }
198  }
199 
200  delete targets;
201  }
202  break;
203  }
204  case SMART_ACTION_SOUND:
205  {
206  ObjectList* targets = GetTargets(e, unit);
207  if (targets)
208  {
209  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
210  {
211  if (IsUnit(*itr))
212  {
213  (*itr)->PlayDirectSound(e.action.sound.sound, e.action.sound.onlySelf ? (*itr)->ToPlayer() : nullptr);
214  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SOUND: target: %s (%s), sound: %u, onlyself: %u",
215  (*itr)->GetName().c_str(), (*itr)->GetGUID().ToString().c_str(), e.action.sound.sound, e.action.sound.onlySelf);
216  }
217  }
218 
219  delete targets;
220  }
221  break;
222  }
224  {
225  ObjectList* targets = GetTargets(e, unit);
226  if (targets)
227  {
228  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
229  {
230  if (IsCreature(*itr))
231  {
232  if (e.action.faction.factionID)
233  {
234  (*itr)->ToCreature()->setFaction(e.action.faction.factionID);
235  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_FACTION: Creature entry %u, %s set faction to %u",
236  (*itr)->GetEntry(), (*itr)->GetGUID().ToString().c_str(), e.action.faction.factionID);
237  }
238  else
239  {
240  if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate((*itr)->ToCreature()->GetEntry()))
241  {
242  if ((*itr)->ToCreature()->getFaction() != ci->faction)
243  {
244  (*itr)->ToCreature()->setFaction(ci->faction);
245  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_FACTION: Creature entry %u, %s set faction to %u",
246  (*itr)->GetEntry(), (*itr)->GetGUID().ToString().c_str(), ci->faction);
247  }
248  }
249  }
250  }
251  }
252 
253  delete targets;
254  }
255  break;
256  }
258  {
259  ObjectList* targets = GetTargets(e, unit);
260  if (!targets)
261  break;
262 
263  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
264  {
265  if (!IsCreature(*itr))
266  continue;
267 
268  if (e.action.morphOrMount.creature || e.action.morphOrMount.model)
269  {
270  //set model based on entry from creature_template
271  if (e.action.morphOrMount.creature)
272  {
273  if (CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(e.action.morphOrMount.creature))
274  {
275  uint32 displayId = ObjectMgr::ChooseDisplayId(ci);
276  (*itr)->ToCreature()->SetDisplayId(displayId);
277  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry %u, %s set displayid to %u",
278  (*itr)->GetEntry(), (*itr)->GetGUID().ToString().c_str(), displayId);
279  }
280  }
281  //if no param1, then use value from param2 (modelId)
282  else
283  {
284  (*itr)->ToCreature()->SetDisplayId(e.action.morphOrMount.model);
285  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry %u, %s set displayid to %u",
286  (*itr)->GetEntry(), (*itr)->GetGUID().ToString().c_str(), e.action.morphOrMount.model);
287  }
288  }
289  else
290  {
291  (*itr)->ToCreature()->DeMorph();
292  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: Creature entry %u, %s demorphs.",
293  (*itr)->GetEntry(), (*itr)->GetGUID().ToString().c_str());
294  }
295  }
296 
297  delete targets;
298  break;
299  }
301  {
302  ObjectList* targets = GetTargets(e, unit);
303  if (!targets)
304  break;
305 
306  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
307  {
308  if (IsPlayer(*itr))
309  {
310  (*itr)->ToPlayer()->FailQuest(e.action.quest.quest);
311  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_FAIL_QUEST: Player %s fails quest %u",
312  (*itr)->GetGUID().ToString().c_str(), e.action.quest.quest);
313  }
314  }
315 
316  delete targets;
317  break;
318  }
320  {
321  ObjectList* targets = GetTargets(e, unit);
322  if (!targets)
323  break;
324 
325  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
326  {
327  if (IsPlayer(*itr))
328  {
329  if (Quest const* q = sObjectMgr->GetQuestTemplate(e.action.quest.quest))
330  {
331  (*itr)->ToPlayer()->AddQuestAndCheckCompletion(q, NULL);
332  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ADD_QUEST: Player %s add quest %u",
333  (*itr)->GetGUID().ToString().c_str(), e.action.quest.quest);
334  }
335  }
336  }
337 
338  delete targets;
339  break;
340  }
342  {
343  ObjectList* targets = GetTargets(e, unit);
344  if (!targets)
345  break;
346 
347  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
348  {
349  if (!IsCreature(*itr))
350  continue;
351 
352  (*itr)->ToCreature()->SetReactState(ReactStates(e.action.react.state));
353  }
354 
355  delete targets;
356  break;
357  }
359  {
360  ObjectList* targets = GetTargets(e, unit);
361  if (!targets)
362  break;
363 
365  emotes[0] = e.action.randomEmote.emote1;
366  emotes[1] = e.action.randomEmote.emote2;
367  emotes[2] = e.action.randomEmote.emote3;
368  emotes[3] = e.action.randomEmote.emote4;
369  emotes[4] = e.action.randomEmote.emote5;
370  emotes[5] = e.action.randomEmote.emote6;
372  uint32 count = 0;
373  for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT; i++)
374  {
375  if (emotes[i])
376  {
377  temp[count] = emotes[i];
378  ++count;
379  }
380  }
381 
382  if (count == 0)
383  {
384  delete targets;
385  break;
386  }
387 
388  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
389  {
390  if (IsUnit(*itr))
391  {
392  uint32 emote = temp[urand(0, count - 1)];
393  (*itr)->ToUnit()->HandleEmoteCommand(emote);
394  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_EMOTE: Creature %s handle random emote %u",
395  (*itr)->GetGUID().ToString().c_str(), emote);
396  }
397  }
398 
399  delete targets;
400  break;
401  }
403  {
404  if (!me)
405  break;
406 
408  for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
409  {
410  if (Unit* target = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
411  {
412  me->getThreatManager().modifyThreatPercent(target, e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
413  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_ALL_PCT: Creature %s modify threat for %s, value %i",
414  me->GetGUID().ToString().c_str(), target->GetGUID().ToString().c_str(),
415  e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
416  }
417  }
418  break;
419  }
421  {
422  if (!me)
423  break;
424 
425  ObjectList* targets = GetTargets(e, unit);
426  if (!targets)
427  break;
428 
429  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
430  {
431  if (IsUnit(*itr))
432  {
433  me->getThreatManager().modifyThreatPercent((*itr)->ToUnit(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
434  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_SINGLE_PCT: Creature %s modify threat for %s, value %i",
435  me->GetGUID().ToString().c_str(), (*itr)->GetGUID().ToString().c_str(),
436  e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
437  }
438  }
439 
440  delete targets;
441  break;
442  }
444  {
445  ObjectList* targets = GetTargets(e, unit);
446  if (!targets)
447  break;
448 
449  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
450  {
451  // Special handling for vehicles
452  if (IsUnit(*itr))
453  if (Vehicle* vehicle = (*itr)->ToUnit()->GetVehicleKit())
454  for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it)
455  if (Player* player = ObjectAccessor::FindPlayer(it->second.Passenger.Guid))
456  player->AreaExploredOrEventHappens(e.action.quest.quest);
457 
458  if (IsPlayer(*itr))
459  {
460  (*itr)->ToPlayer()->GroupEventHappens(e.action.quest.quest, me);
461 
462  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS: %s credited quest %u",
463  (*itr)->GetGUID().ToString().c_str(), e.action.quest.quest);
464  }
465  }
466 
467  delete targets;
468  break;
469  }
470  case SMART_ACTION_CAST:
471  {
472  ObjectList* targets = GetTargets(e, unit);
473  if (!targets)
474  break;
475 
476  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
477  {
478  if (!IsUnit(*itr))
479  continue;
480 
481  if (!(e.action.cast.flags & SMARTCAST_AURA_NOT_PRESENT) || !(*itr)->ToUnit()->HasAura(e.action.cast.spell))
482  {
483  if (me)
484  {
486  me->InterruptNonMeleeSpells(false);
487 
488  if (e.action.cast.flags & SMARTCAST_COMBAT_MOVE)
489  {
490  // If cast flag SMARTCAST_COMBAT_MOVE is set combat movement will not be allowed
491  // unless target is outside spell range, out of mana, or LOS.
492 
493  bool _allowMove = false;
494  SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(e.action.cast.spell);
495  std::vector<SpellInfo::CostData> costs = spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask());
496  bool hasPower = true;
497  for (SpellInfo::CostData const& cost : costs)
498  {
499  if (cost.Power == POWER_HEALTH)
500  {
501  if (me->GetHealth() <= uint32(cost.Amount))
502  {
503  hasPower = false;
504  break;
505  }
506  }
507  else
508  {
509  if (me->GetPower(cost.Power) < cost.Amount)
510  {
511  hasPower = false;
512  break;
513  }
514  }
515 
516  }
517 
518  if (me->GetDistance(*itr) > spellInfo->GetMaxRange(true) ||
519  me->GetDistance(*itr) < spellInfo->GetMinRange(true) ||
520  !me->IsWithinLOSInMap(*itr) || !hasPower)
521  _allowMove = true;
522 
523  ENSURE_AI(SmartAI, me->AI())->SetCombatMove(_allowMove);
524  }
525 
526  me->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
527  }
528  else if (go)
529  go->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
530 
531  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_CAST:: %s casts spell %u on target %s with castflags %u",
532  (me ? me->GetGUID() : go->GetGUID()).ToString().c_str(), e.action.cast.spell, (*itr)->GetGUID().ToString().c_str(), e.action.cast.flags);
533  }
534  else
535  TC_LOG_DEBUG("scripts.ai", "Spell %u not cast because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (%s) already has the aura", e.action.cast.spell, (*itr)->GetGUID().ToString().c_str());
536  }
537 
538  delete targets;
539  break;
540  }
542  {
543  Unit* tempLastInvoker = GetLastInvoker();
544  if (!tempLastInvoker)
545  break;
546 
547  ObjectList* targets = GetTargets(e, unit);
548  if (!targets)
549  break;
550 
551  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
552  {
553  if (!IsUnit(*itr))
554  continue;
555 
556  if (!(e.action.cast.flags & SMARTCAST_AURA_NOT_PRESENT) || !(*itr)->ToUnit()->HasAura(e.action.cast.spell))
557  {
559  tempLastInvoker->InterruptNonMeleeSpells(false);
560 
561  tempLastInvoker->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
562  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_INVOKER_CAST: Invoker %s casts spell %u on target %s with castflags %u",
563  tempLastInvoker->GetGUID().ToString().c_str(), e.action.cast.spell, (*itr)->GetGUID().ToString().c_str(), e.action.cast.flags);
564  }
565  else
566  TC_LOG_DEBUG("scripts.ai", "Spell %u not cast because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (%s) already has the aura", e.action.cast.spell, (*itr)->GetGUID().ToString().c_str());
567  }
568 
569  delete targets;
570  break;
571  }
573  {
574  ObjectList* targets = GetTargets(e, unit);
575  if (!targets)
576  break;
577 
578  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
579  {
580  if (IsUnit(*itr))
581  {
582  (*itr)->ToUnit()->AddAura(e.action.cast.spell, (*itr)->ToUnit());
583  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ADD_AURA: Adding aura %u to %s",
584  e.action.cast.spell, (*itr)->GetGUID().ToString().c_str());
585  }
586  }
587 
588  delete targets;
589  break;
590  }
592  {
593  ObjectList* targets = GetTargets(e, unit);
594  if (!targets)
595  break;
596 
597  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
598  {
599  if (IsGameObject(*itr))
600  {
601  // Activate
602  (*itr)->ToGameObject()->SetLootState(GO_READY);
603  (*itr)->ToGameObject()->UseDoorOrButton(0, false, unit);
604  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ACTIVATE_GOBJECT. %s (entry: %u) activated",
605  (*itr)->GetGUID().ToString().c_str(), (*itr)->GetEntry());
606  }
607  }
608 
609  delete targets;
610  break;
611  }
613  {
614  ObjectList* targets = GetTargets(e, unit);
615  if (!targets)
616  break;
617 
618  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
619  {
620  if (IsGameObject(*itr))
621  {
622  (*itr)->ToGameObject()->ResetDoorOrButton();
623  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RESET_GOBJECT. %s (entry: %u) reset",
624  (*itr)->GetGUID().ToString().c_str(), (*itr)->GetEntry());
625  }
626  }
627 
628  delete targets;
629  break;
630  }
632  {
633  ObjectList* targets = GetTargets(e, unit);
634  if (!targets)
635  break;
636 
637  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
638  {
639  if (IsUnit(*itr))
640  {
641  (*itr)->ToUnit()->SetUInt32Value(UNIT_NPC_EMOTESTATE, e.action.emote.emote);
642  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_EMOTE_STATE. %s set emotestate to %u",
643  (*itr)->GetGUID().ToString().c_str(), e.action.emote.emote);
644  }
645  }
646 
647  delete targets;
648  break;
649  }
651  {
652  ObjectList* targets = GetTargets(e, unit);
653  if (!targets)
654  break;
655 
656  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
657  {
658  if (IsUnit(*itr))
659  {
660  if (!e.action.unitFlag.type)
661  {
662  (*itr)->ToUnit()->SetFlag(UNIT_FIELD_FLAGS, e.action.unitFlag.flag);
663  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_UNIT_FLAG. %s added flag %u to UNIT_FIELD_FLAGS",
664  (*itr)->GetGUID().ToString().c_str(), e.action.unitFlag.flag);
665  }
666  else
667  {
668  (*itr)->ToUnit()->SetFlag(UNIT_FIELD_FLAGS_2, e.action.unitFlag.flag);
669  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_UNIT_FLAG. %s added flag %u to UNIT_FIELD_FLAGS_2",
670  (*itr)->GetGUID().ToString().c_str(), e.action.unitFlag.flag);
671  }
672  }
673  }
674 
675  delete targets;
676  break;
677  }
679  {
680  ObjectList* targets = GetTargets(e, unit);
681  if (!targets)
682  break;
683 
684  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
685  {
686  if (IsUnit(*itr))
687  {
688  if (!e.action.unitFlag.type)
689  {
690  (*itr)->ToUnit()->RemoveFlag(UNIT_FIELD_FLAGS, e.action.unitFlag.flag);
691  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_REMOVE_UNIT_FLAG. %s removed flag %u to UNIT_FIELD_FLAGS",
692  (*itr)->GetGUID().ToString().c_str(), e.action.unitFlag.flag);
693  }
694  else
695  {
696  (*itr)->ToUnit()->RemoveFlag(UNIT_FIELD_FLAGS_2, e.action.unitFlag.flag);
697  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_REMOVE_UNIT_FLAG. %s removed flag %u to UNIT_FIELD_FLAGS_2",
698  (*itr)->GetGUID().ToString().c_str(), e.action.unitFlag.flag);
699  }
700  }
701  }
702 
703  delete targets;
704  break;
705  }
707  {
708  if (!IsSmart())
709  break;
710 
711  ENSURE_AI(SmartAI, me->AI())->SetAutoAttack(e.action.autoAttack.attack != 0);
712  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_AUTO_ATTACK: %s bool on = %u",
713  me->GetGUID().ToString().c_str(), e.action.autoAttack.attack);
714  break;
715  }
717  {
718  if (!IsSmart())
719  break;
720 
721  bool move = e.action.combatMove.move != 0;
722  ENSURE_AI(SmartAI, me->AI())->SetCombatMove(move);
723  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ALLOW_COMBAT_MOVEMENT: %s bool on = %u",
724  me->GetGUID().ToString().c_str(), e.action.combatMove.move);
725  break;
726  }
728  {
729  if (!GetBaseObject())
730  break;
731 
732  SetPhase(e.action.setEventPhase.phase);
733  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_EVENT_PHASE: %s set event phase %u",
734  GetBaseObject()->GetGUID().ToString().c_str(), e.action.setEventPhase.phase);
735  break;
736  }
738  {
739  if (!GetBaseObject())
740  break;
741 
744  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_INC_EVENT_PHASE: %s inc event phase by %u, "
745  "decrease by %u", GetBaseObject()->GetGUID().ToString().c_str(), e.action.incEventPhase.inc, e.action.incEventPhase.dec);
746  break;
747  }
748  case SMART_ACTION_EVADE:
749  {
750  if (!me)
751  break;
752 
753  me->AI()->EnterEvadeMode();
754  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_EVADE: %s EnterEvadeMode", me->GetGUID().ToString().c_str());
755  break;
756  }
758  {
759  if (!me)
760  break;
761 
763  if (e.action.flee.withEmote)
764  {
767  }
768  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_FLEE_FOR_ASSIST: %s DoFleeToGetAssistance", me->GetGUID().ToString().c_str());
769  break;
770  }
772  {
773  if (!unit)
774  break;
775 
776  if (IsPlayer(unit) && GetBaseObject())
777  {
778  unit->ToPlayer()->GroupEventHappens(e.action.quest.quest, GetBaseObject());
779  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_GROUPEVENTHAPPENS: %s, group credit for quest %u",
780  unit->GetGUID().ToString().c_str(), e.action.quest.quest);
781  }
782 
783  // Special handling for vehicles
784  if (Vehicle* vehicle = unit->GetVehicleKit())
785  for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it)
786  if (Player* player = ObjectAccessor::FindPlayer(it->second.Passenger.Guid))
787  player->GroupEventHappens(e.action.quest.quest, GetBaseObject());
788  break;
789  }
791  {
792  if (!me)
793  break;
794 
795  me->CombatStop(true);
796  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_COMBAT_STOP: %s CombatStop", me->GetGUID().ToString().c_str());
797  break;
798  }
800  {
801  ObjectList* targets = GetTargets(e, unit);
802  if (!targets)
803  break;
804 
805  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
806  {
807  if (!IsUnit(*itr))
808  continue;
809 
810  if (e.action.removeAura.spell)
811  {
812  if (e.action.removeAura.charges)
813  {
814  if (Aura* aur = (*itr)->ToUnit()->GetAura(e.action.removeAura.spell))
815  aur->ModCharges(-static_cast<int32>(e.action.removeAura.charges), AURA_REMOVE_BY_EXPIRE);
816  }
817  else
818  (*itr)->ToUnit()->RemoveAurasDueToSpell(e.action.removeAura.spell);
819  }
820  else
821  (*itr)->ToUnit()->RemoveAllAuras();
822 
823  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_REMOVEAURASFROMSPELL: %s, spell %u",
824  (*itr)->GetGUID().ToString().c_str(), e.action.removeAura.spell);
825  }
826 
827  delete targets;
828  break;
829  }
830  case SMART_ACTION_FOLLOW:
831  {
832  if (!IsSmart())
833  break;
834 
835  ObjectList* targets = GetTargets(e, unit);
836  if (!targets)
837  {
838  ENSURE_AI(SmartAI, me->AI())->StopFollow();
839  break;
840  }
841 
842  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
843  {
844  if (IsUnit(*itr))
845  {
846  ENSURE_AI(SmartAI, me->AI())->SetFollow((*itr)->ToUnit(), (float)e.action.follow.dist, (float)e.action.follow.angle, e.action.follow.credit, e.action.follow.entry, e.action.follow.creditType);
847  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_FOLLOW: %s following target %s",
848  me->GetGUID().ToString().c_str(), (*itr)->GetGUID().ToString().c_str());
849  break;
850  }
851  }
852 
853  delete targets;
854  break;
855  }
857  {
858  if (!GetBaseObject())
859  break;
860 
862  phases[0] = e.action.randomPhase.phase1;
863  phases[1] = e.action.randomPhase.phase2;
864  phases[2] = e.action.randomPhase.phase3;
865  phases[3] = e.action.randomPhase.phase4;
866  phases[4] = e.action.randomPhase.phase5;
867  phases[5] = e.action.randomPhase.phase6;
869  uint32 count = 0;
870  for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT; i++)
871  {
872  if (phases[i] > 0)
873  {
874  temp[count] = phases[i];
875  ++count;
876  }
877  }
878 
879  if (count == 0)
880  break;
881 
882  uint32 phase = temp[urand(0, count - 1)];
883  SetPhase(phase);
884  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_RANDOM_PHASE: %s sets event phase to %u",
885  GetBaseObject()->GetGUID().ToString().c_str(), phase);
886  break;
887  }
889  {
890  if (!GetBaseObject())
891  break;
892 
893  uint32 phase = urand(e.action.randomPhaseRange.phaseMin, e.action.randomPhaseRange.phaseMax);
894  SetPhase(phase);
895  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_RANDOM_PHASE_RANGE: %s sets event phase to %u",
896  GetBaseObject()->GetGUID().ToString().c_str(), phase);
897  break;
898  }
900  {
901  if (e.target.type == SMART_TARGET_NONE || e.target.type == SMART_TARGET_SELF) // Loot recipient and his group members
902  {
903  if (!me)
904  break;
905 
906  if (Player* player = me->GetLootRecipient())
907  {
908  player->RewardPlayerAndGroupAtEvent(e.action.killedMonster.creature, player);
909  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_KILLEDMONSTER: %s, Killcredit: %u",
910  player->GetGUID().ToString().c_str(), e.action.killedMonster.creature);
911  }
912  }
913  else // Specific target type
914  {
915  ObjectList* targets = GetTargets(e, unit);
916  if (!targets)
917  break;
918 
919  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
920  {
921  if (IsPlayer(*itr))
922  {
923  (*itr)->ToPlayer()->KilledMonsterCredit(e.action.killedMonster.creature);
924  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_KILLEDMONSTER: %s, Killcredit: %u",
925  (*itr)->GetGUID().ToString().c_str(), e.action.killedMonster.creature);
926  }
927  else if (IsUnit(*itr)) // Special handling for vehicles
928  if (Vehicle* vehicle = (*itr)->ToUnit()->GetVehicleKit())
929  for (SeatMap::iterator seatItr = vehicle->Seats.begin(); seatItr != vehicle->Seats.end(); ++seatItr)
930  if (Player* player = ObjectAccessor::FindPlayer(seatItr->second.Passenger.Guid))
931  player->KilledMonsterCredit(e.action.killedMonster.creature);
932  }
933 
934  delete targets;
935  }
936  break;
937  }
939  {
940  WorldObject* obj = GetBaseObject();
941  if (!obj)
942  obj = unit;
943 
944  if (!obj)
945  break;
946 
947  InstanceScript* instance = obj->GetInstanceScript();
948  if (!instance)
949  {
950  TC_LOG_ERROR("sql.sql", "SmartScript: Event %u attempt to set instance data without instance script. EntryOrGuid " SI64FMTD "", e.GetEventType(), e.entryOrGuid);
951  break;
952  }
953 
954  instance->SetData(e.action.setInstanceData.field, e.action.setInstanceData.data);
955  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_INST_DATA: Field: %u, data: %u",
956  e.action.setInstanceData.field, e.action.setInstanceData.data);
957  break;
958  }
960  {
961  WorldObject* obj = GetBaseObject();
962  if (!obj)
963  obj = unit;
964 
965  if (!obj)
966  break;
967 
968  InstanceScript* instance = obj->GetInstanceScript();
969  if (!instance)
970  {
971  TC_LOG_ERROR("sql.sql", "SmartScript: Event %u attempt to set instance data without instance script. EntryOrGuid " SI64FMTD "", e.GetEventType(), e.entryOrGuid);
972  break;
973  }
974 
975  ObjectList* targets = GetTargets(e, unit);
976  if (!targets)
977  break;
978 
979  instance->SetGuidData(e.action.setInstanceData64.field, targets->front()->GetGUID());
980  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_INST_DATA64: Field: %u, data: %s",
981  e.action.setInstanceData64.field, targets->front()->GetGUID().ToString().c_str());
982 
983  delete targets;
984  break;
985  }
987  {
988  ObjectList* targets = GetTargets(e, unit);
989 
990  if (!targets)
991  break;
992 
993  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
994  if (IsCreature(*itr))
995  (*itr)->ToCreature()->UpdateEntry(e.action.updateTemplate.creature);
996 
997  delete targets;
998  break;
999  }
1000  case SMART_ACTION_DIE:
1001  {
1002  if (me && !me->isDead())
1003  {
1004  me->KillSelf();
1005  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_DIE: %s", me->GetGUID().ToString().c_str());
1006  }
1007  break;
1008  }
1010  {
1011  if (me)
1012  {
1014  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_IN_COMBAT_WITH_ZONE: %s", me->GetGUID().ToString().c_str());
1015  }
1016  break;
1017  }
1019  {
1020  if (me)
1021  {
1022  me->CallForHelp((float)e.action.callHelp.range);
1023  if (e.action.callHelp.withEmote)
1024  {
1027  }
1028  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_CALL_FOR_HELP: %s", me->GetGUID().ToString().c_str());
1029  }
1030  break;
1031  }
1033  {
1034  if (me)
1035  {
1036  me->SetSheath(SheathState(e.action.setSheath.sheath));
1037  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_SHEATH: %s, State: %u",
1038  me->GetGUID().ToString().c_str(), e.action.setSheath.sheath);
1039  }
1040  break;
1041  }
1043  {
1044  ObjectList* targets = GetTargets(e, unit);
1045 
1046  if (!targets)
1047  break;
1048 
1049  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1050  {
1051  if (Creature* target = (*itr)->ToCreature())
1052  {
1053  if (target->IsAlive() && IsSmart(target))
1054  {
1055  ENSURE_AI(SmartAI, target->AI())->SetDespawnTime(e.action.forceDespawn.delay + 1); // Next tick
1056  ENSURE_AI(SmartAI, target->AI())->StartDespawn();
1057  }
1058  else
1059  target->DespawnOrUnsummon(e.action.forceDespawn.delay);
1060  }
1061  else if (GameObject* goTarget = (*itr)->ToGameObject())
1062  {
1063  if (IsSmartGO(goTarget))
1064  goTarget->SetRespawnTime(e.action.forceDespawn.delay + 1);
1065  }
1066  }
1067 
1068  delete targets;
1069  break;
1070  }
1072  {
1073  ObjectList* targets = GetTargets(e, unit);
1074 
1075  if (!targets)
1076  break;
1077 
1078  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1079  (*itr)->SetInPhase(e.action.ingamePhaseId.id, true, e.action.ingamePhaseId.apply == 1);
1080 
1081  delete targets;
1082  break;
1083  }
1085  {
1086  ObjectList* targets = GetTargets(e, unit);
1087 
1088  if (!targets)
1089  break;
1090 
1091  std::set<uint32> phases = sDB2Manager.GetPhasesForGroup(e.action.ingamePhaseGroup.groupId);
1092 
1093  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1094  for (auto phase : phases)
1095  (*itr)->SetInPhase(phase, true, e.action.ingamePhaseGroup.apply == 1);
1096 
1097  delete targets;
1098  break;
1099  }
1101  {
1102  ObjectList* targets = GetTargets(e, unit);
1103  if (!targets)
1104  break;
1105 
1106  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1107  {
1108  if (!IsUnit(*itr))
1109  continue;
1110 
1111  if (e.action.morphOrMount.creature || e.action.morphOrMount.model)
1112  {
1113  if (e.action.morphOrMount.creature > 0)
1114  {
1115  if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(e.action.morphOrMount.creature))
1116  (*itr)->ToUnit()->Mount(ObjectMgr::ChooseDisplayId(cInfo));
1117  }
1118  else
1119  (*itr)->ToUnit()->Mount(e.action.morphOrMount.model);
1120  }
1121  else
1122  (*itr)->ToUnit()->Dismount();
1123  }
1124 
1125  delete targets;
1126  break;
1127  }
1129  {
1130  if (!me)
1131  break;
1132 
1133  SmartAI* ai = CAST_AI(SmartAI, me->AI());
1134 
1135  if (!ai)
1136  break;
1137 
1138  if (e.action.invincHP.percent)
1140  else
1142 
1143  break;
1144  }
1145  case SMART_ACTION_SET_DATA:
1146  {
1147  ObjectList* targets = GetTargets(e, unit);
1148  if (!targets)
1149  break;
1150 
1151  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1152  {
1153  if (IsCreature(*itr))
1154  (*itr)->ToCreature()->AI()->SetData(e.action.setData.field, e.action.setData.data);
1155  else if (IsGameObject(*itr))
1156  (*itr)->ToGameObject()->AI()->SetData(e.action.setData.field, e.action.setData.data);
1157  }
1158 
1159  delete targets;
1160  break;
1161  }
1163  {
1164  if (!me)
1165  break;
1166 
1167  float x, y, z;
1168  me->GetClosePoint(x, y, z, me->GetObjectSize() / 3, (float)e.action.moveRandom.distance);
1170  break;
1171  }
1172  case SMART_ACTION_RISE_UP:
1173  {
1174  if (!me)
1175  break;
1176 
1178  break;
1179  }
1181  {
1182  if (me)
1183  me->SetVisible(e.action.visibility.state != 0);
1184  break;
1185  }
1187  {
1188  if (WorldObject* baseObj = GetBaseObject())
1189  baseObj->setActive(e.action.active.state != 0);
1190 
1191  break;
1192  }
1194  {
1195  if (!me)
1196  break;
1197 
1198  ObjectList* targets = GetTargets(e, unit);
1199  if (!targets)
1200  break;
1201 
1202  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1203  {
1204  if (IsUnit(*itr))
1205  {
1206  me->AI()->AttackStart((*itr)->ToUnit());
1207  break;
1208  }
1209  }
1210 
1211  delete targets;
1212  break;
1213  }
1215  {
1216  ObjectList* targets = GetTargets(e, unit);
1217  if (targets)
1218  {
1219  float x, y, z, o;
1220  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1221  {
1222  (*itr)->GetPosition(x, y, z, o);
1223  x += e.target.x;
1224  y += e.target.y;
1225  z += e.target.z;
1226  o += e.target.o;
1227  if (Creature* summon = GetBaseObject()->SummonCreature(e.action.summonCreature.creature, x, y, z, o, (TempSummonType)e.action.summonCreature.type, e.action.summonCreature.duration))
1228  if (e.action.summonCreature.attackInvoker)
1229  summon->AI()->AttackStart((*itr)->ToUnit());
1230  }
1231 
1232  delete targets;
1233  }
1234 
1236  break;
1237 
1239  if (unit && e.action.summonCreature.attackInvoker)
1240  summon->AI()->AttackStart(unit);
1241  break;
1242  }
1244  {
1245  if (!GetBaseObject())
1246  break;
1247 
1248  ObjectList* targets = GetTargets(e, unit);
1249  if (targets)
1250  {
1251  float x, y, z, o;
1252  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1253  {
1254  if (!IsUnit(*itr))
1255  continue;
1256 
1257  (*itr)->GetPosition(x, y, z, o);
1258  x += e.target.x;
1259  y += e.target.y;
1260  z += e.target.z;
1261  o += e.target.o;
1262  GetBaseObject()->SummonGameObject(e.action.summonGO.entry, x, y, z, o, 0, 0, 0, 0, e.action.summonGO.despawnTime);
1263  }
1264 
1265  delete targets;
1266  }
1267 
1269  break;
1270 
1271  GetBaseObject()->SummonGameObject(e.action.summonGO.entry, e.target.x, e.target.y, e.target.z, e.target.o, 0, 0, 0, 0, e.action.summonGO.despawnTime);
1272  break;
1273  }
1275  {
1276  ObjectList* targets = GetTargets(e, unit);
1277  if (!targets)
1278  break;
1279 
1280  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1281  {
1282  if (!IsUnit(*itr))
1283  continue;
1284 
1285  (*itr)->ToUnit()->KillSelf();
1286  }
1287 
1288  delete targets;
1289  break;
1290  }
1292  {
1293  InstallTemplate(e);
1294  break;
1295  }
1296  case SMART_ACTION_ADD_ITEM:
1297  {
1298  ObjectList* targets = GetTargets(e, unit);
1299  if (!targets)
1300  break;
1301 
1302  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1303  {
1304  if (!IsPlayer(*itr))
1305  continue;
1306 
1307  (*itr)->ToPlayer()->AddItem(e.action.item.entry, e.action.item.count);
1308  }
1309 
1310  delete targets;
1311  break;
1312  }
1314  {
1315  ObjectList* targets = GetTargets(e, unit);
1316  if (!targets)
1317  break;
1318 
1319  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1320  {
1321  if (!IsPlayer(*itr))
1322  continue;
1323 
1324  (*itr)->ToPlayer()->DestroyItemCount(e.action.item.entry, e.action.item.count, true);
1325  }
1326 
1327  delete targets;
1328  break;
1329  }
1331  {
1332  ObjectList* targets = GetTargets(e, unit);
1333  StoreTargetList(targets, e.action.storeTargets.id);
1334  break;
1335  }
1336  case SMART_ACTION_TELEPORT:
1337  {
1338  ObjectList* targets = GetTargets(e, unit);
1339  if (!targets)
1340  break;
1341 
1342  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1343  {
1344  if (IsPlayer(*itr))
1345  (*itr)->ToPlayer()->TeleportTo(e.action.teleport.mapID, e.target.x, e.target.y, e.target.z, e.target.o);
1346  else if (IsCreature(*itr))
1347  (*itr)->ToCreature()->NearTeleportTo(e.target.x, e.target.y, e.target.z, e.target.o);
1348  }
1349 
1350  delete targets;
1351  break;
1352  }
1353  case SMART_ACTION_SET_FLY:
1354  {
1355  if (!IsSmart())
1356  break;
1357 
1358  ENSURE_AI(SmartAI, me->AI())->SetFly(e.action.setFly.fly != 0);
1359  break;
1360  }
1361  case SMART_ACTION_SET_RUN:
1362  {
1363  if (!IsSmart())
1364  break;
1365 
1366  ENSURE_AI(SmartAI, me->AI())->SetRun(e.action.setRun.run != 0);
1367  break;
1368  }
1369  case SMART_ACTION_SET_SWIM:
1370  {
1371  if (!IsSmart())
1372  break;
1373 
1374  ENSURE_AI(SmartAI, me->AI())->SetSwim(e.action.setSwim.swim != 0);
1375  break;
1376  }
1378  {
1379  if (ObjectList* targets = GetTargets(e, unit))
1380  {
1381  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1382  {
1383  if (IsCreature(*itr))
1384  {
1385  if (SmartAI* ai = CAST_AI(SmartAI, (*itr)->ToCreature()->AI()))
1386  ai->GetScript()->StoreCounter(e.action.setCounter.counterId, e.action.setCounter.value, e.action.setCounter.reset);
1387  else
1388  TC_LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SET_COUNTER is not using SmartAI, skipping");
1389  }
1390  else if (IsGameObject(*itr))
1391  {
1392  if (SmartGameObjectAI* ai = CAST_AI(SmartGameObjectAI, (*itr)->ToGameObject()->AI()))
1393  ai->GetScript()->StoreCounter(e.action.setCounter.counterId, e.action.setCounter.value, e.action.setCounter.reset);
1394  else
1395  TC_LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SET_COUNTER is not using SmartGameObjectAI, skipping");
1396  }
1397  }
1398 
1399  delete targets;
1400  }
1401  else
1402  StoreCounter(e.action.setCounter.counterId, e.action.setCounter.value, e.action.setCounter.reset);
1403 
1404  break;
1405  }
1406  case SMART_ACTION_WP_START:
1407  {
1408  if (!IsSmart())
1409  break;
1410 
1411  bool run = e.action.wpStart.run != 0;
1412  uint32 entry = e.action.wpStart.pathID;
1413  bool repeat = e.action.wpStart.repeat != 0;
1414  ObjectList* targets = GetTargets(e, unit);
1416  me->SetReactState((ReactStates)e.action.wpStart.reactState);
1417  ENSURE_AI(SmartAI, me->AI())->StartPath(run, entry, repeat, unit);
1418 
1419  uint32 quest = e.action.wpStart.quest;
1420  uint32 DespawnTime = e.action.wpStart.despawnTime;
1421  ENSURE_AI(SmartAI, me->AI())->mEscortQuestID = quest;
1422  ENSURE_AI(SmartAI, me->AI())->SetDespawnTime(DespawnTime);
1423  break;
1424  }
1425  case SMART_ACTION_WP_PAUSE:
1426  {
1427  if (!IsSmart())
1428  break;
1429 
1430  uint32 delay = e.action.wpPause.delay;
1431  ENSURE_AI(SmartAI, me->AI())->PausePath(delay, e.GetEventType() == SMART_EVENT_WAYPOINT_REACHED ? false : true);
1432  break;
1433  }
1434  case SMART_ACTION_WP_STOP:
1435  {
1436  if (!IsSmart())
1437  break;
1438 
1439  uint32 DespawnTime = e.action.wpStop.despawnTime;
1440  uint32 quest = e.action.wpStop.quest;
1441  bool fail = e.action.wpStop.fail != 0;
1442  ENSURE_AI(SmartAI, me->AI())->StopPath(DespawnTime, quest, fail);
1443  break;
1444  }
1446  {
1447  if (!IsSmart())
1448  break;
1449 
1450  ENSURE_AI(SmartAI, me->AI())->ResumePath();
1451  break;
1452  }
1454  {
1455  if (!me)
1456  break;
1457 
1458  if (e.GetTargetType() == SMART_TARGET_SELF)
1459  me->SetFacingTo((me->GetTransport() ? me->GetTransportHomePosition() : me->GetHomePosition()).GetOrientation());
1460  else if (e.GetTargetType() == SMART_TARGET_POSITION)
1461  me->SetFacingTo(e.target.o);
1462  else if (ObjectList* targets = GetTargets(e, unit))
1463  {
1464  if (!targets->empty())
1465  me->SetFacingToObject(*targets->begin());
1466 
1467  delete targets;
1468  }
1469 
1470  break;
1471  }
1473  {
1474  ObjectList* targets = GetTargets(e, unit);
1475  if (!targets)
1476  break;
1477 
1478  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1479  {
1480  if (!IsPlayer(*itr))
1481  continue;
1482 
1483  (*itr)->ToPlayer()->SendMovieStart(e.action.movie.entry);
1484  }
1485 
1486  delete targets;
1487  break;
1488  }
1490  {
1491  if (!IsSmart())
1492  break;
1493 
1494  WorldObject* target = NULL;
1495 
1502  {
1503  ObjectList* targets = GetTargets(e, unit);
1504  if (!targets)
1505  break;
1506 
1507  target = targets->front();
1508  delete targets;
1509  }
1510 
1511  if (!target)
1512  {
1513  G3D::Vector3 dest(e.target.x, e.target.y, e.target.z);
1514  if (e.action.MoveToPos.transport)
1515  if (TransportBase* trans = me->GetDirectTransport())
1516  trans->CalculatePassengerPosition(dest.x, dest.y, dest.z);
1517 
1518  me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, dest.x, dest.y, dest.z);
1519  }
1520  else
1521  me->GetMotionMaster()->MovePoint(e.action.MoveToPos.pointId, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ());
1522  break;
1523  }
1525  {
1526  ObjectList* targets = GetTargets(e, unit);
1527  if (!targets)
1528  break;
1529 
1530  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1531  {
1532  if (IsCreature(*itr))
1533  (*itr)->ToCreature()->Respawn();
1534  else if (IsGameObject(*itr))
1535  (*itr)->ToGameObject()->SetRespawnTime(e.action.RespawnTarget.goRespawnTime);
1536  }
1537 
1538  delete targets;
1539  break;
1540  }
1542  {
1543  ObjectList* targets = GetTargets(e, unit);
1544  if (!targets)
1545  break;
1546 
1547  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1548  if (IsPlayer(*itr))
1549  (*itr)->ToPlayer()->PlayerTalkClass->SendCloseGossip();
1550 
1551  delete targets;
1552  break;
1553  }
1554  case SMART_ACTION_EQUIP:
1555  {
1556  ObjectList* targets = GetTargets(e, unit);
1557  if (!targets)
1558  break;
1559 
1560  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1561  {
1562  if (Creature* npc = (*itr)->ToCreature())
1563  {
1564  uint32 slot[3];
1565  int8 equipId = (int8)e.action.equip.entry;
1566  if (equipId)
1567  {
1568  EquipmentInfo const* einfo = sObjectMgr->GetEquipmentInfo(npc->GetEntry(), equipId);
1569  if (!einfo)
1570  {
1571  TC_LOG_ERROR("sql.sql", "SmartScript: SMART_ACTION_EQUIP uses non-existent equipment info id %u for creature %u", equipId, npc->GetEntry());
1572  break;
1573  }
1574 
1575  npc->SetCurrentEquipmentId(equipId);
1576  slot[0] = einfo->ItemEntry[0];
1577  slot[1] = einfo->ItemEntry[1];
1578  slot[2] = einfo->ItemEntry[2];
1579  }
1580  else
1581  {
1582  slot[0] = e.action.equip.slot1;
1583  slot[1] = e.action.equip.slot2;
1584  slot[2] = e.action.equip.slot3;
1585  }
1586  if (!e.action.equip.mask || (e.action.equip.mask & 1))
1587  npc->SetVirtualItem(0, slot[0]);
1588  if (!e.action.equip.mask || (e.action.equip.mask & 2))
1589  npc->SetVirtualItem(1, slot[1]);
1590  if (!e.action.equip.mask || (e.action.equip.mask & 4))
1591  npc->SetVirtualItem(2, slot[2]);
1592  }
1593  }
1594 
1595  delete targets;
1596  break;
1597  }
1599  {
1600  SmartEvent ne = SmartEvent();
1602  ne.event_chance = e.action.timeEvent.chance;
1603  if (!ne.event_chance) ne.event_chance = 100;
1604 
1605  ne.minMaxRepeat.min = e.action.timeEvent.min;
1606  ne.minMaxRepeat.max = e.action.timeEvent.max;
1607  ne.minMaxRepeat.repeatMin = e.action.timeEvent.repeatMin;
1608  ne.minMaxRepeat.repeatMax = e.action.timeEvent.repeatMax;
1609 
1610  ne.event_flags = 0;
1611  if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
1613 
1614  SmartAction ac = SmartAction();
1616  ac.timeEvent.id = e.action.timeEvent.id;
1617 
1619  ev.event = ne;
1620  ev.event_id = e.action.timeEvent.id;
1621  ev.target = e.target;
1622  ev.action = ac;
1623  InitTimer(ev);
1624  mStoredEvents.push_back(ev);
1625  break;
1626  }
1629  break;
1631  mRemIDs.push_back(e.action.timeEvent.id);
1632  break;
1634  {
1635  ObjectList* targets = GetTargets(e, unit);
1636  if (!targets)
1637  break;
1638 
1639  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
1640  {
1641  if (IsCreature(*itr))
1642  {
1643  if (!meOrigGUID && me)
1644  meOrigGUID = me->GetGUID();
1645  if (!goOrigGUID && go)
1646  goOrigGUID = go->GetGUID();
1647  go = NULL;
1648  me = (*itr)->ToCreature();
1649  break;
1650  }
1651  else if (IsGameObject(*itr))
1652  {
1653  if (!meOrigGUID && me)
1654  meOrigGUID = me->GetGUID();
1655  if (!goOrigGUID && go)
1656  goOrigGUID = go->GetGUID();
1657  go = (*itr)->ToGameObject();
1658  me = NULL;
1659  break;
1660  }
1661  }
1662 
1663  delete targets;
1664  break;
1665  }
1667  ResetBaseObject();
1668  break;
1670  OnReset();
1671  break;
1673  {
1674  if (!IsSmart())
1675  break;
1676 
1677  float attackDistance = float(e.action.setRangedMovement.distance);
1678  float attackAngle = float(e.action.setRangedMovement.angle) / 180.0f * float(M_PI);
1679 
1680  ObjectList* targets = GetTargets(e, unit);
1681  if (targets)
1682  {
1683  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
1684  if (Creature* target = (*itr)->ToCreature())
1685  if (IsSmart(target) && target->GetVictim())
1686  if (ENSURE_AI(SmartAI, target->AI())->CanCombatMove())
1687  target->GetMotionMaster()->MoveChase(target->GetVictim(), attackDistance, attackAngle);
1688 
1689  delete targets;
1690  }
1691  break;
1692  }
1694  {
1695  if (e.GetTargetType() == SMART_TARGET_NONE)
1696  {
1697  TC_LOG_ERROR("sql.sql", "SmartScript: Entry " SI64FMTD " SourceType %u Event %u Action %u is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1698  break;
1699  }
1700 
1701  if (ObjectList* targets = GetTargets(e, unit))
1702  {
1703  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
1704  {
1705  if (Creature* target = (*itr)->ToCreature())
1706  {
1707  if (IsSmart(target))
1708  ENSURE_AI(SmartAI, target->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());
1709  }
1710  else if (GameObject* goTarget = (*itr)->ToGameObject())
1711  {
1712  if (IsSmartGO(goTarget))
1714  }
1715  }
1716 
1717  delete targets;
1718  }
1719  break;
1720  }
1722  {
1723  ObjectList* targets = GetTargets(e, unit);
1724  if (!targets)
1725  break;
1726 
1727  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1728  if (IsCreature(*itr))
1729  (*itr)->ToUnit()->SetUInt64Value(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
1730 
1731  delete targets;
1732  break;
1733  }
1735  {
1736  ObjectList* targets = GetTargets(e, unit);
1737  if (!targets)
1738  break;
1739 
1740  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1741  if (IsCreature(*itr))
1742  (*itr)->ToUnit()->SetFlag64(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
1743 
1744  delete targets;
1745  break;
1746  }
1748  {
1749  ObjectList* targets = GetTargets(e, unit);
1750  if (!targets)
1751  break;
1752 
1753  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1754  if (IsCreature(*itr))
1755  (*itr)->ToUnit()->RemoveFlag64(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
1756 
1757  delete targets;
1758  break;
1759  }
1761  {
1762  ObjectList* casters = GetTargets(CreateEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, 0, 0, SMART_ACTION_NONE, 0, 0, 0, 0, 0, 0, (SMARTAI_TARGETS)e.action.cast.targetType, e.action.cast.targetParam1, e.action.cast.targetParam2, e.action.cast.targetParam3, 0), unit);
1763  if (!casters)
1764  break;
1765 
1766  ObjectList* targets = GetTargets(e, unit);
1767  if (!targets)
1768  {
1769  delete casters; // casters already validated, delete now
1770  break;
1771  }
1772 
1773  for (ObjectList::const_iterator itr = casters->begin(); itr != casters->end(); ++itr)
1774  {
1775  if (!IsUnit(*itr))
1776  continue;
1777 
1778  Unit* targetUnit = (*itr)->ToUnit();
1779 
1780  bool interruptedSpell = false;
1781 
1782  for (ObjectList::const_iterator it = targets->begin(); it != targets->end(); ++it)
1783  {
1784  if (!IsUnit(*it))
1785  continue;
1786 
1787  if (!(e.action.cast.flags & SMARTCAST_AURA_NOT_PRESENT) || !(*it)->ToUnit()->HasAura(e.action.cast.spell))
1788  {
1789  if (!interruptedSpell && e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
1790  {
1791  targetUnit->InterruptNonMeleeSpells(false);
1792  interruptedSpell = true;
1793  }
1794 
1795  targetUnit->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
1796  }
1797  else
1798  TC_LOG_DEBUG("scripts.ai", "Spell %u not cast because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (%s) already has the aura", e.action.cast.spell, (*it)->GetGUID().ToString().c_str());
1799  }
1800  }
1801 
1802  delete targets;
1803  delete casters;
1804  break;
1805  }
1807  {
1809  actions[0] = e.action.randTimedActionList.entry1;
1810  actions[1] = e.action.randTimedActionList.entry2;
1811  actions[2] = e.action.randTimedActionList.entry3;
1812  actions[3] = e.action.randTimedActionList.entry4;
1813  actions[4] = e.action.randTimedActionList.entry5;
1814  actions[5] = e.action.randTimedActionList.entry6;
1816  uint32 count = 0;
1817  for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT; i++)
1818  {
1819  if (actions[i] > 0)
1820  {
1821  temp[count] = actions[i];
1822  ++count;
1823  }
1824  }
1825 
1826  if (count == 0)
1827  break;
1828 
1829  uint32 id = temp[urand(0, count - 1)];
1830  if (e.GetTargetType() == SMART_TARGET_NONE)
1831  {
1832  TC_LOG_ERROR("sql.sql", "SmartScript: Entry " SI64FMTD " SourceType %u Event %u Action %u is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1833  break;
1834  }
1835 
1836  ObjectList* targets = GetTargets(e, unit);
1837  if (targets)
1838  {
1839  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
1840  {
1841  if (Creature* target = (*itr)->ToCreature())
1842  {
1843  if (IsSmart(target))
1844  ENSURE_AI(SmartAI, target->AI())->SetScript9(e, id, GetLastInvoker());
1845  }
1846  else if (GameObject* goTarget = (*itr)->ToGameObject())
1847  {
1848  if (IsSmartGO(goTarget))
1849  ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker());
1850  }
1851  }
1852 
1853  delete targets;
1854  }
1855  break;
1856  }
1858  {
1860  if (e.GetTargetType() == SMART_TARGET_NONE)
1861  {
1862  TC_LOG_ERROR("sql.sql", "SmartScript: Entry " SI64FMTD " SourceType %u Event %u Action %u is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
1863  break;
1864  }
1865 
1866  ObjectList* targets = GetTargets(e, unit);
1867  if (targets)
1868  {
1869  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
1870  {
1871  if (Creature* target = (*itr)->ToCreature())
1872  {
1873  if (IsSmart(target))
1874  ENSURE_AI(SmartAI, target->AI())->SetScript9(e, id, GetLastInvoker());
1875  }
1876  else if (GameObject* goTarget = (*itr)->ToGameObject())
1877  {
1878  if (IsSmartGO(goTarget))
1879  ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker());
1880  }
1881  }
1882 
1883  delete targets;
1884  }
1885  break;
1886  }
1888  {
1889  ObjectList* targets = GetTargets(e, unit);
1890  if (!targets)
1891  break;
1892 
1893  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1894  if (IsPlayer(*itr))
1895  (*itr)->ToPlayer()->ActivateTaxiPathTo(e.action.taxi.id);
1896 
1897  delete targets;
1898  break;
1899  }
1901  {
1902  ObjectList* targets = GetTargets(e, unit);
1903  if (!targets)
1904  break;
1905 
1906  bool foundTarget = false;
1907 
1908  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1909  {
1910  if (IsCreature((*itr)))
1911  {
1912  foundTarget = true;
1913 
1914  if (e.action.moveRandom.distance)
1915  (*itr)->ToCreature()->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
1916  else
1917  (*itr)->ToCreature()->GetMotionMaster()->MoveIdle();
1918  }
1919  }
1920 
1921  if (!foundTarget && me && IsCreature(me))
1922  {
1923  if (e.action.moveRandom.distance)
1924  me->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
1925  else
1926  me->GetMotionMaster()->MoveIdle();
1927  }
1928 
1929  delete targets;
1930  break;
1931  }
1933  {
1934  ObjectList* targets = GetTargets(e, unit);
1935  if (!targets)
1936  break;
1937  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1938  if (IsUnit(*itr))
1939  (*itr)->ToUnit()->SetByteFlag(UNIT_FIELD_BYTES_1, e.action.setunitByte.type, e.action.setunitByte.byte1);
1940 
1941  delete targets;
1942  break;
1943  }
1945  {
1946  ObjectList* targets = GetTargets(e, unit);
1947  if (!targets)
1948  break;
1949 
1950  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1951  if (IsUnit(*itr))
1952  (*itr)->ToUnit()->RemoveByteFlag(UNIT_FIELD_BYTES_1, e.action.delunitByte.type, e.action.delunitByte.byte1);
1953 
1954  delete targets;
1955  break;
1956  }
1958  {
1959  ObjectList* targets = GetTargets(e, unit);
1960  if (!targets)
1961  break;
1962 
1963  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1964  if (IsUnit(*itr))
1965  (*itr)->ToUnit()->InterruptNonMeleeSpells(e.action.interruptSpellCasting.withDelayed != 0, e.action.interruptSpellCasting.spell_id, e.action.interruptSpellCasting.withInstant != 0);
1966 
1967  delete targets;
1968  break;
1969  }
1971  {
1972  ObjectList* targets = GetTargets(e, unit);
1973  if (!targets)
1974  break;
1975 
1976  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1977  if (IsGameObject(*itr))
1978  (*itr)->ToGameObject()->SendCustomAnim(e.action.sendGoCustomAnim.anim);
1979 
1980  delete targets;
1981  break;
1982  }
1984  {
1985  ObjectList* targets = GetTargets(e, unit);
1986  if (!targets)
1987  break;
1988 
1989  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
1990  if (IsUnit(*itr))
1991  (*itr)->ToUnit()->SetUInt32Value(OBJECT_DYNAMIC_FLAGS, e.action.unitFlag.flag);
1992 
1993  delete targets;
1994  break;
1995  }
1997  {
1998  ObjectList* targets = GetTargets(e, unit);
1999  if (!targets)
2000  break;
2001 
2002  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2003  if (IsUnit(*itr))
2004  (*itr)->ToUnit()->SetFlag(OBJECT_DYNAMIC_FLAGS, e.action.unitFlag.flag);
2005 
2006  delete targets;
2007  break;
2008  }
2010  {
2011  ObjectList* targets = GetTargets(e, unit);
2012  if (!targets)
2013  break;
2014 
2015  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2016  if (IsUnit(*itr))
2017  (*itr)->ToUnit()->RemoveFlag(OBJECT_DYNAMIC_FLAGS, e.action.unitFlag.flag);
2018 
2019  delete targets;
2020  break;
2021  }
2023  {
2024  ObjectList* targets = GetTargets(e, unit);
2025  if (!targets)
2026  break;
2027 
2028  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2029  {
2030  if (Creature* creature = (*itr)->ToCreature())
2031  {
2032  creature->GetMotionMaster()->Clear();
2033  creature->GetMotionMaster()->MoveJump(e.target.x, e.target.y, e.target.z, 0.0f, (float)e.action.jump.speedxy, (float)e.action.jump.speedz); // @todo add optional jump orientation support?
2034  }
2035  }
2037 
2038  delete targets;
2039  break;
2040  }
2042  {
2043  ObjectList* targets = GetTargets(e, unit);
2044 
2045  if (!targets)
2046  break;
2047 
2048  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2049  if (IsGameObject(*itr))
2050  (*itr)->ToGameObject()->SetLootState((LootState)e.action.setGoLootState.state);
2051 
2052  delete targets;
2053  break;
2054  }
2056  {
2057  ObjectList* targets = GetTargets(e, unit);
2058  if (!targets)
2059  break;
2060 
2061  ObjectList* storedTargets = GetTargetList(e.action.sendTargetToTarget.id);
2062  if (!storedTargets)
2063  {
2064  delete targets;
2065  break;
2066  }
2067 
2068  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2069  {
2070  if (IsCreature(*itr))
2071  {
2072  if (SmartAI* ai = CAST_AI(SmartAI, (*itr)->ToCreature()->AI()))
2073  ai->GetScript()->StoreTargetList(new ObjectList(*storedTargets), e.action.sendTargetToTarget.id); // store a copy of target list
2074  else
2075  TC_LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SEND_TARGET_TO_TARGET is not using SmartAI, skipping");
2076  }
2077  else if (IsGameObject(*itr))
2078  {
2079  if (SmartGameObjectAI* ai = CAST_AI(SmartGameObjectAI, (*itr)->ToGameObject()->AI()))
2080  ai->GetScript()->StoreTargetList(new ObjectList(*storedTargets), e.action.sendTargetToTarget.id); // store a copy of target list
2081  else
2082  TC_LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SEND_TARGET_TO_TARGET is not using SmartGameObjectAI, skipping");
2083  }
2084  }
2085 
2086  delete targets;
2087  break;
2088  }
2090  {
2091  if (!GetBaseObject())
2092  break;
2093 
2094  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SEND_GOSSIP_MENU: gossipMenuId %d, gossipNpcTextId %d",
2095  e.action.sendGossipMenu.gossipMenuId, e.action.sendGossipMenu.gossipNpcTextId);
2096 
2097  ObjectList* targets = GetTargets(e, unit);
2098  if (!targets)
2099  break;
2100 
2101  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2102  {
2103  if (Player* player = (*itr)->ToPlayer())
2104  {
2105  if (e.action.sendGossipMenu.gossipMenuId)
2106  player->PrepareGossipMenu(GetBaseObject(), e.action.sendGossipMenu.gossipMenuId, true);
2107  else
2108  player->PlayerTalkClass->ClearMenus();
2109 
2110  player->SEND_GOSSIP_MENU(e.action.sendGossipMenu.gossipNpcTextId, GetBaseObject()->GetGUID());
2111  }
2112  }
2113 
2114  delete targets;
2115  break;
2116  }
2118  {
2119  ObjectList* targets = GetTargets(e, unit);
2120  if (!targets)
2121  break;
2122 
2123  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2124  {
2125  if (IsCreature(*itr))
2126  {
2127  if (e.GetTargetType() == SMART_TARGET_SELF)
2128  (*itr)->ToCreature()->SetHomePosition(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), me->GetOrientation());
2129  else if (e.GetTargetType() == SMART_TARGET_POSITION)
2130  (*itr)->ToCreature()->SetHomePosition(e.target.x, e.target.y, e.target.z, e.target.o);
2137  {
2138  (*itr)->ToCreature()->SetHomePosition((*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetOrientation());
2139  }
2140  else
2141  TC_LOG_ERROR("sql.sql", "SmartScript: Action target for SMART_ACTION_SET_HOME_POS is invalid, skipping");
2142  }
2143  }
2144 
2145  delete targets;
2146  break;
2147  }
2149  {
2150  ObjectList* targets = GetTargets(e, unit);
2151  if (!targets)
2152  break;
2153 
2154  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2155  if (IsCreature(*itr))
2156  (*itr)->ToCreature()->setRegeneratingHealth(e.action.setHealthRegen.regenHealth != 0);
2157 
2158  delete targets;
2159  break;
2160  }
2161  case SMART_ACTION_SET_ROOT:
2162  {
2163  ObjectList* targets = GetTargets(e, unit);
2164  if (!targets)
2165  break;
2166 
2167  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2168  if (IsCreature(*itr))
2169  (*itr)->ToCreature()->SetControlled(e.action.setRoot.root != 0, UNIT_STATE_ROOT);
2170 
2171  delete targets;
2172  break;
2173  }
2175  {
2176  ObjectList* targets = GetTargets(e, unit);
2177  if (!targets)
2178  break;
2179 
2180  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2181  if (IsGameObject(*itr))
2182  (*itr)->ToGameObject()->SetUInt32Value(GAMEOBJECT_FLAGS, e.action.goFlag.flag);
2183 
2184  delete targets;
2185  break;
2186  }
2188  {
2189  ObjectList* targets = GetTargets(e, unit);
2190  if (!targets)
2191  break;
2192 
2193  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2194  if (IsGameObject(*itr))
2195  (*itr)->ToGameObject()->SetFlag(GAMEOBJECT_FLAGS, e.action.goFlag.flag);
2196 
2197  delete targets;
2198  break;
2199  }
2201  {
2202  ObjectList* targets = GetTargets(e, unit);
2203  if (!targets)
2204  break;
2205 
2206  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2207  if (IsGameObject(*itr))
2208  (*itr)->ToGameObject()->RemoveFlag(GAMEOBJECT_FLAGS, e.action.goFlag.flag);
2209 
2210  delete targets;
2211  break;
2212  }
2214  {
2215  std::list<TempSummon*> summonList;
2216  GetBaseObject()->SummonCreatureGroup(e.action.creatureGroup.group, &summonList);
2217 
2218  for (std::list<TempSummon*>::const_iterator itr = summonList.begin(); itr != summonList.end(); ++itr)
2219  if (unit && e.action.creatureGroup.attackInvoker)
2220  (*itr)->AI()->AttackStart(unit);
2221 
2222  break;
2223  }
2225  {
2226  ObjectList* targets = GetTargets(e, unit);
2227 
2228  if (targets)
2229  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2230  if (IsUnit(*itr))
2231  (*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), e.action.power.newPower);
2232 
2233  delete targets;
2234  break;
2235  }
2237  {
2238  ObjectList* targets = GetTargets(e, unit);
2239 
2240  if (targets)
2241  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2242  if (IsUnit(*itr))
2243  (*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), (*itr)->ToUnit()->GetPower(Powers(e.action.power.powerType)) + e.action.power.newPower);
2244 
2245  delete targets;
2246  break;
2247  }
2249  {
2250  ObjectList* targets = GetTargets(e, unit);
2251 
2252  if (targets)
2253  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
2254  if (IsUnit(*itr))
2255  (*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), (*itr)->ToUnit()->GetPower(Powers(e.action.power.powerType)) - e.action.power.newPower);
2256 
2257  delete targets;
2258  break;
2259  }
2261  {
2262  uint32 eventId = e.action.gameEventStop.id;
2263  if (!sGameEventMgr->IsActiveEvent(eventId))
2264  {
2265  TC_LOG_ERROR("sql.sql", "SmartScript::ProcessAction: At case SMART_ACTION_GAME_EVENT_STOP, inactive event (id: %u)", eventId);
2266  break;
2267  }
2268  sGameEventMgr->StopEvent(eventId, true);
2269  break;
2270  }
2272  {
2273  uint32 eventId = e.action.gameEventStart.id;
2274  if (sGameEventMgr->IsActiveEvent(eventId))
2275  {
2276  TC_LOG_ERROR("sql.sql", "SmartScript::ProcessAction: At case SMART_ACTION_GAME_EVENT_START, already activated event (id: %u)", eventId);
2277  break;
2278  }
2279  sGameEventMgr->StartEvent(eventId, true);
2280  break;
2281  }
2283  {
2284  uint32 waypoints[SMART_ACTION_PARAM_COUNT];
2285  waypoints[0] = e.action.closestWaypointFromList.wp1;
2286  waypoints[1] = e.action.closestWaypointFromList.wp2;
2287  waypoints[2] = e.action.closestWaypointFromList.wp3;
2288  waypoints[3] = e.action.closestWaypointFromList.wp4;
2289  waypoints[4] = e.action.closestWaypointFromList.wp5;
2290  waypoints[5] = e.action.closestWaypointFromList.wp6;
2291  float distanceToClosest = std::numeric_limits<float>::max();
2292  WayPoint* closestWp = NULL;
2293 
2294  ObjectList* targets = GetTargets(e, unit);
2295  if (targets)
2296  {
2297  for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
2298  {
2299  if (Creature* target = (*itr)->ToCreature())
2300  {
2301  if (IsSmart(target))
2302  {
2303  for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT; i++)
2304  {
2305  if (!waypoints[i])
2306  continue;
2307 
2308  WPPath* path = sSmartWaypointMgr->GetPath(waypoints[i]);
2309 
2310  if (!path || path->empty())
2311  continue;
2312 
2313  WPPath::const_iterator itrWp = path->find(0);
2314 
2315  if (itrWp != path->end())
2316  {
2317  if (WayPoint* wp = itrWp->second)
2318  {
2319  float distToThisPath = target->GetDistance(wp->x, wp->y, wp->z);
2320 
2321  if (distToThisPath < distanceToClosest)
2322  {
2323  distanceToClosest = distToThisPath;
2324  closestWp = wp;
2325  }
2326  }
2327  }
2328  }
2329 
2330  if (closestWp)
2331  CAST_AI(SmartAI, target->AI())->StartPath(false, closestWp->id, true);
2332  }
2333  }
2334  }
2335 
2336  delete targets;
2337  }
2338  break;
2339  }
2341  {
2342  std::vector<uint32> sounds;
2343  std::copy_if(e.action.randomSound.sounds.begin(), e.action.randomSound.sounds.end(),
2344  std::back_inserter(sounds), [](uint32 sound) { return sound != 0; });
2345 
2346  bool onlySelf = e.action.randomSound.onlySelf != 0;
2347 
2348  if (ObjectList* targets = GetTargets(e, unit))
2349  {
2350  for (WorldObject* const obj : *targets)
2351  {
2352  if (IsUnit(obj))
2353  {
2355  obj->PlayDirectSound(sound, onlySelf ? obj->ToPlayer() : nullptr);
2356  TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_SOUND: target: %s (%s), sound: %u, onlyself: %s",
2357  obj->GetName().c_str(), obj->GetGUID().ToString().c_str(), sound, onlySelf ? "true" : "false");
2358  }
2359  }
2360 
2361  delete targets;
2362  break;
2363  }
2364  }
2365  default:
2366  TC_LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry " SI64FMTD " SourceType %u, Event %u, Unhandled Action type %u", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
2367  break;
2368  }
2369 
2370  if (e.link && e.link != e.event_id)
2371  {
2373  if (linked)
2374  ProcessEvent(linked, unit, var0, var1, bvar, spell, gob);
2375  else
2376  TC_LOG_DEBUG("sql.sql", "SmartScript::ProcessAction: Entry " SI64FMTD " SourceType %u, Event %u, Link Event %u not found or invalid, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.link);
2377  }
2378 }
Definition: SmartScriptMgr.h:1352
struct SmartAction::@114::@186 goFlag
struct SmartAction::@114::@139 setInstanceData64
void ResetBaseObject()
Definition: SmartScript.h:204
Definition: SmartScriptMgr.h:452
Definition: SmartAI.h:233
Definition: SmartScriptMgr.h:1086
struct SmartAction::@114::@156 item
struct SmartAction::@114::@168 unitFlag
Definition: SmartScriptMgr.h:1099
struct SmartAction::@114::@178 RespawnTarget
struct SmartAction::@114::@136 randomPhaseRange
Definition: SmartScriptMgr.h:532
#define sDB2Manager
Definition: DB2Stores.h:224
GameObject * SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime)
Definition: Object.cpp:2372
Definition: Language.h:25
Definition: SmartScriptMgr.h:491
Definition: SmartScriptMgr.h:53
Definition: SmartScriptMgr.h:445
uint32 mLastTextID
Definition: SmartScript.h:277
Definition: Vehicle.h:32
Definition: UpdateFields.h:136
Definition: SmartScriptMgr.h:1081
void GetTransportHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:677
Definition: SmartScriptMgr.h:543
int8_t int8
Definition: Define.h:148
void MoveRandom(float spawndist=0.0f)
Definition: MotionMaster.cpp:192
void KillSelf(bool durabilityLoss=true)
Definition: Unit.h:1515
struct SmartAction::@114::@116 talk
Definition: SmartScriptMgr.h:529
void MoveIdle()
Definition: MotionMaster.cpp:185
void StoreTargetList(ObjectList *targets, uint32 id)
Definition: SmartScript.h:94
Definition: SmartScriptMgr.h:495
Definition: SmartScriptMgr.h:474
void PlayDirectSound(uint32 sound_id, Player *target=NULL)
Definition: Object.cpp:2966
struct SmartAction::@114::@165 timeEvent
void modifyThreatPercent(Unit *victim, int32 percent)
Definition: ThreatManager.cpp:452
void InstallTemplate(SmartScriptHolder const &e)
Definition: SmartScript.cpp:2388
Definition: SmartScriptMgr.h:451
LootState
Definition: GameObject.h:866
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
Definition: QuestDef.h:279
Definition: SmartScriptMgr.h:492
struct SmartAction::@114::@152 taxi
Definition: SmartScriptMgr.h:496
Definition: CreatureTextMgr.h:31
Definition: SmartScriptMgr.h:531
SmartEvent event
Definition: SmartScriptMgr.h:1372
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
C::value_type const & SelectRandomContainerElement(C const &container)
Definition: Containers.h:68
Definition: SmartScriptMgr.h:503
Definition: SmartScriptMgr.h:480
struct SmartAction::@114::@122 react
#define M_PI
Definition: Common.h:163
Definition: SpellInfo.h:326
Definition: SmartScriptMgr.h:461
SMARTAI_TARGETS type
Definition: SmartScriptMgr.h:1117
Definition: Language.h:26
static void SendChatPacket(WorldObject *source, Builder const &builder, ChatMsg msgType, WorldObject const *whisperTarget=nullptr, CreatureTextRange range=TEXT_RANGE_NORMAL, Team team=TEAM_OTHER, bool gmOnly=false)
Definition: CreatureTextMgr.h:166
bool IsWithinLOSInMap(WorldObject const *obj) const
Definition: Object.cpp:1584
Definition: SmartScriptMgr.h:1098
SmartAIEventList mStoredEvents
Definition: SmartScript.h:273
InstanceScript * GetInstanceScript()
Definition: Object.cpp:1540
Definition: SmartScriptMgr.h:550
Definition: SmartScriptMgr.h:548
Definition: SmartScriptMgr.h:460
struct SmartAction::@114::@154 wpPause
Definition: SmartScriptMgr.h:498
struct SmartAction::@114::@132 incEventPhase
struct SmartAction::@114::@172 timedActionList
uint32 link
Definition: SmartScriptMgr.h:1370
Definition: SmartScriptMgr.h:54
Definition: SmartScriptMgr.h:526
Definition: SmartScriptMgr.h:1335
struct SmartAction::@114::@125 summonCreature
std::string const & GetName() const
Definition: Object.h:479
Definition: SmartScriptMgr.h:559
float GetMaxRange(bool positive=false, Unit *caster=NULL, Spell *spell=NULL) const
Definition: SpellInfo.cpp:2475
virtual void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition: CreatureAI.cpp:168
struct SmartAction::@114::@182 sendTargetToTarget
Definition: SmartScriptMgr.h:485
MotionMaster * GetMotionMaster()
Definition: Unit.h:2101
int8_t int8
Definition: g3dmath.h:163
Definition: SmartScriptMgr.h:454
struct SmartAction::@114::@129 autoAttack
Definition: SmartScriptMgr.h:439
struct SmartAction::@114::@173 randTimedActionList
struct SmartAction::@114::@190 gameEventStart
uint32 mTextTimer
Definition: SmartScript.h:276
struct SmartAction::@114::@158 setRun
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1377
Definition: SmartScriptMgr.h:489
bool IsSmart(Creature *c=NULL)
Definition: SmartScript.h:111
Definition: SmartScriptMgr.h:518
Definition: SmartScriptMgr.h:478
struct SmartAction::@114::@130 combatMove
struct SmartAction::@114::@184 setHealthRegen
void OnReset()
Definition: SmartScript.cpp:66
struct SmartAction::@114::@162 setCounter
Definition: SmartScriptMgr.h:1082
arena_t NULL
Definition: jemalloc_internal.h:624
ThreatContainer::StorageType const & getThreatList() const
Definition: ThreatManager.h:263
struct SmartAction::@114::@170 delunitByte
struct SmartAction::@114::@161 teleport
float y
Definition: SmartScriptMgr.h:1118
Definition: SmartScriptMgr.h:525
void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:3326
SMART_ACTION
Definition: SmartScriptMgr.h:437
virtual void SetGuidData(uint32, ObjectGuid)
Definition: ZoneScript.h:45
struct SmartAction::@114::@143 forceDespawn
Definition: UpdateFields.h:110
static uint32 ChooseDisplayId(CreatureTemplate const *cinfo, CreatureData const *data=NULL)
Definition: ObjectMgr.cpp:1265
Definition: SmartAI.h:45
Definition: SmartScriptMgr.h:511
Definition: SmartScriptMgr.h:515
Definition: SmartScriptMgr.h:509
void DecPhase(int32 p=1)
Definition: SmartScript.h:249
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32 event_id
Definition: SmartScriptMgr.h:1369
struct SmartAction::@114::@137 killedMonster
Definition: Object.h:423
Definition: SmartScriptMgr.h:479
Definition: Creature.h:467
Definition: SmartScriptMgr.h:466
Definition: SmartScriptMgr.h:494
Definition: SmartScriptMgr.h:163
float GetMinRange(bool positive=false) const
Definition: SpellInfo.cpp:2466
ObjectList * GetTargets(SmartScriptHolder const &e, Unit *invoker=NULL)
Definition: SmartScript.cpp:2497
struct SmartAction::@114::@188 power
Definition: SmartScriptMgr.h:549
Definition: SmartScriptMgr.h:551
Definition: SpellInfo.h:553
struct SmartAction::@114::@145 ingamePhaseId
Definition: SmartScriptMgr.h:444
Definition: SmartScriptMgr.h:1084
TempSummonType
Definition: Object.h:52
int32 GetPower(Powers power) const
Definition: Unit.cpp:11589
uint32 event_flags
Definition: SmartScriptMgr.h:191
#define sObjectMgr
Definition: ObjectMgr.h:1567
struct SmartAction::@114::@155 wpStop
GameObject * ToGameObject()
Definition: Object.h:200
Definition: SmartScriptMgr.h:440
T max(const T &x, const T &y)
Definition: g3dmath.h:320
bool IsPlayer(WorldObject *obj)
Definition: SmartScript.h:71
Definition: Vector3.h:58
Player * ToPlayer()
Definition: Object.h:191
Definition: VehicleDefines.h:119
Definition: SmartScriptMgr.h:31
struct SmartAction::@114::@183 setRangedMovement
struct SmartEvent::@77::@79 minMaxRepeat
uint32 id
Definition: SmartScriptMgr.h:41
struct SmartAction::@114::@166 movie
Definition: SmartScriptMgr.h:510
std::vector< CostData > CalcPowerCost(Unit const *caster, SpellSchoolMask schoolMask) const
Definition: SpellInfo.cpp:2564
Definition: SmartScriptMgr.h:50
struct SmartAction::@114::@147 setData
Definition: SmartScriptMgr.h:441
SmartTarget target
Definition: SmartScriptMgr.h:1374
Definition: SmartScriptMgr.h:462
Definition: SmartScriptMgr.h:534
Definition: SmartScriptMgr.h:499
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
struct SmartAction::@114::@181 setGoLootState
void DoFleeToGetAssistance()
Definition: Creature.cpp:761
void MovePoint(uint32 id, Position const &pos, bool generatePath=true)
Definition: MotionMaster.h:172
std::list< WorldObject * > ObjectList
Definition: SmartScriptMgr.h:1391
Definition: SmartScriptMgr.h:453
Definition: SmartScriptMgr.h:536
#define ENSURE_AI(a, b)
Definition: ScriptedCreature.h:29
void SetFacingToObject(WorldObject const *object)
Definition: Unit.cpp:15787
Definition: SmartScriptMgr.h:1096
Definition: SmartScriptMgr.h:1074
Powers
Definition: SharedDefines.h:246
Definition: SmartScriptMgr.h:475
float GetOrientation() const
Definition: Position.h:107
Definition: SmartScriptMgr.h:507
Definition: SmartScriptMgr.h:472
SmartScriptHolder CreateEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, 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 phaseMask=0)
Definition: SmartScript.cpp:2467
Definition: SharedDefines.h:4247
struct SmartAction::@114::@164 storeTargets
string ToString(int i)
Definition: strutil.h:491
Definition: SmartScriptMgr.h:477
Definition: SmartScriptMgr.h:442
void IncPhase(int32 p=1)
Definition: SmartScript.h:241
Definition: SmartScriptMgr.h:547
struct SmartAction::@114::@177 flee
float GetDistance(WorldObject const *obj) const
Definition: Object.cpp:1594
Definition: SmartScriptMgr.h:450
Definition: SmartScriptMgr.h:469
Definition: SmartScriptMgr.h:522
Definition: SmartScriptMgr.h:1087
Definition: SmartScriptMgr.h:517
Definition: SmartScriptMgr.h:521
Definition: SmartScriptMgr.h:448
struct SmartAction::@114::@123 randomEmote
Definition: SmartScriptMgr.h:458
struct SmartAction::@114::@151 active
Definition: SmartScriptMgr.h:490
Definition: SmartScriptMgr.h:533
Definition: ChatTextBuilder.h:27
Definition: SmartScriptMgr.h:471
ObjectGuid meOrigGUID
Definition: SmartScript.h:265
ObjectGuid mLastInvoker
Definition: SmartScript.h:236
bool IsSmartGO(GameObject *g=NULL)
Definition: SmartScript.h:126
#define CAST_AI(a, b)
Definition: ScriptedCreature.h:28
SheathState
Definition: Unit.h:296
Definition: SmartScriptMgr.h:1357
struct SmartAction::@114::@135 randomPhase
Definition: SmartScriptMgr.h:502
struct SmartAction::@114::@149 visibility
float GetPositionY() const
Definition: Position.h:105
G3D::int16 z
Definition: Vector3int16.h:46
Definition: SmartScriptMgr.h:470
Definition: SmartScriptMgr.h:505
struct SmartAction::@114::@142 setSheath
Definition: SmartScriptMgr.h:473
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
virtual void SetData(uint32, uint32)
Definition: ZoneScript.h:52
TransportBase * GetDirectTransport() const
Returns the transport this unit is on directly (if on vehicle and transport, return vehicle) ...
Definition: Unit.cpp:14365
CreatureAI * AI() const
Definition: Creature.h:525
Definition: SmartScriptMgr.h:530
void ProcessEvent(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:2788
#define SI64FMTD
Definition: Define.h:140
struct SmartAction::@114::@176 jump
void SetVisible(bool x)
Definition: Unit.cpp:10368
#define sSpellMgr
Definition: SpellMgr.h:756
Definition: SmartScriptMgr.h:468
float GetPositionZ() const
Definition: Position.h:106
int32_t int32
Definition: Define.h:146
#define sCreatureTextMgr
Definition: CreatureTextMgr.h:113
Definition: SmartScriptMgr.h:446
SMART_EVENT
Definition: SmartScriptMgr.h:102
uint32_t uint32
Definition: Define.h:150
Definition: SmartScriptMgr.h:455
struct SmartAction::@114::@131 setEventPhase
struct SmartAction::@114::@133 removeAura
float z
Definition: SmartScriptMgr.h:1118
Definition: SmartScriptMgr.h:527
G3D::int16 y
Definition: Vector2int16.h:38
struct SmartAction::@114::@175 sendGoCustomAnim
void CallForHelp(float fRadius)
Definition: Creature.cpp:2061
std::unordered_map< uint32, WayPoint * > WPPath
Definition: SmartScriptMgr.h:1389
struct SmartAction::@114::@138 setInstanceData
#define sSmartWaypointMgr
Definition: SmartScriptMgr.h:1670
Definition: SmartScriptMgr.h:488
struct SmartAction::@114::@167 equip
Definition: GameObject.h:880
Definition: SmartScriptMgr.h:457
void SetFacingTo(float ori)
Definition: Unit.cpp:15777
bool IsGameObject(WorldObject *obj)
Definition: SmartScript.h:81
Definition: SmartScriptMgr.h:164
Definition: SmartScriptMgr.h:165
GameObject * go
Definition: SmartScript.h:266
Definition: SmartScriptMgr.h:449
struct SmartAction::@114::@169 setunitByte
Definition: SmartScriptMgr.h:524
void StoreCounter(uint32 id, uint32 value, uint32 reset)
Definition: SmartScript.h:148
SMART_EVENT type
Definition: SmartScriptMgr.h:188
Definition: SmartScriptMgr.h:465
Definition: SmartScriptMgr.h:1080
void CastSpell(Unit *target, uint32 spell, bool triggered=true)
Definition: GameObject.cpp:1833
virtual void SetSheath(SheathState sheathed)
Definition: Unit.h:1463
uint32 mTalkerEntry
Definition: SmartScript.h:278
struct SmartAction::@114::@179 MoveToPos
ReactStates
Definition: Unit.h:1127
Definition: SmartScriptMgr.h:537
Unit * GetLastInvoker()
Definition: SmartScript.cpp:3731
struct SmartAction::@114::@140 updateTemplate
Definition: SmartScriptMgr.h:459
Definition: UpdateFields.h:319
float x
Definition: SmartScriptMgr.h:1118
Definition: SmartScriptMgr.h:1088
struct SmartAction::@114::@150 summonGO
Definition: SmartScriptMgr.h:519
float o
Definition: SmartScriptMgr.h:1118
Definition: SmartScriptMgr.h:481
Definition: SharedDefines.h:1006
Definition: SmartScriptMgr.h:1356
Definition: SmartScriptMgr.h:476
Player * GetLootRecipient() const
Definition: Creature.cpp:977
struct SmartAction::@114::@191 closestWaypointFromList
uint8_t uint8
Definition: g3dmath.h:164
Definition: SmartScriptMgr.h:1093
Definition: SmartScriptMgr.h:487
ObjectGuid const & GetGUID() const
Definition: Object.h:105
struct SmartAction::@114::@192 randomSound
Definition: SmartScriptMgr.h:516
Definition: Unit.h:454
Transport * GetTransport() const
Definition: Object.h:602
bool isDead() const
Definition: Unit.h:1694
#define sGameEventMgr
Definition: GameEventMgr.h:184
struct SmartAction::@114::@153 wpStart
struct SmartAction::@114::@126 threatPCT
struct SmartAction::@114::@148 moveRandom
Definition: SmartScriptMgr.h:1351
int64 entryOrGuid
Definition: SmartScriptMgr.h:1367
void SummonCreatureGroup(uint8 group, std::list< TempSummon * > *list=NULL)
Definition: Object.cpp:2429
Definition: SmartScriptMgr.h:482
uint32 GetActionType() const
Definition: SmartScriptMgr.h:1378
std::list< HostileReference * > StorageType
Definition: ThreatManager.h:149
Definition: UpdateFields.h:109
SmartAction action
Definition: SmartScriptMgr.h:1373
Definition: SharedDefines.h:4230
Definition: SmartScriptMgr.h:544
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition: SmartScript.cpp:3702
uint32 GetScriptType() const
Definition: SmartScriptMgr.h:1376
Definition: SmartScriptMgr.h:456
Creature * ToCreature()
Definition: Object.h:194
Definition: SmartScriptMgr.h:523
bool IsUnit(WorldObject *obj)
Definition: SmartScript.h:66
Definition: SmartScriptMgr.h:538
Definition: Unit.h:560
SpellSchoolMask GetSchoolMask() const
Definition: SpellInfo.cpp:2131
Definition: SmartScriptMgr.h:1073
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition: Unit.cpp:2916
struct SmartAction::@114::@117 faction
Definition: SmartScriptMgr.h:506
ThreatManager & getThreatManager()
Definition: Unit.h:1998
Definition: SmartScriptMgr.h:545
void SetPhase(uint32 p=0)
Definition: SmartScript.h:258
int32_t int32
Definition: g3dmath.h:167
Definition: SmartScriptMgr.h:514
Definition: UpdateFields.h:124
Definition: InstanceScript.h:141
Definition: SmartScriptMgr.h:483
uint8_t uint8
Definition: Define.h:152
void SetInCombatWithZone()
Definition: Creature.cpp:2299
ObjectGuid goOrigGUID
Definition: SmartScript.h:267
struct SmartAction::@114::@187 creatureGroup
Definition: SmartScriptMgr.h:520
Definition: SmartScriptMgr.h:104
Definition: SmartScriptMgr.h:513
Definition: UpdateFields.h:135
uint32 sound
Definition: SmartScriptMgr.h:585
Definition: SmartScriptMgr.h:554
uint32 GetTargetType() const
Definition: SmartScriptMgr.h:1379
Definition: UpdateFields.h:30
Definition: SmartScriptMgr.h:501
struct SmartAction::@114::@144 invincHP
SmartScript * GetScript()
Definition: SmartAI.h:69
Definition: SmartScriptMgr.h:1092
struct SmartAction::@114::@160 setSwim
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
struct SmartAction::@114::@180 sendGossipMenu
Definition: SmartScriptMgr.h:443
uint32 event_chance
Definition: SmartScriptMgr.h:190
struct SmartAction::@114::@124 cast
Definition: SmartScriptMgr.h:186
struct SmartAction::@114::@141 callHelp
Definition: SmartScriptMgr.h:497
Definition: SmartScriptMgr.h:1361
SmartAIEventList mEvents
Definition: SmartScript.h:260
uint32_t uint32
Definition: g3dmath.h:168
Definition: SmartScriptMgr.h:493
Definition: SmartScriptMgr.h:508
Definition: SmartScriptMgr.h:542
Definition: SmartScriptMgr.h:1083
Definition: SmartScriptMgr.h:552
G3D::int16 x
Definition: Vector2int16.h:37
Definition: Creature.h:277
struct SmartAction::@114::@174 interruptSpellCasting
Definition: SpellAuras.h:116
float GetPositionX() const
Definition: Position.h:104
Definition: SmartScriptMgr.h:464
struct SmartAction::@114::@118 morphOrMount
void SetInvincibilityHpLevel(uint32 level)
Definition: SmartAI.h:175
uint32 GetHealth() const
Definition: Unit.h:1426
Definition: SmartScriptMgr.h:447
bool IsCreature(WorldObject *obj)
Definition: SmartScript.h:76
Definition: SmartScriptMgr.h:512
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:7371
Definition: SmartScriptMgr.h:484
Definition: SmartScriptMgr.h:467
struct SmartAction::@114::@189 gameEventStop
uint32 quest
Definition: SmartScriptMgr.h:596
Creature * me
Definition: SmartScript.h:264
Definition: SmartScriptMgr.h:463
Definition: SmartScriptMgr.h:528
Definition: Unit.h:1305
Definition: SmartScriptMgr.h:500
float GetObjectSize() const
Definition: Object.cpp:2656
Definition: GameObject.h:869
Definition: SmartScriptMgr.h:504
void SetReactState(ReactStates st)
Definition: Creature.h:502
void CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=NULL, AuraEffect const *triggeredByAura=NULL, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:869
virtual void AttackStart(Unit *)
Definition: UnitAI.cpp:29
bool mUseTextTimer
Definition: SmartScript.h:279
Definition: Creature.h:79
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:672
bool runOnce
Definition: SmartScriptMgr.h:1383
std::string ToString() const
Definition: ObjectGuid.cpp:99
Unit * ToUnit()
Definition: Object.h:197
Definition: SmartScriptMgr.h:144
Definition: SmartScriptMgr.h:535
std::list< uint32 > mRemIDs
Definition: SmartScript.h:274
SMARTAI_TARGETS
Definition: SmartScriptMgr.h:1071
SMART_ACTION type
Definition: SmartScriptMgr.h:561
struct SmartAction::@114::@134 follow
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0) const
Definition: Object.cpp:2346
uint32 ItemEntry[MAX_EQUIPMENT_ITEMS]
Definition: Creature.h:279
struct SmartAction::@114::@159 setFly
Vehicle * GetVehicleKit() const
Definition: Unit.h:2165
Definition: SmartScriptMgr.h:546
struct SmartAction::@114::@146 ingamePhaseGroup
uint32 emote
Definition: SmartScriptMgr.h:591
struct SmartAction::@114::@185 setRoot
Definition: SmartScriptMgr.h:540
Definition: SharedDefines.h:985
void GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0) const
Definition: Object.cpp:2623
Definition: SmartScriptMgr.h:486
static SmartScriptHolder & FindLinkedEvent(SmartAIEventList &list, uint32 link)
Definition: SmartScriptMgr.h:1513
Definition: SmartScriptMgr.h:539
Definition: SmartScriptMgr.h:553
Definition: SharedDefines.h:267
Definition: SmartScriptMgr.h:541
ObjectList * GetTargetList(uint32 id)
Definition: SmartScript.h:140
uint32 CountPctFromMaxHealth(int32 pct) const
Definition: Unit.h:1435

+ Here is the caller graph for this function:

void SmartScript::ProcessEvent ( SmartScriptHolder e,
Unit unit = NULL,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
const SpellInfo spell = NULL,
GameObject gob = NULL 
)
2789 {
2790  if (!e.active && e.GetEventType() != SMART_EVENT_LINK)
2791  return;
2792 
2794  return;
2795 
2796  switch (e.GetEventType())
2797  {
2798  case SMART_EVENT_LINK://special handling
2799  ProcessAction(e, unit, var0, var1, bvar, spell, gob);
2800  break;
2801  //called from Update tick
2802  case SMART_EVENT_UPDATE:
2803  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
2804  break;
2806  if (me && me->IsInCombat())
2807  return;
2808  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
2809  break;
2810  case SMART_EVENT_UPDATE_IC:
2811  if (!me || !me->IsInCombat())
2812  return;
2813  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
2814  break;
2815  case SMART_EVENT_HEALT_PCT:
2816  {
2817  if (!me || !me->IsInCombat() || !me->GetMaxHealth())
2818  return;
2819  uint32 perc = (uint32)me->GetHealthPct();
2820  if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
2821  return;
2822  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
2823  break;
2824  }
2826  {
2827  if (!me || !me->IsInCombat() || !me->GetVictim() || !me->EnsureVictim()->GetMaxHealth())
2828  return;
2829  uint32 perc = (uint32)me->EnsureVictim()->GetHealthPct();
2830  if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
2831  return;
2832  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, me->GetVictim());
2833  break;
2834  }
2835  case SMART_EVENT_MANA_PCT:
2836  {
2837  if (!me || !me->IsInCombat() || !me->GetMaxPower(POWER_MANA))
2838  return;
2839  uint32 perc = uint32(100.0f * me->GetPower(POWER_MANA) / me->GetMaxPower(POWER_MANA));
2840  if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
2841  return;
2842  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
2843  break;
2844  }
2846  {
2847  if (!me || !me->IsInCombat() || !me->GetVictim() || !me->EnsureVictim()->GetMaxPower(POWER_MANA))
2848  return;
2850  if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
2851  return;
2852  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, me->GetVictim());
2853  break;
2854  }
2855  case SMART_EVENT_RANGE:
2856  {
2857  if (!me || !me->IsInCombat() || !me->GetVictim())
2858  return;
2859 
2860  if (me->IsInRange(me->GetVictim(), (float)e.event.minMaxRepeat.min, (float)e.event.minMaxRepeat.max))
2861  ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, me->GetVictim());
2862  break;
2863  }
2865  {
2866  if (!me || !me->IsInCombat())
2867  return;
2868 
2869  Unit* victim = me->GetVictim();
2870 
2871  if (!victim || !victim->IsNonMeleeSpellCast(false, false, true))
2872  return;
2873 
2874  if (e.event.targetCasting.spellId > 0)
2875  if (Spell* currSpell = victim->GetCurrentSpell(CURRENT_GENERIC_SPELL))
2876  if (currSpell->m_spellInfo->Id != e.event.targetCasting.spellId)
2877  return;
2878 
2879  ProcessTimedAction(e, e.event.targetCasting.repeatMin, e.event.targetCasting.repeatMax, me->GetVictim());
2880  break;
2881  }
2883  {
2884  if (!me || !me->IsInCombat())
2885  return;
2886 
2887  Unit* target = DoSelectLowestHpFriendly((float)e.event.friendlyHealth.radius, e.event.friendlyHealth.hpDeficit);
2888  if (!target || !target->IsInCombat())
2889  return;
2890  ProcessTimedAction(e, e.event.friendlyHealth.repeatMin, e.event.friendlyHealth.repeatMax, target);
2891  break;
2892  }
2894  {
2895  if (!me || !me->IsInCombat())
2896  return;
2897 
2898  std::list<Creature*> pList;
2899  DoFindFriendlyCC(pList, (float)e.event.friendlyCC.radius);
2900  if (pList.empty())
2901  return;
2902  ProcessTimedAction(e, e.event.friendlyCC.repeatMin, e.event.friendlyCC.repeatMax, *pList.begin());
2903  break;
2904  }
2906  {
2907  std::list<Creature*> pList;
2908  DoFindFriendlyMissingBuff(pList, (float)e.event.missingBuff.radius, e.event.missingBuff.spell);
2909 
2910  if (pList.empty())
2911  return;
2912 
2913  ProcessTimedAction(e, e.event.missingBuff.repeatMin, e.event.missingBuff.repeatMax, *pList.begin());
2914  break;
2915  }
2916  case SMART_EVENT_HAS_AURA:
2917  {
2918  if (!me)
2919  return;
2920  uint32 count = me->GetAuraCount(e.event.aura.spell);
2921  if ((!e.event.aura.count && !count) || (e.event.aura.count && count >= e.event.aura.count))
2922  ProcessTimedAction(e, e.event.aura.repeatMin, e.event.aura.repeatMax);
2923  break;
2924  }
2926  {
2927  if (!me || !me->GetVictim())
2928  return;
2929  uint32 count = me->EnsureVictim()->GetAuraCount(e.event.aura.spell);
2930  if (count < e.event.aura.count)
2931  return;
2932  ProcessTimedAction(e, e.event.aura.repeatMin, e.event.aura.repeatMax);
2933  break;
2934  }
2935  //no params
2936  case SMART_EVENT_AGGRO:
2937  case SMART_EVENT_DEATH:
2938  case SMART_EVENT_EVADE:
2940  case SMART_EVENT_CHARMED:
2943  case SMART_EVENT_AI_INIT:
2952  case SMART_EVENT_RESET:
2957  ProcessAction(e, unit, var0, var1, bvar, spell, gob);
2958  break;
2960  {
2961  if (!me)
2962  return;
2963 
2964  if (Unit* victim = me->GetVictim())
2965  {
2966  if (!victim->HasInArc(static_cast<float>(M_PI), me))
2967  ProcessTimedAction(e, e.event.behindTarget.cooldownMin, e.event.behindTarget.cooldownMax, victim);
2968  }
2969  break;
2970  }
2972  if (e.event.emote.emote == var0)
2973  {
2974  ProcessAction(e, unit);
2975  RecalcTimer(e, e.event.emote.cooldownMin, e.event.emote.cooldownMax);
2976  }
2977  break;
2978  case SMART_EVENT_KILL:
2979  {
2980  if (!me || !unit)
2981  return;
2982  if (e.event.kill.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
2983  return;
2984  if (e.event.kill.creature && unit->GetEntry() != e.event.kill.creature)
2985  return;
2986  ProcessAction(e, unit);
2987  RecalcTimer(e, e.event.kill.cooldownMin, e.event.kill.cooldownMax);
2988  break;
2989  }
2991  case SMART_EVENT_SPELLHIT:
2992  {
2993  if (!spell)
2994  return;
2995  if ((!e.event.spellHit.spell || spell->Id == e.event.spellHit.spell) &&
2996  (!e.event.spellHit.school || (spell->SchoolMask & e.event.spellHit.school)))
2997  {
2998  ProcessAction(e, unit, 0, 0, bvar, spell);
2999  RecalcTimer(e, e.event.spellHit.cooldownMin, e.event.spellHit.cooldownMax);
3000  }
3001  break;
3002  }
3003  case SMART_EVENT_OOC_LOS:
3004  {
3005  if (!me || me->IsInCombat())
3006  return;
3007  //can trigger if closer than fMaxAllowedRange
3008  float range = (float)e.event.los.maxDist;
3009 
3010  //if range is ok and we are actually in LOS
3011  if (me->IsWithinDistInMap(unit, range) && me->IsWithinLOSInMap(unit))
3012  {
3013  //if friendly event&&who is not hostile OR hostile event&&who is hostile
3014  if ((e.event.los.noHostile && !me->IsHostileTo(unit)) ||
3015  (!e.event.los.noHostile && me->IsHostileTo(unit)))
3016  {
3017  ProcessAction(e, unit);
3018  RecalcTimer(e, e.event.los.cooldownMin, e.event.los.cooldownMax);
3019  }
3020  }
3021  break;
3022  }
3023  case SMART_EVENT_IC_LOS:
3024  {
3025  if (!me || !me->IsInCombat())
3026  return;
3027  //can trigger if closer than fMaxAllowedRange
3028  float range = (float)e.event.los.maxDist;
3029 
3030  //if range is ok and we are actually in LOS
3031  if (me->IsWithinDistInMap(unit, range) && me->IsWithinLOSInMap(unit))
3032  {
3033  //if friendly event&&who is not hostile OR hostile event&&who is hostile
3034  if ((e.event.los.noHostile && !me->IsHostileTo(unit)) ||
3035  (!e.event.los.noHostile && me->IsHostileTo(unit)))
3036  {
3037  ProcessAction(e, unit);
3038  RecalcTimer(e, e.event.los.cooldownMin, e.event.los.cooldownMax);
3039  }
3040  }
3041  break;
3042  }
3043  case SMART_EVENT_RESPAWN:
3044  {
3045  if (!GetBaseObject())
3046  return;
3047  if (e.event.respawn.type == SMART_SCRIPT_RESPAWN_CONDITION_MAP && GetBaseObject()->GetMapId() != e.event.respawn.map)
3048  return;
3049  if (e.event.respawn.type == SMART_SCRIPT_RESPAWN_CONDITION_AREA && GetBaseObject()->GetZoneId() != e.event.respawn.area)
3050  return;
3051  ProcessAction(e);
3052  break;
3053  }
3055  {
3056  if (!IsCreature(unit))
3057  return;
3058  if (e.event.summoned.creature && unit->GetEntry() != e.event.summoned.creature)
3059  return;
3060  ProcessAction(e, unit);
3061  RecalcTimer(e, e.event.summoned.cooldownMin, e.event.summoned.cooldownMax);
3062  break;
3063  }
3065  case SMART_EVENT_DAMAGED:
3067  {
3068  if (var0 > e.event.minMaxRepeat.max || var0 < e.event.minMaxRepeat.min)
3069  return;
3070  ProcessAction(e, unit);
3071  RecalcTimer(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
3072  break;
3073  }
3075  {
3076  if ((e.event.movementInform.type && var0 != e.event.movementInform.type) || (e.event.movementInform.id && var1 != e.event.movementInform.id))
3077  return;
3078  ProcessAction(e, unit, var0, var1);
3079  break;
3080  }
3083  {
3084  if (e.event.waypoint.pathID && var0 != e.event.waypoint.pathID)
3085  return;
3086  ProcessAction(e, unit, var0);
3087  break;
3088  }
3094  {
3095  if (!me || (e.event.waypoint.pointID && var0 != e.event.waypoint.pointID) || (e.event.waypoint.pathID && GetPathId() != e.event.waypoint.pathID))
3096  return;
3097  ProcessAction(e, unit);
3098  break;
3099  }
3102  {
3103  if (e.event.instancePlayerEnter.team && var0 != e.event.instancePlayerEnter.team)
3104  return;
3105  ProcessAction(e, unit, var0);
3106  RecalcTimer(e, e.event.instancePlayerEnter.cooldownMin, e.event.instancePlayerEnter.cooldownMax);
3107  break;
3108  }
3111  {
3112  if (e.event.quest.quest && var0 != e.event.quest.quest)
3113  return;
3114  ProcessAction(e, unit, var0);
3115  break;
3116  }
3118  {
3119  if (e.event.transportAddCreature.creature && var0 != e.event.transportAddCreature.creature)
3120  return;
3121  ProcessAction(e, unit, var0);
3122  break;
3123  }
3125  {
3126  if (e.event.areatrigger.id && var0 != e.event.areatrigger.id)
3127  return;
3128  ProcessAction(e, unit, var0);
3129  break;
3130  }
3131  case SMART_EVENT_TEXT_OVER:
3132  {
3133  if (var0 != e.event.textOver.textGroupID || (e.event.textOver.creatureEntry && e.event.textOver.creatureEntry != var1))
3134  return;
3135  ProcessAction(e, unit, var0);
3136  break;
3137  }
3138  case SMART_EVENT_DATA_SET:
3139  {
3140  if (e.event.dataSet.id != var0 || e.event.dataSet.value != var1)
3141  return;
3142  ProcessAction(e, unit, var0, var1);
3143  RecalcTimer(e, e.event.dataSet.cooldownMin, e.event.dataSet.cooldownMax);
3144  break;
3145  }
3148  {
3149  if (!unit)
3150  return;
3151  ProcessAction(e, unit);
3152  RecalcTimer(e, e.event.minMax.repeatMin, e.event.minMax.repeatMax);
3153  break;
3154  }
3156  {
3157  if (e.event.timedEvent.id == var0)
3158  ProcessAction(e, unit);
3159  break;
3160  }
3162  {
3163  TC_LOG_DEBUG("scripts.ai", "SmartScript: Gossip Select: menu %u action %u", var0, var1);//little help for scripters
3164  if (e.event.gossip.sender != var0 || e.event.gossip.action != var1)
3165  return;
3166  ProcessAction(e, unit, var0, var1);
3167  break;
3168  }
3170  {
3171  if (e.event.dummy.spell != var0 || e.event.dummy.effIndex != var1)
3172  return;
3173  ProcessAction(e, unit, var0, var1);
3174  break;
3175  }
3178  {
3179  if (e.event.gameEvent.gameEventId != var0)
3180  return;
3181  ProcessAction(e, NULL, var0);
3182  break;
3183  }
3185  {
3186  if (e.event.goStateChanged.state != var0)
3187  return;
3188  ProcessAction(e, unit, var0, var1);
3189  break;
3190  }
3192  {
3193  if (e.event.eventInform.eventId != var0)
3194  return;
3195  ProcessAction(e, NULL, var0);
3196  break;
3197  }
3199  {
3200  if (e.event.doAction.eventId != var0)
3201  return;
3202  ProcessAction(e, unit, var0);
3203  break;
3204  }
3206  {
3207  if (!me || !me->IsInCombat())
3208  return;
3209 
3210  ObjectList* _targets = NULL;
3211 
3212  switch (e.GetTargetType())
3213  {
3221  _targets = GetTargets(e);
3222  break;
3223  default:
3224  return;
3225  }
3226 
3227  if (!_targets)
3228  return;
3229 
3230  Unit* target = NULL;
3231 
3232  for (ObjectList::const_iterator itr = _targets->begin(); itr != _targets->end(); ++itr)
3233  {
3234  if (IsUnit(*itr) && me->IsFriendlyTo((*itr)->ToUnit()) && (*itr)->ToUnit()->IsAlive() && (*itr)->ToUnit()->IsInCombat())
3235  {
3236  uint32 healthPct = uint32((*itr)->ToUnit()->GetHealthPct());
3237 
3238  if (healthPct > e.event.friendlyHealthPct.maxHpPct || healthPct < e.event.friendlyHealthPct.minHpPct)
3239  continue;
3240 
3241  target = (*itr)->ToUnit();
3242  break;
3243  }
3244  }
3245 
3246  delete _targets;
3247 
3248  if (!target)
3249  return;
3250 
3251  ProcessTimedAction(e, e.event.friendlyHealthPct.repeatMin, e.event.friendlyHealthPct.repeatMax, target);
3252  break;
3253  }
3255  {
3256  if (!me)
3257  return;
3258 
3259  WorldObject* creature = NULL;
3260 
3261  if (e.event.distance.guid != 0)
3262  {
3263  creature = FindCreatureNear(me, e.event.distance.guid);
3264 
3265  if (!creature)
3266  return;
3267 
3268  if (!me->IsInRange(creature, 0, (float)e.event.distance.dist))
3269  return;
3270  }
3271  else if (e.event.distance.entry != 0)
3272  {
3273  std::list<Creature*> list;
3274  me->GetCreatureListWithEntryInGrid(list, e.event.distance.entry, (float)e.event.distance.dist);
3275 
3276  if (!list.empty())
3277  creature = list.front();
3278  }
3279 
3280  if (creature)
3281  ProcessTimedAction(e, e.event.distance.repeat, e.event.distance.repeat);
3282 
3283  break;
3284  }
3286  {
3287  if (!me)
3288  return;
3289 
3290  WorldObject* gameobject = NULL;
3291 
3292  if (e.event.distance.guid != 0)
3293  {
3294  gameobject = FindGameObjectNear(me, e.event.distance.guid);
3295 
3296  if (!gameobject)
3297  return;
3298 
3299  if (!me->IsInRange(gameobject, 0, (float)e.event.distance.dist))
3300  return;
3301  }
3302  else if (e.event.distance.entry != 0)
3303  {
3304  std::list<GameObject*> list;
3305  me->GetGameObjectListWithEntryInGrid(list, e.event.distance.entry, (float)e.event.distance.dist);
3306 
3307  if (!list.empty())
3308  gameobject = list.front();
3309  }
3310 
3311  if (gameobject)
3312  ProcessTimedAction(e, e.event.distance.repeat, e.event.distance.repeat);
3313 
3314  break;
3315  }
3317  if (GetCounterId(e.event.counter.id) != 0 && GetCounterValue(e.event.counter.id) == e.event.counter.value)
3318  ProcessTimedAction(e, e.event.counter.cooldownMin, e.event.counter.cooldownMax);
3319  break;
3320  default:
3321  TC_LOG_ERROR("sql.sql", "SmartScript::ProcessEvent: Unhandled Event type %u", e.GetEventType());
3322  break;
3323  }
3324 }
Definition: SmartScriptMgr.h:106
Definition: SmartScriptMgr.h:175
struct SmartEvent::@77::@99 instancePlayerEnter
Definition: SmartScriptMgr.h:125
Unit * EnsureVictim() const
Definition: Unit.h:1381
Definition: Unit.h:1109
Definition: SmartScriptMgr.h:109
uint32 Id
Definition: SpellInfo.h:329
struct SmartEvent::@77::@92 aura
uint32 event_phase_mask
Definition: SmartScriptMgr.h:189
Definition: SmartScriptMgr.h:174
Definition: SmartScriptMgr.h:161
Definition: SmartScriptMgr.h:152
Definition: SmartScriptMgr.h:118
uint32 emote
Definition: SmartScriptMgr.h:283
uint32 GetMaxHealth() const
Definition: Unit.h:1427
Definition: SmartScriptMgr.h:178
Definition: SmartScriptMgr.h:179
Definition: SmartScriptMgr.h:166
SmartEvent event
Definition: SmartScriptMgr.h:1372
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
Definition: SmartScriptMgr.h:173
#define M_PI
Definition: Common.h:163
Definition: SmartScriptMgr.h:115
struct SmartEvent::@77::@102 timedEvent
Definition: SmartScriptMgr.h:151
bool IsWithinLOSInMap(WorldObject const *obj) const
Definition: Object.cpp:1584
Definition: SmartScriptMgr.h:122
Definition: SmartScriptMgr.h:112
Definition: SmartScriptMgr.h:143
Definition: SmartScriptMgr.h:181
Definition: SmartScriptMgr.h:1335
struct SmartEvent::@77::@104 dummy
Definition: SmartScriptMgr.h:135
Definition: SmartScriptMgr.h:123
struct SmartEvent::@77::@95 dataSet
uint32 SchoolMask
Definition: SpellInfo.h:401
Definition: SmartScriptMgr.h:140
Definition: SmartScriptMgr.h:108
bool IsInCombat() const
Definition: Unit.h:1584
Definition: SmartScriptMgr.h:137
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1377
Definition: SmartScriptMgr.h:131
void ProcessAction(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:97
Definition: SmartScriptMgr.h:124
Definition: SmartScriptMgr.h:180
Definition: SmartScriptMgr.h:141
Definition: SmartScriptMgr.h:1082
bool IsInPhase(uint32 p) const
Definition: SmartScript.h:257
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: SmartScriptMgr.h:145
Definition: SmartScriptMgr.h:150
struct SmartEvent::@77::@88 missingBuff
bool active
Definition: SmartScriptMgr.h:1382
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: SmartScriptMgr.h:176
Definition: Object.h:423
Definition: SmartScriptMgr.h:163
Definition: SmartScriptMgr.h:138
void GetGameObjectListWithEntryInGrid(std::list< GameObject * > &lList, uint32 uiEntry, float fMaxSearchRange) const
Definition: Object.cpp:2470
ObjectList * GetTargets(SmartScriptHolder const &e, Unit *invoker=NULL)
Definition: SmartScript.cpp:2497
Definition: SmartScriptMgr.h:160
void DoFindFriendlyMissingBuff(std::list< Creature * > &list, float range, uint32 spellid)
Definition: SmartScript.cpp:3673
struct SmartEvent::@77::@105 behindTarget
Definition: SmartScriptMgr.h:177
Definition: SmartScriptMgr.h:170
Definition: SmartScriptMgr.h:116
Definition: SmartScriptMgr.h:114
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true) const
Definition: Unit.cpp:2886
Definition: SmartScriptMgr.h:1084
Definition: SmartScriptMgr.h:130
int32 GetPower(Powers power) const
Definition: Unit.cpp:11589
uint32 event_flags
Definition: SmartScriptMgr.h:191
Definition: SmartScriptMgr.h:171
Definition: SmartScriptMgr.h:111
Definition: SmartScriptMgr.h:169
struct SmartEvent::@77::@103 gossip
struct SmartEvent::@77::@83 respawn
Definition: SmartScriptMgr.h:120
struct SmartEvent::@77::@108 eventInform
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition: Object.cpp:1663
struct SmartEvent::@77::@107 goStateChanged
struct SmartEvent::@77::@79 minMaxRepeat
void GetCreatureListWithEntryInGrid(std::list< Creature * > &lList, uint32 uiEntry, float fMaxSearchRange) const
Definition: Object.cpp:2483
Definition: SmartScriptMgr.h:127
Definition: SmartScriptMgr.h:121
Definition: SmartScriptMgr.h:148
Definition: SmartScriptMgr.h:432
Definition: SmartScriptMgr.h:154
Definition: SmartScriptMgr.h:158
TypeID GetTypeId() const
Definition: Object.h:113
struct SmartEvent::@77::@94 movementInform
std::list< WorldObject * > ObjectList
Definition: SmartScriptMgr.h:1391
Definition: SmartScriptMgr.h:142
struct SmartEvent::@77::@82 los
Definition: SmartScriptMgr.h:172
Definition: SmartScriptMgr.h:110
Definition: SmartScriptMgr.h:128
Unit * DoSelectLowestHpFriendly(float range, uint32 MinHPDiff)
Definition: SmartScript.cpp:3636
Definition: SmartScriptMgr.h:167
struct SmartEvent::@77::@81 spellHit
Unit * GetVictim() const
Definition: Unit.h:1379
Definition: SmartScriptMgr.h:162
struct SmartEvent::@77::@85 targetCasting
struct SmartEvent::@77::@89 summoned
Definition: SmartScriptMgr.h:149
void RecalcTimer(SmartScriptHolder &e, uint32 min, uint32 max)
Definition: SmartScript.cpp:3345
struct SmartEvent::@77::@96 waypoint
Definition: SmartScriptMgr.h:107
Spell * GetCurrentSpell(CurrentSpellTypes spellType) const
Definition: Unit.h:1920
Definition: SmartScriptMgr.h:157
Definition: SmartScriptMgr.h:113
uint32_t uint32
Definition: Define.h:150
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:7170
uint32 GetAuraCount(uint32 spellId) const
Definition: Unit.cpp:4224
Definition: SmartScriptMgr.h:153
Definition: SmartScriptMgr.h:139
bool HasInArc(float arcangle, Position const *pos, float border=2.0f) const
Definition: Position.cpp:129
Definition: SmartScriptMgr.h:164
Definition: SmartScriptMgr.h:165
GameObject * FindGameObjectNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:178
void ProcessTimedAction(SmartScriptHolder &e, uint32 const &min, uint32 const &max, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:2380
struct SmartEvent::@77::@87 friendlyCC
struct SmartEvent::@77::@86 friendlyHealth
Definition: SmartScriptMgr.h:105
Definition: SmartScriptMgr.h:1091
struct SmartEvent::@77::@84 minMax
bool IsInRange(WorldObject const *obj, float minRange, float maxRange, bool is3D=true) const
Definition: Object.cpp:1703
Definition: SmartScriptMgr.h:168
uint32 GetPathId() const
Definition: SmartScript.h:55
uint32 quest
Definition: SmartScriptMgr.h:278
Definition: ObjectGuid.h:33
Definition: SmartScriptMgr.h:146
struct SmartEvent::@77::@101 textOver
bool IsUnit(WorldObject *obj)
Definition: SmartScript.h:66
Definition: SmartScriptMgr.h:134
Definition: SmartScriptMgr.h:1094
Definition: SmartScriptMgr.h:136
Definition: SmartScriptMgr.h:119
struct SmartEvent::@77::@106 gameEvent
bool IsHostileTo(Unit const *unit) const
Definition: Unit.cpp:7165
void DoFindFriendlyCC(std::list< Creature * > &_list, float range)
Definition: SmartScript.cpp:3656
Definition: SmartScriptMgr.h:117
Definition: SmartScriptMgr.h:132
uint32 GetCounterId(uint32 id)
Definition: SmartScript.h:162
Definition: SmartScriptMgr.h:104
Definition: SmartScriptMgr.h:1090
uint32 GetTargetType() const
Definition: SmartScriptMgr.h:1379
Definition: SmartScriptMgr.h:1092
int32 GetMaxPower(Powers power) const
Definition: Unit.cpp:11598
Definition: SmartScriptMgr.h:147
Definition: SmartScriptMgr.h:133
uint32 GetCounterValue(uint32 id)
Definition: SmartScript.h:170
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
struct SmartEvent::@77::@80 kill
uint32_t uint32
Definition: g3dmath.h:168
struct SmartEvent::@77::@112 counter
Definition: SmartScriptMgr.h:1083
Definition: SmartScriptMgr.h:159
Creature * FindCreatureNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:187
struct SmartEvent::@77::@109 doAction
bool IsCreature(WorldObject *obj)
Definition: SmartScript.h:76
struct SmartEvent::@77::@111 distance
Creature * me
Definition: SmartScript.h:264
Definition: Unit.h:1305
struct SmartEvent::@77::@110 friendlyHealthPct
Definition: SmartScriptMgr.h:129
Definition: SmartScriptMgr.h:433
Definition: SmartScriptMgr.h:155
Definition: SmartScriptMgr.h:126
struct SmartEvent::@77::@100 areatrigger
struct SmartEvent::@77::@97 transportAddCreature
bool runOnce
Definition: SmartScriptMgr.h:1383
Unit * ToUnit()
Definition: Object.h:197
Definition: SmartScriptMgr.h:144
Definition: SharedDefines.h:248
float GetHealthPct() const
Definition: Unit.h:1434
Definition: SmartScriptMgr.h:156
Definition: Spell.h:294

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::ProcessEventsFor ( SMART_EVENT  e,
Unit unit = NULL,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
const SpellInfo spell = NULL,
GameObject gob = NULL 
)
84 {
85  for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
86  {
87  SMART_EVENT eventType = SMART_EVENT(i->GetEventType());
88  if (eventType == SMART_EVENT_LINK)//special handling
89  continue;
90 
91  if (eventType == e /*&& (!i->event.event_phase_mask || IsInPhase(i->event.event_phase_mask)) && !(i->event.event_flags & SMART_EVENT_FLAG_NOT_REPEATABLE && i->runOnce)*/)
92  if (sConditionMgr->IsObjectMeetingSmartEventConditions(i->entryOrGuid, i->event_id, i->source_type, unit, GetBaseObject()))
93  ProcessEvent(*i, unit, var0, var1, bvar, spell, gob);
94  }
95 }
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
void ProcessEvent(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:2788
SMART_EVENT
Definition: SmartScriptMgr.h:102
Definition: SmartScriptMgr.h:165
#define sConditionMgr
Definition: ConditionMgr.h:307
SmartAIEventList mEvents
Definition: SmartScript.h:260

+ Here is the call graph for this function:

void SmartScript::ProcessTimedAction ( SmartScriptHolder e,
uint32 const min,
uint32 const max,
Unit unit = NULL,
uint32  var0 = 0,
uint32  var1 = 0,
bool  bvar = false,
const SpellInfo spell = NULL,
GameObject gob = NULL 
)
2381 {
2382  if (sConditionMgr->IsObjectMeetingSmartEventConditions(e.entryOrGuid, e.event_id, e.source_type, unit, GetBaseObject()))
2383  ProcessAction(e, unit, var0, var1, bvar, spell, gob);
2384 
2385  RecalcTimer(e, min, max);
2386 }
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
void ProcessAction(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:97
uint32 event_id
Definition: SmartScriptMgr.h:1369
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
void RecalcTimer(SmartScriptHolder &e, uint32 min, uint32 max)
Definition: SmartScript.cpp:3345
#define sConditionMgr
Definition: ConditionMgr.h:307
int64 entryOrGuid
Definition: SmartScriptMgr.h:1367
SmartScriptType source_type
Definition: SmartScriptMgr.h:1368

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::RecalcTimer ( SmartScriptHolder e,
uint32  min,
uint32  max 
)
3346 {
3347  // min/max was checked at loading!
3348  e.timer = urand(min, max);
3349  e.active = e.timer ? false : true;
3350 }
bool active
Definition: SmartScriptMgr.h:1382
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32 timer
Definition: SmartScriptMgr.h:1381

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

void SmartScript::ResetBaseObject ( )
inline
205  {
206  WorldObject* lookupRoot = me;
207  if (!lookupRoot)
208  lookupRoot = go;
209 
210  if (lookupRoot)
211  {
212  if (!meOrigGUID.IsEmpty())
213  {
214  if (Creature* m = ObjectAccessor::GetCreature(*lookupRoot, meOrigGUID))
215  {
216  me = m;
217  go = NULL;
218  }
219  }
220  if (!goOrigGUID.IsEmpty())
221  {
222  if (GameObject* o = ObjectAccessor::GetGameObject(*lookupRoot, goOrigGUID))
223  {
224  me = NULL;
225  go = o;
226  }
227  }
228  }
229  goOrigGUID.Clear();
230  meOrigGUID.Clear();
231  }
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Object.h:423
Definition: Creature.h:467
ObjectGuid meOrigGUID
Definition: SmartScript.h:265
Definition: GameObject.h:880
GameObject * go
Definition: SmartScript.h:266
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:174
void Clear()
Definition: ObjectGuid.h:215
TC_GAME_API GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:143
ObjectGuid goOrigGUID
Definition: SmartScript.h:267
Creature * me
Definition: SmartScript.h:264
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::SetPathId ( uint32  id)
inline
54 { mPathId = id; }
uint32 mPathId
Definition: SmartScript.h:272

+ Here is the caller graph for this function:

void SmartScript::SetPhase ( uint32  p = 0)
inlineprivate
258 { mEventPhase = p; }
uint32 mEventPhase
Definition: SmartScript.h:270

+ Here is the caller graph for this function:

void SmartScript::SetScript9 ( SmartScriptHolder e,
uint32  entry 
)
3703 {
3704  //do NOT clear mTimedActionList if it's being iterated because it will invalidate the iterator and delete
3705  // any SmartScriptHolder contained like the "e" parameter passed to this function
3707  {
3708  TC_LOG_ERROR("scripts.ai", "Entry " SI64FMTD " SourceType %u Event %u Action %u is trying to overwrite timed action list from a timed action, this is not allowed!.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
3709  return;
3710  }
3711 
3712  mTimedActionList.clear();
3714  if (mTimedActionList.empty())
3715  return;
3716  for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
3717  {
3718  i->enableTimed = i == mTimedActionList.begin();//enable processing only for the first action
3719 
3720  if (e.action.timedActionList.timerType == 0)
3721  i->event.type = SMART_EVENT_UPDATE_OOC;
3722  else if (e.action.timedActionList.timerType == 1)
3723  i->event.type = SMART_EVENT_UPDATE_IC;
3724  else if (e.action.timedActionList.timerType > 1)
3725  i->event.type = SMART_EVENT_UPDATE;
3726 
3727  InitTimer((*i));
3728  }
3729 }
SmartAIEventList mTimedActionList
Definition: SmartScript.h:262
struct SmartAction::@114::@172 timedActionList
bool isProcessingTimedActionList
Definition: SmartScript.h:263
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1377
void InitTimer(SmartScriptHolder &e)
Definition: SmartScript.cpp:3326
Definition: SmartScriptMgr.h:1219
#define SI64FMTD
Definition: Define.h:140
Definition: SmartScriptMgr.h:164
Definition: SmartScriptMgr.h:105
int64 entryOrGuid
Definition: SmartScriptMgr.h:1367
uint32 GetActionType() const
Definition: SmartScriptMgr.h:1378
SmartAction action
Definition: SmartScriptMgr.h:1373
uint32 GetScriptType() const
Definition: SmartScriptMgr.h:1376
Definition: SmartScriptMgr.h:104
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
#define sSmartScriptMgr
Definition: SmartScriptMgr.h:1669

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SmartScript::StoreCounter ( uint32  id,
uint32  value,
uint32  reset 
)
inline
149  {
150  CounterMap::const_iterator itr = mCounterList.find(id);
151  if (itr != mCounterList.end())
152  {
153  if (reset == 0)
154  value += GetCounterValue(id);
155  mCounterList.erase(id);
156  }
157 
158  mCounterList.insert(std::make_pair(id, value));
160  }
CounterMap mCounterList
Definition: SmartScript.h:238
Definition: SmartScriptMgr.h:181
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:83
uint32 GetCounterValue(uint32 id)
Definition: SmartScript.h:170
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

void SmartScript::StoreTargetList ( ObjectList targets,
uint32  id 
)
inline
95  {
96  if (!targets)
97  return;
98 
99  if (mTargetStorage->find(id) != mTargetStorage->end())
100  {
101  // check if already stored
102  if ((*mTargetStorage)[id]->Equals(targets))
103  return;
104 
105  delete (*mTargetStorage)[id];
106  }
107 
108  (*mTargetStorage)[id] = new ObjectGuidList(targets, GetBaseObject());
109  }
WorldObject * GetBaseObject()
Definition: SmartScript.h:56
ObjectListMap * mTargetStorage
Definition: SmartScript.h:201
Definition: SmartScriptMgr.h:1393

+ Here is the caller graph for this function:

void SmartScript::UpdateTimer ( SmartScriptHolder e,
uint32 const  diff 
)
3353 {
3354  if (e.GetEventType() == SMART_EVENT_LINK)
3355  return;
3356 
3358  return;
3359 
3360  if (e.GetEventType() == SMART_EVENT_UPDATE_IC && (!me || !me->IsInCombat()))
3361  return;
3362 
3363  if (e.GetEventType() == SMART_EVENT_UPDATE_OOC && (me && me->IsInCombat())) //can be used with me=NULL (go script)
3364  return;
3365 
3366  if (e.timer < diff)
3367  {
3368  // delay spell cast event if another spell is being cast
3369  if (e.GetActionType() == SMART_ACTION_CAST)
3370  {
3371  if (!(e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS))
3372  {
3374  {
3375  e.timer = 1;
3376  return;
3377  }
3378  }
3379  }
3380 
3381  e.active = true;//activate events with cooldown
3382  switch (e.GetEventType())//process ONLY timed events
3383  {
3384  case SMART_EVENT_UPDATE:
3386  case SMART_EVENT_UPDATE_IC:
3387  case SMART_EVENT_HEALT_PCT:
3389  case SMART_EVENT_MANA_PCT:
3391  case SMART_EVENT_RANGE:
3396  case SMART_EVENT_HAS_AURA:
3402  {
3403  ProcessEvent(e);
3405  {
3406  e.enableTimed = false;//disable event if it is in an ActionList and was processed once
3407  for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
3408  {
3409  //find the first event which is not the current one and enable it
3410  if (i->event_id > e.event_id)
3411  {
3412  i->enableTimed = true;
3413  break;
3414  }
3415  }
3416  }
3417  break;
3418  }
3419  }
3420  }
3421  else
3422  e.timer -= diff;
3423 }
Definition: SmartScriptMgr.h:106
uint32 event_phase_mask
Definition: SmartScriptMgr.h:189
Definition: SmartScriptMgr.h:118
Definition: SmartScriptMgr.h:178
SmartAIEventList mTimedActionList
Definition: SmartScript.h:262
Definition: SmartScriptMgr.h:179
Definition: Unit.h:565
SmartEvent event
Definition: SmartScriptMgr.h:1372
Definition: SmartScriptMgr.h:122
bool IsInCombat() const
Definition: Unit.h:1584
uint32 GetEventType() const
Definition: SmartScriptMgr.h:1377
Definition: SmartScriptMgr.h:180
bool IsInPhase(uint32 p) const
Definition: SmartScript.h:257
bool active
Definition: SmartScriptMgr.h:1382
uint32 event_id
Definition: SmartScriptMgr.h:1369
Definition: SmartScriptMgr.h:116
Definition: SmartScriptMgr.h:171
Definition: SmartScriptMgr.h:120
Definition: SmartScriptMgr.h:127
Definition: SmartScriptMgr.h:128
Definition: SmartScriptMgr.h:450
Definition: SmartScriptMgr.h:1219
void ProcessEvent(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Definition: SmartScript.cpp:2788
uint32 timer
Definition: SmartScriptMgr.h:1381
Definition: SmartScriptMgr.h:107
Definition: SmartScriptMgr.h:113
Definition: SmartScriptMgr.h:164
Definition: SmartScriptMgr.h:165
bool enableTimed
Definition: SmartScriptMgr.h:1384
Definition: SmartScriptMgr.h:105
Definition: SmartScriptMgr.h:1351
uint32 GetActionType() const
Definition: SmartScriptMgr.h:1378
SmartAction action
Definition: SmartScriptMgr.h:1373
uint32 GetScriptType() const
Definition: SmartScriptMgr.h:1376
Definition: SmartScriptMgr.h:119
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1395
Definition: SmartScriptMgr.h:117
Definition: SmartScriptMgr.h:104
struct SmartAction::@114::@124 cast
Creature * me
Definition: SmartScript.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

GameObject* SmartScript::go
private
ObjectGuid SmartScript::goOrigGUID
private
bool SmartScript::isProcessingTimedActionList
private
CounterMap SmartScript::mCounterList
Creature* SmartScript::me
private
ObjectGuid SmartScript::meOrigGUID
private
uint32 SmartScript::mEventPhase
private
SmartAIEventList SmartScript::mEvents
private
SmartAIEventList SmartScript::mInstallEvents
private
ObjectGuid SmartScript::mLastInvoker
uint32 SmartScript::mLastTextID
private
uint32 SmartScript::mPathId
private
std::list<uint32> SmartScript::mRemIDs
private
SmartScriptType SmartScript::mScriptType
private
SmartAIEventList SmartScript::mStoredEvents
private
uint32 SmartScript::mTalkerEntry
private
ObjectListMap* SmartScript::mTargetStorage
SMARTAI_TEMPLATE SmartScript::mTemplate
private
uint32 SmartScript::mTextTimer
private
SmartAIEventList SmartScript::mTimedActionList
private
bool SmartScript::mUseTextTimer
private
AreaTriggerEntry const* SmartScript::trigger
private

The documentation for this class was generated from the following files: