From 654f71e75fc3be44b87dd546749278e96372d675 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 31 Jan 2013 00:50:20 -0200 Subject: [PATCH] Fix autowalk sometimes not being canceled --- src/client/game.cpp | 10 ++++++---- src/client/localplayer.cpp | 21 +++++++++++---------- src/client/localplayer.h | 7 ++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index d627b856..c6c2b215 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -533,9 +533,11 @@ bool Game::walk(Otc::Direction direction) if(isFollowing()) cancelFollow(); - // must cancel auto walking and wait next try - if(m_localPlayer->isAutoWalking()) { + // must cancel auto walking, and wait next try + if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) { m_protocolGame->sendStop(); + if(m_localPlayer->isAutoWalking()) + m_localPlayer->stopAutoWalk(); return false; } @@ -558,10 +560,10 @@ bool Game::walk(Otc::Direction direction) Position toPos = m_localPlayer->getPosition().translatedToDirection(direction); TilePtr toTile = g_map.getTile(toPos); // only do prewalks to walkable tiles (like grounds and not walls) - if(toTile && toTile->isWalkable()) + if(toTile && toTile->isWalkable()) { m_localPlayer->preWalk(direction); // check walk to another floor (e.g: when above 3 parcels) - else { + } else { // check if can walk to a lower floor auto canChangeFloorDown = [&]() -> bool { Position pos = toPos; diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 15342cab..5c9a7ee2 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -114,9 +114,9 @@ void LocalPlayer::walk(const Position& oldPos, const Position& newPos) // no prewalk was going on, this must be an server side automated walk else { m_walkPingTimer.restart(); - m_autoWalking = true; - if(m_autoWalkEndEvent) - m_autoWalkEndEvent->cancel(); + m_serverWalking = true; + if(m_serverWalkEndEvent) + m_serverWalkEndEvent->cancel(); Creature::walk(oldPos, newPos); } @@ -138,8 +138,8 @@ void LocalPlayer::preWalk(Otc::Direction direction) m_preWalking = true; - if(m_autoWalkEndEvent) - m_autoWalkEndEvent->cancel(); + if(m_serverWalkEndEvent) + m_serverWalkEndEvent->cancel(); // start walking to direction m_lastPrewalkDone = false; @@ -207,6 +207,7 @@ bool LocalPlayer::autoWalk(const Position& destination) result = g_map.findPath(m_position, destination, 50000, Otc::PathFindAllowNotSeenTiles); if(std::get<1>(result) != Otc::PathFindResultOk) { callLuaField("onAutoWalkFail", std::get<1>(result)); + stopAutoWalk(); return false; } @@ -295,11 +296,11 @@ void LocalPlayer::terminateWalk() auto self = asLocalPlayer(); - if(m_autoWalking) { - if(m_autoWalkEndEvent) - m_autoWalkEndEvent->cancel(); - m_autoWalkEndEvent = g_dispatcher.scheduleEvent([self] { - self->m_autoWalking = false; + if(m_serverWalking) { + if(m_serverWalkEndEvent) + m_serverWalkEndEvent->cancel(); + m_serverWalkEndEvent = g_dispatcher.scheduleEvent([self] { + self->m_serverWalking = false; }, 100); } } diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 10837252..de68fef5 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -93,7 +93,8 @@ public: bool hasSight(const Position& pos); bool isKnown() { return m_known; } bool isPreWalking() { return m_preWalking; } - bool isAutoWalking() { return m_autoWalking; } + bool isAutoWalking() { return m_autoWalkDestination.isValid(); } + bool isServerWalking() { return m_serverWalking; } bool isPremium() { return m_premium; } bool isPendingGame() { return m_pending; } @@ -122,13 +123,13 @@ private: Position m_lastPrewalkDestination; Position m_autoWalkDestination; Position m_lastAutoWalkPosition; - ScheduledEventPtr m_autoWalkEndEvent; + ScheduledEventPtr m_serverWalkEndEvent; ScheduledEventPtr m_autoWalkContinueEvent; ticks_t m_walkLockExpiration; int m_lastWalkPing; stdext::boolean m_preWalking; stdext::boolean m_lastPrewalkDone; - stdext::boolean m_autoWalking; + stdext::boolean m_serverWalking; stdext::boolean m_waitingWalkPong; stdext::boolean m_knownCompletePath;