mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
More fixes and edits!
* Fixed a bug with client_exit module button appearing on full reload. * Fixed the battle window to work properly now (left click: attack, right click: menu). * Added auto walk checker for more accurate aut walking: - It will always find the path now, except in rare occasions gets stuck running back and forward - Re-calculates path every 10 steps and also when you hit an object that cancels your step. - Right now this is just a temporary method. - Cancels the checker when you move or press escape (has to be done client-side). * Added a new setting to UIComboBox class 'mouse-scroll' to enable/disable mouse wheel scrolling. * Added support for no ping in cooldowns. * Added missing PlayerStates (hungry and bleeding).
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
WALK_AUTO_REPEAT_DELAY = 150
|
||||
WALK_STEPS_RETRY = 10
|
||||
|
||||
gameRootPanel = nil
|
||||
gameMapPanel = nil
|
||||
@@ -27,9 +28,17 @@ arrowKeys = {
|
||||
function init()
|
||||
g_ui.importStyle('styles/countwindow.otui')
|
||||
|
||||
connect(g_game, { onGameStart = show,
|
||||
onGameEnd = hide,
|
||||
onLoginAdvice = onLoginAdvice }, true)
|
||||
connect(g_game, {
|
||||
onGameStart = show,
|
||||
onGameEnd = hide,
|
||||
onLoginAdvice = onLoginAdvice,
|
||||
onWalk = onWalk,
|
||||
}, true)
|
||||
|
||||
connect(LocalPlayer, {
|
||||
onCancelWalk = onCancelWalk,
|
||||
onPositionChange = onPositionChange
|
||||
})
|
||||
|
||||
gameRootPanel = g_ui.displayUI('gameinterface.otui')
|
||||
gameRootPanel:hide()
|
||||
@@ -83,7 +92,7 @@ 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() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Escape', function() cancelAutoWalkCheck() 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)
|
||||
@@ -184,6 +193,45 @@ 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]
|
||||
@@ -233,6 +281,7 @@ 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)
|
||||
@@ -517,12 +566,10 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
|
||||
end
|
||||
|
||||
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
||||
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), autoWalkPos, 127, PathFindFlags.AllowNullTiles)
|
||||
if #dirs == 0 then
|
||||
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
|
||||
return true
|
||||
local player = g_game.getLocalPlayer()
|
||||
if not player:autoWalk(autoWalkPos) then
|
||||
return false
|
||||
end
|
||||
g_game.autoWalk(dirs)
|
||||
return true
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user