1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* 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_SCRIPTEDESCORTAI_H
#define TRINITY_SCRIPTEDESCORTAI_H
#include "ScriptedCreature.h"
#include "WaypointDefines.h"
class Quest;
#define DEFAULT_MAX_PLAYER_DISTANCE 100
enum EscortState : uint32
{
STATE_ESCORT_NONE = 0x00, // nothing in progress
STATE_ESCORT_ESCORTING = 0x01, // escort is in progress
STATE_ESCORT_RETURNING = 0x02, // escort is returning after being in combat
STATE_ESCORT_PAUSED = 0x04 // escort is paused, wont continue with next waypoint
};
struct TC_GAME_API EscortAI : public ScriptedAI
{
public:
explicit EscortAI(Creature* creature) noexcept;
~EscortAI() { }
void InitializeAI() override;
void MoveInLineOfSight(Unit* who) override;
void JustDied(Unit*) override;
void ReturnToLastPoint();
void EnterEvadeMode(EvadeReason why) override;
void MovementInform(uint32, uint32) override;
void UpdateAI(uint32 diff) override; // the "internal" update, calls UpdateEscortAI()
virtual void UpdateEscortAI(uint32 diff); // used when it's needed to add code in update (abilities, scripted events, etc)
void AddWaypoint(uint32 id, float x, float y, float z, bool run);
void AddWaypoint(uint32 id, float x, float y, float z, float orientation = 0.f, Optional<Milliseconds> waitTime = {}, bool run = false);
void ResetPath();
void LoadPath(uint32 pathId);
void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false);
void SetEscortPaused(bool on);
void SetPauseTimer(Milliseconds timer) { _pauseTimer = timer; }
bool HasEscortState(uint32 escortState) { return (_escortState & escortState) != 0; }
bool IsEscorted() const override { return !_playerGUID.IsEmpty(); }
void SetMaxPlayerDistance(float newMax) { _maxPlayerDistance = newMax; }
float GetMaxPlayerDistance() const { return _maxPlayerDistance; }
void SetDespawnAtEnd(bool despawn) { _despawnAtEnd = despawn; }
void SetDespawnAtFar(bool despawn) { _despawnAtFar = despawn; }
bool IsActiveAttacker() const { return _activeAttacker; } // obsolete
void SetActiveAttacker(bool enable) { _activeAttacker = enable; }
ObjectGuid GetEventStarterGUID() const { return _playerGUID; }
protected:
Player* GetPlayerForEscort();
private:
bool AssistPlayerInCombatAgainst(Unit* who);
bool IsPlayerOrGroupInRange();
void AddEscortState(uint32 escortState) { _escortState |= escortState; }
void RemoveEscortState(uint32 escortState) { _escortState &= ~escortState; }
ObjectGuid _playerGUID;
Milliseconds _pauseTimer;
uint32 _playerCheckTimer;
uint32 _escortState;
float _maxPlayerDistance;
Quest const* _escortQuest; // generally passed in Start() when regular escort script.
WaypointPath _path;
bool _activeAttacker; // obsolete, determined by faction.
bool _instantRespawn; // if creature should respawn instantly after escort over (if not, database respawntime are used)
bool _returnToStart; // if creature can walk same path (loop) without despawn. Not for regular escort quests.
bool _despawnAtEnd;
bool _despawnAtFar;
bool _hasImmuneToNPCFlags;
bool _started;
bool _ended;
bool _resume;
};
#endif
|