diff --git a/src/client/creature.cpp b/src/client/creature.cpp index 61a7b1a89d..68fca6c58a 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -607,13 +607,22 @@ void Creature::updateWalk(const bool isPreWalking) updateWalkOffset(m_walkedPixels); updateWalkingTile(); - if (!isPreWalking && m_walkedPixels == g_gameConfig.getSpriteSize()) { - terminateWalk(); + if (m_walkedPixels == g_gameConfig.getSpriteSize()) { + terminateWalk(isPreWalking); } } -void Creature::terminateWalk() +void Creature::terminateWalk(bool onlyResetWalkAni) { + const auto self = static_self_cast(); + m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] { + self->m_walkAnimationPhase = 0; + self->m_walkFinishAnimEvent = nullptr; + }, g_game.getServerBeat()); + + if (onlyResetWalkAni) + return; + // remove any scheduled walk update if (m_walkUpdateEvent) { m_walkUpdateEvent->cancel(); @@ -634,12 +643,6 @@ void Creature::terminateWalk() m_walkedPixels = 0; m_walkOffset = {}; m_walking = false; - - const auto self = static_self_cast(); - m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] { - self->m_walkAnimationPhase = 0; - self->m_walkFinishAnimEvent = nullptr; - }, g_game.getServerBeat()); } void Creature::setHealthPercent(uint8_t healthPercent) diff --git a/src/client/creature.h b/src/client/creature.h index fb0314e0c0..c3951b441b 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -147,12 +147,11 @@ class Creature : public Thing } protected: - - virtual void onDeath(); virtual void updateWalkOffset(uint8_t totalPixelsWalked); virtual void updateWalk(bool isPreWalking = false); - virtual void terminateWalk(); + virtual void terminateWalk(bool onlyResetWalkAni = false); + void onDeath(); void onPositionChange(const Position& newPos, const Position& oldPos) override; bool m_walking{ false }; diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index a3906f47b3..34b8d44b22 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -204,9 +204,9 @@ void LocalPlayer::updateWalkOffset(uint8_t totalPixelsWalked) m_walkOffset.x = -totalPixelsWalked; } -void LocalPlayer::terminateWalk() +void LocalPlayer::terminateWalk(bool onlyResetWalkAni) { - Creature::terminateWalk(); + Creature::terminateWalk(onlyResetWalkAni); m_preWalking = false; } diff --git a/src/client/localplayer.h b/src/client/localplayer.h index a88efccf12..086869af01 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -117,10 +117,10 @@ class LocalPlayer : public Player protected: void walk(const Position& oldPos, const Position& newPos) override; - void stopWalk() override; void updateWalk(const bool /*isPreWalking*/ = false) override { Creature::updateWalk(m_preWalking); } + void stopWalk() override; void updateWalkOffset(uint8_t totalPixelsWalked) override; - void terminateWalk() override; + void terminateWalk(bool onlyResetWalkAni = false) override; friend class Game;