TrinityCore
Loading...
Searching...
No Matches
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 Creature;
25class GameObject;
26class Player;
27class SpellInfo;
28class Unit;
29class WorldObject;
30struct AreaTriggerEntry;
31
33{
34 public:
37
38 void OnInitialize(WorldObject* obj, AreaTriggerEntry const* at = nullptr);
39 void GetScript();
40 void FillScript(SmartAIEventList e, WorldObject* obj, AreaTriggerEntry const* at);
41
42 void ProcessEventsFor(SMART_EVENT e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr);
43 void ProcessEvent(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr);
44 bool CheckTimer(SmartScriptHolder const& e) const;
45 static void RecalcTimer(SmartScriptHolder& e, uint32 min, uint32 max);
46 void UpdateTimer(SmartScriptHolder& e, uint32 const diff);
47 static void InitTimer(SmartScriptHolder& e);
48 void ProcessAction(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, SpellInfo const* spell = nullptr, GameObject* gob = nullptr);
49 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);
50 void GetTargets(ObjectVector& targets, SmartScriptHolder const& e, WorldObject* invoker = nullptr) const;
51 void GetWorldObjectsInDist(ObjectVector& objects, float dist) const;
52 static SmartScriptHolder CreateSmartEvent(SMART_EVENT e, uint32 event_flags, uint32 event_param1, uint32 event_param2, uint32 event_param3, uint32 event_param4, uint32 event_param5, SMART_ACTION action, uint32 action_param1, uint32 action_param2, uint32 action_param3, uint32 action_param4, uint32 action_param5, uint32 action_param6, SMARTAI_TARGETS t, uint32 target_param1, uint32 target_param2, uint32 target_param3, uint32 target_param4, uint32 phaseMask);
53 void SetPathId(uint32 id) { mPathId = id; }
54 uint32 GetPathId() const { return mPathId; }
55 WorldObject* GetBaseObject() const;
56 WorldObject* GetBaseObjectOrPlayerTrigger() const;
57 bool HasAnyEventWithFlag(uint32 flag) const { return mAllEventFlags & flag; }
58 static bool IsUnit(WorldObject* obj);
59 static bool IsPlayer(WorldObject* obj);
60 static bool IsCreature(WorldObject* obj);
61 static bool IsCharmedCreature(WorldObject* obj);
62 static bool IsGameObject(WorldObject* obj);
63
64 void OnUpdate(const uint32 diff);
65 void OnMoveInLineOfSight(Unit* who);
66
67 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const;
68 Unit* DoSelectLowestHpPercentFriendly(float range, uint32 minHpPct, uint32 maxHpPct) const;
69 void DoFindFriendlyCC(std::vector<Creature*>& creatures, float range) const;
70 void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const;
71 Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const;
72
73 bool IsSmart(Creature* c, bool silent = false) const;
74 bool IsSmart(GameObject* g, bool silent = false) const;
75 bool IsSmart(bool silent = false) const;
76
77 void StoreTargetList(ObjectVector const& targets, uint32 id);
78 void AddToStoredTargetList(ObjectVector const& targets, uint32 id);
79 ObjectVector const* GetStoredTargetVector(uint32 id, WorldObject const& ref) const;
80
81 void StoreCounter(uint32 id, uint32 value, uint32 reset);
82 uint32 GetCounterValue(uint32 id) const;
83
84 GameObject* FindGameObjectNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
85 Creature* FindCreatureNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
86
87 void OnReset();
88 void ResetBaseObject();
89
90 void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker);
91 Unit* GetLastInvoker(Unit* invoker = nullptr) const;
93 typedef std::unordered_map<uint32, uint32> CounterMap;
95
96 private:
97
98 void IncPhase(uint32 p);
99 void DecPhase(uint32 p);
100
101 void SetPhase(uint32 p);
102 bool IsInPhase(uint32 p) const;
103
104 void SortEvents(SmartAIEventList& events);
105 void RaisePriority(SmartScriptHolder& e);
106 void RetryLater(SmartScriptHolder& e, bool ignoreChanceRoll = false);
107
121
124 std::vector<uint32> mRemIDs;
125
134
135 // Max number of nested ProcessEventsFor() calls to avoid infinite loops
136 static constexpr uint32 MAX_NESTED_EVENTS = 10;
137
139
140 void InstallEvents();
141
142 void RemoveStoredEvent(uint32 id);
143};
144
145#endif
#define TC_GAME_API
Definition Define.h:114
uint32_t uint32
Definition Define.h:133
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
uint32 LowType
Definition ObjectGuid.h:142
uint32 mEventPhase
Creature * me
uint32 mPathId
ObjectGuid mLastInvoker
Definition SmartScript.h:92
SmartScriptType mScriptType
CounterMap mCounterList
Definition SmartScript.h:94
bool mUseTextTimer
uint32 mLastTextID
uint32 mTextTimer
SmartAIEventStoredList mStoredEvents
bool HasAnyEventWithFlag(uint32 flag) const
Definition SmartScript.h:57
Player * atPlayer
uint32 GetPathId() const
Definition SmartScript.h:54
GameObject * go
SmartAIEventList mInstallEvents
AreaTriggerEntry const * trigger
uint32 mAllEventFlags
std::unordered_map< uint32, uint32 > CounterMap
Definition SmartScript.h:93
uint32 mCurrentPriority
uint32 mNestedEventsCounter
uint32 mTalkerEntry
SmartAIEventList mEvents
bool isProcessingTimedActionList
ObjectGuid goOrigGUID
SmartAIEventList mTimedActionList
ObjectGuid meOrigGUID
ObjectVectorMap _storedTargets
bool mEventSortingRequired
ObjectGuid mTimedActionListInvoker
void SetPathId(uint32 id)
Definition SmartScript.h:53
std::vector< uint32 > mRemIDs
Definition Unit.h:769