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#include <memory>
24
25class AreaTrigger;
26class Creature;
27class GameObject;
28class Player;
29class Quest;
30class SpellInfo;
31class Unit;
32class WorldObject;
33struct AreaTriggerEntry;
34struct SceneTemplate;
35
37{
38class ActionBase;
39}
40
42{
43 public:
45 SmartScript(SmartScript const& other);
46 SmartScript(SmartScript&& other) noexcept;
48 SmartScript& operator=(SmartScript&& other) noexcept;
50
51 void OnInitialize(WorldObject* obj, AreaTriggerEntry const* at = nullptr, SceneTemplate const* scene = nullptr, Quest const* qst = nullptr, uint32 evnt = 0);
52 void GetScript();
53 void FillScript(SmartAIEventList&& e, WorldObject* obj, AreaTriggerEntry const* at, SceneTemplate const* scene, Quest const* quest, uint32 event = 0);
54
55 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_view varString = { });
56 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_view varString = { });
57 static void RecalcTimer(SmartScriptHolder& e, uint32 min, uint32 max);
58 void UpdateTimer(SmartScriptHolder& e, uint32 const diff);
59 static void InitTimer(SmartScriptHolder& e);
60 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_view varString = { });
61 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_view varString = { });
62 void GetTargets(ObjectVector& targets, SmartScriptHolder const& e, WorldObject* invoker = nullptr) const;
63 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, std::string_view targetParamString, uint32 phaseMask);
64 void SetPathId(uint32 id) { mPathId = id; }
65 uint32 GetPathId() const { return mPathId; }
66 WorldObject* GetBaseObject() const;
67 WorldObject* GetBaseObjectOrUnitInvoker(Unit* invoker);
68 bool HasAnyEventWithFlag(uint32 flag) const { return mAllEventFlags & flag; }
69
70 void OnUpdate(const uint32 diff);
71 void OnMoveInLineOfSight(Unit* who);
72
73 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const;
74 Unit* DoSelectLowestHpPercentFriendly(float range, uint32 minHpPct, uint32 maxHpPct) const;
75 void DoFindFriendlyCC(std::vector<Creature*>& creatures, float range) const;
76 void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const;
77 Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const;
78
79 bool IsSmart(Creature* c, bool silent = false) const;
80 bool IsSmart(GameObject* g, bool silent = false) const;
81 bool IsSmart(bool silent = false) const;
82
83 void ClearTargetList(uint32 id);
84 void StoreTargetList(ObjectVector const& targets, uint32 id);
85 void AddToStoredTargetList(ObjectVector const& targets, uint32 id);
86 ObjectVector const* GetStoredTargetVector(uint32 id, WorldObject const& ref) const;
87
88 void StoreCounter(uint32 id, uint32 value, uint32 reset);
89 uint32 GetCounterValue(uint32 id) const;
90
91 GameObject* FindGameObjectNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
92 Creature* FindCreatureNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
93
94 void OnReset();
95 void ResetBaseObject();
96
97 void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker, uint32 startFromEventId = 0);
98 Unit* GetLastInvoker(Unit* invoker = nullptr) const;
100 typedef std::unordered_map<uint32, uint32> CounterMap;
102
103 private:
104
105 void IncPhase(uint32 p);
106 void DecPhase(uint32 p);
107
108 void SetPhase(uint32 p);
109 bool IsInPhase(uint32 p) const;
110
111 void SortEvents(SmartAIEventList& events);
112 void RaisePriority(SmartScriptHolder& e);
113 void RetryLater(SmartScriptHolder& e, bool ignoreChanceRoll = false);
114
118 std::shared_ptr<Scripting::v2::ActionBase> mTimedActionWaitEvent;
128 Quest const* quest;
132
135 std::vector<uint32> mRemIDs;
136
145
146 // Max number of nested ProcessEventsFor() calls to avoid infinite loops
147 static constexpr uint32 MAX_NESTED_EVENTS = 10;
148
150
151 void RemoveStoredEvent(uint32 id);
152};
153
154#endif
#define TC_GAME_API
Definition Define.h:129
uint32_t uint32
Definition Define.h:154
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:321
uint32 mEventPhase
Creature * me
uint32 mPathId
ObjectGuid mLastInvoker
Definition SmartScript.h:99
SmartScriptType mScriptType
CounterMap mCounterList
bool mUseTextTimer
uint32 mLastTextID
SceneTemplate const * sceneTemplate
uint32 mTextTimer
SmartAIEventStoredList mStoredEvents
bool HasAnyEventWithFlag(uint32 flag) const
Definition SmartScript.h:68
SmartScript(SmartScript const &other)
uint32 GetPathId() const
Definition SmartScript.h:65
GameObject * go
AreaTriggerEntry const * trigger
uint32 mAllEventFlags
SmartScript & operator=(SmartScript const &other)
Player * player
AreaTrigger * areaTrigger
std::unordered_map< uint32, uint32 > CounterMap
uint32 mCurrentPriority
uint32 mNestedEventsCounter
SmartScript & operator=(SmartScript &&other) noexcept
uint32 mTalkerEntry
SmartAIEventList mEvents
SmartScript(SmartScript &&other) noexcept
Quest const * quest
std::shared_ptr< Scripting::v2::ActionBase > mTimedActionWaitEvent
bool isProcessingTimedActionList
ObjectGuid goOrigGUID
SmartAIEventList mTimedActionList
ObjectGuid meOrigGUID
ObjectVectorMap _storedTargets
bool mEventSortingRequired
ObjectGuid mTimedActionListInvoker
void SetPathId(uint32 id)
Definition SmartScript.h:64
std::vector< uint32 > mRemIDs
Definition Unit.h:635