2010-10-27 21:01:47 +02:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2010-10-27 21:01:47 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef TRINITY_SMARTSCRIPT_H
|
|
|
|
|
#define TRINITY_SMARTSCRIPT_H
|
|
|
|
|
|
2017-05-18 23:52:58 +02:00
|
|
|
#include "Define.h"
|
2010-10-27 21:01:47 +02:00
|
|
|
#include "SmartScriptMgr.h"
|
|
|
|
|
|
2017-05-18 23:52:58 +02:00
|
|
|
class Creature;
|
|
|
|
|
class GameObject;
|
2017-03-17 21:21:35 +01:00
|
|
|
class Player;
|
2017-05-18 23:52:58 +02:00
|
|
|
class SpellInfo;
|
|
|
|
|
class Unit;
|
|
|
|
|
class WorldObject;
|
|
|
|
|
struct AreaTriggerEntry;
|
|
|
|
|
struct SceneTemplate;
|
2017-03-17 21:21:35 +01:00
|
|
|
|
2016-03-11 16:37:14 +01:00
|
|
|
class TC_GAME_API SmartScript
|
2010-10-27 21:01:47 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SmartScript();
|
2011-03-27 12:54:11 +02:00
|
|
|
~SmartScript();
|
2010-10-27 21:01:47 +02:00
|
|
|
|
2017-03-17 21:21:35 +01:00
|
|
|
void OnInitialize(WorldObject* obj, AreaTriggerEntry const* at = nullptr, SceneTemplate const* scene = nullptr);
|
2010-10-27 21:01:47 +02:00
|
|
|
void GetScript();
|
2017-03-17 21:21:35 +01:00
|
|
|
void FillScript(SmartAIEventList e, WorldObject* obj, AreaTriggerEntry const* at, SceneTemplate const* scene);
|
2010-10-27 21:01:47 +02:00
|
|
|
|
2017-03-17 21:21:35 +01:00
|
|
|
void ProcessEventsFor(SMART_EVENT e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
|
|
|
|
|
void ProcessEvent(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
|
2011-03-27 12:54:42 +02:00
|
|
|
bool CheckTimer(SmartScriptHolder const& e) const;
|
2017-06-03 10:21:06 +02:00
|
|
|
static void RecalcTimer(SmartScriptHolder& e, uint32 min, uint32 max);
|
2011-03-27 12:54:42 +02:00
|
|
|
void UpdateTimer(SmartScriptHolder& e, uint32 const diff);
|
2017-06-03 10:21:06 +02:00
|
|
|
static void InitTimer(SmartScriptHolder& e);
|
2017-03-17 21:21:35 +01:00
|
|
|
void ProcessAction(SmartScriptHolder& e, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
|
|
|
|
|
void ProcessTimedAction(SmartScriptHolder& e, uint32 const& min, uint32 const& max, Unit* unit = nullptr, uint32 var0 = 0, uint32 var1 = 0, bool bvar = false, const SpellInfo* spell = nullptr, GameObject* gob = nullptr, std::string const& varString = "");
|
2017-06-03 10:21:06 +02:00
|
|
|
void GetTargets(ObjectVector& targets, SmartScriptHolder const& e, Unit* invoker = nullptr) const;
|
|
|
|
|
void GetWorldObjectsInDist(ObjectVector& objects, float dist) const;
|
2011-05-12 10:42:25 +02:00
|
|
|
void InstallTemplate(SmartScriptHolder const& e);
|
2017-06-03 10:21:06 +02:00
|
|
|
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 phaseMask = 0);
|
2019-04-30 13:03:49 +02:00
|
|
|
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);
|
2010-10-27 21:01:47 +02:00
|
|
|
void SetPathId(uint32 id) { mPathId = id; }
|
2010-12-06 02:07:53 +01:00
|
|
|
uint32 GetPathId() const { return mPathId; }
|
2011-03-27 12:54:42 +02:00
|
|
|
|
2017-06-03 10:21:06 +02:00
|
|
|
WorldObject* GetBaseObject() const;
|
2017-05-18 23:52:58 +02:00
|
|
|
WorldObject* GetBaseObjectOrUnit(Unit* unit);
|
|
|
|
|
static bool IsUnit(WorldObject* obj);
|
|
|
|
|
static bool IsPlayer(WorldObject* obj);
|
|
|
|
|
static bool IsCreature(WorldObject* obj);
|
2016-10-14 03:59:13 -03:00
|
|
|
static bool IsCharmedCreature(WorldObject* obj);
|
2017-05-18 23:52:58 +02:00
|
|
|
static bool IsGameObject(WorldObject* obj);
|
2011-03-27 12:54:42 +02:00
|
|
|
|
2010-10-27 21:01:47 +02:00
|
|
|
void OnUpdate(const uint32 diff);
|
2011-03-27 12:54:42 +02:00
|
|
|
void OnMoveInLineOfSight(Unit* who);
|
2010-10-27 21:01:47 +02:00
|
|
|
|
2017-06-03 10:21:06 +02:00
|
|
|
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const;
|
|
|
|
|
void DoFindFriendlyCC(std::vector<Creature*>& creatures, float range) const;
|
|
|
|
|
void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const;
|
|
|
|
|
Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const;
|
2010-10-27 21:01:47 +02:00
|
|
|
|
2020-08-14 17:06:03 +02:00
|
|
|
bool IsSmart(Creature* c = nullptr);
|
|
|
|
|
bool IsSmartGO(GameObject* g = nullptr);
|
2011-06-15 17:33:06 +02:00
|
|
|
|
2017-06-03 10:21:06 +02:00
|
|
|
void StoreTargetList(ObjectVector const& targets, uint32 id)
|
|
|
|
|
{
|
|
|
|
|
// insert or replace
|
|
|
|
|
_storedTargets.erase(id);
|
2017-06-04 16:43:36 -03:00
|
|
|
_storedTargets.emplace(id, ObjectGuidVector(targets));
|
2017-06-03 10:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-04 16:43:36 -03:00
|
|
|
ObjectVector const* GetStoredTargetVector(uint32 id, WorldObject const& ref) const
|
2017-06-03 10:21:06 +02:00
|
|
|
{
|
|
|
|
|
auto itr = _storedTargets.find(id);
|
|
|
|
|
if (itr != _storedTargets.end())
|
2017-06-04 16:43:36 -03:00
|
|
|
return itr->second.GetObjectVector(ref);
|
2017-06-03 10:21:06 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2015-04-02 18:02:34 +02:00
|
|
|
|
2017-05-18 23:52:58 +02:00
|
|
|
void StoreCounter(uint32 id, uint32 value, uint32 reset);
|
2017-02-17 21:33:18 +01:00
|
|
|
uint32 GetCounterValue(uint32 id) const;
|
2015-04-02 18:02:34 +02:00
|
|
|
|
2017-05-18 23:52:58 +02:00
|
|
|
GameObject* FindGameObjectNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
|
|
|
|
|
Creature* FindCreatureNear(WorldObject* searchObject, ObjectGuid::LowType guid) const;
|
2010-10-27 21:01:47 +02:00
|
|
|
|
|
|
|
|
void OnReset();
|
2017-05-18 23:52:58 +02:00
|
|
|
void ResetBaseObject();
|
2010-10-27 21:01:47 +02:00
|
|
|
|
2010-12-07 18:31:34 +01:00
|
|
|
//TIMED_ACTIONLIST (script type 9 aka script9)
|
2011-03-27 12:54:42 +02:00
|
|
|
void SetScript9(SmartScriptHolder& e, uint32 entry);
|
2017-06-03 10:21:06 +02:00
|
|
|
Unit* GetLastInvoker(Unit* invoker = nullptr) const;
|
2014-09-14 16:14:12 +02:00
|
|
|
ObjectGuid mLastInvoker;
|
2015-04-02 18:02:34 +02:00
|
|
|
typedef std::unordered_map<uint32, uint32> CounterMap;
|
|
|
|
|
CounterMap mCounterList;
|
2010-12-07 18:31:34 +01:00
|
|
|
|
2010-10-27 21:01:47 +02:00
|
|
|
private:
|
2017-02-17 21:33:18 +01:00
|
|
|
|
2017-06-10 19:17:41 -03:00
|
|
|
void IncPhase(uint32 p);
|
|
|
|
|
void DecPhase(uint32 p);
|
2015-06-14 18:34:11 +02:00
|
|
|
|
2017-06-10 19:17:41 -03:00
|
|
|
void SetPhase(uint32 p);
|
|
|
|
|
bool IsInPhase(uint32 p) const;
|
2010-10-27 21:01:47 +02:00
|
|
|
|
|
|
|
|
SmartAIEventList mEvents;
|
|
|
|
|
SmartAIEventList mInstallEvents;
|
2010-11-03 14:10:16 +01:00
|
|
|
SmartAIEventList mTimedActionList;
|
2014-02-08 21:57:28 +01:00
|
|
|
bool isProcessingTimedActionList;
|
2010-10-27 21:01:47 +02:00
|
|
|
Creature* me;
|
2014-09-14 16:14:12 +02:00
|
|
|
ObjectGuid meOrigGUID;
|
2010-10-27 21:01:47 +02:00
|
|
|
GameObject* go;
|
2014-09-14 16:14:12 +02:00
|
|
|
ObjectGuid goOrigGUID;
|
2010-10-27 21:01:47 +02:00
|
|
|
AreaTriggerEntry const* trigger;
|
2017-03-17 21:21:35 +01:00
|
|
|
SceneTemplate const* sceneTemplate;
|
2010-10-27 21:01:47 +02:00
|
|
|
SmartScriptType mScriptType;
|
|
|
|
|
uint32 mEventPhase;
|
2010-12-13 22:37:56 +01:00
|
|
|
|
2010-10-27 21:01:47 +02:00
|
|
|
uint32 mPathId;
|
2017-02-17 21:33:18 +01:00
|
|
|
SmartAIEventStoredList mStoredEvents;
|
|
|
|
|
std::vector<uint32> mRemIDs;
|
2010-10-27 21:01:47 +02:00
|
|
|
|
|
|
|
|
uint32 mTextTimer;
|
|
|
|
|
uint32 mLastTextID;
|
2011-09-19 09:24:59 -04:00
|
|
|
uint32 mTalkerEntry;
|
2010-10-27 21:01:47 +02:00
|
|
|
bool mUseTextTimer;
|
2010-11-01 11:00:53 +01:00
|
|
|
|
2017-06-03 10:21:06 +02:00
|
|
|
ObjectVectorMap _storedTargets;
|
|
|
|
|
|
2010-10-27 21:01:47 +02:00
|
|
|
SMARTAI_TEMPLATE mTemplate;
|
|
|
|
|
void InstallEvents();
|
|
|
|
|
|
2017-05-18 23:52:58 +02:00
|
|
|
void RemoveStoredEvent(uint32 id);
|
2010-10-27 21:01:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|