TrinityCore
SmartScript.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_SMARTSCRIPT_H
19#define TRINITY_SMARTSCRIPT_H
20
21#include "Define.h"
22#include "SmartScriptMgr.h"
23
24class AreaTrigger;
25class Creature;
26class GameObject;
27class Player;
28class Quest;
29class SpellInfo;
30class Unit;
31class WorldObject;
32struct AreaTriggerEntry;
33struct SceneTemplate;
34
36{
37 public:
40
41 void OnInitialize(WorldObject* obj, AreaTriggerEntry const* at = nullptr, SceneTemplate const* scene = nullptr, Quest const* qst = nullptr, uint32 evnt = 0);
42 void GetScript();
43 void FillScript(SmartAIEventList e, WorldObject* obj, AreaTriggerEntry const* at, SceneTemplate const* scene, Quest const* quest, uint32 event = 0);
44
45 void ProcessEventsFor(SMART_EVENT e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
46 void ProcessEvent(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
47 bool CheckTimer(SmartScriptHolder const& e) const;
48 static void RecalcTimer(SmartScriptHolder& e, uint32 min, uint32 max);
49 void UpdateTimer(SmartScriptHolder& e, uint32 const diff);
50 static void InitTimer(SmartScriptHolder& e);
51 void ProcessAction(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
52 void ProcessTimedAction(SmartScriptHolder& e, uint32 const& min, uint32 const& max, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
53 void GetTargets(ObjectVector& targets, SmartScriptHolder const& e, WorldObject* invoker = nullptr) const;
54 void GetWorldObjectsInDist(ObjectVector& objects, float dist) const;
55 static SmartScriptHolder CreateSmartEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, uint32 action_param7, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask);
56 void SetPathId(uint32 id) { mPathId = id; }
57 uint32 GetPathId() const { return mPathId; }
58 WorldObject* GetBaseObject() const;
59 WorldObject* GetBaseObjectOrUnitInvoker(Unit* invoker);
60 bool HasAnyEventWithFlag(uint32 flag) const { return mAllEventFlags & flag; }
61 static bool IsUnit(WorldObject* obj);
62 static bool IsPlayer(WorldObject* obj);
63 static bool IsCreature(WorldObject* obj);
64 static bool IsCharmedCreature(WorldObject* obj);
65 static bool IsGameObject(WorldObject* obj);
66
67 void OnUpdate(const uint32 diff);
68 void OnMoveInLineOfSight(Unit* who);
69
70 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const;
71 Unit* DoSelectLowestHpPercentFriendly(float range, uint32 minHpPct, uint32 maxHpPct) const;
72 void DoFindFriendlyCC(std::vector<Creature*>& creatures, float range) const;
73 void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const;
74 Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const;
75
76 bool IsSmart(Creature* c, bool silent = false) const;
77 bool IsSmart(GameObject* g, bool silent = false) const;
78 bool IsSmart(bool silent = false) const;
79
80 void StoreTargetList(ObjectVector const& targets, uint32 id);
81 void AddToStoredTargetList(ObjectVector const& targets, uint32 id);
82 ObjectVector const* GetStoredTargetVector(uint32 id, WorldObject const& ref) const;
83
84 void StoreCounter(uint32 id, uint32 value, uint32 reset);
85 uint32 GetCounterValue(uint32 id) const;
86
87 GameObject* FindGameObjectNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
88 Creature* FindCreatureNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
89
90 void OnReset();
91 void ResetBaseObject();
92
93 void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker, uint32 startFromEventId = 0);
94 Unit* GetLastInvoker(Unit* invoker = nullptr) const;
96 typedef std::unordered_map<uint32, uint32> CounterMap;
98
99 private:
100
101 void IncPhase(uint32 p);
102 void DecPhase(uint32 p);
103
104 void SetPhase(uint32 p);
105 bool IsInPhase(uint32 p) const;
106
107 void SortEvents(SmartAIEventList& events);
108 void RaisePriority(SmartScriptHolder& e);
109 void RetryLater(SmartScriptHolder& e, bool ignoreChanceRoll = false);
110
124 Quest const* quest;
128
131 std::vector<uint32> mRemIDs;
132
141
142 // Max number of nested ProcessEventsFor() calls to avoid infinite loops
143 static constexpr uint32 MAX_NESTED_EVENTS = 10;
144
146
147 void InstallEvents();
148
149 void RemoveStoredEvent(uint32 id);
150};
151
152#endif
#define TC_GAME_API
Definition: Define.h:123
uint32_t uint32
Definition: Define.h:142
SmartScriptType
std::vector< SmartScriptHolder > SmartAIEventList
std::vector< SmartScriptHolder > SmartAIEventStoredList
SMARTAI_TARGETS
std::vector< WorldObject * > ObjectVector
std::unordered_map< uint32, ObjectGuidVector > ObjectVectorMap
SMART_ACTION
SMART_EVENT
uint64 LowType
Definition: ObjectGuid.h:278
uint32 mEventPhase
Definition: SmartScript.h:127
Creature * me
Definition: SmartScript.h:116
uint32 mPathId
Definition: SmartScript.h:129
ObjectGuid mLastInvoker
Definition: SmartScript.h:95
SmartScriptType mScriptType
Definition: SmartScript.h:126
CounterMap mCounterList
Definition: SmartScript.h:97
bool mUseTextTimer
Definition: SmartScript.h:136
uint32 mLastTextID
Definition: SmartScript.h:134
SceneTemplate const * sceneTemplate
Definition: SmartScript.h:123
uint32 mTextTimer
Definition: SmartScript.h:133
SmartAIEventStoredList mStoredEvents
Definition: SmartScript.h:130
bool HasAnyEventWithFlag(uint32 flag) const
Definition: SmartScript.h:60
uint32 GetPathId() const
Definition: SmartScript.h:57
GameObject * go
Definition: SmartScript.h:118
SmartAIEventList mInstallEvents
Definition: SmartScript.h:112
AreaTriggerEntry const * trigger
Definition: SmartScript.h:121
uint32 mAllEventFlags
Definition: SmartScript.h:140
Player * player
Definition: SmartScript.h:120
AreaTrigger * areaTrigger
Definition: SmartScript.h:122
std::unordered_map< uint32, uint32 > CounterMap
Definition: SmartScript.h:96
uint32 mCurrentPriority
Definition: SmartScript.h:137
uint32 mNestedEventsCounter
Definition: SmartScript.h:139
uint32 mTalkerEntry
Definition: SmartScript.h:135
uint32 event
Definition: SmartScript.h:125
SmartAIEventList mEvents
Definition: SmartScript.h:111
Quest const * quest
Definition: SmartScript.h:124
bool isProcessingTimedActionList
Definition: SmartScript.h:115
ObjectGuid goOrigGUID
Definition: SmartScript.h:119
SmartAIEventList mTimedActionList
Definition: SmartScript.h:113
ObjectGuid meOrigGUID
Definition: SmartScript.h:117
ObjectVectorMap _storedTargets
Definition: SmartScript.h:145
bool mEventSortingRequired
Definition: SmartScript.h:138
ObjectGuid mTimedActionListInvoker
Definition: SmartScript.h:114
void SetPathId(uint32 id)
Definition: SmartScript.h:56
std::vector< uint32 > mRemIDs
Definition: SmartScript.h:131
Definition: Unit.h:627