From d78af570ea99c57d76ef70b2b4718bab1c21b092 Mon Sep 17 00:00:00 2001 From: OTCv8 Date: Fri, 8 Nov 2019 05:31:38 +0100 Subject: [PATCH] Updaded modaldialog and bot (added anti push) --- modules/game_bot/defaultconfig.lua | 1 + modules/game_bot/panels/attacking.lua | 9 +++- modules/game_bot/panels/healing.lua | 15 +++--- modules/game_bot/panels/war.lua | 62 +++++++++++++++++++++++ modules/game_bot/panels/waypoints.lua | 2 +- modules/game_hotkeys/hotkeys_extra.lua | 3 ++ modules/game_modaldialog/modaldialog.lua | 29 +++++++++-- modules/game_modaldialog/modaldialog.otui | 4 +- 8 files changed, 109 insertions(+), 16 deletions(-) diff --git a/modules/game_bot/defaultconfig.lua b/modules/game_bot/defaultconfig.lua index 59980b0..75b09f4 100644 --- a/modules/game_bot/defaultconfig.lua +++ b/modules/game_bot/defaultconfig.lua @@ -34,6 +34,7 @@ Panels.AttackItem(attackTab) Panels.AttackLeaderTarget(warTab) Panels.LimitFloor(warTab) +Panels.AntiPush(warTab) local waypoints = Panels.Waypoints(caveTab) local attacking = Panels.Attacking(caveTab) diff --git a/modules/game_bot/panels/attacking.lua b/modules/game_bot/panels/attacking.lua index 31d8982..de125a9 100644 --- a/modules/game_bot/panels/attacking.lua +++ b/modules/game_bot/panels/attacking.lua @@ -779,15 +779,18 @@ Panel local getMonsterConfig = function(monster) local name = monster:getName():lower() + local hasConfig = false + hasConfig = hasConfig or (monsters[name] ~= nil) if isConfigPassingConditions(monster, monsters[name]) then return monsters[name] end for i=1, 5 do + hasConfig = hasConfig or (monsters[name .. i] ~= nil) if isConfigPassingConditions(monster, monsters[name .. i]) then return monsters[name .. i] end end - if isConfigPassingConditions(monster, monsters["*"]) then + if not hasConfig and isConfigPassingConditions(monster, monsters["*"]) then return monsters["*"] end return nil @@ -1089,7 +1092,11 @@ Panel end end + target.ignoreByWaypoints = config.dontWalk if config.dontWalk then + if goForLoot() then + return + end return end diff --git a/modules/game_bot/panels/healing.lua b/modules/game_bot/panels/healing.lua index 74f5864..561b9a7 100644 --- a/modules/game_bot/panels/healing.lua +++ b/modules/game_bot/panels/healing.lua @@ -313,15 +313,15 @@ Panels.Eating = function(parent) widget:setOn(context.storage[panelName].enabled) end - if type(context.storage["autoEating" .. panelId]) ~= 'table' then - context.storage["autoEating" .. panelId] = {3725, 0, 0, 0, 0} + if type(context.storage[panelName].items) ~= 'table' then + context.storage[panelName].items = {3725, 0, 0, 0, 0} end for i=1,5 do ui.items:getChildByIndex(i).onItemChange = function(widget) - context.storage["autoEating" .. panelId][i] = widget:getItemId() + context.storage[panelName].items[i] = widget:getItemId() end - ui.items:getChildByIndex(i):setItemId(context.storage["autoEating" .. panelId][i]) + ui.items:getChildByIndex(i):setItemId(context.storage[panelName].items[i]) end context.macro(15000, function() @@ -329,16 +329,15 @@ Panels.Eating = function(parent) return end local candidates = {} - for i, item in pairs(context.storage["autoEating" .. panelId]) do + for i, item in pairs(context.storage[panelName].items) do if item >= 100 then table.insert(candidates, item) end end if #candidates == 0 then return - end - context.usewith(candidates[math.random(1, #candidates)], context.player) + end + context.use(candidates[math.random(1, #candidates)]) end) end -Panels.ManaItem = Panels.Mana diff --git a/modules/game_bot/panels/war.lua b/modules/game_bot/panels/war.lua index 68f0eda..bfc3d11 100644 --- a/modules/game_bot/panels/war.lua +++ b/modules/game_bot/panels/war.lua @@ -63,3 +63,65 @@ Panels.LimitFloor = function(parent) switch:setOn(context.storage.limitFloor) end +Panels.AntiPush = function(parent) + if not parent then + parent = context.panel + end + + local panelName = "antiPushPanel" + local ui = g_ui.createWidget("ItemsPanel", parent) + ui:setId(panelName) + + if not context.storage[panelName] then + context.storage[panelName] = {} + end + + ui.title:setText("Anti push") + ui.title:setOn(context.storage[panelName].enabled) + ui.title.onClick = function(widget) + context.storage[panelName].enabled = not context.storage[panelName].enabled + widget:setOn(context.storage[panelName].enabled) + end + + if type(context.storage[panelName].items) ~= 'table' then + context.storage[panelName].items = {3031, 3035, 0, 0, 0} + end + + for i=1,5 do + ui.items:getChildByIndex(i).onItemChange = function(widget) + context.storage[panelName].items[i] = widget:getItemId() + end + ui.items:getChildByIndex(i):setItemId(context.storage[panelName].items[i]) + end + + context.macro(100, function() + if not context.storage[panelName].enabled then + return + end + local tile = g_map.getTile(context.player:getPosition()) + if not tile then + return + end + local topItem = tile:getTopUseThing() + if topItem and topItem:isStackable() then + topItem = topItem:getId() + else + topItem = 0 + end + local candidates = {} + for i, item in pairs(context.storage[panelName].items) do + if item >= 100 and item ~= topItem and context.findItem(item) then + table.insert(candidates, item) + end + end + if #candidates == 0 then + return + end + if type(context.storage[panelName].lastItem) ~= 'number' or context.storage[panelName].lastItem > #candidates then + context.storage[panelName].lastItem = 1 + end + local item = context.findItem(candidates[context.storage[panelName].lastItem]) + g_game.move(item, context.player:getPosition(), 1) + context.storage[panelName].lastItem = context.storage[panelName].lastItem + 1 + end) +end diff --git a/modules/game_bot/panels/waypoints.lua b/modules/game_bot/panels/waypoints.lua index fe4f2bf..78c7426 100644 --- a/modules/game_bot/panels/waypoints.lua +++ b/modules/game_bot/panels/waypoints.lua @@ -578,7 +578,7 @@ Panel -- wait if attacking/following creature local attacking = g_game.getAttackingCreature() local following = g_game.getFollowingCreature() - if (attacking and context.getCreatureById(attacking:getId())) or (following and context.getCreatureById(following:getId())) then + if (attacking and context.getCreatureById(attacking:getId()) and not attacking.ignoreByWaypoints) or (following and context.getCreatureById(following:getId())) then executeNextMacroCall = false return end diff --git a/modules/game_hotkeys/hotkeys_extra.lua b/modules/game_hotkeys/hotkeys_extra.lua index 930fc0a..de95d17 100644 --- a/modules/game_hotkeys/hotkeys_extra.lua +++ b/modules/game_hotkeys/hotkeys_extra.lua @@ -37,6 +37,9 @@ function setupExtraHotkeys(combobox) nextChild = battlePanel:getFirstChild() end end + if not breakNext then + nextChild = battlePanel:getFirstChild() + end if nextChild and nextChild.creature ~= attackedCreature then g_game.attack(nextChild.creature) end diff --git a/modules/game_modaldialog/modaldialog.lua b/modules/game_modaldialog/modaldialog.lua index 7c89ca1..c842553 100644 --- a/modules/game_modaldialog/modaldialog.lua +++ b/modules/game_modaldialog/modaldialog.lua @@ -1,4 +1,7 @@ modalDialog = nil +lastDialogChoices = 0 +lastDialogChoice = 0 +lastDialogAnswer = 0 function init() g_ui.importStyle('modaldialog') @@ -53,7 +56,13 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c labelHeight = label:getHeight() end end - choiceList:focusNextChild() + if #choices > 0 then + if g_clock.millis() < lastDialogAnswer + 1000 and lastDialogChoices == #choices then + choiceList:focusChild(choiceList:getChildByIndex(lastDialogChoice)) + else + choiceList:focusChild(choiceList:getFirstChild()) + end + end local buttonsWidth = 0 for i = 1, #buttons do @@ -67,6 +76,8 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c local choice = 0xFF if focusedChoice then choice = focusedChoice.choiceId + lastDialogChoice = choiceList:getChildIndex(focusedChoice) + lastDialogAnswer = g_clock.millis() end g_game.answerModalDialog(id, buttonId, choice) destroyDialog() @@ -85,16 +96,20 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c local horizontalPadding = modalDialog:getPaddingLeft() + modalDialog:getPaddingRight() buttonsWidth = buttonsWidth + horizontalPadding - - modalDialog:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), modalDialog.minimumWidth))) - messageLabel:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), modalDialog.minimumWidth)) - horizontalPadding) - modalDialog:setHeight(modalDialog:getHeight() + additionalHeight + messageLabel:getHeight() - 8) + + local labelWidth = math.min(600, math.floor(message:len() * 1.5)) + modalDialog:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, labelWidth, modalDialog.minimumWidth))) + messageLabel:setTextWrap(true) + + modalDialog:setHeight(90 + additionalHeight + messageLabel:getHeight()) local enterFunc = function() local focusedChoice = choiceList:getFocusedChild() local choice = 0xFF if focusedChoice then choice = focusedChoice.choiceId + lastDialogChoice = choiceList:getChildIndex(focusedChoice) + lastDialogAnswer = g_clock.millis() end g_game.answerModalDialog(id, enterButton, choice) destroyDialog() @@ -105,6 +120,8 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c local choice = 0xFF if focusedChoice then choice = focusedChoice.choiceId + lastDialogChoice = choiceList:getChildIndex(focusedChoice) + lastDialogAnswer = g_clock.millis() end g_game.answerModalDialog(id, escapeButton, choice) destroyDialog() @@ -114,4 +131,6 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c modalDialog.onEnter = enterFunc modalDialog.onEscape = escapeFunc + + lastDialogChoices = #choices end \ No newline at end of file diff --git a/modules/game_modaldialog/modaldialog.otui b/modules/game_modaldialog/modaldialog.otui index 2f1824d..2d67bea 100644 --- a/modules/game_modaldialog/modaldialog.otui +++ b/modules/game_modaldialog/modaldialog.otui @@ -40,7 +40,7 @@ ModalButton < Button ModalDialog < MainWindow id: modalDialog size: 280 97 - &minimumWidth: 200 + &minimumWidth: 300 &maximumWidth: 600 &minimumChoices: 4 &maximumChoices: 10 @@ -49,6 +49,7 @@ ModalDialog < MainWindow id: messageLabel anchors.top: parent.top anchors.left: parent.left + anchors.right: parent.right text-align: left text-auto-resize: true text-wrap: true @@ -59,6 +60,7 @@ ModalDialog < MainWindow anchors.left: parent.left anchors.right: parent.right anchors.bottom: next.top + margin-bottom: 5 Panel id: buttonsPanel