Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SmartScript.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRE_SMARTSCRIPT_H
7#define SKYFIRE_SMARTSCRIPT_H
8
9#include "Common.h"
10#include "Creature.h"
11#include "CreatureAI.h"
12#include "GridNotifiers.h"
13#include "Spell.h"
14#include "Unit.h"
15
16#include "SmartScriptMgr.h"
17
19{
20public:
23
24 void OnInitialize(WorldObject* obj, AreaTriggerEntry const* at = NULL);
25 void GetScript();
27
28 void ProcessEventsFor(SMART_EVENT e, Unit* unit = NULL, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = NULL, GameObject* gob = NULL);
29 void ProcessEvent(SmartScriptHolder& e, Unit* unit = NULL, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = NULL, GameObject* gob = NULL);
30 bool CheckTimer(SmartScriptHolder const& e) const;
31 void RecalcTimer(SmartScriptHolder& e, uint32 min, uint32 max);
32 void UpdateTimer(SmartScriptHolder& e, uint32 const diff);
34 void ProcessAction(SmartScriptHolder& e, Unit* unit = NULL, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = NULL, GameObject* gob = NULL);
35 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);
36 ObjectList* GetTargets(SmartScriptHolder const& e, Unit* invoker = NULL);
39 SmartScriptHolder CreateEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 phaseMask = 0);
40 void AddEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 phaseMask = 0);
41 void SetPathId(uint32 id) { mPathId = id; }
42 uint32 GetPathId() const { return mPathId; }
44 {
45 WorldObject* obj = NULL;
46 if (me)
47 obj = me;
48 else if (go)
49 obj = go;
50 return obj;
51 }
52
54 {
55 return obj && (obj->GetTypeId() == TypeID::TYPEID_UNIT || obj->GetTypeId() == TypeID::TYPEID_PLAYER);
56 }
57
59 {
60 return obj && obj->GetTypeId() == TypeID::TYPEID_PLAYER;
61 }
62
64 {
65 return obj && obj->GetTypeId() == TypeID::TYPEID_UNIT;
66 }
67
69 {
70 return obj && obj->GetTypeId() == TypeID::TYPEID_GAMEOBJECT;
71 }
72
73 void OnUpdate(const uint32 diff);
74 void OnMoveInLineOfSight(Unit* who);
75
76 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff);
77 void DoFindFriendlyCC(std::list<Creature*>& _list, float range);
78 void DoFindFriendlyMissingBuff(std::list<Creature*>& list, float range, uint32 spellid);
79 Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly);
80
81 void StoreTargetList(ObjectList* targets, uint32 id);
82
83 bool IsSmart(Creature* c = NULL)
84 {
85 bool smart = true;
86 if (c && c->GetAIName() != "SmartAI")
87 smart = false;
88
89 if (!me || me->GetAIName() != "SmartAI")
90 smart = false;
91
92 if (!smart)
93 SF_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: %u Entry: %u) is not using SmartAI, action skipped to prevent crash.", c ? c->GetDBTableGUIDLow() : (me ? me->GetDBTableGUIDLow() : 0), c ? c->GetEntry() : (me ? me->GetEntry() : 0));
94
95 return smart;
96 }
97
98 bool IsSmartGO(GameObject* g = NULL)
99 {
100 bool smart = true;
101 if (g && g->GetAIName() != "SmartGameObjectAI")
102 smart = false;
103
104 if (!go || go->GetAIName() != "SmartGameObjectAI")
105 smart = false;
106 if (!smart)
107 SF_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: %u Entry: %u) is not using SmartGameObjectAI, action skipped to prevent crash.", g ? g->GetDBTableGUIDLow() : (go ? go->GetDBTableGUIDLow() : 0), g ? g->GetEntry() : (go ? go->GetEntry() : 0));
108
109 return smart;
110 }
111
113 {
114 ObjectListMap::iterator itr = mTargetStorage->find(id);
115 if (itr != mTargetStorage->end())
116 return (*itr).second;
117 return NULL;
118 }
119
121 {
122 GameObject* gameObject = NULL;
123
124 CellCoord p(Skyfire::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY()));
125 Cell cell(p);
126
127 Skyfire::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid);
128 Skyfire::GameObjectSearcher<Skyfire::GameObjectWithDbGUIDCheck> checker(searchObject, gameObject, goCheck);
129
131 cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange());
132
133 return gameObject;
134 }
135
136 Creature* FindCreatureNear(WorldObject* searchObject, uint32 guid) const
137 {
138 Creature* creature = NULL;
139 CellCoord p(Skyfire::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY()));
140 Cell cell(p);
141
142 Skyfire::CreatureWithDbGUIDCheck target_check(searchObject, guid);
143 Skyfire::CreatureSearcher<Skyfire::CreatureWithDbGUIDCheck> checker(searchObject, creature, target_check);
144
146 cell.Visit(p, unit_checker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange());
147
148 return creature;
149 }
150
152
153 void OnReset();
154 void ResetBaseObject();
155
156 //TIMED_ACTIONLIST (script type 9 aka script9)
157 void SetScript9(SmartScriptHolder& e, uint32 entry);
160
161private:
162 void IncPhase(int32 p = 1)
163 {
164 if (p >= 0)
165 mEventPhase += (uint32)p;
166 else
167 DecPhase(abs(p));
168 }
169
170 void DecPhase(int32 p = 1) { mEventPhase -= (mEventPhase < (uint32)p ? (uint32)p - mEventPhase : (uint32)p); }
171 bool IsInPhase(uint32 p) const { return (1 << (mEventPhase - 1)) & p; }
172 void SetPhase(uint32 p = 0) { mEventPhase = p; }
173
184
188 std::list<uint32> mRemIDs;
189
194
196 void InstallEvents();
197
198 void RemoveStoredEvent(uint32 id);
199
201 {
202 if (!mEvents.empty())
203 {
204 for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i)
205 {
206 if (i->event_id == link)
207 {
208 return (*i);
209 }
210 }
211 }
213 return s;
214 }
215};
216
217#endif
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
TypeMapContainer< AllGridObjectTypes > GridTypeMapContainer
Definition GridDefines.h:71
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
@ TYPEID_PLAYER
Definition Object.h:55
@ TYPEID_GAMEOBJECT
Definition Object.h:56
@ TYPEID_UNIT
Definition Object.h:54
SmartScriptType
SMARTAI_TEMPLATE
std::vector< SmartScriptHolder > SmartAIEventList
SMARTAI_TARGETS
SMART_ACTION
SMART_EVENT
UNORDERED_MAP< uint32, ObjectList * > ObjectListMap
std::list< WorldObject * > ObjectList
#define UNORDERED_MAP
TypeID GetTypeId() const
Definition Object.h:131
bool CheckTimer(SmartScriptHolder const &e) const
uint32 mEventPhase
SmartAIEventList mStoredEvents
SMARTAI_TEMPLATE mTemplate
uint64 goOrigGUID
Creature * FindCreatureNear(WorldObject *searchObject, uint32 guid) const
Creature * me
uint32 mPathId
void OnUpdate(const uint32 diff)
SmartScriptType mScriptType
ObjectList * GetWorldObjectsInDist(float dist)
void InstallEvents()
void UpdateTimer(SmartScriptHolder &e, uint32 const diff)
void SetScript9(SmartScriptHolder &e, uint32 entry)
SmartScriptHolder CreateEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 phaseMask=0)
bool mUseTextTimer
uint32 mLastTextID
void DoFindFriendlyCC(std::list< Creature * > &_list, float range)
void RecalcTimer(SmartScriptHolder &e, uint32 min, uint32 max)
void ProcessEventsFor(SMART_EVENT e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Unit * DoSelectLowestHpFriendly(float range, uint32 MinHPDiff)
SmartScriptHolder FindLinkedEvent(uint32 link)
bool IsUnit(WorldObject *obj)
Definition SmartScript.h:53
ObjectList * GetTargets(SmartScriptHolder const &e, Unit *invoker=NULL)
uint32 mTextTimer
void DecPhase(int32 p=1)
void OnInitialize(WorldObject *obj, AreaTriggerEntry const *at=NULL)
bool IsPlayer(WorldObject *obj)
Definition SmartScript.h:58
uint64 mLastInvoker
void AddEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 phaseMask=0)
Unit * DoFindClosestFriendlyInRange(float range, bool playerOnly)
bool IsCreature(WorldObject *obj)
Definition SmartScript.h:63
void FillScript(SmartAIEventList e, WorldObject *obj, AreaTriggerEntry const *at)
GameObject * FindGameObjectNear(WorldObject *searchObject, uint32 guid) const
void OnMoveInLineOfSight(Unit *who)
uint32 GetPathId() const
Definition SmartScript.h:42
GameObject * go
ObjectList * GetTargetList(uint32 id)
bool IsInPhase(uint32 p) const
SmartAIEventList mInstallEvents
void InitTimer(SmartScriptHolder &e)
AreaTriggerEntry const * trigger
void IncPhase(int32 p=1)
ObjectListMap * mTargetStorage
UNORDERED_MAP< int32, int32 > mStoredDecimals
void DoFindFriendlyMissingBuff(std::list< Creature * > &list, float range, uint32 spellid)
std::list< uint32 > mRemIDs
uint32 mTalkerEntry
bool IsGameObject(WorldObject *obj)
Definition SmartScript.h:68
void ProcessEvent(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
bool IsSmartGO(GameObject *g=NULL)
Definition SmartScript.h:98
void SetPhase(uint32 p=0)
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)
SmartAIEventList mEvents
void InstallTemplate(SmartScriptHolder const &e)
bool IsSmart(Creature *c=NULL)
Definition SmartScript.h:83
WorldObject * GetBaseObject()
Definition SmartScript.h:43
SmartAIEventList mTimedActionList
void ProcessAction(SmartScriptHolder &e, Unit *unit=NULL, uint32 var0=0, uint32 var1=0, bool bvar=false, const SpellInfo *spell=NULL, GameObject *gob=NULL)
Unit * GetLastInvoker()
uint64 meOrigGUID
void StoreTargetList(ObjectList *targets, uint32 id)
void RemoveStoredEvent(uint32 id)
void SetPathId(uint32 id)
Definition SmartScript.h:41
void ResetBaseObject()
Definition Unit.h:1367
Map * GetMap() const
Definition Object.h:740
float GetGridActivationRange() const
Definition Object.cpp:2054
CellCoord ComputeCellCoord(float x, float y)
Definition Cell.h:37
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition CellImpl.h:109
float GetPositionX() const
Definition Object.h:328
float GetPositionY() const
Definition Object.h:329