TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ScriptedEscortAI.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef SC_ESCORTAI_H
20 #define SC_ESCORTAI_H
21 
22 #include "ScriptSystem.h"
23 
24 #define DEFAULT_MAX_PLAYER_DISTANCE 50
25 
27 {
28  Escort_Waypoint(uint32 _id, float _x, float _y, float _z, uint32 _w)
29  {
30  id = _id;
31  x = _x;
32  y = _y;
33  z = _z;
34  WaitTimeMs = _w;
35  }
36 
38  float x;
39  float y;
40  float z;
42 };
43 
45 {
46  STATE_ESCORT_NONE = 0x000, //nothing in progress
47  STATE_ESCORT_ESCORTING = 0x001, //escort are in progress
48  STATE_ESCORT_RETURNING = 0x002, //escort is returning after being in combat
49  STATE_ESCORT_PAUSED = 0x004 //will not proceed with waypoints before state is removed
50 };
51 
53 {
54  public:
55  explicit npc_escortAI(Creature* creature);
57 
58  // CreatureAI functions
59  void AttackStart(Unit* who) override;
60 
61  void MoveInLineOfSight(Unit* who) override;
62 
63  void JustDied(Unit*) override;
64 
65  void JustRespawned() override;
66 
67  void ReturnToLastPoint();
68 
69  void EnterEvadeMode(EvadeReason /*why*/ = EVADE_REASON_OTHER) override;
70 
71  void UpdateAI(uint32 diff) override; // the "internal" update, calls UpdateEscortAI()
72  virtual void UpdateEscortAI(uint32 diff); // used when it's needed to add code in update (abilities, scripted events, etc)
73 
74  void MovementInform(uint32, uint32) override;
75 
76  // EscortAI functions
77  void AddWaypoint(uint32 id, float x, float y, float z, uint32 waitTime = 0); // waitTime is in ms
78 
79  //this will set the current position to x/y/z/o, and the current WP to pointId.
80  bool SetNextWaypoint(uint32 pointId, float x, float y, float z, float orientation);
81 
82  //this will set the current position to WP start position (if setPosition == true),
83  //and the current WP to pointId
84  bool SetNextWaypoint(uint32 pointId, bool setPosition = true, bool resetWaypointsOnFail = true);
85 
86  bool GetWaypointPosition(uint32 pointId, float& x, float& y, float& z);
87 
88  virtual void WaypointReached(uint32 pointId) = 0;
89  virtual void WaypointStart(uint32 /*pointId*/) { }
90 
91  void Start(bool isActiveAttacker = true, bool run = false, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = NULL, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true);
92 
93  void SetRun(bool on = true);
94  void SetEscortPaused(bool on);
95 
96  bool HasEscortState(uint32 escortState) { return (m_uiEscortState & escortState) != 0; }
97  virtual bool IsEscorted() const override { return (m_uiEscortState & STATE_ESCORT_ESCORTING); }
98 
99  void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; }
100  float GetMaxPlayerDistance() const { return MaxPlayerDistance; }
101 
102  void SetDespawnAtEnd(bool despawn) { DespawnAtEnd = despawn; }
103  void SetDespawnAtFar(bool despawn) { DespawnAtFar = despawn; }
104  bool GetAttack() const { return m_bIsActiveAttacker; }//used in EnterEvadeMode override
105  void SetCanAttack(bool attack) { m_bIsActiveAttacker = attack; }
106  ObjectGuid GetEventStarterGUID() const { return m_uiPlayerGUID; }
107 
108  protected:
109  Player* GetPlayerForEscort() { return ObjectAccessor::GetPlayer(*me, m_uiPlayerGUID); }
110 
111  private:
112  bool AssistPlayerInCombat(Unit* who);
113  bool IsPlayerOrGroupInRange();
114  void FillPointMovementListForCreature();
115 
116  void AddEscortState(uint32 escortState) { m_uiEscortState |= escortState; }
117  void RemoveEscortState(uint32 escortState) { m_uiEscortState &= ~escortState; }
118 
124 
125  Quest const* m_pQuestForEscort; //generally passed in Start() when regular escort script.
126 
127  std::list<Escort_Waypoint> WaypointList;
128  std::list<Escort_Waypoint>::iterator CurrentWP;
129 
130  bool m_bIsActiveAttacker; //obsolete, determined by faction.
131  bool m_bIsRunning; //all creatures are walking by default (has flag MOVEMENTFLAG_WALK)
132  bool m_bCanInstantRespawn; //if creature should respawn instantly after escort over (if not, database respawntime are used)
133  bool m_bCanReturnToStart; //if creature can walk same path (loop) without despawn. Not for regular escort quests.
136  bool ScriptWP;
138 };
139 #endif
~npc_escortAI()
Definition: ScriptedEscortAI.h:56
void SetCanAttack(bool attack)
Definition: ScriptedEscortAI.h:105
void SetDespawnAtEnd(bool despawn)
Definition: ScriptedEscortAI.h:102
uint32 m_uiEscortState
Definition: ScriptedEscortAI.h:122
bool m_bIsActiveAttacker
Definition: ScriptedEscortAI.h:130
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: ScriptedEscortAI.h:52
Definition: QuestDef.h:279
uint32 m_uiPlayerCheckTimer
Definition: ScriptedEscortAI.h:121
std::list< Escort_Waypoint > WaypointList
Definition: ScriptedEscortAI.h:127
float z
Definition: ScriptedEscortAI.h:40
virtual void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition: CreatureAI.cpp:168
Player * GetPlayerForEscort()
Definition: ScriptedEscortAI.h:109
virtual void UpdateAI(uint32 diff) override
Definition: ScriptedCreature.cpp:125
arena_t NULL
Definition: jemalloc_internal.h:624
virtual void JustRespawned()
Definition: CreatureAI.h:140
void RemoveEscortState(uint32 escortState)
Definition: ScriptedEscortAI.h:117
bool HasImmuneToNPCFlags
Definition: ScriptedEscortAI.h:137
void JustDied(Unit *) override
Definition: ScriptedCreature.h:160
Definition: Creature.h:467
Definition: ScriptedEscortAI.h:47
bool DespawnAtEnd
Definition: ScriptedEscortAI.h:134
void SetMaxPlayerDistance(float newMax)
Definition: ScriptedEscortAI.h:99
bool DespawnAtFar
Definition: ScriptedEscortAI.h:135
Escort_Waypoint(uint32 _id, float _x, float _y, float _z, uint32 _w)
Definition: ScriptedEscortAI.h:28
void AddEscortState(uint32 escortState)
Definition: ScriptedEscortAI.h:116
Definition: ScriptedEscortAI.h:26
virtual bool IsEscorted() const override
Definition: ScriptedEscortAI.h:97
Quest const * m_pQuestForEscort
Definition: ScriptedEscortAI.h:125
float MaxPlayerDistance
Definition: ScriptedEscortAI.h:123
Definition: ScriptedEscortAI.h:46
ObjectGuid GetEventStarterGUID() const
Definition: ScriptedEscortAI.h:106
bool m_bCanInstantRespawn
Definition: ScriptedEscortAI.h:132
Definition: ScriptedCreature.h:142
std::list< Escort_Waypoint >::iterator CurrentWP
Definition: ScriptedEscortAI.h:128
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:184
G3D::int16 z
Definition: Vector3int16.h:46
virtual void WaypointStart(uint32)
Definition: ScriptedEscortAI.h:89
uint32_t uint32
Definition: Define.h:150
bool ScriptWP
Definition: ScriptedEscortAI.h:136
G3D::int16 y
Definition: Vector2int16.h:38
float GetMaxPlayerDistance() const
Definition: ScriptedEscortAI.h:100
float y
Definition: ScriptedEscortAI.h:39
bool m_bIsRunning
Definition: ScriptedEscortAI.h:131
ObjectGuid m_uiPlayerGUID
Definition: ScriptedEscortAI.h:119
void AttackStart(Unit *) override
Definition: ScriptedCreature.cpp:117
uint32 m_uiWPWaitTimer
Definition: ScriptedEscortAI.h:120
#define TC_GAME_API
Definition: Define.h:134
Definition: ScriptedEscortAI.h:48
uint32 id
Definition: ScriptedEscortAI.h:37
Definition: ScriptedEscortAI.h:49
virtual void MoveInLineOfSight(Unit *)
Definition: CreatureAI.cpp:128
void SetDespawnAtFar(bool despawn)
Definition: ScriptedEscortAI.h:103
eEscortState
Definition: ScriptedEscortAI.h:44
bool m_bCanReturnToStart
Definition: ScriptedEscortAI.h:133
float x
Definition: ScriptedEscortAI.h:38
Definition: ObjectGuid.h:189
G3D::int16 x
Definition: Vector2int16.h:37
Definition: Unit.h:1305
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:143
bool HasEscortState(uint32 escortState)
Definition: ScriptedEscortAI.h:96
bool GetAttack() const
Definition: ScriptedEscortAI.h:104
uint32 WaitTimeMs
Definition: ScriptedEscortAI.h:41