TrinityCore
ScriptedEscortAI.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_SCRIPTEDESCORTAI_H
19#define TRINITY_SCRIPTEDESCORTAI_H
20
21#include "ScriptedCreature.h"
22#include "WaypointDefines.h"
23
24class Quest;
25
26#define DEFAULT_MAX_PLAYER_DISTANCE 100
27
29{
30 STATE_ESCORT_NONE = 0x00, // nothing in progress
31 STATE_ESCORT_ESCORTING = 0x01, // escort is in progress
32 STATE_ESCORT_RETURNING = 0x02, // escort is returning after being in combat
33 STATE_ESCORT_PAUSED = 0x04 // escort is paused, wont continue with next waypoint
34};
35
37{
38 public:
39 explicit EscortAI(Creature* creature);
41
42 void InitializeAI() override;
43 void MoveInLineOfSight(Unit* who) override;
44 void JustDied(Unit*) override;
45 void ReturnToLastPoint();
46 void EnterEvadeMode(EvadeReason why) override;
47 void MovementInform(uint32, uint32) override;
48 void UpdateAI(uint32 diff) override; // the "internal" update, calls UpdateEscortAI()
49
50 virtual void UpdateEscortAI(uint32 diff); // used when it's needed to add code in update (abilities, scripted events, etc)
51 void AddWaypoint(uint32 id, float x, float y, float z, bool run);
52 void AddWaypoint(uint32 id, float x, float y, float z, float orientation = 0.f, Milliseconds waitTime = 0s, bool run = false);
53 void ResetPath();
54 void LoadPath(uint32 pathId);
55 void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false);
56
57 void SetEscortPaused(bool on);
58 void SetPauseTimer(Milliseconds timer) { _pauseTimer = timer; }
59 bool HasEscortState(uint32 escortState) { return (_escortState & escortState) != 0; }
60 bool IsEscorted() const override { return !_playerGUID.IsEmpty(); }
61 void SetMaxPlayerDistance(float newMax) { _maxPlayerDistance = newMax; }
62 float GetMaxPlayerDistance() const { return _maxPlayerDistance; }
63 void SetDespawnAtEnd(bool despawn) { _despawnAtEnd = despawn; }
64 void SetDespawnAtFar(bool despawn) { _despawnAtFar = despawn; }
65 bool IsActiveAttacker() const { return _activeAttacker; } // obsolete
66 void SetActiveAttacker(bool enable) { _activeAttacker = enable; }
67 ObjectGuid GetEventStarterGUID() const { return _playerGUID; }
68
69 protected:
70 Player* GetPlayerForEscort();
71
72 private:
73 bool AssistPlayerInCombatAgainst(Unit* who);
74 bool IsPlayerOrGroupInRange();
75
76 void AddEscortState(uint32 escortState) { _escortState |= escortState; }
77 void RemoveEscortState(uint32 escortState) { _escortState &= ~escortState; }
78
84
85 Quest const* _escortQuest; // generally passed in Start() when regular escort script.
86
88
89 bool _activeAttacker; // obsolete, determined by faction.
90 bool _instantRespawn; // if creature should respawn instantly after escort over (if not, database respawntime are used)
91 bool _returnToStart; // if creature can walk same path (loop) without despawn. Not for regular escort quests.
96 bool _ended;
97 bool _resume;
98};
99
100#endif
#define TC_GAME_API
Definition: Define.h:123
uint32_t uint32
Definition: Define.h:142
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
EscortState
@ STATE_ESCORT_PAUSED
@ STATE_ESCORT_ESCORTING
@ STATE_ESCORT_NONE
@ STATE_ESCORT_RETURNING
EvadeReason
Definition: UnitAICommon.h:30
virtual void MoveInLineOfSight(Unit *)
Definition: CreatureAI.cpp:122
virtual void JustDied(Unit *)
Definition: CreatureAI.h:105
virtual void EnterEvadeMode(EvadeReason why=EvadeReason::Other)
Definition: CreatureAI.cpp:219
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:154
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
virtual void InitializeAI()
Definition: UnitAI.cpp:43
Definition: Unit.h:627
float _maxPlayerDistance
bool IsEscorted() const override
ObjectGuid GetEventStarterGUID() const
float GetMaxPlayerDistance() const
void SetMaxPlayerDistance(float newMax)
uint32 _escortState
void SetPauseTimer(Milliseconds timer)
ObjectGuid _playerGUID
bool HasEscortState(uint32 escortState)
void SetDespawnAtFar(bool despawn)
Milliseconds _pauseTimer
void SetDespawnAtEnd(bool despawn)
void AddEscortState(uint32 escortState)
Quest const * _escortQuest
bool IsActiveAttacker() const
void RemoveEscortState(uint32 escortState)
bool _activeAttacker
void SetActiveAttacker(bool enable)
bool _despawnAtEnd
WaypointPath _path
bool _despawnAtFar
bool _hasImmuneToNPCFlags
uint32 _playerCheckTimer
bool _instantRespawn
bool _returnToStart
virtual void UpdateAI(uint32 diff) override