Scripts/FollowerAI: Some cleanup:

- FollowerAI properly resumes follow after evading.
- Removed duplicated getters from CreatureAI (IsEscorted vs IsEscortNPC), they were used to do the same thing
- FollowerAI properly assists in combat.
- FollowerAI properly despawns if quest is abandoned.
- FollowerAI now supports dynamic respawning for escort NPCs.
This commit is contained in:
Treeston authored and Ovahlord committed 2020-01-31 07:34:11 +01:00
1 parent eaa635ab32
commit e156f8d571
6 files changed
+120 -232

No files matched your search

@@ -20,18 +20,18 @@
#include "ScriptedCreature.h"
#include "ScriptSystem.h"
#include "World.h"
class Quest;
enum eFollowState
enum FollowerState : uint32
{
STATE_FOLLOW_NONE = 0x000,
STATE_FOLLOW_INPROGRESS = 0x001, //must always have this state for any follow
STATE_FOLLOW_RETURNING = 0x002, //when returning to combat start after being in combat
STATE_FOLLOW_PAUSED = 0x004, //disables following
STATE_FOLLOW_COMPLETE = 0x008, //follow is completed and may end
STATE_FOLLOW_PREEVENT = 0x010, //not implemented (allow pre event to run, before follow is initiated)
STATE_FOLLOW_POSTEVENT = 0x020 //can be set at complete and allow post event to run
STATE_FOLLOW_INPROGRESS = 0x001, // must always have this state for any follow
STATE_FOLLOW_PAUSED = 0x002, // disables following
STATE_FOLLOW_COMPLETE = 0x004, // follow is completed and may end
STATE_FOLLOW_PREEVENT = 0x008, // not implemented (allow pre event to run, before follow is initiated)
STATE_FOLLOW_POSTEVENT = 0x010 // can be set at complete and allow post event to run
};
class TC_GAME_API FollowerAI : public ScriptedAI
@@ -40,42 +40,38 @@ class TC_GAME_API FollowerAI : public ScriptedAI
explicit FollowerAI(Creature* creature);
~FollowerAI() { }
void MovementInform(uint32 motionType, uint32 pointId) override;
void AttackStart(Unit*) override;
void MoveInLineOfSight(Unit*) override;
void EnterEvadeMode(EvadeReason /*why*/ = EVADE_REASON_OTHER) override;
void JustDied(Unit*) override;
void JustReachedHome() override;
void OwnerAttackedBy(Unit* other) override;
void JustAppeared() override;
//the "internal" update, calls UpdateFollowerAI()
void UpdateAI(uint32) override;
void UpdateAI(uint32) override; //the "internal" update, calls UpdateFollowerAI()
virtual void UpdateFollowerAI(uint32); //used when it's needed to add code in update (abilities, scripted events, etc)
//used when it's needed to add code in update (abilities, scripted events, etc)
virtual void UpdateFollowerAI(uint32);
void StartFollow(Player* player, uint32 factionForFollower = 0, Quest const* quest = nullptr);
void StartFollow(Player* player, uint32 factionForFollower = 0, uint32 quest = 0);
void SetFollowPaused(bool bPaused); //if special event require follow mode to hold/resume during the follow
void SetFollowComplete(bool bWithEndEvent = false);
//if special event require follow mode to hold/resume during the follow
void SetFollowPaused(bool paused);
void SetFollowComplete(bool withEndEvent = false);
bool HasFollowState(uint32 uiFollowState) { return (m_uiFollowState & uiFollowState) != 0; }
bool IsEscorted() const override { return HasFollowState(STATE_FOLLOW_INPROGRESS); }
bool HasFollowState(uint32 followState) const { return (_followState & followState) != 0; }
protected:
Player* GetLeaderForFollower();
private:
void AddFollowState(uint32 uiFollowState) { m_uiFollowState |= uiFollowState; }
void RemoveFollowState(uint32 uiFollowState) { m_uiFollowState &= ~uiFollowState; }
void AddFollowState(uint32 followState) { _followState |= followState; }
void RemoveFollowState(uint32 followState) { _followState &= ~followState; }
bool ShouldAssistPlayerInCombatAgainst(Unit* who) const;
bool AssistPlayerInCombatAgainst(Unit* who);
ObjectGuid m_uiLeaderGUID;
uint32 m_uiUpdateFollowTimer;
uint32 m_uiFollowState;
Quest const* m_pQuestForFollow; //normally we have a quest
ObjectGuid _leaderGUID;
uint32 _updateFollowTimer;
uint32 _followState;
uint32 _questForFollow;
};
#endif