Auto walker update must be done from C++ not lua due to bot protection.

* Moved the auto walk checker to the source.
* Implemented a temporary fix for findPath method (will now choose other tiles over null tiles).
This commit is contained in:
BeniS
2013-01-09 04:32:37 +13:00
parent 493202afcf
commit a1a8d28f5c
11 changed files with 84 additions and 105 deletions

View File

@@ -31,15 +31,9 @@ function init()
connect(g_game, {
onGameStart = show,
onGameEnd = hide,
onLoginAdvice = onLoginAdvice,
onWalk = onWalk
onLoginAdvice = onLoginAdvice
}, true)
connect(LocalPlayer, {
onCancelWalk = onCancelWalk,
onPositionChange = onPositionChange
})
gameRootPanel = g_ui.displayUI('gameinterface.otui')
gameRootPanel:hide()
gameRootPanel:lower()
@@ -92,13 +86,12 @@ function bindKeys()
g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Escape', function() cancelAutoWalkCheck() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel, 250)
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel, 250)
g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+L', logout, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+;', toggleDash, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+.', toggleAspectRatio, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+N', function() gameMapPanel:setDrawTexts(not gameMapPanel:isDrawingTexts()) end, gameRootPanel)
end
@@ -193,45 +186,6 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end
function onWalk(dir)
cancelAutoWalkCheck()
end
function onPositionChange(newPos, oldPos)
checkAutoWalking()
end
function onCancelWalk(dir)
checkAutoWalking(true)
end
function checkAutoWalking(stepCancelled)
local stepCancelled = stepCancelled or false
local player = g_game.getLocalPlayer()
if not player:isAutoWalking() then
player:clearWalkSteps()
end
local lastDestination = player:getLastDestination()
if not lastDestination then
return -- auto walk has been cancelled
end
player:setWalkStep(lastDestination)
local playerPos = player:getPosition()
local walkSteps = player:getWalkSteps(lastDestination)
if (not table.empty(walkSteps) and #walkSteps >= WALK_STEPS_RETRY) or stepCancelled then
if lastDestination then player:autoWalk(lastDestination) end
end
end
function cancelAutoWalkCheck()
local player = g_game.getLocalPlayer()
player:setLastDestination(nil) -- cancel retries
player:clearWalkSteps()
end
function smartWalk(defaultDir)
local rebindKey = false
local lastKey = arrowKeys[lastWalkDir]
@@ -281,7 +235,6 @@ function smartWalk(defaultDir)
else
g_game.walk(dir)
end
cancelAutoWalkCheck() -- cancel the auto walker check
if rebindKey then
g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastWalkDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
@@ -565,12 +518,14 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
end
end
local player = g_game.getLocalPlayer()
player:stopAutoWalkUpdate()
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
local player = g_game.getLocalPlayer()
if not player:autoWalk(autoWalkPos) then
return false
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
return true
end
return true
end
return false

View File

@@ -86,7 +86,6 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
local ret = modules.game_interface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
if ret then
modules.game_interface.cancelAutoWalkCheck()
self.cancelNextRelease = true
end

View File

@@ -87,7 +87,6 @@ function UIItem:onMouseRelease(mousePosition, mouseButton)
self.cancelNextRelease = true
return true
elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then
modules.game_interface.cancelAutoWalkCheck()
return true
end
return false