aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2017-11-07 19:22:39 +0100
committerccrs <ccrs@users.noreply.github.com>2017-11-07 19:22:39 +0100
commit60a5535f64e4c0301c338f5c7a5871c59e2ac218 (patch)
treee215ded03f61894895a5a397ef939fd001803c57
parent72e8041e5fcb81a10db8f597d42b6ee1fae7b55c (diff)
Core/AI: rearrange SAI private methods
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp179
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.h6
2 files changed, 96 insertions, 89 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 6bff5022b70..24719902659 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -42,24 +42,6 @@ bool SmartAI::IsAIControlled() const
return !mIsCharmed;
}
-void SmartAI::UpdateDespawn(uint32 diff)
-{
- if (mDespawnState <= 1 || mDespawnState > 3)
- return;
-
- if (mDespawnTime < diff)
- {
- if (mDespawnState == 2)
- {
- me->SetVisible(false);
- mDespawnTime = 5000;
- mDespawnState++;
- }
- else
- me->DespawnOrUnsummon();
- } else mDespawnTime -= diff;
-}
-
void SmartAI::StartPath(bool run/* = false*/, uint32 pathId/* = 0*/, bool repeat/* = false*/, Unit* invoker/* = nullptr*/, uint32 nodeId/* = 1*/)
{
if (me->IsInCombat()) // no wp movement in combat
@@ -296,81 +278,16 @@ void SmartAI::ReturnToLastOOCPos()
me->GetMotionMaster()->MovePoint(SMART_ESCORT_LAST_OOC_POINT, me->GetHomePosition());
}
-void SmartAI::UpdatePath(const uint32 diff)
-{
- if (!HasEscortState(SMART_ESCORT_ESCORTING))
- return;
-
- if (_escortInvokerCheckTimer < diff)
- {
- if (!IsEscortInvokerInRange())
- {
- StopPath(0, mEscortQuestID, true);
-
- // allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
- GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, me);
- me->DespawnOrUnsummon();
- return;
- }
- _escortInvokerCheckTimer = 1000;
- }
- else
- _escortInvokerCheckTimer -= diff;
-
- // handle pause
- if (HasEscortState(SMART_ESCORT_PAUSED) && (_waypointReached || _waypointPauseForced))
- {
- if (_waypointPauseTimer <= diff)
- {
- if (!me->IsInCombat() && !HasEscortState(SMART_ESCORT_RETURNING))
- ResumePath();
- }
- else
- _waypointPauseTimer -= diff;
- }
- else if (_waypointPathEnded) // end path
- {
- _waypointPathEnded = false;
- StopPath();
- return;
- }
-
- if (HasEscortState(SMART_ESCORT_RETURNING))
- {
- if (_OOCReached) // reached OOC WP
- {
- _OOCReached = false;
- RemoveEscortState(SMART_ESCORT_RETURNING);
- if (!HasEscortState(SMART_ESCORT_PAUSED))
- ResumePath();
- }
- }
-}
-
void SmartAI::UpdateAI(uint32 diff)
{
CheckConditions(diff);
+
GetScript()->OnUpdate(diff);
+
UpdatePath(diff);
+ UpdateFollow(diff);
UpdateDespawn(diff);
- /// @todo move to void
- if (mFollowGuid)
- {
- if (mFollowArrivedTimer < diff)
- {
- if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, true))
- {
- StopFollow(true);
- return;
- }
-
- mFollowArrivedTimer = 1000;
- }
- else
- mFollowArrivedTimer -= diff;
- }
-
if (!IsAIControlled())
return;
@@ -969,6 +886,96 @@ void SmartAI::CheckConditions(uint32 diff)
mConditionsTimer -= diff;
}
+void SmartAI::UpdatePath(uint32 diff)
+{
+ if (!HasEscortState(SMART_ESCORT_ESCORTING))
+ return;
+
+ if (_escortInvokerCheckTimer < diff)
+ {
+ if (!IsEscortInvokerInRange())
+ {
+ StopPath(0, mEscortQuestID, true);
+
+ // allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
+ GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, me);
+ me->DespawnOrUnsummon();
+ return;
+ }
+ _escortInvokerCheckTimer = 1000;
+ }
+ else
+ _escortInvokerCheckTimer -= diff;
+
+ // handle pause
+ if (HasEscortState(SMART_ESCORT_PAUSED) && (_waypointReached || _waypointPauseForced))
+ {
+ if (_waypointPauseTimer <= diff)
+ {
+ if (!me->IsInCombat() && !HasEscortState(SMART_ESCORT_RETURNING))
+ ResumePath();
+ }
+ else
+ _waypointPauseTimer -= diff;
+ }
+ else if (_waypointPathEnded) // end path
+ {
+ _waypointPathEnded = false;
+ StopPath();
+ return;
+ }
+
+ if (HasEscortState(SMART_ESCORT_RETURNING))
+ {
+ if (_OOCReached) // reached OOC WP
+ {
+ _OOCReached = false;
+ RemoveEscortState(SMART_ESCORT_RETURNING);
+ if (!HasEscortState(SMART_ESCORT_PAUSED))
+ ResumePath();
+ }
+ }
+}
+
+void SmartAI::UpdateFollow(uint32 diff)
+{
+ if (mFollowGuid)
+ {
+ if (mFollowArrivedTimer < diff)
+ {
+ if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, true))
+ {
+ StopFollow(true);
+ return;
+ }
+
+ mFollowArrivedTimer = 1000;
+ }
+ else
+ mFollowArrivedTimer -= diff;
+ }
+}
+
+void SmartAI::UpdateDespawn(uint32 diff)
+{
+ if (mDespawnState <= 1 || mDespawnState > 3)
+ return;
+
+ if (mDespawnTime < diff)
+ {
+ if (mDespawnState == 2)
+ {
+ me->SetVisible(false);
+ mDespawnTime = 5000;
+ mDespawnState++;
+ }
+ else
+ me->DespawnOrUnsummon();
+ }
+ else
+ mDespawnTime -= diff;
+}
+
void SmartGameObjectAI::UpdateAI(uint32 diff)
{
GetScript()->OnUpdate(diff);
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h
index d967a7512cc..ecf9aaeb97a 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.h
+++ b/src/server/game/AI/SmartScripts/SmartAI.h
@@ -201,10 +201,10 @@ class TC_GAME_API SmartAI : public CreatureAI
private:
bool AssistPlayerInCombatAgainst(Unit* who);
void ReturnToLastOOCPos();
- void UpdatePath(const uint32 diff);
- void UpdateDespawn(uint32 diff);
- // Vehicle conditions
void CheckConditions(uint32 diff);
+ void UpdatePath(uint32 diff);
+ void UpdateFollow(uint32 diff);
+ void UpdateDespawn(uint32 diff);
SmartScript mScript;