From f910147296e3be2816cecd0d7a96606ce0f7a572 Mon Sep 17 00:00:00 2001 From: Benjamin Jackson <38561765+heyitsbench@users.noreply.github.com> Date: Tue, 24 Jun 2025 16:17:59 -0400 Subject: [PATCH] fix(Core/Movement): Use attack speed for leash reset period and only extend timer if in melee range or can't move freely. (#22350) Co-authored-by: ratkosrb <35845488+ratkosrb@users.noreply.github.com> --- .../game/Entities/Creature/Creature.cpp | 12 ++++++++--- src/server/game/Entities/Creature/Creature.h | 2 ++ .../TargetedMovementGenerator.cpp | 21 +++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index b74f98447..7b2ef3e94 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -788,9 +788,7 @@ void Creature::Update(uint32 diff) m_moveBackwardsMovementTime = urand(MOVE_BACKWARDS_CHECK_INTERVAL, MOVE_BACKWARDS_CHECK_INTERVAL * 3); } else - { m_moveBackwardsMovementTime -= diff; - } // Circling the target if (diff >= m_moveCircleMovementTime) @@ -799,9 +797,17 @@ void Creature::Update(uint32 diff) m_moveCircleMovementTime = urand(MOVE_CIRCLE_CHECK_INTERVAL, MOVE_CIRCLE_CHECK_INTERVAL * 2); } else - { m_moveCircleMovementTime -= diff; + + // Periodically check if able to move, if not, extend leash timer + if (diff >= m_extendLeashTime) + { + if (!CanFreeMove()) + UpdateLeashExtensionTime(); + m_extendLeashTime = EXTEND_LEASH_CHECK_INTERVAL; } + else + m_extendLeashTime -= diff; } // Call for assistance if not disabled diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 092cec299..c66b63e8f 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -396,8 +396,10 @@ public: bool IsFreeToMove(); static constexpr uint32 MOVE_CIRCLE_CHECK_INTERVAL = 3000; static constexpr uint32 MOVE_BACKWARDS_CHECK_INTERVAL = 2000; + static constexpr uint32 EXTEND_LEASH_CHECK_INTERVAL = 3000; uint32 m_moveCircleMovementTime = MOVE_CIRCLE_CHECK_INTERVAL; uint32 m_moveBackwardsMovementTime = MOVE_BACKWARDS_CHECK_INTERVAL; + uint32 m_extendLeashTime = EXTEND_LEASH_CHECK_INTERVAL; [[nodiscard]] bool HasSwimmingFlagOutOfCombat() const { diff --git a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp index 96ac2f1f5..7dec2d8ce 100644 --- a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp @@ -153,18 +153,20 @@ bool ChaseMovementGenerator::DoUpdate(T* owner, uint32 time_diff) MovementInform(owner); } - if (owner->movespline->Finalized()) - { // Mobs should chase you infinitely if you stop and wait every few seconds. - i_leashExtensionTimer.Update(time_diff); - if (i_leashExtensionTimer.Passed()) - { - i_leashExtensionTimer.Reset(5000); - if (cOwner) + if (cOwner) + { + if (owner->movespline->Finalized() && cOwner->IsWithinMeleeRange(target)) + { // Mobs should chase you infinitely if you stop and wait every few seconds. + i_leashExtensionTimer.Update(time_diff); + if (i_leashExtensionTimer.Passed()) + { + i_leashExtensionTimer.Reset(cOwner->GetAttackTime(BASE_ATTACK)); cOwner->UpdateLeashExtensionTime(); + } } + else if (i_recalculateTravel) + i_leashExtensionTimer.Reset(cOwner->GetAttackTime(BASE_ATTACK)); } - else if (i_recalculateTravel) - i_leashExtensionTimer.Reset(5000); // if the target moved, we have to consider whether to adjust if (!_lastTargetPosition || target->GetPosition() != _lastTargetPosition.value() || mutualChase != _mutualChase || !owner->IsWithinLOSInMap(target)) @@ -298,6 +300,7 @@ void ChaseMovementGenerator::DoInitialize(Creature* owner) i_path = nullptr; _lastTargetPosition.reset(); i_recheckDistance.Reset(0); + i_leashExtensionTimer.Reset(owner->GetAttackTime(BASE_ATTACK)); owner->SetWalk(false); owner->AddUnitState(UNIT_STATE_CHASE); }