diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 71de524c7e..5ccbcc044f 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -308,8 +308,10 @@ class TC_GAME_API UnitAI // Called when the dialog status between a player and the creature is requested. virtual uint32 GetDialogStatus(Player* /*player*/); + virtual void WaypointPathStarted(uint32 /*nodeId*/, uint32 /*pathId*/) { } virtual void WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/) { } virtual void WaypointReached(uint32 /*nodeId*/, uint32 /*pathId*/) { } + virtual void WaypointPathEnded(uint32 /*nodeId*/, uint32 /*pathId*/) { } private: UnitAI(UnitAI const& right) = delete; diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index a19f0bba73..6b2acb1d57 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -31,8 +31,8 @@ SmartAI::SmartAI(Creature* creature) : CreatureAI(creature), mIsCharmed(false), mFollowCreditType(0), mFollowArrivedTimer(0), mFollowCredit(0), mFollowArrivedEntry(0), mFollowDist(0.f), mFollowAngle(0.f), _escortState(SMART_ESCORT_NONE), _escortNPCFlags(0), _escortInvokerCheckTimer(1000), _currentWaypointNode(0), _waypointReached(false), _waypointPauseTimer(0), _waypointPauseForced(false), _repeatWaypointPath(false), - _OOCReached(false), _waypointPathEnded(false), mRun(true), mEvadeDisabled(false), mCanAutoAttack(true), mCanCombatMove(true), mInvincibilityHpLevel(0), mDespawnTime(0), mDespawnState(0), mJustReset(false), - mConditionsTimer(0), _gossipReturn(false) + _OOCReached(false), _waypointPathEnded(false), mRun(true), mEvadeDisabled(false), mCanAutoAttack(true), mCanCombatMove(true), mInvincibilityHpLevel(0), mDespawnTime(0), mDespawnState(0), mConditionsTimer(0), + _gossipReturn(false) { mHasConditions = sConditionMgr->HasConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, creature->GetEntry()); } @@ -129,7 +129,15 @@ bool SmartAI::LoadPath(uint32 entry) void SmartAI::PausePath(uint32 delay, bool forced) { if (!HasEscortState(SMART_ESCORT_ESCORTING)) + { + me->PauseMovement(delay, MOTION_SLOT_IDLE, forced); + if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + { + std::pair waypointInfo = me->GetCurrentWaypointInfo(); + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_PAUSED, nullptr, waypointInfo.first, waypointInfo.second); + } return; + } if (HasEscortState(SMART_ESCORT_PAUSED)) { @@ -156,7 +164,28 @@ void SmartAI::PausePath(uint32 delay, bool forced) void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail) { if (!HasEscortState(SMART_ESCORT_ESCORTING)) + { + std::pair waypointInfo = { 0, 0 }; + if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + waypointInfo = me->GetCurrentWaypointInfo(); + + if (mDespawnState != 2) + SetDespawnTime(DespawnTime); + + me->GetMotionMaster()->MoveIdle(); + + if (waypointInfo.first) + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, nullptr, waypointInfo.first, waypointInfo.second); + + if (!fail) + { + if (waypointInfo.first) + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, waypointInfo.first, waypointInfo.second); + if (mDespawnState == 1) + StartDespawn(); + } return; + } if (quest) mEscortQuestID = quest; @@ -393,6 +422,16 @@ bool SmartAI::IsEscortInvokerInRange() return true; } +///@todo move escort related logic +void SmartAI::WaypointPathStarted(uint32 nodeId, uint32 pathId) +{ + if (!HasEscortState(SMART_ESCORT_ESCORTING)) + { + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, nodeId, pathId); + return; + } +} + ///@todo Implement new smart event SMART_EVENT_WAYPOINT_STARTED void SmartAI::WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/) { @@ -400,6 +439,12 @@ void SmartAI::WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/) void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId) { + if (!HasEscortState(SMART_ESCORT_ESCORTING)) + { + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, nodeId, pathId); + return; + } + _currentWaypointNode = nodeId; GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, _currentWaypointNode, pathId); @@ -419,6 +464,16 @@ void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId) } } +///@todo move escort related logic +void SmartAI::WaypointPathEnded(uint32 nodeId, uint32 pathId) +{ + if (!HasEscortState(SMART_ESCORT_ESCORTING)) + { + GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, nodeId, pathId); + return; + } +} + void SmartAI::MovementInform(uint32 type, uint32 id) { if (type == POINT_MOTION_TYPE && id == SMART_ESCORT_LAST_OOC_POINT) @@ -452,10 +507,16 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/) me->AddUnitState(UNIT_STATE_EVADE); - GetScript()->ProcessEventsFor(SMART_EVENT_EVADE);//must be after aura clear so we can cast spells from db + GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); // must be after _EnterEvadeMode (spells, auras, ...) SetRun(mRun); - if (HasEscortState(SMART_ESCORT_ESCORTING)) + + if (Unit* owner = me->GetCharmerOrOwner()) + { + me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); + me->ClearUnitState(UNIT_STATE_EVADE); + } + else if (HasEscortState(SMART_ESCORT_ESCORTING)) { AddEscortState(SMART_ESCORT_RETURNING); ReturnToLastOOCPos(); @@ -466,11 +527,6 @@ void SmartAI::EnterEvadeMode(EvadeReason /*why*/) // evade is not cleared in MoveFollow, so we can't keep it me->ClearUnitState(UNIT_STATE_EVADE); } - else if (Unit* owner = me->GetCharmerOrOwner()) - { - me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); - me->ClearUnitState(UNIT_STATE_EVADE); - } else me->GetMotionMaster()->MoveTargetedHome(); @@ -544,11 +600,13 @@ void SmartAI::JustAppeared() mDespawnTime = 0; mDespawnState = 0; _escortState = SMART_ESCORT_NONE; + me->SetVisible(true); + if (me->GetFaction() != me->GetCreatureTemplate()->faction) me->RestoreFaction(); - mJustReset = true; - JustReachedHome(); + + GetScript()->OnReset(); GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); mFollowGuid.Clear(); // do not reset follower on Reset(), we need it after combat evade mFollowDist = 0; @@ -562,24 +620,18 @@ void SmartAI::JustAppeared() void SmartAI::JustReachedHome() { GetScript()->OnReset(); + GetScript()->ProcessEventsFor(SMART_EVENT_REACHED_HOME); - if (!mJustReset) + CreatureGroup* formation = me->GetFormation(); + if (!formation || formation->getLeader() == me || !formation->isFormed()) { - GetScript()->ProcessEventsFor(SMART_EVENT_REACHED_HOME); - - CreatureGroup* formation = me->GetFormation(); - if (!formation || formation->getLeader() == me || !formation->isFormed()) - { - if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE && me->GetWaypointPath()) - me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true); - else - me->ResumeMovement(); - } - else if (formation->isFormed()) - me->GetMotionMaster()->MoveIdle(); // wait the order of leader + if (me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_IDLE) != WAYPOINT_MOTION_TYPE && me->GetWaypointPath()) + me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true); + else + me->ResumeMovement(); } - - mJustReset = false; + else if (formation->isFormed()) + me->GetMotionMaster()->MoveIdle(); // wait the order of leader } void SmartAI::JustEngagedWith(Unit* enemy) diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index e381978c19..79e0ac716a 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -68,8 +68,10 @@ class TC_GAME_API SmartAI : public CreatureAI void StopFollow(bool complete); bool IsEscortInvokerInRange(); + void WaypointPathStarted(uint32 nodeId, uint32 pathId) override; void WaypointStarted(uint32 nodeId, uint32 pathId) override; void WaypointReached(uint32 nodeId, uint32 pathId) override; + void WaypointPathEnded(uint32 nodeId, uint32 pathId) override; void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker); SmartScript* GetScript() { return &mScript; } @@ -234,7 +236,6 @@ class TC_GAME_API SmartAI : public CreatureAI uint32 mDespawnTime; uint32 mDespawnState; - bool mJustReset; // Vehicle conditions bool mHasConditions; diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 4d6744ab93..66e1129d2a 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -3155,7 +3155,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui case SMART_EVENT_WAYPOINT_STOPPED: case SMART_EVENT_WAYPOINT_ENDED: { - if (!me || (e.event.waypoint.pointID && var0 != e.event.waypoint.pointID) || (e.event.waypoint.pathID && GetPathId() != e.event.waypoint.pathID)) + if (!me || (e.event.waypoint.pointID && var0 != e.event.waypoint.pointID) || (e.event.waypoint.pathID && var1 != e.event.waypoint.pathID)) return; ProcessAction(e, unit); break; diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 630316ef4f..5f9d4c3b9b 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -190,7 +190,8 @@ m_lootRecipient(), m_lootRecipientGroup(0), _skinner(), _pickpocketLootRestore(0 m_respawnDelay(300), m_corpseDelay(60), m_respawnradius(0.0f), m_boundaryCheckTime(2500), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_regenHealth(true), m_cannotReachTarget(false), m_cannotReachTimer(0), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), -m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_waypointID(0), m_path_id(0), m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(false), m_focusSpell(nullptr), m_focusDelay(0), m_shouldReacquireTarget(false), m_suppressedOrientation(0.0f) +m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), _waypointPathId(0), _currentWaypointNodeInfo(0, 0), +m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(false), m_focusSpell(nullptr), m_focusDelay(0), m_shouldReacquireTarget(false), m_suppressedOrientation(0.0f) { m_regenTimer = CREATURE_REGEN_INTERVAL; m_valuesCount = UNIT_END; @@ -2454,9 +2455,9 @@ bool Creature::LoadCreaturesAddon() SetMovementAnimKitId(cainfo->movementAnimKit); SetMeleeAnimKitId(cainfo->meleeAnimKit); - //Load Path + // Load Path if (cainfo->path_id != 0) - m_path_id = cainfo->path_id; + _waypointPathId = cainfo->path_id; if (!cainfo->auras.empty()) { diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 236f8bcfe2..210be5421b 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -286,11 +286,12 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma void GetTransportHomePosition(float& x, float& y, float& z, float& ori) const { m_transportHomePosition.GetPosition(x, y, z, ori); } Position const& GetTransportHomePosition() const { return m_transportHomePosition; } - uint32 GetWaypointPath() const { return m_path_id; } - void LoadPath(uint32 pathid) { m_path_id = pathid; } + uint32 GetWaypointPath() const { return _waypointPathId; } + void LoadPath(uint32 pathid) { _waypointPathId = pathid; } - uint32 GetCurrentWaypointID() const { return m_waypointID; } - void UpdateWaypointID(uint32 wpID) { m_waypointID = wpID; } + // nodeId, pathId + std::pair GetCurrentWaypointInfo() const { return _currentWaypointNodeInfo; } + void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId) { _currentWaypointNodeInfo = { nodeId, pathId }; } bool IsReturningHome() const; @@ -403,9 +404,10 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma void ForcedDespawn(uint32 timeMSToDespawn = 0, Seconds forceRespawnTimer = 0s); bool CheckNoGrayAggroConfig(uint32 playerLevel, uint32 creatureLevel) const; // No aggro from gray creatures - //WaypointMovementGenerator vars - uint32 m_waypointID; - uint32 m_path_id; + // Waypoint path + uint32 _waypointPathId; + std::pair _currentWaypointNodeInfo; + //Formation var CreatureGroup* m_formation; diff --git a/src/server/game/Entities/Creature/CreatureGroups.cpp b/src/server/game/Entities/Creature/CreatureGroups.cpp index dea3ed9a0f..cad954b756 100644 --- a/src/server/game/Entities/Creature/CreatureGroups.cpp +++ b/src/server/game/Entities/Creature/CreatureGroups.cpp @@ -243,7 +243,7 @@ void CreatureGroup::LeaderMoveTo(Position destination, uint32 id /*= 0*/, uint32 continue; if (itr->second->point_1) - if (m_leader->GetCurrentWaypointID() == itr->second->point_1 - 1 || m_leader->GetCurrentWaypointID() == itr->second->point_2 - 1) + if (m_leader->GetCurrentWaypointInfo().first == itr->second->point_1 || m_leader->GetCurrentWaypointInfo().first == itr->second->point_2) itr->second->follow_angle = float(M_PI) * 2 - itr->second->follow_angle; float angle = itr->second->follow_angle; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 63d1e301ff..229de660f0 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -10945,15 +10945,16 @@ void Unit::StopMoving() init.Stop(); } -void Unit::PauseMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/) +void Unit::PauseMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/, bool forced/* = true*/) { if (slot >= MAX_MOTION_SLOT) return; - if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(slot)) + if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot))) movementGenerator->Pause(timer); - StopMoving(); + if (forced) + StopMoving(); } void Unit::ResumeMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/) @@ -10961,7 +10962,7 @@ void Unit::ResumeMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/) if (slot >= MAX_MOTION_SLOT) return; - if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(slot)) + if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot))) movementGenerator->Resume(timer); } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 1727bbb87c..e0630f449e 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1771,7 +1771,7 @@ class TC_GAME_API Unit : public WorldObject bool IsStopped() const { return !(HasUnitState(UNIT_STATE_MOVING)); } void StopMoving(); - void PauseMovement(uint32 timer = 0, uint8 slot = 0); // timer in ms + void PauseMovement(uint32 timer = 0, uint8 slot = 0, bool forced = true); // timer in ms void ResumeMovement(uint32 timer = 0, uint8 slot = 0); // timer in ms void AddUnitMovementFlag(uint32 f) { m_movementInfo.AddMovementFlag(f); } diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index aed99b25ee..a5d6689298 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -155,17 +155,19 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const return top()->GetMovementGeneratorType(); } -MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const +MovementGeneratorType MotionMaster::GetMotionSlotType(MovementSlot slot) const { - if (!_slot[slot]) + if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot]) return MAX_MOTION_TYPE; - else - return _slot[slot]->GetMovementGeneratorType(); + + return _slot[slot]->GetMovementGeneratorType(); } -MovementGenerator* MotionMaster::GetMotionSlot(int slot) const +MovementGenerator* MotionMaster::GetMotionSlot(MovementSlot slot) const { - ASSERT(slot >= 0); + if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot]) + return nullptr; + return _slot[slot]; } diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index a6e704056b..00cdb5371c 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -110,8 +110,8 @@ class TC_GAME_API MotionMaster void MovementExpired(bool reset = true); MovementGeneratorType GetCurrentMovementGeneratorType() const; - MovementGeneratorType GetMotionSlotType(int slot) const; - MovementGenerator* GetMotionSlot(int slot) const; + MovementGeneratorType GetMotionSlotType(MovementSlot slot) const; + MovementGenerator* GetMotionSlot(MovementSlot slot) const; void PropagateSpeedChange(); diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index d8b0ed91a1..ff60fcb0c0 100755 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -60,6 +60,10 @@ void WaypointMovementGenerator::LoadPath(Creature* creature) } _nextMoveTime.Reset(1000); + + // inform AI + if (creature->AI()) + creature->AI()->WaypointPathStarted(1, _path->id); } void WaypointMovementGenerator::DoInitialize(Creature* creature) @@ -91,6 +95,7 @@ void WaypointMovementGenerator::OnArrived(Creature* creature) if (!_path || _path->nodes.empty()) return; + ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::OnArrived: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); WaypointNode const &waypoint = _path->nodes.at(_currentNode); if (waypoint.delay) { @@ -109,12 +114,10 @@ void WaypointMovementGenerator::OnArrived(Creature* creature) if (creature->AI()) { creature->AI()->MovementInform(WAYPOINT_MOTION_TYPE, _currentNode); - - ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::OnArrived: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); - creature->AI()->WaypointReached(_path->nodes[_currentNode].id, _path->id); + creature->AI()->WaypointReached(waypoint.id, _path->id); } - creature->UpdateWaypointID(_currentNode); + creature->UpdateCurrentWaypointInfo(waypoint.id, _path->id); } bool WaypointMovementGenerator::StartMove(Creature* creature) @@ -136,10 +139,11 @@ bool WaypointMovementGenerator::StartMove(Creature* creature) if (_isArrivalDone) { + ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); + WaypointNode const &waypoint = _path->nodes.at(_currentNode); + if ((_currentNode == _path->nodes.size() - 1) && !_repeating) // If that's our last waypoint { - WaypointNode const &waypoint = _path->nodes.at(_currentNode); - float x = waypoint.x; float y = waypoint.y; float z = waypoint.z; @@ -161,6 +165,11 @@ bool WaypointMovementGenerator::StartMove(Creature* creature) // else if (vehicle) - this should never happen, vehicle offsets are const } _done = true; + creature->UpdateCurrentWaypointInfo(0, 0); + + // inform AI + if (creature->AI()) + creature->AI()->WaypointPathEnded(waypoint.id, _path->id); return true; } @@ -168,12 +177,10 @@ bool WaypointMovementGenerator::StartMove(Creature* creature) // inform AI if (creature->AI()) - { - ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); - creature->AI()->WaypointStarted(_path->nodes[_currentNode].id, _path->id); - } + creature->AI()->WaypointStarted(waypoint.id, _path->id); } + ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); WaypointNode const &waypoint = _path->nodes.at(_currentNode); Position formationDest(waypoint.x, waypoint.y, waypoint.z, (waypoint.orientation && waypoint.delay) ? waypoint.orientation : 0.0f); @@ -246,16 +253,15 @@ bool WaypointMovementGenerator::DoUpdate(Creature* creature, uint32 di if (!_nextMoveTime.Passed()) { - _nextMoveTime.Update(diff); - if (_nextMoveTime.Passed()) - return StartMoveNow(creature); + if (creature->movespline->Finalized()) + { + _nextMoveTime.Update(diff); + if (_nextMoveTime.Passed()) + return StartMoveNow(creature); + } } else { - // Set home position at place on waypoint movement. - if (creature->GetTransGUID().IsEmpty()) - creature->SetHomePosition(creature->GetPosition()); - if (creature->movespline->Finalized()) { OnArrived(creature); @@ -264,10 +270,17 @@ bool WaypointMovementGenerator::DoUpdate(Creature* creature, uint32 di if (_nextMoveTime.Passed()) return StartMove(creature); } - else if (_recalculateSpeed) + else { - if (_nextMoveTime.Passed()) - StartMove(creature); + // Set home position at place on waypoint movement. + if (creature->GetTransGUID().IsEmpty()) + creature->SetHomePosition(creature->GetPosition()); + + if (_recalculateSpeed) + { + if (_nextMoveTime.Passed()) + StartMove(creature); + } } } return true; @@ -285,6 +298,7 @@ bool WaypointMovementGenerator::GetResetPos(Creature*, float& x, float if (!_path || _path->nodes.empty()) return false; + ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::GetResetPos: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id); WaypointNode const &waypoint = _path->nodes.at(_currentNode); x = waypoint.x; diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 4f84f0eb01..130f27b3da 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -2122,9 +2122,9 @@ public: float x, y, z; motionMaster->GetDestination(x, y, z); - for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i) + for (uint8 itr = 0; itr < MAX_MOTION_SLOT; ++itr) { - MovementGenerator* movementGenerator = motionMaster->GetMotionSlot(i); + MovementGenerator* movementGenerator = motionMaster->GetMotionSlot(MovementSlot(itr)); if (!movementGenerator) { handler->SendSysMessage("Empty"); diff --git a/src/server/scripts/Commands/cs_wp.cpp b/src/server/scripts/Commands/cs_wp.cpp index c2420ecfd5..65922fd948 100644 --- a/src/server/scripts/Commands/cs_wp.cpp +++ b/src/server/scripts/Commands/cs_wp.cpp @@ -270,7 +270,7 @@ public: stmt->setUInt32(0, guidLow); WorldDatabase.Execute(stmt); - target->UpdateWaypointID(0); + target->UpdateCurrentWaypointInfo(0, 0); stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_MOVEMENT_TYPE); stmt->setUInt8(0, uint8(IDLE_MOTION_TYPE));