From 294a3a2789582e05a7847620173d533bd07e44e9 Mon Sep 17 00:00:00 2001 From: ccrs Date: Fri, 12 Jul 2019 20:06:27 +0200 Subject: Core/Unit: movement related corrections prior to getting Charmed --- src/server/game/Entities/Unit/Unit.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index cdb2c2ace75..c1ee51ef98c 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -11405,17 +11405,24 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au _oldFactionId = GetFaction(); SetFaction(charmer->GetFaction()); - // Set charmed - charmer->SetCharm(this, true); + // Pause any Idle movement + PauseMovement(0, 0, false); - if (GetTypeId() == TYPEID_UNIT) - { - PauseMovement(0, 0, false); - GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); + // Remove any active voluntary movement + GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); + // Stop any remaining spline, if no involuntary movement is found + auto criteria = [](MovementGenerator const* movement) -> bool + { + return movement->Priority == MOTION_PRIORITY_HIGHEST; + }; + if (!GetMotionMaster()->HasMovementGenerator(criteria)) StopMoving(); - } - else if (Player* player = ToPlayer()) + + // Set charmed + charmer->SetCharm(this, true); + + if (Player* player = ToPlayer()) { if (player->isAFK()) player->ToggleAFK(); -- cgit v1.2.3