diff --git a/src/client/creature.cpp b/src/client/creature.cpp index c6bc9ae44..b69cf2490 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -392,9 +392,6 @@ void Creature::walk(const Position& oldPos, const Position& newPos) m_walkTimer.restart(); m_walkedPixels = 0; - if (++m_walkSteps == 0) - m_walkSteps = 1; - // no direction need to be changed when the walk ends m_walkTurnDirection = Otc::InvalidDirection; @@ -701,7 +698,6 @@ void Creature::terminateWalk() const auto self = static_self_cast(); m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] { - self->m_walkSteps = 0; self->m_walkAnimationPhase = 0; self->m_walkFinishAnimEvent = nullptr; }, g_game.getServerBeat()); diff --git a/src/client/creature.h b/src/client/creature.h index 195be8a16..e806eb303 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -94,8 +94,6 @@ class Creature : public Thing void hideStaticSquare() { m_showStaticSquare = false; } // walk related - int getWalkSteps() const { return m_walkSteps; } - void setWalkSteps(uint8_t step) { m_walkSteps = step; } void turn(Otc::Direction direction); void jump(int height, int duration); void allowAppearWalk() { m_allowAppearWalk = true; } @@ -294,8 +292,6 @@ class Creature : public Thing uint8_t m_disableWalkAnimation{ 0 }; - uint8_t m_walkSteps{ 0 }; - // Mount Shader uint8_t m_mountShaderId{ 0 }; diff --git a/src/client/game.cpp b/src/client/game.cpp index 07e41fe38..ce86500c4 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -630,19 +630,9 @@ void Game::safeLogout() m_protocolGame->sendLogout(); } -bool Game::walk(const Otc::Direction direction, bool force) +bool Game::walk(const Otc::Direction direction) { - static ScheduledEventPtr nextWalkSchedule = nullptr; - - if (direction == Otc::InvalidDirection) { - if (nextWalkSchedule) { - nextWalkSchedule->cancel(); - nextWalkSchedule = nullptr; - } - return false; - } - - if (!canPerformGameAction()) + if (!canPerformGameAction() || direction == Otc::InvalidDirection) return false; // must cancel auto walking, and wait next try @@ -652,39 +642,32 @@ bool Game::walk(const Otc::Direction direction, bool force) return false; } - if (!force) { - if (nextWalkSchedule) - return false; + static ScheduledEventPtr nextWalkSchedule = nullptr; + static uint16_t steps = 0; + static Timer timer; - if (m_localPlayer->getWalkSteps() > 0) { - uint16_t delay = 0; - if (m_localPlayer->getWalkSteps() == 1) { - if (m_localPlayer->isWalking()) - return false; - - delay = m_walkFirstStepDelay; - } else if (direction != m_localPlayer->getDirection()) - delay = m_walkTurnDelay; - - if (delay > 0) { - nextWalkSchedule = g_dispatcher.scheduleEvent([this, direction] { - if (m_localPlayer) { - m_localPlayer->setWalkSteps(1); - walk(direction, true); - } - - nextWalkSchedule = nullptr; - }, delay); - return false; - } - } - } + if (nextWalkSchedule) nextWalkSchedule->cancel(); + nextWalkSchedule = g_dispatcher.scheduleEvent([this] { + nextWalkSchedule = nullptr; + steps = 0; + }, 150); // check we can walk and add new walk event if false if (!m_localPlayer->canWalk(direction)) { return false; } + if (steps == 1) { + if (timer.ticksElapsed() <= m_walkFirstStepDelay) + return false; + } else if (direction != m_localPlayer->getDirection()) { + if (timer.ticksElapsed() <= m_walkTurnDelay) + return false; + } + + ++steps; + timer.restart(); + const auto& toPos = m_localPlayer->getPosition().translatedToDirection(direction); // only do prewalks to walkable tiles (like grounds and not walls) diff --git a/src/client/game.h b/src/client/game.h index 53fe2b620..500bbe0f8 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -541,7 +541,7 @@ class Game void safeLogout(); // walk related - bool walk(const Otc::Direction direction, bool force = false); + bool walk(const Otc::Direction direction); void autoWalk(const std::vector& dirs, const Position& startPos); void forceWalk(const Otc::Direction direction); void turn(const Otc::Direction direction);