aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp268
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedEscortAI.h15
-rw-r--r--src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp4
-rw-r--r--src/server/scripts/Northrend/zone_borean_tundra.cpp2
-rw-r--r--src/server/scripts/Northrend/zone_howling_fjord.cpp2
5 files changed, 141 insertions, 150 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
index 79919e46397..831ddeb466a 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
@@ -39,55 +39,6 @@ EscortAI::EscortAI(Creature* creature) : ScriptedAI(creature), _pauseTimer(2500)
{
}
-Player* EscortAI::GetPlayerForEscort()
-{
- return ObjectAccessor::GetPlayer(*me, _playerGUID);
-}
-
-// see followerAI
-bool EscortAI::AssistPlayerInCombatAgainst(Unit* who)
-{
- if (!who || !who->GetVictim())
- return false;
-
- if (me->HasReactState(REACT_PASSIVE))
- return false;
-
- // experimental (unknown) flag not present
- if (!(me->GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_CAN_ASSIST))
- return false;
-
- // not a player
- if (!who->EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
- return false;
-
- if (!who->isInAccessiblePlaceFor(me))
- return false;
-
- if (!CanAIAttack(who))
- return false;
-
- // we cannot attack in evade mode
- if (me->IsInEvadeMode())
- return false;
-
- // or if enemy is in evade mode
- if (who->GetTypeId() == TYPEID_UNIT && who->ToCreature()->IsInEvadeMode())
- return false;
-
- if (!me->IsValidAssistTarget(who->GetVictim()))
- return false;
-
- // too far away and no free sight
- if (me->IsWithinDistInMap(who, GetMaxPlayerDistance()) && me->IsWithinLOSInMap(who))
- {
- me->EngageWithTarget(who);
- return true;
- }
-
- return false;
-}
-
void EscortAI::MoveInLineOfSight(Unit* who)
{
if (!who)
@@ -161,24 +112,54 @@ void EscortAI::EnterEvadeMode(EvadeReason /*why*/)
}
}
-bool EscortAI::IsPlayerOrGroupInRange()
+void EscortAI::MovementInform(uint32 type, uint32 id)
{
- if (Player* player = GetPlayerForEscort())
+ // no action allowed if there is no escort
+ if (!HasEscortState(STATE_ESCORT_ESCORTING))
+ return;
+
+ if (type == POINT_MOTION_TYPE)
{
- if (Group* group = player->GetGroup())
+ if (!_pauseTimer)
+ _pauseTimer = 2000;
+
+ // continue waypoint movement
+ if (id == POINT_LAST_POINT)
{
- for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
- if (Player* member = groupRef->GetSource())
- if (me->IsWithinDistInMap(member, GetMaxPlayerDistance()))
- return true;
+ TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: returned to before combat position");
+ me->SetWalk(!_running);
+ RemoveEscortState(STATE_ESCORT_RETURNING);
+ }
+ else if (id == POINT_HOME)
+ {
+ TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: returned to home location and restarting waypoint path");
+ _started = false;
}
- else if (me->IsWithinDistInMap(player, GetMaxPlayerDistance()))
- return true;
}
+ else if (type == WAYPOINT_MOTION_TYPE)
+ {
+ ASSERT(id < _path.nodes.size(), "EscortAI::MovementInform: referenced movement id (%u) points to non-existing node in loaded path", id);
+ WaypointNode waypoint = _path.nodes[id];
- return false;
+ TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: waypoint node %u reached", waypoint.id);
+
+ // last point
+ if (id == _path.nodes.size() - 1)
+ {
+ _started = false;
+ _ended = true;
+ _pauseTimer = 1000;
+ }
+ }
}
+///@todo investigate whether if its necessary to handle anything on charm
+/*
+void EscortAI::OnCharmed(bool apply)
+{
+}
+*/
+
void EscortAI::UpdateAI(uint32 diff)
{
// Waypoint Updating
@@ -274,54 +255,6 @@ void EscortAI::UpdateEscortAI(uint32 /*diff*/)
DoMeleeAttackIfReady();
}
-void EscortAI::MovementInform(uint32 type, uint32 id)
-{
- // no action allowed if there is no escort
- if (!HasEscortState(STATE_ESCORT_ESCORTING))
- return;
-
- if (type == POINT_MOTION_TYPE)
- {
- if (!_pauseTimer)
- _pauseTimer = 2000;
-
- // continue waypoint movement
- if (id == POINT_LAST_POINT)
- {
- TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: returned to before combat position");
- me->SetWalk(!_running);
- RemoveEscortState(STATE_ESCORT_RETURNING);
- }
- else if (id == POINT_HOME)
- {
- TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: returned to home location and restarting waypoint path");
- _started = false;
- }
- }
- else if (type == WAYPOINT_MOTION_TYPE)
- {
- ASSERT(id < _path.nodes.size(), "EscortAI::MovementInform: referenced movement id (%u) points to non-existing node in loaded path", id);
- WaypointNode waypoint = _path.nodes[id];
-
- TC_LOG_DEBUG("scripts", "EscortAI::MovementInform: waypoint node %u reached", waypoint.id);
-
- // last point
- if (id == _path.nodes.size() - 1)
- {
- _started = false;
- _ended = true;
- _pauseTimer = 1000;
- }
- }
-}
-
-///@todo investigate whether if its necessary to handle anything on charm
-/*
-void EscortAI::OnCharmed(bool apply)
-{
-}
-*/
-
void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientation/* = 0*/, uint32 waitTime/* = 0*/)
{
Trinity::NormalizeMapCoord(x);
@@ -342,33 +275,6 @@ void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientati
_manualPath = true;
}
-void EscortAI::FillPointMovementListForCreature()
-{
- WaypointPath const* path = sScriptSystemMgr->GetPath(me->GetEntry());
- if (!path)
- return;
-
- for (WaypointNode const& value : path->nodes)
- {
- WaypointNode node = value;
- Trinity::NormalizeMapCoord(node.x);
- Trinity::NormalizeMapCoord(node.y);
- node.moveType = _running ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
-
- _path.nodes.push_back(std::move(node));
- }
-}
-
-void EscortAI::SetRun(bool on)
-{
- if (on && !_running)
- me->SetWalk(false);
- else if (!on && _running)
- me->SetWalk(true);
-
- _running = on;
-}
-
/// @todo get rid of this many variables passed in function.
void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, ObjectGuid playerGUID /* = 0 */, Quest const* quest /* = nullptr */, bool instantRespawn /* = false */, bool canLoopPath /* = false */, bool resetWaypoints /* = true */)
{
@@ -441,6 +347,16 @@ void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */,
AddEscortState(STATE_ESCORT_ESCORTING);
}
+void EscortAI::SetRun(bool on)
+{
+ if (on && !_running)
+ me->SetWalk(false);
+ else if (!on && _running)
+ me->SetWalk(true);
+
+ _running = on;
+}
+
void EscortAI::SetEscortPaused(bool on)
{
if (!HasEscortState(STATE_ESCORT_ESCORTING))
@@ -469,3 +385,87 @@ bool EscortAI::IsEscortNPC(bool onlyIfActive) const
return false;
}
+
+Player* EscortAI::GetPlayerForEscort()
+{
+ return ObjectAccessor::GetPlayer(*me, _playerGUID);
+}
+
+// see followerAI
+bool EscortAI::AssistPlayerInCombatAgainst(Unit* who)
+{
+ if (!who || !who->GetVictim())
+ return false;
+
+ if (me->HasReactState(REACT_PASSIVE))
+ return false;
+
+ // experimental (unknown) flag not present
+ if (!(me->GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_CAN_ASSIST))
+ return false;
+
+ // not a player
+ if (!who->EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
+ return false;
+
+ if (!who->isInAccessiblePlaceFor(me))
+ return false;
+
+ if (!CanAIAttack(who))
+ return false;
+
+ // we cannot attack in evade mode
+ if (me->IsInEvadeMode())
+ return false;
+
+ // or if enemy is in evade mode
+ if (who->GetTypeId() == TYPEID_UNIT && who->ToCreature()->IsInEvadeMode())
+ return false;
+
+ if (!me->IsValidAssistTarget(who->GetVictim()))
+ return false;
+
+ // too far away and no free sight
+ if (me->IsWithinDistInMap(who, GetMaxPlayerDistance()) && me->IsWithinLOSInMap(who))
+ {
+ me->EngageWithTarget(who);
+ return true;
+ }
+
+ return false;
+}
+
+bool EscortAI::IsPlayerOrGroupInRange()
+{
+ if (Player* player = GetPlayerForEscort())
+ {
+ if (Group* group = player->GetGroup())
+ {
+ for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
+ if (Player* member = groupRef->GetSource())
+ if (me->IsWithinDistInMap(member, GetMaxPlayerDistance()))
+ return true;
+ }
+ else if (me->IsWithinDistInMap(player, GetMaxPlayerDistance()))
+ return true;
+ }
+
+ return false;
+}
+
+void EscortAI::FillPointMovementListForCreature()
+{
+ WaypointPath const* path = sScriptSystemMgr->GetPath(me->GetEntry());
+ if (!path)
+ return;
+
+ for (WaypointNode const& value : path->nodes)
+ {
+ WaypointNode node = value;
+ Trinity::NormalizeMapCoord(node.x);
+ Trinity::NormalizeMapCoord(node.y);
+ node.moveType = _running ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
+
+ _path.nodes.push_back(std::move(node));
+ }
+}
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
index 4020d90815e..fe8f6eb37fb 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
@@ -39,39 +39,30 @@ struct TC_GAME_API EscortAI : public ScriptedAI
explicit EscortAI(Creature* creature);
~EscortAI() { }
- void UpdateAI(uint32 diff) override; // the "internal" update, calls UpdateEscortAI()
void MoveInLineOfSight(Unit* who) override;
void JustDied(Unit*) override;
void JustAppeared() override;
void ReturnToLastPoint();
void EnterEvadeMode(EvadeReason /*why*/ = EVADE_REASON_OTHER) 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, float orientation = 0.f, uint32 waitTime = 0); // waitTime is in ms
-
void Start(bool isActiveAttacker = true, bool run = false, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true);
void SetRun(bool on = true);
-
void SetEscortPaused(bool on);
void SetPauseTimer(uint32 Timer) { _pauseTimer = Timer; }
-
bool HasEscortState(uint32 escortState) { return (_escortState & escortState) != 0; }
virtual bool IsEscorted() const override { return (_escortState & STATE_ESCORT_ESCORTING); }
-
void SetMaxPlayerDistance(float newMax) { _maxPlayerDistance = newMax; }
float GetMaxPlayerDistance() const { return _maxPlayerDistance; }
-
void SetDespawnAtEnd(bool despawn) { _despawnAtEnd = despawn; }
void SetDespawnAtFar(bool despawn) { _despawnAtFar = despawn; }
-
- bool GetAttack() const { return _activeAttacker; } // used in EnterEvadeMode override
- void SetCanAttack(bool attack) { _activeAttacker = attack; }
-
+ bool IsActiveAttacker() const { return _activeAttacker; } // obsolete
+ void SetActiveAttacker(bool enable) { _activeAttacker = enable; }
ObjectGuid GetEventStarterGUID() const { return _playerGUID; }
-
virtual bool IsEscortNPC(bool isEscorting) const override;
protected:
diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp
index 8fa32166e6d..cbcb5e81713 100644
--- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp
+++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp
@@ -1188,7 +1188,7 @@ public:
if (IsEvent || IsOverrun)
{
- ENSURE_AI(hyjal_trashAI, me->AI())->SetCanAttack(false);
+ ENSURE_AI(hyjal_trashAI, me->AI())->SetActiveAttacker(false);
EscortAI::UpdateAI(diff);
}
@@ -1309,7 +1309,7 @@ public:
if (IsEvent || IsOverrun)
{
- ENSURE_AI(hyjal_trashAI, me->AI())->SetCanAttack(false);
+ ENSURE_AI(hyjal_trashAI, me->AI())->SetActiveAttacker(false);
EscortAI::UpdateAI(diff);
}
diff --git a/src/server/scripts/Northrend/zone_borean_tundra.cpp b/src/server/scripts/Northrend/zone_borean_tundra.cpp
index dd160545a7c..0be916f8aba 100644
--- a/src/server/scripts/Northrend/zone_borean_tundra.cpp
+++ b/src/server/scripts/Northrend/zone_borean_tundra.cpp
@@ -1750,7 +1750,7 @@ public:
void UpdateEscortAI(uint32 /*diff*/) override
{
- if (GetAttack() && UpdateVictim())
+ if (IsActiveAttacker() && UpdateVictim())
{
if (Bonker_agro == 0)
{
diff --git a/src/server/scripts/Northrend/zone_howling_fjord.cpp b/src/server/scripts/Northrend/zone_howling_fjord.cpp
index 83ef9f8e355..ccc2ffdc63c 100644
--- a/src/server/scripts/Northrend/zone_howling_fjord.cpp
+++ b/src/server/scripts/Northrend/zone_howling_fjord.cpp
@@ -130,7 +130,7 @@ public:
} else PotTimer -= diff;
}
- if (GetAttack() && UpdateVictim())
+ if (IsActiveAttacker() && UpdateVictim())
DoMeleeAttackIfReady();
EscortAI::UpdateAI(diff);