diff options
author | Rat <none@none> | 2009-04-03 17:57:57 +0200 |
---|---|---|
committer | Rat <none@none> | 2009-04-03 17:57:57 +0200 |
commit | 335c04b79156e4262e91894141bf5fa687d4c926 (patch) | |
tree | f19d9a22008574383ab01c4a78aa379d2f010350 /src | |
parent | c2dfb661e7fdfa4f24c14d1b334984cba512d63e (diff) |
*added new escortAI functions (does not effect already coded escort scripts)
--HG--
branch : trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/scripts/scripts/npc/npc_escortAI.cpp | 52 | ||||
-rw-r--r-- | src/bindings/scripts/scripts/npc/npc_escortAI.h | 15 |
2 files changed, 45 insertions, 22 deletions
diff --git a/src/bindings/scripts/scripts/npc/npc_escortAI.cpp b/src/bindings/scripts/scripts/npc/npc_escortAI.cpp index 97f3f088a31..9699505f293 100644 --- a/src/bindings/scripts/scripts/npc/npc_escortAI.cpp +++ b/src/bindings/scripts/scripts/npc/npc_escortAI.cpp @@ -13,7 +13,6 @@ EndScriptData */ #include "npc_escortAI.h" #define WP_LAST_POINT -1 -#define MAX_PLAYER_DISTANCE 50 bool npc_escortAI::IsVisible(Unit* who) const { @@ -132,21 +131,29 @@ void npc_escortAI::UpdateAI(const uint32 diff) //End of the line, Despawn self then immediatly respawn if (CurrentWP == WaypointList.end()) { - debug_log("SD2: EscortAI reached end of waypoints"); + if(DespawnAtEnd) + { + debug_log("SD2: EscortAI reached end of waypoints"); - m_creature->setDeathState(JUST_DIED); - m_creature->SetHealth(0); - m_creature->CombatStop(); - m_creature->DeleteThreatList(); - m_creature->Respawn(); - m_creature->GetMotionMaster()->Clear(true); + m_creature->setDeathState(JUST_DIED); + m_creature->SetHealth(0); + m_creature->CombatStop(); + m_creature->DeleteThreatList(); + m_creature->Respawn(); + m_creature->GetMotionMaster()->Clear(true); - //Re-Enable gossip - m_creature->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); + //Re-Enable gossip + m_creature->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); - IsBeingEscorted = false; - WaitTimer = 0; - return; + IsBeingEscorted = false; + WaitTimer = 0; + return; + }else{ + debug_log("SD2: EscortAI reached end of waypoints with Despawn off"); + IsBeingEscorted = false; + WaitTimer = 0; + return; + } } if( !IsOnHold ) @@ -165,7 +172,7 @@ void npc_escortAI::UpdateAI(const uint32 diff) { Unit* p = Unit::GetUnit(*m_creature, PlayerGUID); - if (!p || m_creature->GetDistance(p) > MAX_PLAYER_DISTANCE) + if (DespawnAtFar && (!p || m_creature->GetDistance(p) > GetMaxPlayerDistance())) { JustDied(m_creature); IsBeingEscorted = false; @@ -187,16 +194,19 @@ void npc_escortAI::UpdateAI(const uint32 diff) }else PlayerTimer -= diff; } - //Check if we have a current target - if( m_creature->isAlive() && UpdateVictim()) + if(CanMelee) { - //If we are within range melee the target - if( m_creature->IsWithinMeleeRange(m_creature->getVictim())) + //Check if we have a current target + if( m_creature->isAlive() && UpdateVictim()) { - if( m_creature->isAttackReady() ) + //If we are within range melee the target + if( m_creature->IsWithinMeleeRange(m_creature->getVictim())) { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); + if( m_creature->isAttackReady() ) + { + m_creature->AttackerStateUpdate(m_creature->getVictim()); + m_creature->resetAttackTimer(); + } } } } diff --git a/src/bindings/scripts/scripts/npc/npc_escortAI.h b/src/bindings/scripts/scripts/npc/npc_escortAI.h index 906726dd0c2..79365f7129b 100644 --- a/src/bindings/scripts/scripts/npc/npc_escortAI.h +++ b/src/bindings/scripts/scripts/npc/npc_escortAI.h @@ -5,6 +5,8 @@ #ifndef SC_ESCORTAI_H #define SC_ESCORTAI_H +#define DEFAULT_MAX_PLAYER_DISTANCE 50 + struct Escort_Waypoint { Escort_Waypoint(uint32 _id, float _x, float _y, float _z, uint32 _w) @@ -35,7 +37,7 @@ struct TRINITY_DLL_DECL npc_escortAI : public ScriptedAI virtual void Reset() = 0; // CreatureAI functions - npc_escortAI(Creature *c) : ScriptedAI(c), IsBeingEscorted(false), PlayerTimer(1000) {m_creature->GetPosition(LastPos.x, LastPos.y, LastPos.z);} + npc_escortAI(Creature *c) : ScriptedAI(c), IsBeingEscorted(false), PlayerTimer(1000), MaxPlayerDistance(DEFAULT_MAX_PLAYER_DISTANCE), CanMelee(true), DespawnAtEnd(true), DespawnAtFar(true) {m_creature->GetPosition(LastPos.x, LastPos.y, LastPos.z);} bool IsVisible(Unit*) const; @@ -58,6 +60,13 @@ struct TRINITY_DLL_DECL npc_escortAI : public ScriptedAI void Start(bool bAttack, bool bDefend, bool bRun, uint64 pGUID = 0); + void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; } + float GetMaxPlayerDistance() { return MaxPlayerDistance; } + + void SetCanMelee(bool usemelee) { CanMelee = usemelee; } + void SetDespawnAtEnd(bool despawn) { DespawnAtEnd = despawn; } + void SetDespawnAtFar(bool despawn) { DespawnAtFar = despawn; } + // EscortAI variables protected: uint64 PlayerGUID; @@ -67,6 +76,7 @@ struct TRINITY_DLL_DECL npc_escortAI : public ScriptedAI private: uint32 WaitTimer; uint32 PlayerTimer; + float MaxPlayerDistance; struct { @@ -83,6 +93,9 @@ struct TRINITY_DLL_DECL npc_escortAI : public ScriptedAI bool Returning; bool ReconnectWP; bool Run; + bool CanMelee; + bool DespawnAtEnd; + bool DespawnAtFar; }; #endif |