From 7ba22c44c3c4ef2154174a94731abce801445529 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 19:16:48 +0000 Subject: [PATCH] Fix: Distract spell stops target movement The Distract spell was causing the target to stop moving because it was forcing the target to face the caster. This was happening because the `SetFacingTo` function in `Spell::EffectDistract` was clearing the movement stack. This commit fixes the bug by removing the call to `SetFacingTo`, which prevents the movement stack from being cleared. A test case has been added to verify that the original movement is not interrupted. --- src/server/game/Spells/SpellEffects.cpp | 1 - src/test/CMakeLists.txt | 4 ++ .../server/game/Spells/SpellEffectsTest.cpp | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/server/game/Spells/SpellEffectsTest.cpp diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 7e44054907..794fbf65f1 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -2706,7 +2706,6 @@ void Spell::EffectDistract(SpellEffIndex /*effIndex*/) if (unitTarget->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_STUNNED | UNIT_STATE_FLEEING)) return; - unitTarget->SetFacingTo(unitTarget->GetAngle(destTarget)); /// @BUG Causes the player to stop moving. unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILLISECONDS); } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 62ae235783..1dbe77feda 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -14,6 +14,10 @@ CollectSourceFiles( PRIVATE_SOURCES ) +list(APPEND PRIVATE_SOURCES + "server/game/Spells/SpellEffectsTest.cpp" +) + include_directories( "mocks" ) diff --git a/src/test/server/game/Spells/SpellEffectsTest.cpp b/src/test/server/game/Spells/SpellEffectsTest.cpp new file mode 100644 index 0000000000..c82c378581 --- /dev/null +++ b/src/test/server/game/Spells/SpellEffectsTest.cpp @@ -0,0 +1,45 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "Mocks/WorldMock.h" +#include "Player.h" +#include "Spell.h" +#include "gtest/gtest.h" + +TEST(SpellEffectsTest, DistractDoesNotStopMovement) +{ + WorldMock world; + Player* player = new Player(nullptr); + player->Create(sObjectMgr->GenerateLowGuid(), nullptr); + + Unit* target = new Unit(false); + target->Create(sObjectMgr->GenerateLowGuid(), nullptr, 0, 0); + + target->GetMotionMaster()->MovePoint(1, 10.0f, 10.0f, 10.0f); + + // Verify that the target is moving and the stack size is 1 + ASSERT_EQ(target->GetMotionMaster()->size(), 1); + + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(1725); // Distract + Spell* spell = new Spell(player, spellInfo, TriggerCastFlags(TRIGGERED_NONE)); + spell->m_targets.SetUnitTarget(target); + + spell->EffectDistract(EFFECT_0); + + // Verify that the movement stack size is now 2, meaning the original movement was not cleared + EXPECT_EQ(target->GetMotionMaster()->size(), 2); +}