diff options
author | ModoX <moardox@gmail.com> | 2023-04-10 04:04:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 04:04:33 +0200 |
commit | 89e09dc44ed15567f77f862d1936e8e0d9019456 (patch) | |
tree | f5664f4a2798acd965e8b589bd6ed7ff596ff780 /src/server/game/AI/ScriptedAI | |
parent | 083b8d6c846cfdf75abb1fae481a3eeb25c13c56 (diff) |
Core/AI: Drop script_waypoints and move data to waypoint_data (#28879)
Diffstat (limited to 'src/server/game/AI/ScriptedAI')
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp | 79 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.h | 11 |
2 files changed, 39 insertions, 51 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index f5a26fa4efc..572ab846ef2 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -25,6 +25,7 @@ #include "ObjectAccessor.h" #include "Player.h" #include "ScriptSystem.h" +#include "WaypointManager.h" #include "World.h" enum Points @@ -34,7 +35,7 @@ enum Points }; EscortAI::EscortAI(Creature* creature) : ScriptedAI(creature), _pauseTimer(2500ms), _playerCheckTimer(1000), _escortState(STATE_ESCORT_NONE), _maxPlayerDistance(DEFAULT_MAX_PLAYER_DISTANCE), - _escortQuest(nullptr), _activeAttacker(true), _running(false), _instantRespawn(false), _returnToStart(false), _despawnAtEnd(true), _despawnAtFar(true), _manualPath(false), + _escortQuest(nullptr), _activeAttacker(true), _instantRespawn(false), _returnToStart(false), _despawnAtEnd(true), _despawnAtFar(true), _hasImmuneToNPCFlags(false), _started(false), _ended(false), _resume(false) { } @@ -129,7 +130,7 @@ void EscortAI::MovementInform(uint32 type, uint32 id) if (id == POINT_LAST_POINT) { TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::MovementInform: returned to before combat position ({})", me->GetGUID().ToString()); - me->SetWalk(!_running); + me->SetWalk(false); RemoveEscortState(STATE_ESCORT_RETURNING); } else if (id == POINT_HOME) @@ -253,7 +254,12 @@ void EscortAI::UpdateEscortAI(uint32 /*diff*/) DoMeleeAttackIfReady(); } -void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientation/* = 0*/, Milliseconds waitTime/* = 0s*/) +void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, bool run) +{ + AddWaypoint(id, x, y, z, 0.0f, 0s, run); +} + +void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientation/* = 0*/, Milliseconds waitTime/* = 0s*/, bool run /*= false*/) { Trinity::NormalizeMapCoord(x); Trinity::NormalizeMapCoord(y); @@ -264,18 +270,38 @@ void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientati waypoint.y = y; waypoint.z = z; waypoint.orientation = orientation; - waypoint.moveType = _running ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK; + waypoint.moveType = run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK; waypoint.delay = waitTime.count(); waypoint.eventId = 0; waypoint.eventChance = 100; _path.nodes.push_back(std::move(waypoint)); +} - _manualPath = true; +void EscortAI::ResetPath() +{ + _path.nodes.clear(); +} + +void EscortAI::LoadPath(uint32 pathId) +{ + WaypointPath const* path = sWaypointMgr->GetPath(pathId); + if (!path) + { + TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::LoadPath: (script: {}) path {} is invalid ({})", me->GetScriptName(), pathId, me->GetGUID().ToString()); + return; + } + _path = *path; } /// @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 */) +void EscortAI::Start(bool isActiveAttacker /* = true*/, ObjectGuid playerGUID /* = 0 */, Quest const* quest /* = nullptr */, bool instantRespawn /* = false */, bool canLoopPath /* = false */) { + if (_path.nodes.empty()) + { + TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) path is empty ({})", me->GetScriptName(), me->GetGUID().ToString()); + return; + } + // Queue respawn from the point it starts if (CreatureData const* cdata = me->GetCreatureData()) { @@ -295,11 +321,6 @@ void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, return; } - _running = run; - - if (!_manualPath && resetWaypoints) - FillPointMovementListForCreature(); - if (_path.nodes.empty()) { TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn ({})", me->GetScriptName(), me->GetGUID().ToString()); @@ -328,28 +349,13 @@ void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, me->SetImmuneToNPC(false); } - TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::Start: (script: {}) started with {} waypoints. ActiveAttacker = {}, Run = {}, Player = {} ({})", - me->GetScriptName(), uint32(_path.nodes.size()), _activeAttacker, _running, _playerGUID.ToString(), me->GetGUID().ToString()); - - // set initial speed - me->SetWalk(!_running); + TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::Start: (script: {}) started with {} waypoints. ActiveAttacker = {}, Player = {} ({})", + me->GetScriptName(), uint32(_path.nodes.size()), _activeAttacker, _playerGUID.ToString(), me->GetGUID().ToString()); _started = false; AddEscortState(STATE_ESCORT_ESCORTING); } -void EscortAI::SetRun(bool on) -{ - if (on == _running) - return; - - for (auto& node : _path.nodes) - node.moveType = on ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK; - - me->SetWalk(!on); - _running = on; -} - void EscortAI::SetEscortPaused(bool on) { if (!HasEscortState(STATE_ESCORT_ESCORTING)) @@ -434,20 +440,3 @@ bool EscortAI::IsPlayerOrGroupInRange() 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 3a5ed989f43..0108a7a8c21 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h @@ -48,10 +48,12 @@ struct TC_GAME_API EscortAI : public ScriptedAI 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, Milliseconds waitTime = 0s); - 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 AddWaypoint(uint32 id, float x, float y, float z, bool run); + void AddWaypoint(uint32 id, float x, float y, float z, float orientation = 0.f, Milliseconds waitTime = 0s, bool run = false); + void ResetPath(); + void LoadPath(uint32 pathId); + void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false); - void SetRun(bool on = true); void SetEscortPaused(bool on); void SetPauseTimer(Milliseconds timer) { _pauseTimer = timer; } bool HasEscortState(uint32 escortState) { return (_escortState & escortState) != 0; } @@ -70,7 +72,6 @@ struct TC_GAME_API EscortAI : public ScriptedAI private: bool AssistPlayerInCombatAgainst(Unit* who); bool IsPlayerOrGroupInRange(); - void FillPointMovementListForCreature(); void AddEscortState(uint32 escortState) { _escortState |= escortState; } void RemoveEscortState(uint32 escortState) { _escortState &= ~escortState; } @@ -86,12 +87,10 @@ struct TC_GAME_API EscortAI : public ScriptedAI WaypointPath _path; bool _activeAttacker; // obsolete, determined by faction. - bool _running; // all creatures are walking by default (has flag MOVEMENTFLAG_WALK) bool _instantRespawn; // if creature should respawn instantly after escort over (if not, database respawntime are used) bool _returnToStart; // if creature can walk same path (loop) without despawn. Not for regular escort quests. bool _despawnAtEnd; bool _despawnAtFar; - bool _manualPath; bool _hasImmuneToNPCFlags; bool _started; bool _ended; |