Fix autowalk sometimes not being canceled

This commit is contained in:
Eduardo Bart 2013-01-31 00:50:20 -02:00
parent 1bf77c35c6
commit 654f71e75f
3 changed files with 21 additions and 17 deletions

View File

@ -533,9 +533,11 @@ bool Game::walk(Otc::Direction direction)
if(isFollowing()) if(isFollowing())
cancelFollow(); cancelFollow();
// must cancel auto walking and wait next try // must cancel auto walking, and wait next try
if(m_localPlayer->isAutoWalking()) { if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) {
m_protocolGame->sendStop(); m_protocolGame->sendStop();
if(m_localPlayer->isAutoWalking())
m_localPlayer->stopAutoWalk();
return false; return false;
} }
@ -558,10 +560,10 @@ bool Game::walk(Otc::Direction direction)
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction); Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
TilePtr toTile = g_map.getTile(toPos); TilePtr toTile = g_map.getTile(toPos);
// only do prewalks to walkable tiles (like grounds and not walls) // only do prewalks to walkable tiles (like grounds and not walls)
if(toTile && toTile->isWalkable()) if(toTile && toTile->isWalkable()) {
m_localPlayer->preWalk(direction); m_localPlayer->preWalk(direction);
// check walk to another floor (e.g: when above 3 parcels) // check walk to another floor (e.g: when above 3 parcels)
else { } else {
// check if can walk to a lower floor // check if can walk to a lower floor
auto canChangeFloorDown = [&]() -> bool { auto canChangeFloorDown = [&]() -> bool {
Position pos = toPos; Position pos = toPos;

View File

@ -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 // no prewalk was going on, this must be an server side automated walk
else { else {
m_walkPingTimer.restart(); m_walkPingTimer.restart();
m_autoWalking = true; m_serverWalking = true;
if(m_autoWalkEndEvent) if(m_serverWalkEndEvent)
m_autoWalkEndEvent->cancel(); m_serverWalkEndEvent->cancel();
Creature::walk(oldPos, newPos); Creature::walk(oldPos, newPos);
} }
@ -138,8 +138,8 @@ void LocalPlayer::preWalk(Otc::Direction direction)
m_preWalking = true; m_preWalking = true;
if(m_autoWalkEndEvent) if(m_serverWalkEndEvent)
m_autoWalkEndEvent->cancel(); m_serverWalkEndEvent->cancel();
// start walking to direction // start walking to direction
m_lastPrewalkDone = false; m_lastPrewalkDone = false;
@ -207,6 +207,7 @@ bool LocalPlayer::autoWalk(const Position& destination)
result = g_map.findPath(m_position, destination, 50000, Otc::PathFindAllowNotSeenTiles); result = g_map.findPath(m_position, destination, 50000, Otc::PathFindAllowNotSeenTiles);
if(std::get<1>(result) != Otc::PathFindResultOk) { if(std::get<1>(result) != Otc::PathFindResultOk) {
callLuaField("onAutoWalkFail", std::get<1>(result)); callLuaField("onAutoWalkFail", std::get<1>(result));
stopAutoWalk();
return false; return false;
} }
@ -295,11 +296,11 @@ void LocalPlayer::terminateWalk()
auto self = asLocalPlayer(); auto self = asLocalPlayer();
if(m_autoWalking) { if(m_serverWalking) {
if(m_autoWalkEndEvent) if(m_serverWalkEndEvent)
m_autoWalkEndEvent->cancel(); m_serverWalkEndEvent->cancel();
m_autoWalkEndEvent = g_dispatcher.scheduleEvent([self] { m_serverWalkEndEvent = g_dispatcher.scheduleEvent([self] {
self->m_autoWalking = false; self->m_serverWalking = false;
}, 100); }, 100);
} }
} }

View File

@ -93,7 +93,8 @@ public:
bool hasSight(const Position& pos); bool hasSight(const Position& pos);
bool isKnown() { return m_known; } bool isKnown() { return m_known; }
bool isPreWalking() { return m_preWalking; } 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 isPremium() { return m_premium; }
bool isPendingGame() { return m_pending; } bool isPendingGame() { return m_pending; }
@ -122,13 +123,13 @@ private:
Position m_lastPrewalkDestination; Position m_lastPrewalkDestination;
Position m_autoWalkDestination; Position m_autoWalkDestination;
Position m_lastAutoWalkPosition; Position m_lastAutoWalkPosition;
ScheduledEventPtr m_autoWalkEndEvent; ScheduledEventPtr m_serverWalkEndEvent;
ScheduledEventPtr m_autoWalkContinueEvent; ScheduledEventPtr m_autoWalkContinueEvent;
ticks_t m_walkLockExpiration; ticks_t m_walkLockExpiration;
int m_lastWalkPing; int m_lastWalkPing;
stdext::boolean<false> m_preWalking; stdext::boolean<false> m_preWalking;
stdext::boolean<true> m_lastPrewalkDone; stdext::boolean<true> m_lastPrewalkDone;
stdext::boolean<false> m_autoWalking; stdext::boolean<false> m_serverWalking;
stdext::boolean<false> m_waitingWalkPong; stdext::boolean<false> m_waitingWalkPong;
stdext::boolean<false> m_knownCompletePath; stdext::boolean<false> m_knownCompletePath;