From bb139955dcbfd479448e0fa9f722a428f2ba9dd6 Mon Sep 17 00:00:00 2001 From: BeniS Date: Tue, 8 Jan 2013 06:17:01 +1300 Subject: [PATCH] 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). --- modules/client_exit/exit.lua | 4 +- modules/corelib/ui/uicombobox.lua | 17 +++++++ modules/game_battle/battle.lua | 4 +- modules/game_cooldown/cooldown.lua | 6 ++- modules/game_interface/gameinterface.lua | 65 ++++++++++++++++++++---- modules/game_minimap/minimap.lua | 8 +-- modules/gamelib/player.lua | 48 ++++++++++++++++- src/otclient/CMakeLists.txt | 2 +- src/otclient/const.h | 4 +- src/otclient/game.cpp | 2 +- src/otclient/localplayer.cpp | 2 + src/otclient/luafunctions.cpp | 1 + 12 files changed, 139 insertions(+), 24 deletions(-) diff --git a/modules/client_exit/exit.lua b/modules/client_exit/exit.lua index 0208038b..14db6b66 100644 --- a/modules/client_exit/exit.lua +++ b/modules/client_exit/exit.lua @@ -4,7 +4,9 @@ local exitWindow local exitButton function Exit.init() - exitButton = TopMenu.addRightButton('exitButton', tr('Exit Client'), 'exit.png', Exit.tryExit) + if not g_game.isOnline() then + exitButton = TopMenu.addRightButton('exitButton', tr('Exit Client'), 'exit.png', Exit.tryExit) + end connect(g_game, { onGameStart = Exit.hide, diff --git a/modules/corelib/ui/uicombobox.lua b/modules/corelib/ui/uicombobox.lua index ecee16db..be1b3b17 100644 --- a/modules/corelib/ui/uicombobox.lua +++ b/modules/corelib/ui/uicombobox.lua @@ -5,6 +5,7 @@ function UIComboBox.create() local combobox = UIComboBox.internalCreate() combobox.options = {} combobox.currentIndex = -1 + combobox.mouseScroll = true return combobox end @@ -76,6 +77,9 @@ function UIComboBox:onMousePress(mousePos, mouseButton) end function UIComboBox:onMouseWheel(mousePos, direction) + if not self.mouseScroll then + return false + end if direction == MouseWheelUp and self.currentIndex > 1 then self:setCurrentIndex(self.currentIndex - 1) elseif direction == MouseWheelDown and self.currentIndex < #self.options then @@ -90,6 +94,19 @@ function UIComboBox:onStyleApply(styleName, styleNode) self:addOption(option) end end + for name,value in pairs(styleNode) do + if name == 'mouse-scroll' then + self.mouseScroll = value + end + end +end + +function UIComboBox:setMouseScroll(scroll) + self.mouseScroll = scroll +end + +function UIComboBox:canMouseScroll() + return self.mouseScroll end function UIComboBox:onOptionChange(optionText, optionData) diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index c173f3cb..46ef2463 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -230,10 +230,10 @@ function onMouseRelease(self, mousePosition, mouseButton) mouseWidget.cancelNextRelease = true g_game.look(self.creature) return true - elseif mouseButton == MouseRightButton and g_keyboard.isCtrlPressed() and not g_mouse.isPressed(MouseLeftButton) then + elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature) return true - elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then + elseif mouseButton == MouseLeftButton and not g_mouse.isPressed(MouseRightButton) then if self.isTarget then g_game.cancelAttack() else diff --git a/modules/game_cooldown/cooldown.lua b/modules/game_cooldown/cooldown.lua index 25ac82ac..2d5aaa54 100644 --- a/modules/game_cooldown/cooldown.lua +++ b/modules/game_cooldown/cooldown.lua @@ -78,7 +78,8 @@ function onSpellCooldown(iconId, duration) local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId] if not spellName then return end - local duration = duration - (g_game.getPing()/2) + local ping = g_game.getPing() + if ping > 0 then local duration = duration - (ping/2) end local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon) if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1] @@ -103,7 +104,8 @@ end function onSpellGroupCooldown(groupId, duration) if not SpellGroups[groupId] then return end - local duration = duration - (g_game.getPing()/2) + local ping = g_game.getPing() + if ping > 0 then local duration = duration - (ping/2) end local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId]) local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId]) if icon then diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 26597824..788e939b 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -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 diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index aef70933..73aad9b9 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -382,12 +382,8 @@ function onMinimapMouseRelease(self, mousePosition, mouseButton) end local pos = self:getPosition(mousePosition) if pos and mouseButton == MouseLeftButton and self:isPressed() then - local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), pos, 127, PathFindFlags.AllowNullTiles) - if #dirs == 0 then - modules.game_textmessage.displayStatusMessage(tr('There is no way.')) - return true - end - g_game.autoWalk(dirs) + local player = g_game.getLocalPlayer() + if not player:autoWalk(pos) then return false end return true end return false diff --git a/modules/gamelib/player.lua b/modules/gamelib/player.lua index 2abe6e06..7576926c 100644 --- a/modules/gamelib/player.lua +++ b/modules/gamelib/player.lua @@ -16,7 +16,9 @@ PlayerStates = { Cursed = 2048, PartyBuff = 4096, PzBlock = 8192, - Pz = 16384 + Pz = 16384, + Bleeding = 32768, + Hungry = 65536 } InventorySlotOther = 0 @@ -96,3 +98,47 @@ function Player:dismount() g_game.mount(false) end end + +function Player:getLastDestination() + return self.lastDestination +end + +function Player:setLastDestination(destination) + self.lastDestination = destination +end + +function Player:getWalkSteps(destination) + if not self.walkSteps or not destination then + return nil + end + return self.walkSteps[destination] +end + +function Player:setWalkStep(destination) + if not self.walkSteps then + self.walkSteps = {} + end + if destination then + if not self.walkSteps[destination] then + self.walkSteps[destination] = {} + end + table.insert(self.walkSteps[destination], true) + end +end + +function Player:clearWalkSteps() + self.walkSteps = {} +end + +function Player:autoWalk(destination) + self:clearWalkSteps() + self:setLastDestination(destination) + local dirs = g_map.findPath(self:getPosition(), destination, 127, PathFindFlags.AllowNullTiles) + + if #dirs == 0 then + modules.game_textmessage.displayStatusMessage(tr('There is no way.')) + return false + end + g_game.autoWalk(dirs) + return true +end \ No newline at end of file diff --git a/src/otclient/CMakeLists.txt b/src/otclient/CMakeLists.txt index 86c91ffe..45473b42 100644 --- a/src/otclient/CMakeLists.txt +++ b/src/otclient/CMakeLists.txt @@ -5,7 +5,7 @@ endif(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6) # otclient options add_definitions(-DOTCLIENT) -option(BOT_PROTECTION "Enable bot protection" ON) +option(BOT_PROTECTION "Enable bot protection" OFF) if(BOT_PROTECTION) add_definitions(-DBOT_PROTECTION) message(STATUS "Bot protection: ON") diff --git a/src/otclient/const.h b/src/otclient/const.h index a77d9c48..745cb392 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -255,7 +255,9 @@ namespace Otc IconCursed = 2048, IconPartyBuff = 4096, IconPzBlock = 8192, - IconPz = 16384 + IconPz = 16384, + IconBleeding = 32768, + IconHungry = 65536 }; enum MessageMode { diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index e7fb7253..22f6730c 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -158,7 +158,7 @@ void Game::processGameStart() m_protocolGame->sendPing(); disableBotCall(); } - }, 4000); + }, 3000); } } diff --git a/src/otclient/localplayer.cpp b/src/otclient/localplayer.cpp index c1284762..50768f26 100644 --- a/src/otclient/localplayer.cpp +++ b/src/otclient/localplayer.cpp @@ -160,6 +160,8 @@ void LocalPlayer::cancelWalk(Otc::Direction direction) // turn to the cancel direction if(direction != Otc::InvalidDirection) setDirection(direction); + + callLuaField("onCancelWalk", direction); } void LocalPlayer::stopWalk() diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index bacd6ded..cfe69c18 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -458,6 +458,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("isKnown", &LocalPlayer::isKnown); g_lua.bindClassMemberFunction("isPreWalking", &LocalPlayer::isPreWalking); g_lua.bindClassMemberFunction("hasSight", &LocalPlayer::hasSight); + g_lua.bindClassMemberFunction("isAutoWalking", &LocalPlayer::isAutoWalking); g_lua.registerClass(); g_lua.bindClassMemberFunction("clean", &Tile::clean);