Fix autowalk sometimes not being canceled
This commit is contained in:
parent
1bf77c35c6
commit
654f71e75f
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<false> m_preWalking;
|
||||
stdext::boolean<true> m_lastPrewalkDone;
|
||||
stdext::boolean<false> m_autoWalking;
|
||||
stdext::boolean<false> m_serverWalking;
|
||||
stdext::boolean<false> m_waitingWalkPong;
|
||||
stdext::boolean<false> m_knownCompletePath;
|
||||
|
||||
|
|
Loading…
Reference in New Issue