diff options
author | ccrs <ccrs@users.noreply.github.com> | 2017-11-07 19:22:39 +0100 |
---|---|---|
committer | funjoker <funjoker109@gmail.com> | 2021-01-29 19:23:53 +0100 |
commit | 3e5a955fc8980df1332a3faa741731fbddc31b24 (patch) | |
tree | e20175917f8c122b9eff226db8ae7dc14be2c210 | |
parent | 343389dc8411b9b3ea5f7e3623ad7f32cf304490 (diff) |
Core/AI: rearrange SAI private methods
(cherry picked from commit 60a5535f64e4c0301c338f5c7a5871c59e2ac218)
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 179 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.h | 6 |
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 3935591fc73..734795d0a66 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(0, Seconds(mRespawnTime)); - } 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.IsEmpty()) - { - if (mFollowArrivedTimer < diff) - { - if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, true)) - { - StopFollow(true); - return; - } - - mFollowArrivedTimer = 1000; - } - else - mFollowArrivedTimer -= diff; - } - if (!IsAIControlled()) return; @@ -970,6 +887,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.IsEmpty()) + { + 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(0, Seconds(mRespawnTime)); + } + 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 804cf7ab0d4..3c7dc4015c8 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -203,10 +203,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; |