| @@ -0,0 +1,24 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | if type(context.UI) ~= "table" then | |
| 3 | + | context.UI = {} | |
| 4 | + | end | |
| 5 | + | local UI = context.UI | |
| 6 | + | ||
| 7 | + | UI.createWidget = function(name, parent) | |
| 8 | + | if parent == nil then | |
| 9 | + | parent = context.panel | |
| 10 | + | end | |
| 11 | + | local widget = g_ui.createWidget(name, parent) | |
| 12 | + | widget.botWidget = true | |
| 13 | + | return widget | |
| 14 | + | end | |
| 15 | + | ||
| 16 | + | UI.createWindow = function(name) | |
| 17 | + | local widget = g_ui.createWidget(name, g_ui.getRootWidget()) | |
| 18 | + | widget.botWidget = true | |
| 19 | + | widget:show() | |
| 20 | + | widget:raise() | |
| 21 | + | widget:focus() | |
| 22 | + | return widget | |
| 23 | + | end | |
| 24 | + |
| @@ -0,0 +1,273 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | if type(context.UI) ~= "table" then | |
| 3 | + | context.UI = {} | |
| 4 | + | end | |
| 5 | + | local UI = context.UI | |
| 6 | + | ||
| 7 | + | UI.Button = function(text, callback, parent) | |
| 8 | + | local widget = UI.createWidget("BotButton", parent) | |
| 9 | + | widget:setText(text) | |
| 10 | + | widget.onClick = callback | |
| 11 | + | return widget | |
| 12 | + | end | |
| 13 | + | ||
| 14 | + | ||
| 15 | + | UI.Config = function(parent) | |
| 16 | + | return UI.createWidget("BotConfig", parent) | |
| 17 | + | end | |
| 18 | + | ||
| 19 | + | -- call :setItems(table) to set items, call :getItems() to get them | |
| 20 | + | -- unique if true, won't allow duplicates | |
| 21 | + | -- callback (can be nil) gets table with new item list, eg: {{id=2160, count=1}, {id=268, count=100}, {id=269, count=20}} | |
| 22 | + | UI.Container = function(callback, unique, parent, widget) | |
| 23 | + | if not widget then | |
| 24 | + | widget = UI.createWidget("BotContainer", parent) | |
| 25 | + | end | |
| 26 | + | ||
| 27 | + | local oldItems = {} | |
| 28 | + | ||
| 29 | + | local updateItems = function() | |
| 30 | + | local items = widget:getItems() | |
| 31 | + | ||
| 32 | + | -- callback part | |
| 33 | + | local somethingNew = (#items ~= #oldItems) | |
| 34 | + | for i, item in ipairs(items) do | |
| 35 | + | if type(oldItems[i]) ~= "table" then | |
| 36 | + | somethingNew = true | |
| 37 | + | break | |
| 38 | + | end | |
| 39 | + | if oldItems[i].id ~= item.id or oldItems[i].count ~= item.count then | |
| 40 | + | somethingNew = true | |
| 41 | + | break | |
| 42 | + | end | |
| 43 | + | end | |
| 44 | + | ||
| 45 | + | if somethingNew then | |
| 46 | + | oldItems = items | |
| 47 | + | callback(widget, items) | |
| 48 | + | end | |
| 49 | + | ||
| 50 | + | widget:setItems(items) | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | widget.setItems = function(self, items) | |
| 54 | + | if type(self) == 'table' then | |
| 55 | + | items = self | |
| 56 | + | end | |
| 57 | + | local itemsToShow = math.max(10, #items + 2) | |
| 58 | + | if itemsToShow % 5 ~= 0 then | |
| 59 | + | itemsToShow = itemsToShow + 5 - itemsToShow % 5 | |
| 60 | + | end | |
| 61 | + | widget.items:destroyChildren() | |
| 62 | + | for i = 1, itemsToShow do | |
| 63 | + | local widget = g_ui.createWidget("BotItem", widget.items) | |
| 64 | + | if type(items[i]) == 'number' then | |
| 65 | + | items[i] = {id=items[i], count=1} | |
| 66 | + | end | |
| 67 | + | if type(items[i]) == 'table' then | |
| 68 | + | widget:setItem(Item.create(items[i].id, items[i].count)) | |
| 69 | + | end | |
| 70 | + | end | |
| 71 | + | oldItems = items | |
| 72 | + | for i, child in ipairs(widget.items:getChildren()) do | |
| 73 | + | child.onItemChange = updateItems | |
| 74 | + | end | |
| 75 | + | end | |
| 76 | + | ||
| 77 | + | widget.getItems = function() | |
| 78 | + | local items = {} | |
| 79 | + | local duplicates = {} | |
| 80 | + | for i, child in ipairs(widget.items:getChildren()) do | |
| 81 | + | if child:getItemId() >= 100 then | |
| 82 | + | if not duplicates[child:getItemId()] or not unique then | |
| 83 | + | table.insert(items, {id=child:getItemId(), count=child:getItemCountOrSubType()}) | |
| 84 | + | duplicates[child:getItemId()] = true | |
| 85 | + | end | |
| 86 | + | end | |
| 87 | + | end | |
| 88 | + | return items | |
| 89 | + | end | |
| 90 | + | ||
| 91 | + | widget:setItems({}) | |
| 92 | + | ||
| 93 | + | return widget | |
| 94 | + | end | |
| 95 | + | ||
| 96 | + | UI.DualScrollPanel = function(params, callback, parent) -- callback = function(widget, newParams) | |
| 97 | + | --[[ params: | |
| 98 | + | on - bool, | |
| 99 | + | text - string, | |
| 100 | + | title - string, | |
| 101 | + | min - number, | |
| 102 | + | max - number, | |
| 103 | + | ]] | |
| 104 | + | params.title = params.title or "title" | |
| 105 | + | params.text = params.text or "" | |
| 106 | + | params.min = params.min or 20 | |
| 107 | + | params.max = params.max or 80 | |
| 108 | + | ||
| 109 | + | local widget = UI.createWidget('DualScrollPanel', parent) | |
| 110 | + | ||
| 111 | + | widget.title:setOn(params.on) | |
| 112 | + | widget.title.onClick = function() | |
| 113 | + | params.on = not params.on | |
| 114 | + | widget.title:setOn(params.on) | |
| 115 | + | if callback then | |
| 116 | + | callback(widget, params) | |
| 117 | + | end | |
| 118 | + | end | |
| 119 | + | ||
| 120 | + | widget.text:setText(params.text or "") | |
| 121 | + | widget.text.onTextChange = function(widget, text) | |
| 122 | + | params.text = text | |
| 123 | + | if callback then | |
| 124 | + | callback(widget, params) | |
| 125 | + | end | |
| 126 | + | end | |
| 127 | + | ||
| 128 | + | local update = function(dontSignal) | |
| 129 | + | widget.title:setText("" .. params.min .. "% <= " .. params.title .. " <= " .. params.max .. "%") | |
| 130 | + | if callback and not dontSignal then | |
| 131 | + | callback(widget, params) | |
| 132 | + | end | |
| 133 | + | end | |
| 134 | + | ||
| 135 | + | widget.scroll1:setValue(params.min) | |
| 136 | + | widget.scroll2:setValue(params.max) | |
| 137 | + | ||
| 138 | + | widget.scroll1.onValueChange = function(scroll, value) | |
| 139 | + | params.min = value | |
| 140 | + | update() | |
| 141 | + | end | |
| 142 | + | widget.scroll2.onValueChange = function(scroll, value) | |
| 143 | + | params.max = value | |
| 144 | + | update() | |
| 145 | + | end | |
| 146 | + | update(true) | |
| 147 | + | end | |
| 148 | + | ||
| 149 | + | UI.DualScrollItemPanel = function(params, callback, parent) -- callback = function(widget, newParams) | |
| 150 | + | --[[ params: | |
| 151 | + | on - bool, | |
| 152 | + | item - number, | |
| 153 | + | subType - number, | |
| 154 | + | title - string, | |
| 155 | + | min - number, | |
| 156 | + | max - number, | |
| 157 | + | ]] | |
| 158 | + | params.title = params.title or "title" | |
| 159 | + | params.item = params.item or 0 | |
| 160 | + | params.subType = params.subType or 0 | |
| 161 | + | params.min = params.min or 20 | |
| 162 | + | params.max = params.max or 80 | |
| 163 | + | ||
| 164 | + | local widget = UI.createWidget('DualScrollItemPanel', parent) | |
| 165 | + | ||
| 166 | + | widget.title:setOn(params.on) | |
| 167 | + | widget.title.onClick = function() | |
| 168 | + | params.on = not params.on | |
| 169 | + | widget.title:setOn(params.on) | |
| 170 | + | if callback then | |
| 171 | + | callback(widget, params) | |
| 172 | + | end | |
| 173 | + | end | |
| 174 | + | ||
| 175 | + | widget.item:setItem(Item.create(params.item, params.subType)) | |
| 176 | + | widget.item.onItemChange = function() | |
| 177 | + | params.item = widget.item:getItemId() | |
| 178 | + | params.subType = widget.item:getItemSubType() | |
| 179 | + | if callback then | |
| 180 | + | callback(widget, params) | |
| 181 | + | end | |
| 182 | + | end | |
| 183 | + | ||
| 184 | + | local update = function(dontSignal) | |
| 185 | + | widget.title:setText("" .. params.min .. "% <= " .. params.title .. " <= " .. params.max .. "%") | |
| 186 | + | if callback and not dontSignal then | |
| 187 | + | callback(widget, params) | |
| 188 | + | end | |
| 189 | + | end | |
| 190 | + | ||
| 191 | + | widget.scroll1:setValue(params.min) | |
| 192 | + | widget.scroll2:setValue(params.max) | |
| 193 | + | ||
| 194 | + | widget.scroll1.onValueChange = function(scroll, value) | |
| 195 | + | params.min = value | |
| 196 | + | update() | |
| 197 | + | end | |
| 198 | + | widget.scroll2.onValueChange = function(scroll, value) | |
| 199 | + | params.max = value | |
| 200 | + | update() | |
| 201 | + | end | |
| 202 | + | update(true) | |
| 203 | + | end | |
| 204 | + | ||
| 205 | + | UI.Label = function(text, parent) | |
| 206 | + | local label = UI.createWidget('BotLabel', parent) | |
| 207 | + | label:setText(text) | |
| 208 | + | return label | |
| 209 | + | end | |
| 210 | + | ||
| 211 | + | UI.Separator = function(parent) | |
| 212 | + | local separator = UI.createWidget('BotSeparator', parent) | |
| 213 | + | return separator | |
| 214 | + | end | |
| 215 | + | ||
| 216 | + | UI.TextEdit = function(text, callback, parent) | |
| 217 | + | local widget = UI.createWidget('BotTextEdit', parent) | |
| 218 | + | widget.onTextChange = callback | |
| 219 | + | widget:setText(text) | |
| 220 | + | return widget | |
| 221 | + | end | |
| 222 | + | ||
| 223 | + | UI.TwoItemsAndSlotPanel = function(params, callback, parent) | |
| 224 | + | --[[ params: | |
| 225 | + | on - bool, | |
| 226 | + | title - string, | |
| 227 | + | item1 - number, | |
| 228 | + | item2 - number, | |
| 229 | + | slot - number, | |
| 230 | + | ]] | |
| 231 | + | params.title = params.title or "title" | |
| 232 | + | params.item1 = params.item1 or 0 | |
| 233 | + | params.item2 = params.item2 or 0 | |
| 234 | + | params.slot = params.slot or 1 | |
| 235 | + | ||
| 236 | + | local widget = UI.createWidget("TwoItemsAndSlotPanel", parent) | |
| 237 | + | ||
| 238 | + | widget.title:setText(params.title) | |
| 239 | + | widget.title:setOn(params.on) | |
| 240 | + | widget.title.onClick = function() | |
| 241 | + | params.on = not params.on | |
| 242 | + | widget.title:setOn(params.on) | |
| 243 | + | if callback then | |
| 244 | + | callback(widget, params) | |
| 245 | + | end | |
| 246 | + | end | |
| 247 | + | ||
| 248 | + | widget.slot:setCurrentIndex(params.slot) | |
| 249 | + | widget.slot.onOptionChange = function() | |
| 250 | + | params.slot = widget.slot.currentIndex | |
| 251 | + | if callback then | |
| 252 | + | callback(widget, params) | |
| 253 | + | end | |
| 254 | + | end | |
| 255 | + | ||
| 256 | + | widget.item1:setItemId(params.item1) | |
| 257 | + | widget.item1.onItemChange = function() | |
| 258 | + | params.item1 = widget.item1:getItemId() | |
| 259 | + | if callback then | |
| 260 | + | callback(widget, params) | |
| 261 | + | end | |
| 262 | + | end | |
| 263 | + | ||
| 264 | + | widget.item2:setItemId(params.item2) | |
| 265 | + | widget.item2.onItemChange = function() | |
| 266 | + | params.item2 = widget.item2:getItemId() | |
| 267 | + | if callback then | |
| 268 | + | callback(widget, params) | |
| 269 | + | end | |
| 270 | + | end | |
| 271 | + | ||
| 272 | + | return widget | |
| 273 | + | end |
| @@ -0,0 +1,135 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | ||
| 3 | + | -- DO NOT USE THIS CODE. | |
| 4 | + | -- IT'S ONLY HERE FOR BACKWARD COMPATIBILITY, MAY BE REMOVED IN THE FUTURE | |
| 5 | + | ||
| 6 | + | context.createWidget = function(name, parent) | |
| 7 | + | if parent == nil then | |
| 8 | + | parent = context.panel | |
| 9 | + | end | |
| 10 | + | g_ui.createWidget(name, parent) | |
| 11 | + | end | |
| 12 | + | ||
| 13 | + | context.setupUI = function(otml, parent) | |
| 14 | + | if parent == nil then | |
| 15 | + | parent = context.panel | |
| 16 | + | end | |
| 17 | + | local widget = g_ui.loadUIFromString(otml, parent) | |
| 18 | + | widget.botWidget = true | |
| 19 | + | return widget | |
| 20 | + | end | |
| 21 | + | ||
| 22 | + | context.importStyle = function(otml) | |
| 23 | + | if type(otml) ~= "string" then | |
| 24 | + | return error("Invalid parameter for importStyle, should be string") | |
| 25 | + | end | |
| 26 | + | if otml:find(".otui") and not otml:find("\n") then | |
| 27 | + | return g_ui.importStyle(context.configDir .. "/" .. otml) | |
| 28 | + | end | |
| 29 | + | return g_ui.importStyleFromString(otml) | |
| 30 | + | end | |
| 31 | + | ||
| 32 | + | context.addTab = function(name) | |
| 33 | + | local tab = context.tabs:getTab(name) | |
| 34 | + | if tab then -- return existing tab | |
| 35 | + | return tab.tabPanel.content | |
| 36 | + | end | |
| 37 | + | ||
| 38 | + | local smallTabs = #(context.tabs.tabs) >= 5 | |
| 39 | + | local newTab = context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content | |
| 40 | + | context.tabs:setOn(true) | |
| 41 | + | if smallTabs then | |
| 42 | + | for k,tab in pairs(context.tabs.tabs) do | |
| 43 | + | tab:setFont('small-9px') | |
| 44 | + | end | |
| 45 | + | end | |
| 46 | + | ||
| 47 | + | return newTab | |
| 48 | + | end | |
| 49 | + | context.getTab = context.addTab | |
| 50 | + | ||
| 51 | + | context.setDefaultTab = function(name) | |
| 52 | + | local tab = context.addTab(name) | |
| 53 | + | context.panel = tab | |
| 54 | + | end | |
| 55 | + | ||
| 56 | + | context.addSwitch = function(id, text, onClickCallback, parent) | |
| 57 | + | if not parent then | |
| 58 | + | parent = context.panel | |
| 59 | + | end | |
| 60 | + | local switch = g_ui.createWidget('BotSwitch', parent) | |
| 61 | + | switch:setId(id) | |
| 62 | + | switch:setText(text) | |
| 63 | + | switch.onClick = onClickCallback | |
| 64 | + | return switch | |
| 65 | + | end | |
| 66 | + | ||
| 67 | + | context.addButton = function(id, text, onClickCallback, parent) | |
| 68 | + | if not parent then | |
| 69 | + | parent = context.panel | |
| 70 | + | end | |
| 71 | + | local button = g_ui.createWidget('BotButton', parent) | |
| 72 | + | button:setId(id) | |
| 73 | + | button:setText(text) | |
| 74 | + | button.onClick = onClickCallback | |
| 75 | + | return button | |
| 76 | + | end | |
| 77 | + | ||
| 78 | + | context.addLabel = function(id, text, parent) | |
| 79 | + | if not parent then | |
| 80 | + | parent = context.panel | |
| 81 | + | end | |
| 82 | + | local label = g_ui.createWidget('BotLabel', parent) | |
| 83 | + | label:setId(id) | |
| 84 | + | label:setText(text) | |
| 85 | + | return label | |
| 86 | + | end | |
| 87 | + | ||
| 88 | + | context.addTextEdit = function(id, text, onTextChangeCallback, parent) | |
| 89 | + | if not parent then | |
| 90 | + | parent = context.panel | |
| 91 | + | end | |
| 92 | + | local widget = g_ui.createWidget('BotTextEdit', parent) | |
| 93 | + | widget:setId(id) | |
| 94 | + | widget.onTextChange = onTextChangeCallback | |
| 95 | + | widget:setText(text) | |
| 96 | + | return widget | |
| 97 | + | end | |
| 98 | + | ||
| 99 | + | context.addSeparator = function(id, parent) | |
| 100 | + | if not parent then | |
| 101 | + | parent = context.panel | |
| 102 | + | end | |
| 103 | + | local separator = g_ui.createWidget('BotSeparator', parent) | |
| 104 | + | separator:setId(id) | |
| 105 | + | return separator | |
| 106 | + | end | |
| 107 | + | ||
| 108 | + | context._addMacroSwitch = function(name, keys, parent) | |
| 109 | + | if not parent then | |
| 110 | + | parent = context.panel | |
| 111 | + | end | |
| 112 | + | local text = name | |
| 113 | + | if keys:len() > 0 then | |
| 114 | + | text = name .. " [" .. keys .. "]" | |
| 115 | + | end | |
| 116 | + | local switch = context.addSwitch("macro_" .. #context._macros, text, function(widget) | |
| 117 | + | context.storage._macros[name] = not context.storage._macros[name] | |
| 118 | + | widget:setOn(context.storage._macros[name]) | |
| 119 | + | end, parent) | |
| 120 | + | switch:setOn(context.storage._macros[name]) | |
| 121 | + | return switch | |
| 122 | + | end | |
| 123 | + | ||
| 124 | + | context._addHotkeySwitch = function(name, keys, parent) | |
| 125 | + | if not parent then | |
| 126 | + | parent = context.panel | |
| 127 | + | end | |
| 128 | + | local text = name | |
| 129 | + | if keys:len() > 0 then | |
| 130 | + | text = name .. " [" .. keys .. "]" | |
| 131 | + | end | |
| 132 | + | local switch = context.addSwitch("hotkey_" .. #context._hotkeys, text, nil, parent) | |
| 133 | + | switch:setOn(false) | |
| 134 | + | return switch | |
| 135 | + | end |
| @@ -0,0 +1,49 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | if type(context.UI) ~= "table" then | |
| 3 | + | context.UI = {} | |
| 4 | + | end | |
| 5 | + | local UI = context.UI | |
| 6 | + | ||
| 7 | + | UI.EditorWindow = function(text, options, callback) | |
| 8 | + | --[[ | |
| 9 | + | Available options: | |
| 10 | + | title = text | |
| 11 | + | description = text | |
| 12 | + | multiline = true / false | |
| 13 | + | width = number | |
| 14 | + | validation = text (regex) | |
| 15 | + | examples = {{name, text}, {name, text}} | |
| 16 | + | ]]-- | |
| 17 | + | local window = modules.client_textedit.edit(text, options, callback) | |
| 18 | + | window.botWidget = true | |
| 19 | + | return window | |
| 20 | + | end | |
| 21 | + | ||
| 22 | + | UI.SinglelineEditorWindow = function(text, options, callback) | |
| 23 | + | options = options or {} | |
| 24 | + | options.multiline = false | |
| 25 | + | return UI.EditorWindow(text, options, callback) | |
| 26 | + | end | |
| 27 | + | ||
| 28 | + | UI.MultilineEditorWindow = function(text, options, callback) | |
| 29 | + | options = options or {} | |
| 30 | + | options.multiline = true | |
| 31 | + | return UI.EditorWindow(text, options, callback) | |
| 32 | + | end | |
| 33 | + | ||
| 34 | + | UI.ConfirmationWindow = function(title, question, callback) | |
| 35 | + | local window = nil | |
| 36 | + | local onConfirm = function() | |
| 37 | + | window:destroy() | |
| 38 | + | callback() | |
| 39 | + | end | |
| 40 | + | local closeWindow = function() | |
| 41 | + | window:destroy() | |
| 42 | + | end | |
| 43 | + | window = context.displayGeneralBox(title, question, { | |
| 44 | + | { text=tr('Yes'), callback=onConfirm }, | |
| 45 | + | { text=tr('No'), callback=closeWindow }, | |
| 46 | + | anchor=AnchorHorizontalCenter}, onConfirm, closeWindow) | |
| 47 | + | window.botWidget = true | |
| 48 | + | return window | |
| 49 | + | end |
| @@ -0,0 +1,1186 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.MonsterEditor = function(monster, config, callback, parent) | |
| 5 | + | local otherWindow = g_ui.getRootWidget():getChildById('monsterEditor') | |
| 6 | + | if otherWindow then | |
| 7 | + | otherWindow:destory() | |
| 8 | + | end | |
| 9 | + | ||
| 10 | + | local window = context.setupUI([[ | |
| 11 | + | MainWindow | |
| 12 | + | id: monsterEditor | |
| 13 | + | size: 450 450 | |
| 14 | + | !text: tr("Edit monster") | |
| 15 | + | ||
| 16 | + | Label | |
| 17 | + | id: info | |
| 18 | + | anchors.left: parent.left | |
| 19 | + | anchors.right: parent.right | |
| 20 | + | anchors.top: parent.top | |
| 21 | + | text-align: center | |
| 22 | + | text: Use monster name * for any other monster not on the list | |
| 23 | + | ||
| 24 | + | Label | |
| 25 | + | id: info2 | |
| 26 | + | anchors.left: parent.left | |
| 27 | + | anchors.right: parent.right | |
| 28 | + | anchors.top: prev.bottom | |
| 29 | + | text-align: center | |
| 30 | + | text: Add number (1-5) at the end of the name to create multiple configs | |
| 31 | + | ||
| 32 | + | TextEdit | |
| 33 | + | id: name | |
| 34 | + | anchors.top: prev.bottom | |
| 35 | + | anchors.left: parent.left | |
| 36 | + | anchors.right: parent.right | |
| 37 | + | margin-left: 100 | |
| 38 | + | margin-top: 5 | |
| 39 | + | multiline: false | |
| 40 | + | ||
| 41 | + | Label | |
| 42 | + | anchors.verticalCenter: prev.verticalCenter | |
| 43 | + | anchors.left: parent.left | |
| 44 | + | text: Target name: | |
| 45 | + | ||
| 46 | + | Label | |
| 47 | + | id: priorityText | |
| 48 | + | anchors.left: parent.left | |
| 49 | + | anchors.right: parent.horizontalCenter | |
| 50 | + | anchors.top: prev.bottom | |
| 51 | + | margin-right: 10 | |
| 52 | + | margin-top: 10 | |
| 53 | + | text: Priority | |
| 54 | + | text-align: center | |
| 55 | + | ||
| 56 | + | HorizontalScrollBar | |
| 57 | + | id: priority | |
| 58 | + | anchors.left: prev.left | |
| 59 | + | anchors.right: prev.right | |
| 60 | + | anchors.top: prev.bottom | |
| 61 | + | margin-top: 5 | |
| 62 | + | minimum: 0 | |
| 63 | + | maximum: 10 | |
| 64 | + | step: 1 | |
| 65 | + | ||
| 66 | + | Label | |
| 67 | + | id: dangerText | |
| 68 | + | anchors.left: parent.left | |
| 69 | + | anchors.right: parent.horizontalCenter | |
| 70 | + | anchors.top: prev.bottom | |
| 71 | + | margin-right: 10 | |
| 72 | + | margin-top: 10 | |
| 73 | + | text: Danger | |
| 74 | + | text-align: center | |
| 75 | + | ||
| 76 | + | HorizontalScrollBar | |
| 77 | + | id: danger | |
| 78 | + | anchors.left: prev.left | |
| 79 | + | anchors.right: prev.right | |
| 80 | + | anchors.top: prev.bottom | |
| 81 | + | margin-top: 5 | |
| 82 | + | minimum: 0 | |
| 83 | + | maximum: 10 | |
| 84 | + | step: 1 | |
| 85 | + | ||
| 86 | + | Label | |
| 87 | + | id: maxDistanceText | |
| 88 | + | anchors.left: parent.left | |
| 89 | + | anchors.right: parent.horizontalCenter | |
| 90 | + | anchors.top: prev.bottom | |
| 91 | + | margin-right: 10 | |
| 92 | + | margin-top: 10 | |
| 93 | + | text: Max distance to target | |
| 94 | + | text-align: center | |
| 95 | + | ||
| 96 | + | HorizontalScrollBar | |
| 97 | + | id: maxDistance | |
| 98 | + | anchors.left: prev.left | |
| 99 | + | anchors.right: prev.right | |
| 100 | + | anchors.top: prev.bottom | |
| 101 | + | margin-top: 5 | |
| 102 | + | minimum: 1 | |
| 103 | + | maximum: 10 | |
| 104 | + | step: 1 | |
| 105 | + | ||
| 106 | + | Label | |
| 107 | + | id: distanceText | |
| 108 | + | anchors.left: parent.left | |
| 109 | + | anchors.right: parent.horizontalCenter | |
| 110 | + | anchors.top: prev.bottom | |
| 111 | + | margin-right: 10 | |
| 112 | + | margin-top: 10 | |
| 113 | + | text: Keep distance | |
| 114 | + | text-align: center | |
| 115 | + | ||
| 116 | + | HorizontalScrollBar | |
| 117 | + | id: distance | |
| 118 | + | anchors.left: prev.left | |
| 119 | + | anchors.right: prev.right | |
| 120 | + | anchors.top: prev.bottom | |
| 121 | + | margin-top: 5 | |
| 122 | + | minimum: 0 | |
| 123 | + | maximum: 5 | |
| 124 | + | step: 1 | |
| 125 | + | ||
| 126 | + | Label | |
| 127 | + | id: minHealthText | |
| 128 | + | anchors.left: parent.left | |
| 129 | + | anchors.right: parent.horizontalCenter | |
| 130 | + | anchors.top: prev.bottom | |
| 131 | + | margin-right: 10 | |
| 132 | + | margin-top: 10 | |
| 133 | + | text: Minimum Health | |
| 134 | + | text-align: center | |
| 135 | + | ||
| 136 | + | HorizontalScrollBar | |
| 137 | + | id: minHealth | |
| 138 | + | anchors.left: prev.left | |
| 139 | + | anchors.right: prev.right | |
| 140 | + | anchors.top: prev.bottom | |
| 141 | + | margin-top: 5 | |
| 142 | + | minimum: 0 | |
| 143 | + | maximum: 100 | |
| 144 | + | step: 1 | |
| 145 | + | ||
| 146 | + | Label | |
| 147 | + | id: maxHealthText | |
| 148 | + | anchors.left: parent.left | |
| 149 | + | anchors.right: parent.horizontalCenter | |
| 150 | + | anchors.top: prev.bottom | |
| 151 | + | margin-right: 10 | |
| 152 | + | margin-top: 10 | |
| 153 | + | text: Maximum Health | |
| 154 | + | text-align: center | |
| 155 | + | ||
| 156 | + | HorizontalScrollBar | |
| 157 | + | id: maxHealth | |
| 158 | + | anchors.left: prev.left | |
| 159 | + | anchors.right: prev.right | |
| 160 | + | anchors.top: prev.bottom | |
| 161 | + | margin-top: 5 | |
| 162 | + | minimum: 0 | |
| 163 | + | maximum: 100 | |
| 164 | + | step: 1 | |
| 165 | + | ||
| 166 | + | Label | |
| 167 | + | id: dangerText | |
| 168 | + | anchors.left: parent.left | |
| 169 | + | anchors.right: parent.horizontalCenter | |
| 170 | + | anchors.top: prev.bottom | |
| 171 | + | margin-right: 5 | |
| 172 | + | margin-top: 10 | |
| 173 | + | text: If total danger is high (>8) bot won't auto loot until it's low again and will be trying to minimize it | |
| 174 | + | text-align: center | |
| 175 | + | text-wrap: true | |
| 176 | + | text-auto-resize: true | |
| 177 | + | ||
| 178 | + | Label | |
| 179 | + | id: attackSpellText | |
| 180 | + | anchors.left: parent.left | |
| 181 | + | anchors.right: parent.horizontalCenter | |
| 182 | + | anchors.top: prev.bottom | |
| 183 | + | margin-right: 5 | |
| 184 | + | margin-top: 10 | |
| 185 | + | text: Attack spell and attack rune are only used when you have more than 30% health | |
| 186 | + | text-align: center | |
| 187 | + | text-wrap: true | |
| 188 | + | text-auto-resize: true | |
| 189 | + | ||
| 190 | + | BotSwitch | |
| 191 | + | id: attack | |
| 192 | + | anchors.left: parent.horizontalCenter | |
| 193 | + | anchors.top: name.bottom | |
| 194 | + | margin-left: 10 | |
| 195 | + | margin-top: 10 | |
| 196 | + | width: 55 | |
| 197 | + | text: Attack | |
| 198 | + | ||
| 199 | + | BotSwitch | |
| 200 | + | id: ignore | |
| 201 | + | anchors.left: prev.right | |
| 202 | + | anchors.top: name.bottom | |
| 203 | + | margin-left: 18 | |
| 204 | + | margin-top: 10 | |
| 205 | + | width: 55 | |
| 206 | + | text: Ignore | |
| 207 | + | ||
| 208 | + | BotSwitch | |
| 209 | + | id: avoid | |
| 210 | + | anchors.left: prev.right | |
| 211 | + | anchors.top: name.bottom | |
| 212 | + | margin-left: 18 | |
| 213 | + | margin-top: 10 | |
| 214 | + | width: 55 | |
| 215 | + | text: Avoid | |
| 216 | + | ||
| 217 | + | BotSwitch | |
| 218 | + | id: keepDistance | |
| 219 | + | anchors.left: parent.horizontalCenter | |
| 220 | + | anchors.right: parent.right | |
| 221 | + | anchors.top: prev.bottom | |
| 222 | + | margin-left: 10 | |
| 223 | + | margin-top: 10 | |
| 224 | + | text: Keep distance | |
| 225 | + | ||
| 226 | + | BotSwitch | |
| 227 | + | id: avoidAttacks | |
| 228 | + | anchors.left: parent.horizontalCenter | |
| 229 | + | anchors.right: parent.right | |
| 230 | + | anchors.top: prev.bottom | |
| 231 | + | margin-left: 10 | |
| 232 | + | margin-top: 10 | |
| 233 | + | text: Avoid monster attacks | |
| 234 | + | ||
| 235 | + | BotSwitch | |
| 236 | + | id: chase | |
| 237 | + | anchors.left: parent.horizontalCenter | |
| 238 | + | anchors.right: parent.right | |
| 239 | + | anchors.top: prev.bottom | |
| 240 | + | margin-left: 10 | |
| 241 | + | margin-top: 10 | |
| 242 | + | text: Chase when has low health | |
| 243 | + | ||
| 244 | + | BotSwitch | |
| 245 | + | id: loot | |
| 246 | + | anchors.left: parent.horizontalCenter | |
| 247 | + | anchors.right: parent.right | |
| 248 | + | anchors.top: prev.bottom | |
| 249 | + | margin-left: 10 | |
| 250 | + | margin-top: 10 | |
| 251 | + | text: Loot corpse | |
| 252 | + | ||
| 253 | + | BotSwitch | |
| 254 | + | id: monstersOnly | |
| 255 | + | anchors.left: parent.horizontalCenter | |
| 256 | + | anchors.right: parent.right | |
| 257 | + | anchors.top: prev.bottom | |
| 258 | + | margin-left: 10 | |
| 259 | + | margin-top: 10 | |
| 260 | + | text: Only for monsters | |
| 261 | + | ||
| 262 | + | BotSwitch | |
| 263 | + | id: dontWalk | |
| 264 | + | anchors.left: parent.horizontalCenter | |
| 265 | + | anchors.right: parent.right | |
| 266 | + | anchors.top: prev.bottom | |
| 267 | + | margin-left: 10 | |
| 268 | + | margin-top: 10 | |
| 269 | + | text: Don't walk to target | |
| 270 | + | ||
| 271 | + | Label | |
| 272 | + | id: attackSpellText | |
| 273 | + | anchors.left: parent.horizontalCenter | |
| 274 | + | anchors.right: parent.right | |
| 275 | + | anchors.top: prev.bottom | |
| 276 | + | margin-left: 10 | |
| 277 | + | margin-top: 10 | |
| 278 | + | text: Attack Spell: | |
| 279 | + | text-align: center | |
| 280 | + | ||
| 281 | + | TextEdit | |
| 282 | + | id: attackSpell | |
| 283 | + | anchors.left: prev.left | |
| 284 | + | anchors.right: prev.right | |
| 285 | + | anchors.top: prev.bottom | |
| 286 | + | margin-top: 2 | |
| 287 | + | ||
| 288 | + | Label | |
| 289 | + | id: attackItemText | |
| 290 | + | anchors.left: parent.horizontalCenter | |
| 291 | + | anchors.top: prev.bottom | |
| 292 | + | margin-top: 20 | |
| 293 | + | margin-left: 20 | |
| 294 | + | text: Attack rune: | |
| 295 | + | text-align: left | |
| 296 | + | ||
| 297 | + | BotItem | |
| 298 | + | id: attackItem | |
| 299 | + | anchors.right: parent.right | |
| 300 | + | anchors.verticalCenter: prev.verticalCenter | |
| 301 | + | margin-right: 30 | |
| 302 | + | ||
| 303 | + | Button | |
| 304 | + | id: okButton | |
| 305 | + | !text: tr('Ok') | |
| 306 | + | anchors.bottom: parent.bottom | |
| 307 | + | anchors.right: next.left | |
| 308 | + | margin-right: 10 | |
| 309 | + | width: 60 | |
| 310 | + | ||
| 311 | + | Button | |
| 312 | + | id: cancelButton | |
| 313 | + | !text: tr('Cancel') | |
| 314 | + | anchors.bottom: parent.bottom | |
| 315 | + | anchors.right: parent.right | |
| 316 | + | width: 60 | |
| 317 | + | ]], g_ui.getRootWidget()) | |
| 318 | + | ||
| 319 | + | local destroy = function() | |
| 320 | + | window:destroy() | |
| 321 | + | end | |
| 322 | + | local doneFunc = function() | |
| 323 | + | local monster = window.name:getText() | |
| 324 | + | local config = { | |
| 325 | + | priority = window.priority:getValue(), | |
| 326 | + | danger = window.danger:getValue(), | |
| 327 | + | maxDistance = window.maxDistance:getValue(), | |
| 328 | + | distance = window.distance:getValue(), | |
| 329 | + | minHealth = window.minHealth:getValue(), | |
| 330 | + | maxHealth = window.maxHealth:getValue(), | |
| 331 | + | attack = window.attack:isOn(), | |
| 332 | + | ignore = window.ignore:isOn(), | |
| 333 | + | avoid = window.avoid:isOn(), | |
| 334 | + | keepDistance = window.keepDistance:isOn(), | |
| 335 | + | avoidAttacks = window.avoidAttacks:isOn(), | |
| 336 | + | chase = window.chase:isOn(), | |
| 337 | + | loot = window.loot:isOn(), | |
| 338 | + | monstersOnly = window.monstersOnly:isOn(), | |
| 339 | + | dontWalk = window.dontWalk:isOn(), | |
| 340 | + | attackItem = window.attackItem:getItemId(), | |
| 341 | + | attackSpell = window.attackSpell:getText() | |
| 342 | + | } | |
| 343 | + | destroy() | |
| 344 | + | callback(monster, config) | |
| 345 | + | end | |
| 346 | + | ||
| 347 | + | window.okButton.onClick = doneFunc | |
| 348 | + | window.cancelButton.onClick = destroy | |
| 349 | + | window.onEnter = doneFunc | |
| 350 | + | window.onEscape = destroy | |
| 351 | + | ||
| 352 | + | ||
| 353 | + | window.priority.onValueChange = function(scroll, value) | |
| 354 | + | window.priorityText:setText("Priority: " .. value) | |
| 355 | + | end | |
| 356 | + | window.danger.onValueChange = function(scroll, value) | |
| 357 | + | window.dangerText:setText("Danger: " .. value) | |
| 358 | + | end | |
| 359 | + | window.maxDistance.onValueChange = function(scroll, value) | |
| 360 | + | window.maxDistanceText:setText("Max distance to target: " .. value) | |
| 361 | + | end | |
| 362 | + | window.distance.onValueChange = function(scroll, value) | |
| 363 | + | window.distanceText:setText("Keep distance: " .. value) | |
| 364 | + | end | |
| 365 | + | window.minHealth.onValueChange = function(scroll, value) | |
| 366 | + | window.minHealthText:setText("Minimum health: " .. value .. "%") | |
| 367 | + | end | |
| 368 | + | window.maxHealth.onValueChange = function(scroll, value) | |
| 369 | + | window.maxHealthText:setText("Maximum health: " .. value .. "%") | |
| 370 | + | end | |
| 371 | + | ||
| 372 | + | window.priority:setValue(config.priority or 1) | |
| 373 | + | window.danger:setValue(config.danger or 1) | |
| 374 | + | window.maxDistance:setValue(config.maxDistance or 6) | |
| 375 | + | window.distance:setValue(config.distance or 1) | |
| 376 | + | window.minHealth:setValue(1) -- to force onValueChange update | |
| 377 | + | window.maxHealth:setValue(1) -- to force onValueChange update | |
| 378 | + | window.minHealth:setValue(config.minHealth or 0) | |
| 379 | + | window.maxHealth:setValue(config.maxHealth or 100) | |
| 380 | + | ||
| 381 | + | window.attackSpell:setText(config.attackSpell or "") | |
| 382 | + | window.attackItem:setItemId(config.attackItem or 0) | |
| 383 | + | ||
| 384 | + | window.attack.onClick = function(widget) | |
| 385 | + | if widget:isOn() then | |
| 386 | + | return | |
| 387 | + | end | |
| 388 | + | widget:setOn(true) | |
| 389 | + | window.ignore:setOn(false) | |
| 390 | + | window.avoid:setOn(false) | |
| 391 | + | end | |
| 392 | + | window.ignore.onClick = function(widget) | |
| 393 | + | if widget:isOn() then | |
| 394 | + | return | |
| 395 | + | end | |
| 396 | + | widget:setOn(true) | |
| 397 | + | window.attack:setOn(false) | |
| 398 | + | window.avoid:setOn(false) | |
| 399 | + | end | |
| 400 | + | window.avoid.onClick = function(widget) | |
| 401 | + | if widget:isOn() then | |
| 402 | + | return | |
| 403 | + | end | |
| 404 | + | widget:setOn(true) | |
| 405 | + | window.attack:setOn(false) | |
| 406 | + | window.ignore:setOn(false) | |
| 407 | + | end | |
| 408 | + | ||
| 409 | + | window.attack:setOn(config.attack) | |
| 410 | + | window.ignore:setOn(config.ignore) | |
| 411 | + | window.avoid:setOn(config.avoid) | |
| 412 | + | if not window.attack:isOn() and not window.ignore:isOn() and not window.avoid:isOn() then | |
| 413 | + | window.attack:setOn(true) | |
| 414 | + | end | |
| 415 | + | ||
| 416 | + | window.keepDistance.onClick = function(widget) | |
| 417 | + | widget:setOn(not widget:isOn()) | |
| 418 | + | end | |
| 419 | + | window.avoidAttacks.onClick = function(widget) | |
| 420 | + | widget:setOn(not widget:isOn()) | |
| 421 | + | end | |
| 422 | + | window.chase.onClick = function(widget) | |
| 423 | + | widget:setOn(not widget:isOn()) | |
| 424 | + | end | |
| 425 | + | window.loot.onClick = function(widget) | |
| 426 | + | widget:setOn(not widget:isOn()) | |
| 427 | + | end | |
| 428 | + | window.monstersOnly.onClick = function(widget) | |
| 429 | + | widget:setOn(not widget:isOn()) | |
| 430 | + | end | |
| 431 | + | window.dontWalk.onClick = function(widget) | |
| 432 | + | widget:setOn(not widget:isOn()) | |
| 433 | + | end | |
| 434 | + | ||
| 435 | + | window.keepDistance:setOn(config.keepDistance) | |
| 436 | + | window.avoidAttacks:setOn(config.avoidAttacks) | |
| 437 | + | window.chase:setOn(config.chase) | |
| 438 | + | window.loot:setOn(config.loot) | |
| 439 | + | if config.loot == nil then | |
| 440 | + | window.loot:setOn(true) | |
| 441 | + | end | |
| 442 | + | window.monstersOnly:setOn(config.monstersOnly) | |
| 443 | + | if config.monstersOnly == nil then | |
| 444 | + | window.monstersOnly:setOn(true) | |
| 445 | + | end | |
| 446 | + | window.dontWalk:setOn(config.dontWalk) | |
| 447 | + | ||
| 448 | + | window.name:setText(monster) | |
| 449 | + | ||
| 450 | + | window:show() | |
| 451 | + | window:raise() | |
| 452 | + | window:focus() | |
| 453 | + | end | |
| 454 | + | ||
| 455 | + | Panels.Attacking = function(parent) | |
| 456 | + | local ui = context.setupUI([[ | |
| 457 | + | Panel | |
| 458 | + | id: attacking | |
| 459 | + | height: 140 | |
| 460 | + | ||
| 461 | + | BotLabel | |
| 462 | + | anchors.top: parent.top | |
| 463 | + | anchors.left: parent.left | |
| 464 | + | anchors.right: parent.right | |
| 465 | + | text: Attacking | |
| 466 | + | ||
| 467 | + | ComboBox | |
| 468 | + | id: config | |
| 469 | + | anchors.top: prev.bottom | |
| 470 | + | anchors.left: parent.left | |
| 471 | + | margin-top: 5 | |
| 472 | + | text-offset: 3 0 | |
| 473 | + | width: 130 | |
| 474 | + | ||
| 475 | + | Button | |
| 476 | + | id: enableButton | |
| 477 | + | anchors.top: prev.top | |
| 478 | + | anchors.left: prev.right | |
| 479 | + | anchors.right: parent.right | |
| 480 | + | margin-left: 5 | |
| 481 | + | ||
| 482 | + | Button | |
| 483 | + | margin-top: 1 | |
| 484 | + | id: add | |
| 485 | + | anchors.top: prev.bottom | |
| 486 | + | anchors.left: parent.left | |
| 487 | + | text: Add | |
| 488 | + | width: 60 | |
| 489 | + | height: 17 | |
| 490 | + | ||
| 491 | + | Button | |
| 492 | + | id: edit | |
| 493 | + | anchors.top: prev.top | |
| 494 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 495 | + | text: Edit | |
| 496 | + | width: 60 | |
| 497 | + | height: 17 | |
| 498 | + | ||
| 499 | + | Button | |
| 500 | + | id: remove | |
| 501 | + | anchors.top: prev.top | |
| 502 | + | anchors.right: parent.right | |
| 503 | + | text: Remove | |
| 504 | + | width: 60 | |
| 505 | + | height: 17 | |
| 506 | + | ||
| 507 | + | TextList | |
| 508 | + | id: list | |
| 509 | + | anchors.top: prev.bottom | |
| 510 | + | anchors.left: parent.left | |
| 511 | + | anchors.right: parent.right | |
| 512 | + | vertical-scrollbar: listScrollbar | |
| 513 | + | margin-right: 15 | |
| 514 | + | margin-top: 2 | |
| 515 | + | height: 60 | |
| 516 | + | focusable: false | |
| 517 | + | auto-focus: first | |
| 518 | + | ||
| 519 | + | VerticalScrollBar | |
| 520 | + | id: listScrollbar | |
| 521 | + | anchors.top: prev.top | |
| 522 | + | anchors.bottom: prev.bottom | |
| 523 | + | anchors.right: parent.right | |
| 524 | + | pixels-scroll: true | |
| 525 | + | step: 5 | |
| 526 | + | ||
| 527 | + | Button | |
| 528 | + | margin-top: 2 | |
| 529 | + | id: mAdd | |
| 530 | + | anchors.top: prev.bottom | |
| 531 | + | anchors.left: parent.left | |
| 532 | + | text: Add | |
| 533 | + | width: 60 | |
| 534 | + | height: 17 | |
| 535 | + | ||
| 536 | + | Button | |
| 537 | + | id: mEdit | |
| 538 | + | anchors.top: prev.top | |
| 539 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 540 | + | text: Edit | |
| 541 | + | width: 60 | |
| 542 | + | height: 17 | |
| 543 | + | ||
| 544 | + | Button | |
| 545 | + | id: mRemove | |
| 546 | + | anchors.top: prev.top | |
| 547 | + | anchors.right: parent.right | |
| 548 | + | text: Remove | |
| 549 | + | width: 60 | |
| 550 | + | height: 17 | |
| 551 | + | ||
| 552 | + | ]], parent) | |
| 553 | + | ||
| 554 | + | if type(context.storage.attacking) ~= "table" then | |
| 555 | + | context.storage.attacking = {} | |
| 556 | + | end | |
| 557 | + | if type(context.storage.attacking.configs) ~= "table" then | |
| 558 | + | context.storage.attacking.configs = {} | |
| 559 | + | end | |
| 560 | + | ||
| 561 | + | local getConfigName = function(config) | |
| 562 | + | local matches = regexMatch(config, [[name:\s*([^\n]*)$]]) | |
| 563 | + | if matches[1] and matches[1][2] then | |
| 564 | + | return matches[1][2]:trim() | |
| 565 | + | end | |
| 566 | + | return nil | |
| 567 | + | end | |
| 568 | + | ||
| 569 | + | local commands = {} | |
| 570 | + | local monsters = {} | |
| 571 | + | local configName = nil | |
| 572 | + | local refreshConfig = nil -- declared later | |
| 573 | + | ||
| 574 | + | local createNewConfig = function() | |
| 575 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 576 | + | return | |
| 577 | + | end | |
| 578 | + | ||
| 579 | + | local newConfig = "" | |
| 580 | + | if configName ~= nil then | |
| 581 | + | newConfig = "name:" .. configName .. "\n" | |
| 582 | + | end | |
| 583 | + | for monster, config in pairs(monsters) do | |
| 584 | + | newConfig = newConfig .. "\n" .. monster .. ":" .. json.encode(config, 2) .. "\n" | |
| 585 | + | end | |
| 586 | + | ||
| 587 | + | context.storage.attacking.configs[context.storage.attacking.activeConfig] = newConfig | |
| 588 | + | refreshConfig() | |
| 589 | + | end | |
| 590 | + | ||
| 591 | + | local parseConfig = function(config) | |
| 592 | + | commands = {} | |
| 593 | + | monsters = {} | |
| 594 | + | configName = nil | |
| 595 | + | ||
| 596 | + | local matches = regexMatch(config, [[([^:^\n]+)(:?)([^\n]*)]]) | |
| 597 | + | for i=1,#matches do | |
| 598 | + | local command = matches[i][2] | |
| 599 | + | local validation = (matches[i][3] == ":") | |
| 600 | + | local text = matches[i][4] | |
| 601 | + | if validation then | |
| 602 | + | table.insert(commands, {command=command:lower(), text=text}) | |
| 603 | + | elseif #commands > 0 then | |
| 604 | + | commands[#commands].text = commands[#commands].text .. "\n" .. matches[i][1] | |
| 605 | + | end | |
| 606 | + | end | |
| 607 | + | local labels = {} | |
| 608 | + | for i, command in ipairs(commands) do | |
| 609 | + | if commands[i].command == "name" then | |
| 610 | + | configName = commands[i].text | |
| 611 | + | else | |
| 612 | + | local status, result = pcall(function() return json.decode(command.text) end) | |
| 613 | + | if not status then | |
| 614 | + | context.error("Invalid monster config: " .. commands[i].command .. ", error: " .. result) | |
| 615 | + | else | |
| 616 | + | monsters[commands[i].command] = result | |
| 617 | + | table.insert(labels, commands[i].command) | |
| 618 | + | end | |
| 619 | + | end | |
| 620 | + | end | |
| 621 | + | table.sort(labels) | |
| 622 | + | for i, text in ipairs(labels) do | |
| 623 | + | local label = g_ui.createWidget("CaveBotLabel", ui.list) | |
| 624 | + | label:setText(text) | |
| 625 | + | end | |
| 626 | + | end | |
| 627 | + | ||
| 628 | + | local ignoreOnOptionChange = true | |
| 629 | + | refreshConfig = function(scrollDown) | |
| 630 | + | ignoreOnOptionChange = true | |
| 631 | + | if context.storage.attacking.enabled then | |
| 632 | + | ui.enableButton:setText("On") | |
| 633 | + | ui.enableButton:setColor('#00AA00FF') | |
| 634 | + | else | |
| 635 | + | ui.enableButton:setText("Off") | |
| 636 | + | ui.enableButton:setColor('#FF0000FF') | |
| 637 | + | end | |
| 638 | + | ||
| 639 | + | ui.config:clear() | |
| 640 | + | for i, config in ipairs(context.storage.attacking.configs) do | |
| 641 | + | local name = getConfigName(config) | |
| 642 | + | if not name then | |
| 643 | + | name = "Unnamed config" | |
| 644 | + | end | |
| 645 | + | ui.config:addOption(name) | |
| 646 | + | end | |
| 647 | + | ||
| 648 | + | if (not context.storage.attacking.activeConfig or context.storage.attacking.activeConfig == 0) and #context.storage.attacking.configs > 0 then | |
| 649 | + | context.storage.attacking.activeConfig = 1 | |
| 650 | + | end | |
| 651 | + | ||
| 652 | + | ui.list:destroyChildren() | |
| 653 | + | ||
| 654 | + | if context.storage.attacking.activeConfig and context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 655 | + | ui.config:setCurrentIndex(context.storage.attacking.activeConfig) | |
| 656 | + | parseConfig(context.storage.attacking.configs[context.storage.attacking.activeConfig]) | |
| 657 | + | end | |
| 658 | + | ||
| 659 | + | context.saveConfig() | |
| 660 | + | if scrollDown and ui.list:getLastChild() then | |
| 661 | + | ui.list:focusChild(ui.list:getLastChild()) | |
| 662 | + | end | |
| 663 | + | ||
| 664 | + | ignoreOnOptionChange = false | |
| 665 | + | end | |
| 666 | + | ||
| 667 | + | ||
| 668 | + | ui.config.onOptionChange = function(widget) | |
| 669 | + | if not ignoreOnOptionChange then | |
| 670 | + | context.storage.attacking.activeConfig = widget.currentIndex | |
| 671 | + | refreshConfig() | |
| 672 | + | end | |
| 673 | + | end | |
| 674 | + | ui.enableButton.onClick = function() | |
| 675 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 676 | + | return | |
| 677 | + | end | |
| 678 | + | context.storage.attacking.enabled = not context.storage.attacking.enabled | |
| 679 | + | refreshConfig() | |
| 680 | + | end | |
| 681 | + | ui.add.onClick = function() | |
| 682 | + | modules.client_textedit.multilineEditor("Target list editor", "name:Config name", function(newText) | |
| 683 | + | table.insert(context.storage.attacking.configs, newText) | |
| 684 | + | context.storage.attacking.activeConfig = #context.storage.attacking.configs | |
| 685 | + | refreshConfig() | |
| 686 | + | end) | |
| 687 | + | end | |
| 688 | + | ui.edit.onClick = function() | |
| 689 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 690 | + | return | |
| 691 | + | end | |
| 692 | + | modules.client_textedit.multilineEditor("Target list editor", context.storage.attacking.configs[context.storage.attacking.activeConfig], function(newText) | |
| 693 | + | context.storage.attacking.configs[context.storage.attacking.activeConfig] = newText | |
| 694 | + | refreshConfig() | |
| 695 | + | end) | |
| 696 | + | end | |
| 697 | + | ui.remove.onClick = function() | |
| 698 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 699 | + | return | |
| 700 | + | end | |
| 701 | + | local questionWindow = nil | |
| 702 | + | local closeWindow = function() | |
| 703 | + | questionWindow:destroy() | |
| 704 | + | end | |
| 705 | + | local removeConfig = function() | |
| 706 | + | closeWindow() | |
| 707 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 708 | + | return | |
| 709 | + | end | |
| 710 | + | context.storage.attacking.enabled = false | |
| 711 | + | table.remove(context.storage.attacking.configs, context.storage.attacking.activeConfig) | |
| 712 | + | context.storage.attacking.activeConfig = 0 | |
| 713 | + | refreshConfig() | |
| 714 | + | end | |
| 715 | + | questionWindow = context.displayGeneralBox(tr('Remove config'), tr('Do you want to remove current attacking config?'), { | |
| 716 | + | { text=tr('Yes'), callback=removeConfig }, | |
| 717 | + | { text=tr('No'), callback=closeWindow }, | |
| 718 | + | anchor=AnchorHorizontalCenter}, removeConfig, closeWindow) | |
| 719 | + | end | |
| 720 | + | ||
| 721 | + | ||
| 722 | + | ui.mAdd.onClick = function() | |
| 723 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 724 | + | return | |
| 725 | + | end | |
| 726 | + | Panels.MonsterEditor("", {}, function(name, config) | |
| 727 | + | if name:len() > 0 then | |
| 728 | + | monsters[name] = config | |
| 729 | + | end | |
| 730 | + | createNewConfig() | |
| 731 | + | end, parent) | |
| 732 | + | end | |
| 733 | + | ui.mEdit.onClick = function() | |
| 734 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 735 | + | return | |
| 736 | + | end | |
| 737 | + | local monsterWidget = ui.list:getFocusedChild() | |
| 738 | + | if not monsterWidget or not monsters[monsterWidget:getText()] then | |
| 739 | + | return | |
| 740 | + | end | |
| 741 | + | Panels.MonsterEditor(monsterWidget:getText(), monsters[monsterWidget:getText()], function(name, config) | |
| 742 | + | monsters[monsterWidget:getText()] = nil | |
| 743 | + | if name:len() > 0 then | |
| 744 | + | monsters[name] = config | |
| 745 | + | end | |
| 746 | + | createNewConfig() | |
| 747 | + | end, parent) | |
| 748 | + | end | |
| 749 | + | ui.mRemove.onClick = function() | |
| 750 | + | if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then | |
| 751 | + | return | |
| 752 | + | end | |
| 753 | + | local monsterWidget = ui.list:getFocusedChild() | |
| 754 | + | if not monsterWidget or not monsters[monsterWidget:getText()] then | |
| 755 | + | return | |
| 756 | + | end | |
| 757 | + | monsters[monsterWidget:getText()] = nil | |
| 758 | + | createNewConfig() | |
| 759 | + | end | |
| 760 | + | ||
| 761 | + | refreshConfig() | |
| 762 | + | ||
| 763 | + | -- processing | |
| 764 | + | local isConfigPassingConditions = function(monster, config) | |
| 765 | + | if not config or type(config.priority) ~= 'number' or type(config.danger) ~= 'number' then | |
| 766 | + | return false | |
| 767 | + | end | |
| 768 | + | ||
| 769 | + | if not config.attack then | |
| 770 | + | return false | |
| 771 | + | end | |
| 772 | + | ||
| 773 | + | if monster:isPlayer() and (config.monstersOnly == true or config.monstersOnly == nil) then | |
| 774 | + | return false | |
| 775 | + | end | |
| 776 | + | ||
| 777 | + | local pos = context.player:getPosition() | |
| 778 | + | local mpos = monster:getPosition() | |
| 779 | + | local hp = monster:getHealthPercent() | |
| 780 | + | ||
| 781 | + | if config.minHealth > hp or config.maxHealth < hp then | |
| 782 | + | return false | |
| 783 | + | end | |
| 784 | + | ||
| 785 | + | local maxDistance = 5 | |
| 786 | + | if type(config.maxDistance) == 'number' then | |
| 787 | + | maxDistance = config.maxDistance | |
| 788 | + | end | |
| 789 | + | if config.chase and hp < 25 then | |
| 790 | + | maxDistance = maxDistance + 2 | |
| 791 | + | end | |
| 792 | + | ||
| 793 | + | local distance = math.max(math.abs(pos.x-mpos.x), math.abs(pos.y-mpos.y)) | |
| 794 | + | if distance > maxDistance then | |
| 795 | + | return false | |
| 796 | + | end | |
| 797 | + | ||
| 798 | + | local pathTo = context.findPath(context.player:getPosition(), {x=mpos.x, y=mpos.y, z=mpos.z}, maxDistance + 2, { ignoreNonPathable = true, precision=1, allowOnlyVisibleTiles = true, ignoreCost = true }) | |
| 799 | + | if not pathTo or #pathTo > maxDistance + 1 then | |
| 800 | + | return false | |
| 801 | + | end | |
| 802 | + | return true | |
| 803 | + | end | |
| 804 | + | ||
| 805 | + | local getMonsterConfig = function(monster) | |
| 806 | + | local name = monster:getName():lower() | |
| 807 | + | local hasConfig = false | |
| 808 | + | hasConfig = hasConfig or (monsters[name] ~= nil) | |
| 809 | + | if isConfigPassingConditions(monster, monsters[name]) then | |
| 810 | + | return monsters[name] | |
| 811 | + | end | |
| 812 | + | for i=1, 5 do | |
| 813 | + | hasConfig = hasConfig or (monsters[name .. i] ~= nil) | |
| 814 | + | if isConfigPassingConditions(monster, monsters[name .. i]) then | |
| 815 | + | return monsters[name .. i] | |
| 816 | + | end | |
| 817 | + | end | |
| 818 | + | if not hasConfig and isConfigPassingConditions(monster, monsters["*"]) then | |
| 819 | + | return monsters["*"] | |
| 820 | + | end | |
| 821 | + | return nil | |
| 822 | + | end | |
| 823 | + | ||
| 824 | + | local calculatePriority = function(monster) | |
| 825 | + | local priority = 0 | |
| 826 | + | local config = getMonsterConfig(monster) | |
| 827 | + | if not config then | |
| 828 | + | return -1 | |
| 829 | + | end | |
| 830 | + | ||
| 831 | + | local pos = context.player:getPosition() | |
| 832 | + | local mpos = monster:getPosition() | |
| 833 | + | local hp = monster:getHealthPercent() | |
| 834 | + | local pathTo = context.findPath(context.player:getPosition(), {x=mpos.x, y=mpos.y, z=mpos.z}, 10, { ignoreNonPathable = true, ignoreLastCreature = true, precision=0, allowOnlyVisibleTiles = true }) | |
| 835 | + | if not pathTo then | |
| 836 | + | pathTo = context.findPath(context.player:getPosition(), {x=mpos.x, y=mpos.y, z=mpos.z}, 10, { ignoreNonPathable = true, precision=1, allowOnlyVisibleTiles = true }) | |
| 837 | + | if not pathTo then | |
| 838 | + | return -1 | |
| 839 | + | end | |
| 840 | + | end | |
| 841 | + | local distance = #pathTo | |
| 842 | + | ||
| 843 | + | if monster == g_game.getAttackingCreature() then | |
| 844 | + | priority = priority + 10 | |
| 845 | + | end | |
| 846 | + | ||
| 847 | + | if distance <= 4 then | |
| 848 | + | priority = priority + 10 | |
| 849 | + | end | |
| 850 | + | if distance <= 2 then | |
| 851 | + | priority = priority + 10 | |
| 852 | + | end | |
| 853 | + | if distance <= 1 then | |
| 854 | + | priority = priority + 10 | |
| 855 | + | end | |
| 856 | + | ||
| 857 | + | if hp <= 25 and config.chase then | |
| 858 | + | priority = priority + 30 | |
| 859 | + | end | |
| 860 | + | ||
| 861 | + | if hp <= 10 then | |
| 862 | + | priority = priority + 10 | |
| 863 | + | end | |
| 864 | + | if hp <= 25 then | |
| 865 | + | priority = priority + 10 | |
| 866 | + | end | |
| 867 | + | if hp <= 50 then | |
| 868 | + | priority = priority + 10 | |
| 869 | + | end | |
| 870 | + | if hp <= 75 then | |
| 871 | + | priority = priority + 10 | |
| 872 | + | end | |
| 873 | + | ||
| 874 | + | priority = priority + config.priority * 10 | |
| 875 | + | return priority | |
| 876 | + | end | |
| 877 | + | ||
| 878 | + | local calculateMonsterDanger = function(monster) | |
| 879 | + | local danger = 0 | |
| 880 | + | local config = getMonsterConfig(monster) | |
| 881 | + | if not config or type(config.danger) ~= 'number' then | |
| 882 | + | return danger | |
| 883 | + | end | |
| 884 | + | danger = danger + config.danger | |
| 885 | + | return danger | |
| 886 | + | end | |
| 887 | + | ||
| 888 | + | local lastAttack = context.now | |
| 889 | + | local lootContainers = {} | |
| 890 | + | local lootTries = 0 | |
| 891 | + | local openContainerRequest = 0 | |
| 892 | + | local waitForLooting = 0 | |
| 893 | + | local lastAttackSpell = 0 | |
| 894 | + | local lastAttackRune = 0 | |
| 895 | + | ||
| 896 | + | local goForLoot = function() | |
| 897 | + | if #lootContainers == 0 or not context.storage.looting.enabled then | |
| 898 | + | return false | |
| 899 | + | end | |
| 900 | + | if modules.game_walking.lastManualWalk + 500 > context.now then | |
| 901 | + | return true | |
| 902 | + | end | |
| 903 | + | ||
| 904 | + | local pos = context.player:getPosition() | |
| 905 | + | table.sort(lootContainers, function(pos1, pos2) | |
| 906 | + | local dist1 = math.max(math.abs(pos.x-pos1.x), math.abs(pos.y-pos1.y)) | |
| 907 | + | local dist2 = math.max(math.abs(pos.x-pos2.x), math.abs(pos.y-pos2.y)) | |
| 908 | + | return dist1 < dist2 | |
| 909 | + | end) | |
| 910 | + | ||
| 911 | + | local cpos = lootContainers[1] | |
| 912 | + | if cpos.z ~= pos.z then | |
| 913 | + | table.remove(lootContainers, 1) | |
| 914 | + | return true | |
| 915 | + | end | |
| 916 | + | ||
| 917 | + | if lootTries >= 5 then | |
| 918 | + | lootTries = 0 | |
| 919 | + | table.remove(lootContainers, 1) | |
| 920 | + | return true | |
| 921 | + | end | |
| 922 | + | local dist = math.max(math.abs(pos.x-cpos.x), math.abs(pos.y-cpos.y)) | |
| 923 | + | if dist <= 5 then | |
| 924 | + | local tile = g_map.getTile(cpos) | |
| 925 | + | if not tile then | |
| 926 | + | table.remove(lootContainers, 1) | |
| 927 | + | return true | |
| 928 | + | end | |
| 929 | + | ||
| 930 | + | local topItem = tile:getTopUseThing() | |
| 931 | + | if not topItem or not topItem:isContainer() then | |
| 932 | + | table.remove(lootContainers, 1) | |
| 933 | + | return true | |
| 934 | + | end | |
| 935 | + | topItem:setMarked('orange') | |
| 936 | + | ||
| 937 | + | if dist <= 1 then | |
| 938 | + | lootTries = lootTries + 1 | |
| 939 | + | openContainerRequest = context.now | |
| 940 | + | g_game.open(topItem) | |
| 941 | + | waitForLooting = math.max(waitForLooting, context.now + 500) | |
| 942 | + | return true | |
| 943 | + | end | |
| 944 | + | end | |
| 945 | + | ||
| 946 | + | if dist <= 25 then | |
| 947 | + | if context.player:isWalking() then | |
| 948 | + | return true | |
| 949 | + | end | |
| 950 | + | ||
| 951 | + | lootTries = lootTries + 1 | |
| 952 | + | if context.autoWalk(cpos, 20, { precision = 1}) then | |
| 953 | + | return true | |
| 954 | + | end | |
| 955 | + | ||
| 956 | + | if context.autoWalk(cpos, 20, { ignoreNonPathable = true, precision = 1}) then | |
| 957 | + | return true | |
| 958 | + | end | |
| 959 | + | ||
| 960 | + | if context.autoWalk(cpos, 20, { ignoreNonPathable = true, precision = 2}) then | |
| 961 | + | return true | |
| 962 | + | end | |
| 963 | + | ||
| 964 | + | if context.autoWalk(cpos, 20, { ignoreNonPathable = true, ignoreCreatures = true, precision = 2}) then | |
| 965 | + | return true | |
| 966 | + | end | |
| 967 | + | else | |
| 968 | + | table.remove(lootContainers, 1) | |
| 969 | + | return false | |
| 970 | + | end | |
| 971 | + | return true | |
| 972 | + | end | |
| 973 | + | ||
| 974 | + | context.onCreatureDisappear(function(creature) | |
| 975 | + | if not creature:isMonster() then | |
| 976 | + | return | |
| 977 | + | end | |
| 978 | + | local pos = context.player:getPosition() | |
| 979 | + | local tpos = creature:getPosition() | |
| 980 | + | if tpos.z ~= pos.z then | |
| 981 | + | return | |
| 982 | + | end | |
| 983 | + | ||
| 984 | + | local config = getMonsterConfig(creature) | |
| 985 | + | if not config or not config.loot then | |
| 986 | + | return | |
| 987 | + | end | |
| 988 | + | local distance = math.max(math.abs(pos.x-tpos.x), math.abs(pos.y-tpos.y)) | |
| 989 | + | if distance > 6 then | |
| 990 | + | return | |
| 991 | + | end | |
| 992 | + | ||
| 993 | + | local tile = g_map.getTile(tpos) | |
| 994 | + | if not tile then | |
| 995 | + | return | |
| 996 | + | end | |
| 997 | + | ||
| 998 | + | local topItem = tile:getTopUseThing() | |
| 999 | + | if not topItem or not topItem:isContainer() then | |
| 1000 | + | return | |
| 1001 | + | end | |
| 1002 | + | ||
| 1003 | + | topItem:setMarked('blue') | |
| 1004 | + | table.insert(lootContainers, tpos) | |
| 1005 | + | end) | |
| 1006 | + | ||
| 1007 | + | context.onContainerOpen(function(container, prevContainer) | |
| 1008 | + | lootTries = 0 | |
| 1009 | + | if not context.storage.attacking.enabled then | |
| 1010 | + | return | |
| 1011 | + | end | |
| 1012 | + | ||
| 1013 | + | if openContainerRequest + 500 > context.now and #lootContainers > 0 then | |
| 1014 | + | waitForLooting = math.max(waitForLooting, context.now + 1000 + container:getItemsCount() * 100) | |
| 1015 | + | table.remove(lootContainers, 1) | |
| 1016 | + | end | |
| 1017 | + | if prevContainer then | |
| 1018 | + | container.autoLooting = prevContainer.autoLooting | |
| 1019 | + | else | |
| 1020 | + | container.autoLooting = (openContainerRequest + 3000 > context.now) | |
| 1021 | + | end | |
| 1022 | + | end) | |
| 1023 | + | ||
| 1024 | + | context.macro(200, function() | |
| 1025 | + | if not context.storage.attacking.enabled then | |
| 1026 | + | return | |
| 1027 | + | end | |
| 1028 | + | ||
| 1029 | + | local attacking = nil | |
| 1030 | + | local following = nil | |
| 1031 | + | local attackingCandidate = g_game.getAttackingCreature() | |
| 1032 | + | local followingCandidate = g_game.getFollowingCreature() | |
| 1033 | + | local spectators = context.getSpectators() | |
| 1034 | + | local monsters = {} | |
| 1035 | + | local danger = 0 | |
| 1036 | + | ||
| 1037 | + | for i, spec in ipairs(spectators) do | |
| 1038 | + | if attackingCandidate and attackingCandidate:getId() == spec:getId() then | |
| 1039 | + | attacking = spec | |
| 1040 | + | end | |
| 1041 | + | if followingCandidate and followingCandidate:getId() == spec:getId() then | |
| 1042 | + | following = spec | |
| 1043 | + | end | |
| 1044 | + | if spec:isMonster() or (spec:isPlayer() and not spec:isLocalPlayer()) then | |
| 1045 | + | danger = danger + calculateMonsterDanger(spec) | |
| 1046 | + | spec.attackingPriority = calculatePriority(spec) | |
| 1047 | + | table.insert(monsters, spec) | |
| 1048 | + | end | |
| 1049 | + | end | |
| 1050 | + | ||
| 1051 | + | if following then | |
| 1052 | + | return | |
| 1053 | + | end | |
| 1054 | + | ||
| 1055 | + | if waitForLooting > context.now then | |
| 1056 | + | return | |
| 1057 | + | end | |
| 1058 | + | ||
| 1059 | + | if #monsters == 0 or context.isInProtectionZone() then | |
| 1060 | + | goForLoot() | |
| 1061 | + | return | |
| 1062 | + | end | |
| 1063 | + | ||
| 1064 | + | table.sort(monsters, function(a, b) | |
| 1065 | + | return a.attackingPriority > b.attackingPriority | |
| 1066 | + | end) | |
| 1067 | + | ||
| 1068 | + | local target = monsters[1] | |
| 1069 | + | if target.attackingPriority < 0 then | |
| 1070 | + | return | |
| 1071 | + | end | |
| 1072 | + | ||
| 1073 | + | local pos = context.player:getPosition() | |
| 1074 | + | local tpos = target:getPosition() | |
| 1075 | + | local config = getMonsterConfig(target) | |
| 1076 | + | local offsetX = pos.x - tpos.x | |
| 1077 | + | local offsetY = pos.y - tpos.y | |
| 1078 | + | ||
| 1079 | + | local justStartedAttack = false | |
| 1080 | + | if target ~= attacking then | |
| 1081 | + | g_game.attack(target) | |
| 1082 | + | attacking = target | |
| 1083 | + | lastAttack = context.now | |
| 1084 | + | justStartedAttack = true | |
| 1085 | + | end | |
| 1086 | + | ||
| 1087 | + | -- proceed attack | |
| 1088 | + | if not target:isPlayer() and lastAttack + 15000 < context.now then | |
| 1089 | + | -- stop and attack again, just in case | |
| 1090 | + | g_game.cancelAttack() | |
| 1091 | + | g_game.attack(target) | |
| 1092 | + | lastAttack = context.now | |
| 1093 | + | return | |
| 1094 | + | end | |
| 1095 | + | ||
| 1096 | + | if not justStartedAttack and config.attackSpell and config.attackSpell:len() > 0 then | |
| 1097 | + | if context.now > lastAttackSpell + 1000 and context.player:getHealthPercent() > 30 then | |
| 1098 | + | if context.saySpell(config.attackSpell, 1500) then | |
| 1099 | + | lastAttackRune = context.now | |
| 1100 | + | end | |
| 1101 | + | end | |
| 1102 | + | end | |
| 1103 | + | ||
| 1104 | + | if not justStartedAttack and config.attackItem and config.attackItem >= 100 then | |
| 1105 | + | if context.now > lastAttackRune + 1000 and context.player:getHealthPercent() > 30 then | |
| 1106 | + | if context.useRune(config.attackItem, target, 1500) then | |
| 1107 | + | lastAttackRune = context.now | |
| 1108 | + | end | |
| 1109 | + | end | |
| 1110 | + | end | |
| 1111 | + | ||
| 1112 | + | if modules.game_walking.lastManualWalk + 500 > context.now then | |
| 1113 | + | return | |
| 1114 | + | end | |
| 1115 | + | ||
| 1116 | + | if danger < 8 then | |
| 1117 | + | -- low danger, go for loot first | |
| 1118 | + | if goForLoot() then | |
| 1119 | + | return | |
| 1120 | + | end | |
| 1121 | + | end | |
| 1122 | + | ||
| 1123 | + | target.ignoreByWaypoints = config.dontWalk | |
| 1124 | + | if config.dontWalk then | |
| 1125 | + | if goForLoot() then | |
| 1126 | + | return | |
| 1127 | + | end | |
| 1128 | + | return | |
| 1129 | + | end | |
| 1130 | + | ||
| 1131 | + | local distance = math.max(math.abs(offsetX), math.abs(offsetY)) | |
| 1132 | + | if config.keepDistance then | |
| 1133 | + | local minDistance = config.distance | |
| 1134 | + | if target:getHealthPercent() <= 25 and config.chase and danger < 10 then | |
| 1135 | + | minDistance = 1 | |
| 1136 | + | end | |
| 1137 | + | if (distance == minDistance or distance == minDistance + 1) then | |
| 1138 | + | return | |
| 1139 | + | else | |
| 1140 | + | local bestDist = 10 | |
| 1141 | + | local bestPos = pos | |
| 1142 | + | if not context.autoWalk(tpos, 10, { minMargin=minDistance, maxMargin=minDistance + 1, allowOnlyVisibleTiles = true}) then | |
| 1143 | + | if not context.autoWalk(tpos, 10, { ignoreNonPathable = true, minMargin=minDistance, maxMargin=minDistance + 1, allowOnlyVisibleTiles = true}) then | |
| 1144 | + | if not context.autoWalk(tpos, 10, { ignoreNonPathable = true, ignoreCreatures = true, minMargin=minDistance, maxMargin=minDistance + 2, allowOnlyVisibleTiles = true}) then | |
| 1145 | + | return | |
| 1146 | + | end | |
| 1147 | + | end | |
| 1148 | + | end | |
| 1149 | + | if not target:isPlayer() then | |
| 1150 | + | context.delay(300) | |
| 1151 | + | end | |
| 1152 | + | end | |
| 1153 | + | return | |
| 1154 | + | end | |
| 1155 | + | ||
| 1156 | + | if config.avoidAttacks and distance <= 1 then | |
| 1157 | + | if (offsetX == 0 and offsetY ~= 0) then | |
| 1158 | + | if context.player:canWalk(Directions.East) then | |
| 1159 | + | g_game.walk(Directions.East) | |
| 1160 | + | elseif context.player:canWalk(Directions.West) then | |
| 1161 | + | g_game.walk(Directions.West) | |
| 1162 | + | end | |
| 1163 | + | elseif (offsetX ~= 0 and offsetY == 0) then | |
| 1164 | + | if context.player:canWalk(Directions.North) then | |
| 1165 | + | g_game.walk(Directions.North) | |
| 1166 | + | elseif context.player:canWalk(Directions.South) then | |
| 1167 | + | g_game.walk(Directions.South) | |
| 1168 | + | end | |
| 1169 | + | end | |
| 1170 | + | end | |
| 1171 | + | ||
| 1172 | + | if distance > 1 then | |
| 1173 | + | if not context.autoWalk(tpos, 10, { precision = 1, allowOnlyVisibleTiles = true}) then | |
| 1174 | + | if not context.autoWalk(tpos, 10, { ignoreNonPathable = true, precision = 1, allowOnlyVisibleTiles = true}) then | |
| 1175 | + | if not context.autoWalk(tpos, 10, { ignoreNonPathable = true, precision = 2, allowOnlyVisibleTiles = true}) then | |
| 1176 | + | return | |
| 1177 | + | end | |
| 1178 | + | end | |
| 1179 | + | end | |
| 1180 | + | if not target:isPlayer() then | |
| 1181 | + | context.delay(300) | |
| 1182 | + | end | |
| 1183 | + | end | |
| 1184 | + | end) | |
| 1185 | + | end | |
| 1186 | + |
| @@ -0,0 +1,57 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.Turning = function(parent) | |
| 5 | + | context.macro(1000, "Turning / AntiIdle", nil, function() | |
| 6 | + | context.turn(math.random(1, 4)) | |
| 7 | + | end, parent) | |
| 8 | + | end | |
| 9 | + | Panels.AntiIdle = Panels.Turning | |
| 10 | + | ||
| 11 | + | Panels.AttackSpell = function(parent) | |
| 12 | + | context.macro(500, "Auto attack spell", nil, function() | |
| 13 | + | local target = g_game.getAttackingCreature() | |
| 14 | + | if target and context.getCreatureById(target:getId()) and context.storage.autoAttackText:len() > 0 then | |
| 15 | + | if context.saySpell(context.storage.autoAttackText, 1000) then | |
| 16 | + | context.delay(1000) | |
| 17 | + | end | |
| 18 | + | end | |
| 19 | + | end, parent) | |
| 20 | + | context.addTextEdit("autoAttackText", context.storage.autoAttackText or "exori vis", function(widget, text) | |
| 21 | + | context.storage.autoAttackText = text | |
| 22 | + | end, parent) | |
| 23 | + | end | |
| 24 | + | ||
| 25 | + | Panels.AttackItem = function(parent) | |
| 26 | + | if not parent then | |
| 27 | + | parent = context.panel | |
| 28 | + | end | |
| 29 | + | ||
| 30 | + | local panelName = "attackItem" | |
| 31 | + | local ui = g_ui.createWidget("ItemAndButtonPanel", parent) | |
| 32 | + | ui:setId(panelName) | |
| 33 | + | ||
| 34 | + | ui.title:setText("Auto attack item") | |
| 35 | + | ||
| 36 | + | if not context.storage.attackItem then | |
| 37 | + | context.storage.attackItem = {} | |
| 38 | + | end | |
| 39 | + | ||
| 40 | + | ui.title:setOn(context.storage.attackItem.enabled) | |
| 41 | + | ui.title.onClick = function(widget) | |
| 42 | + | context.storage.attackItem.enabled = not context.storage.attackItem.enabled | |
| 43 | + | widget:setOn(context.storage.attackItem.enabled) | |
| 44 | + | end | |
| 45 | + | ||
| 46 | + | ui.item.onItemChange = function(widget) | |
| 47 | + | context.storage.attackItem.item = widget:getItemId() | |
| 48 | + | end | |
| 49 | + | ui.item:setItemId(context.storage.attackItem.item or 3155) | |
| 50 | + | ||
| 51 | + | context.macro(500, function() | |
| 52 | + | local target = g_game.getAttackingCreature() | |
| 53 | + | if context.storage.attackItem.enabled and target and context.getCreatureById(target:getId()) and context.storage.attackItem.item and context.storage.attackItem.item >= 100 then | |
| 54 | + | context.useWith(context.storage.attackItem.item, target) | |
| 55 | + | end | |
| 56 | + | end) | |
| 57 | + | end |
| @@ -0,0 +1,3 @@ | |||
| 1 | + | DONT USE PANELS | |
| 2 | + | THEY ONLY HERE FOR BACKWARD COMPATIBILITY | |
| 3 | + | MAY BE REMOVED IN THE FUTURE |
| @@ -0,0 +1,346 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.Haste = function(parent) | |
| 5 | + | context.macro(500, "Auto Haste", nil, function() | |
| 6 | + | if not context.hasHaste() and context.storage.autoHasteText:len() > 0 then | |
| 7 | + | if context.saySpell(context.storage.autoHasteText, 2500) then | |
| 8 | + | context.delay(5000) | |
| 9 | + | end | |
| 10 | + | end | |
| 11 | + | end, parent) | |
| 12 | + | context.addTextEdit("autoHasteText", context.storage.autoHasteText or "utani hur", function(widget, text) | |
| 13 | + | context.storage.autoHasteText = text | |
| 14 | + | end, parent) | |
| 15 | + | end | |
| 16 | + | ||
| 17 | + | Panels.ManaShield = function(parent) | |
| 18 | + | local lastManaShield = 0 | |
| 19 | + | context.macro(100, "Auto Mana Shield", nil, function() | |
| 20 | + | if not context.hasManaShield() or context.now > lastManaShield + 90000 then | |
| 21 | + | if context.saySpell("utamo vita", 200) then | |
| 22 | + | lastManaShield = context.now | |
| 23 | + | end | |
| 24 | + | end | |
| 25 | + | end, parent) | |
| 26 | + | end | |
| 27 | + | ||
| 28 | + | Panels.AntiParalyze = function(parent) | |
| 29 | + | context.macro(100, "Anti Paralyze", nil, function() | |
| 30 | + | if context.isParalyzed() and context.storage.autoAntiParalyzeText:len() > 0 then | |
| 31 | + | context.saySpell(context.storage.autoAntiParalyzeText, 750) | |
| 32 | + | end | |
| 33 | + | end, parent) | |
| 34 | + | context.addTextEdit("autoAntiParalyzeText", context.storage.autoAntiParalyzeText or "utani hur", function(widget, text) | |
| 35 | + | context.storage.autoAntiParalyzeText = text | |
| 36 | + | end, parent) | |
| 37 | + | end | |
| 38 | + | ||
| 39 | + | ||
| 40 | + | Panels.Health = function(parent) | |
| 41 | + | if not parent then | |
| 42 | + | parent = context.panel | |
| 43 | + | end | |
| 44 | + | ||
| 45 | + | local panelName = "autoHealthPanel" | |
| 46 | + | local panelId = 1 | |
| 47 | + | while parent:getChildById(panelName .. panelId) do | |
| 48 | + | panelId = panelId + 1 | |
| 49 | + | end | |
| 50 | + | panelName = panelName .. panelId | |
| 51 | + | ||
| 52 | + | local ui = g_ui.createWidget("DualScrollPanel", parent) | |
| 53 | + | ui:setId(panelName) | |
| 54 | + | ||
| 55 | + | if not context.storage[panelName] then | |
| 56 | + | context.storage[panelName] = { | |
| 57 | + | item = 266, | |
| 58 | + | min = 20, | |
| 59 | + | max = 80, | |
| 60 | + | text = "exura" | |
| 61 | + | } | |
| 62 | + | end | |
| 63 | + | ||
| 64 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 65 | + | ui.title.onClick = function(widget) | |
| 66 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 67 | + | widget:setOn(context.storage[panelName].enabled) | |
| 68 | + | end | |
| 69 | + | ||
| 70 | + | ui.text.onTextChange = function(widget, text) | |
| 71 | + | context.storage[panelName].text = text | |
| 72 | + | end | |
| 73 | + | ui.text:setText(context.storage[panelName].text or "exura") | |
| 74 | + | ||
| 75 | + | local updateText = function() | |
| 76 | + | ui.title:setText("" .. context.storage[panelName].min .. "% <= hp <= " .. context.storage[panelName].max .. "%") | |
| 77 | + | end | |
| 78 | + | ||
| 79 | + | ui.scroll1.onValueChange = function(scroll, value) | |
| 80 | + | context.storage[panelName].min = value | |
| 81 | + | updateText() | |
| 82 | + | end | |
| 83 | + | ui.scroll2.onValueChange = function(scroll, value) | |
| 84 | + | context.storage[panelName].max = value | |
| 85 | + | updateText() | |
| 86 | + | end | |
| 87 | + | ||
| 88 | + | ui.scroll1:setValue(context.storage[panelName].min) | |
| 89 | + | ui.scroll2:setValue(context.storage[panelName].max) | |
| 90 | + | ||
| 91 | + | context.macro(25, function() | |
| 92 | + | if context.storage[panelName].enabled and context.storage[panelName].text:len() > 0 and context.storage[panelName].min <= context.hppercent() and context.hppercent() <= context.storage[panelName].max then | |
| 93 | + | if context.saySpell(context.storage[panelName].text, 500) then | |
| 94 | + | context.delay(200) | |
| 95 | + | end | |
| 96 | + | end | |
| 97 | + | end) | |
| 98 | + | end | |
| 99 | + | ||
| 100 | + | Panels.HealthItem = function(parent) | |
| 101 | + | if not parent then | |
| 102 | + | parent = context.panel | |
| 103 | + | end | |
| 104 | + | ||
| 105 | + | local panelName = "autoHealthItemPanel" | |
| 106 | + | local panelId = 1 | |
| 107 | + | while parent:getChildById(panelName .. panelId) do | |
| 108 | + | panelId = panelId + 1 | |
| 109 | + | end | |
| 110 | + | panelName = panelName .. panelId | |
| 111 | + | ||
| 112 | + | local ui = g_ui.createWidget("DualScrollItemPanel", parent) | |
| 113 | + | ui:setId(panelName) | |
| 114 | + | ||
| 115 | + | if not context.storage[panelName] then | |
| 116 | + | context.storage[panelName] = { | |
| 117 | + | item = 266, | |
| 118 | + | min = 0, | |
| 119 | + | max = 60 | |
| 120 | + | } | |
| 121 | + | end | |
| 122 | + | ||
| 123 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 124 | + | ui.title.onClick = function(widget) | |
| 125 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 126 | + | widget:setOn(context.storage[panelName].enabled) | |
| 127 | + | end | |
| 128 | + | ||
| 129 | + | ui.item.onItemChange = function(widget) | |
| 130 | + | context.storage[panelName].item = widget:getItemId() | |
| 131 | + | end | |
| 132 | + | ui.item:setItemId(context.storage[panelName].item) | |
| 133 | + | ||
| 134 | + | local updateText = function() | |
| 135 | + | ui.title:setText("" .. (context.storage[panelName].min or "") .. "% <= hp <= " .. (context.storage[panelName].max or "") .. "%") | |
| 136 | + | end | |
| 137 | + | ||
| 138 | + | ui.scroll1.onValueChange = function(scroll, value) | |
| 139 | + | context.storage[panelName].min = value | |
| 140 | + | updateText() | |
| 141 | + | end | |
| 142 | + | ui.scroll2.onValueChange = function(scroll, value) | |
| 143 | + | context.storage[panelName].max = value | |
| 144 | + | updateText() | |
| 145 | + | end | |
| 146 | + | ||
| 147 | + | ui.scroll1:setValue(context.storage[panelName].min) | |
| 148 | + | ui.scroll2:setValue(context.storage[panelName].max) | |
| 149 | + | ||
| 150 | + | context.macro(25, function() | |
| 151 | + | if context.storage[panelName].enabled and context.storage[panelName].item >= 100 and context.storage[panelName].min <= context.hppercent() and context.hppercent() <= context.storage[panelName].max then | |
| 152 | + | if context.useRune(context.storage[panelName].item, context.player, 500) then | |
| 153 | + | context.delay(300) | |
| 154 | + | end | |
| 155 | + | end | |
| 156 | + | end) | |
| 157 | + | end | |
| 158 | + | ||
| 159 | + | Panels.Mana = function(parent) | |
| 160 | + | if not parent then | |
| 161 | + | parent = context.panel | |
| 162 | + | end | |
| 163 | + | ||
| 164 | + | local panelName = "autoManaItemPanel" | |
| 165 | + | local panelId = 1 | |
| 166 | + | while parent:getChildById(panelName .. panelId) do | |
| 167 | + | panelId = panelId + 1 | |
| 168 | + | end | |
| 169 | + | panelName = panelName .. panelId | |
| 170 | + | ||
| 171 | + | local ui = g_ui.createWidget("DualScrollItemPanel", parent) | |
| 172 | + | ui:setId(panelName) | |
| 173 | + | ||
| 174 | + | if not context.storage[panelName] then | |
| 175 | + | context.storage[panelName] = { | |
| 176 | + | item = 268, | |
| 177 | + | min = 0, | |
| 178 | + | max = 60 | |
| 179 | + | } | |
| 180 | + | end | |
| 181 | + | ||
| 182 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 183 | + | ui.title.onClick = function(widget) | |
| 184 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 185 | + | widget:setOn(context.storage[panelName].enabled) | |
| 186 | + | end | |
| 187 | + | ||
| 188 | + | ui.item.onItemChange = function(widget) | |
| 189 | + | context.storage[panelName].item = widget:getItemId() | |
| 190 | + | end | |
| 191 | + | ui.item:setItemId(context.storage[panelName].item) | |
| 192 | + | ||
| 193 | + | local updateText = function() | |
| 194 | + | ui.title:setText("" .. (context.storage[panelName].min or "") .. "% <= mana <= " .. (context.storage[panelName].max or "") .. "%") | |
| 195 | + | end | |
| 196 | + | ||
| 197 | + | ui.scroll1.onValueChange = function(scroll, value) | |
| 198 | + | context.storage[panelName].min = value | |
| 199 | + | updateText() | |
| 200 | + | end | |
| 201 | + | ui.scroll2.onValueChange = function(scroll, value) | |
| 202 | + | context.storage[panelName].max = value | |
| 203 | + | updateText() | |
| 204 | + | end | |
| 205 | + | ||
| 206 | + | ui.scroll1:setValue(context.storage[panelName].min) | |
| 207 | + | ui.scroll2:setValue(context.storage[panelName].max) | |
| 208 | + | ||
| 209 | + | context.macro(25, function() | |
| 210 | + | if context.storage[panelName].enabled and context.storage[panelName].item >= 100 and context.storage[panelName].min <= context.manapercent() and context.manapercent() <= context.storage[panelName].max then | |
| 211 | + | if context.useRune(context.storage[panelName].item, context.player, 500) then | |
| 212 | + | context.delay(300) | |
| 213 | + | end | |
| 214 | + | end | |
| 215 | + | end) | |
| 216 | + | end | |
| 217 | + | Panels.ManaItem = Panels.Mana | |
| 218 | + | ||
| 219 | + | Panels.Equip = function(parent) | |
| 220 | + | if not parent then | |
| 221 | + | parent = context.panel | |
| 222 | + | end | |
| 223 | + | ||
| 224 | + | local panelName = "autoEquipItem" | |
| 225 | + | local panelId = 1 | |
| 226 | + | while parent:getChildById(panelName .. panelId) do | |
| 227 | + | panelId = panelId + 1 | |
| 228 | + | end | |
| 229 | + | panelName = panelName .. panelId | |
| 230 | + | ||
| 231 | + | local ui = g_ui.createWidget("TwoItemsAndSlotPanel", parent) | |
| 232 | + | ui:setId(panelName) | |
| 233 | + | ||
| 234 | + | if not context.storage[panelName] then | |
| 235 | + | context.storage[panelName] = {} | |
| 236 | + | if panelId == 1 then | |
| 237 | + | context.storage[panelName].item1 = 3052 | |
| 238 | + | context.storage[panelName].item2 = 3089 | |
| 239 | + | context.storage[panelName].slot = 9 | |
| 240 | + | end | |
| 241 | + | end | |
| 242 | + | ||
| 243 | + | ui.title:setText("Auto equip") | |
| 244 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 245 | + | ui.title.onClick = function(widget) | |
| 246 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 247 | + | widget:setOn(context.storage[panelName].enabled) | |
| 248 | + | end | |
| 249 | + | ||
| 250 | + | ui.item1:setItemId(context.storage[panelName].item1 or 0) | |
| 251 | + | ui.item1.onItemChange = function(widget) | |
| 252 | + | context.storage[panelName].item1 = widget:getItemId() | |
| 253 | + | end | |
| 254 | + | ||
| 255 | + | ui.item2:setItemId(context.storage[panelName].item2 or 0) | |
| 256 | + | ui.item2.onItemChange = function(widget) | |
| 257 | + | context.storage[panelName].item2 = widget:getItemId() | |
| 258 | + | end | |
| 259 | + | ||
| 260 | + | if not context.storage[panelName].slot then | |
| 261 | + | context.storage[panelName].slot = 1 | |
| 262 | + | end | |
| 263 | + | ui.slot:setCurrentIndex(context.storage[panelName].slot) | |
| 264 | + | ui.slot.onOptionChange = function(widget) | |
| 265 | + | context.storage[panelName].slot = widget.currentIndex | |
| 266 | + | end | |
| 267 | + | ||
| 268 | + | context.macro(250, function() | |
| 269 | + | if context.storage[panelName].enabled and context.storage[panelName].slot > 0 then | |
| 270 | + | local item1 = context.storage[panelName].item1 or 0 | |
| 271 | + | local item2 = context.storage[panelName].item2 or 0 | |
| 272 | + | if item1 < 100 and item2 < 100 then | |
| 273 | + | return | |
| 274 | + | end | |
| 275 | + | local slotItem = context.getSlot(context.storage[panelName].slot) | |
| 276 | + | if slotItem and (slotItem:getId() == item1 or slotItem:getId() == item2) then | |
| 277 | + | return | |
| 278 | + | end | |
| 279 | + | local newItem = context.findItem(context.storage[panelName].item1) | |
| 280 | + | if not newItem then | |
| 281 | + | newItem = context.findItem(context.storage[panelName].item2) | |
| 282 | + | if not newItem then | |
| 283 | + | return | |
| 284 | + | end | |
| 285 | + | end | |
| 286 | + | g_game.move(newItem, {x=65535, y=context.storage[panelName].slot, z=0}) | |
| 287 | + | context.delay(1000) | |
| 288 | + | end | |
| 289 | + | end) | |
| 290 | + | end | |
| 291 | + | Panels.AutoEquip = Panels.Equip | |
| 292 | + | ||
| 293 | + | Panels.Eating = function(parent) | |
| 294 | + | if not parent then | |
| 295 | + | parent = context.panel | |
| 296 | + | end | |
| 297 | + | ||
| 298 | + | local panelName = "autoEatingPanel" | |
| 299 | + | local panelId = 1 | |
| 300 | + | while parent:getChildById(panelName .. panelId) do | |
| 301 | + | panelId = panelId + 1 | |
| 302 | + | end | |
| 303 | + | panelName = panelName .. panelId | |
| 304 | + | ||
| 305 | + | local ui = g_ui.createWidget("ItemsPanel", parent) | |
| 306 | + | ui:setId(panelName) | |
| 307 | + | ||
| 308 | + | if not context.storage[panelName] then | |
| 309 | + | context.storage[panelName] = {} | |
| 310 | + | end | |
| 311 | + | ||
| 312 | + | ui.title:setText("Auto eating") | |
| 313 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 314 | + | ui.title.onClick = function(widget) | |
| 315 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 316 | + | widget:setOn(context.storage[panelName].enabled) | |
| 317 | + | end | |
| 318 | + | ||
| 319 | + | if type(context.storage[panelName].items) ~= 'table' then | |
| 320 | + | context.storage[panelName].items = {3725, 0, 0, 0, 0} | |
| 321 | + | end | |
| 322 | + | ||
| 323 | + | for i=1,5 do | |
| 324 | + | ui.items:getChildByIndex(i).onItemChange = function(widget) | |
| 325 | + | context.storage[panelName].items[i] = widget:getItemId() | |
| 326 | + | end | |
| 327 | + | ui.items:getChildByIndex(i):setItemId(context.storage[panelName].items[i]) | |
| 328 | + | end | |
| 329 | + | ||
| 330 | + | context.macro(15000, function() | |
| 331 | + | if not context.storage[panelName].enabled then | |
| 332 | + | return | |
| 333 | + | end | |
| 334 | + | local candidates = {} | |
| 335 | + | for i, item in pairs(context.storage[panelName].items) do | |
| 336 | + | if item >= 100 then | |
| 337 | + | table.insert(candidates, item) | |
| 338 | + | end | |
| 339 | + | end | |
| 340 | + | if #candidates == 0 then | |
| 341 | + | return | |
| 342 | + | end | |
| 343 | + | context.use(candidates[math.random(1, #candidates)]) | |
| 344 | + | end) | |
| 345 | + | end | |
| 346 | + |
| @@ -0,0 +1,431 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.Looting = function(parent) | |
| 5 | + | local ui = context.setupUI([[ | |
| 6 | + | Panel | |
| 7 | + | id: looting | |
| 8 | + | height: 180 | |
| 9 | + | ||
| 10 | + | BotLabel | |
| 11 | + | anchors.top: parent.top | |
| 12 | + | anchors.left: parent.left | |
| 13 | + | anchors.right: parent.right | |
| 14 | + | text: Looting | |
| 15 | + | ||
| 16 | + | ComboBox | |
| 17 | + | id: config | |
| 18 | + | anchors.top: prev.bottom | |
| 19 | + | anchors.left: parent.left | |
| 20 | + | margin-top: 5 | |
| 21 | + | text-offset: 3 0 | |
| 22 | + | width: 130 | |
| 23 | + | ||
| 24 | + | Button | |
| 25 | + | id: enableButton | |
| 26 | + | anchors.top: prev.top | |
| 27 | + | anchors.left: prev.right | |
| 28 | + | anchors.right: parent.right | |
| 29 | + | margin-left: 5 | |
| 30 | + | ||
| 31 | + | Button | |
| 32 | + | margin-top: 1 | |
| 33 | + | id: add | |
| 34 | + | anchors.top: prev.bottom | |
| 35 | + | anchors.left: parent.left | |
| 36 | + | text: Add | |
| 37 | + | width: 60 | |
| 38 | + | height: 17 | |
| 39 | + | ||
| 40 | + | Button | |
| 41 | + | id: edit | |
| 42 | + | anchors.top: prev.top | |
| 43 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 44 | + | text: Edit | |
| 45 | + | width: 60 | |
| 46 | + | height: 17 | |
| 47 | + | ||
| 48 | + | Button | |
| 49 | + | id: remove | |
| 50 | + | anchors.top: prev.top | |
| 51 | + | anchors.right: parent.right | |
| 52 | + | text: Remove | |
| 53 | + | width: 60 | |
| 54 | + | height: 17 | |
| 55 | + | ||
| 56 | + | ScrollablePanel | |
| 57 | + | id: items | |
| 58 | + | anchors.top: prev.bottom | |
| 59 | + | anchors.right: parent.right | |
| 60 | + | anchors.left: parent.left | |
| 61 | + | vertical-scrollbar: scrollBar | |
| 62 | + | margin-right: 5 | |
| 63 | + | margin-top: 2 | |
| 64 | + | height: 70 | |
| 65 | + | layout: | |
| 66 | + | type: grid | |
| 67 | + | cell-size: 34 34 | |
| 68 | + | flow: true | |
| 69 | + | ||
| 70 | + | BotSmallScrollBar | |
| 71 | + | id: scrollBar | |
| 72 | + | anchors.top: prev.top | |
| 73 | + | anchors.bottom: prev.bottom | |
| 74 | + | anchors.right: parent.right | |
| 75 | + | step: 10 | |
| 76 | + | pixels-scroll: true | |
| 77 | + | ||
| 78 | + | BotLabel | |
| 79 | + | anchors.top: prev.bottom | |
| 80 | + | anchors.left: parent.left | |
| 81 | + | anchors.right: parent.right | |
| 82 | + | margin-top: 4 | |
| 83 | + | text: Loot Containers | |
| 84 | + | ||
| 85 | + | ItemsRow | |
| 86 | + | id: containers | |
| 87 | + | anchors.top: prev.bottom | |
| 88 | + | anchors.left: parent.left | |
| 89 | + | anchors.right: parent.right | |
| 90 | + | height: 33 | |
| 91 | + | margin-top: 2 | |
| 92 | + | ||
| 93 | + | ]], parent) | |
| 94 | + | ||
| 95 | + | local lootContainers = { ui.containers.item1, ui.containers.item2, ui.containers.item3, ui.containers.item4, ui.containers.item5 } | |
| 96 | + | ||
| 97 | + | if type(context.storage.looting) ~= "table" then | |
| 98 | + | context.storage.looting = {} | |
| 99 | + | end | |
| 100 | + | if type(context.storage.looting.configs) ~= "table" then | |
| 101 | + | context.storage.looting.configs = {} | |
| 102 | + | end | |
| 103 | + | ||
| 104 | + | local getConfigName = function(config) | |
| 105 | + | local matches = regexMatch(config, [[name:\s*([^\n]*)$]]) | |
| 106 | + | if matches[1] and matches[1][2] then | |
| 107 | + | return matches[1][2]:trim() | |
| 108 | + | end | |
| 109 | + | return nil | |
| 110 | + | end | |
| 111 | + | ||
| 112 | + | local items = {} | |
| 113 | + | local itemsByKey = {} | |
| 114 | + | local containers = {} | |
| 115 | + | local commands = {} | |
| 116 | + | local refreshConfig = nil -- declared later | |
| 117 | + | ||
| 118 | + | local createNewConfig = function(focusedWidget) | |
| 119 | + | if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 120 | + | return | |
| 121 | + | end | |
| 122 | + | ||
| 123 | + | local tmpItems = {} | |
| 124 | + | local tmpContainers = {} | |
| 125 | + | local focusIndex = 0 | |
| 126 | + | ||
| 127 | + | local newConfig = "" | |
| 128 | + | for i, text in ipairs(commands) do | |
| 129 | + | newConfig = newConfig .. text .. "\n" | |
| 130 | + | end | |
| 131 | + | for i=1,ui.items:getChildCount() do | |
| 132 | + | local widget = ui.items:getChildByIndex(i) | |
| 133 | + | if widget and widget:getItemId() >= 100 then | |
| 134 | + | if tmpItems[widget:getItemId()] == nil then | |
| 135 | + | tmpItems[widget:getItemId()] = 1 | |
| 136 | + | newConfig = newConfig .. "\n" .. widget:getItemId() | |
| 137 | + | end | |
| 138 | + | end | |
| 139 | + | if widget == focusedWidget then | |
| 140 | + | focusIndex = i | |
| 141 | + | end | |
| 142 | + | end | |
| 143 | + | for i, widget in ipairs(lootContainers) do | |
| 144 | + | if widget:getItemId() >= 100 then | |
| 145 | + | if tmpContainers[widget:getItemId()] == nil then | |
| 146 | + | tmpContainers[widget:getItemId()] = 1 -- remove duplicates | |
| 147 | + | newConfig = newConfig .. "\ncontainer:" .. widget:getItemId() | |
| 148 | + | end | |
| 149 | + | end | |
| 150 | + | end | |
| 151 | + | ||
| 152 | + | context.storage.looting.configs[context.storage.looting.activeConfig] = newConfig | |
| 153 | + | refreshConfig(focusIndex) | |
| 154 | + | end | |
| 155 | + | ||
| 156 | + | local parseConfig = function(config) | |
| 157 | + | items = {} | |
| 158 | + | itemsByKey = {} | |
| 159 | + | containers = {} | |
| 160 | + | commands = {} | |
| 161 | + | local matches = regexMatch(config, [[([^:^\n^\s]+)(:?)([^\n]*)]]) | |
| 162 | + | for i=1,#matches do | |
| 163 | + | local command = matches[i][2] | |
| 164 | + | local validation = (matches[i][3] == ":") | |
| 165 | + | local text = matches[i][4] | |
| 166 | + | local commandAsNumber = tonumber(command) | |
| 167 | + | local textAsNumber = tonumber(text) | |
| 168 | + | if commandAsNumber and commandAsNumber >= 100 then | |
| 169 | + | table.insert(items, commandAsNumber) | |
| 170 | + | itemsByKey[commandAsNumber] = 1 | |
| 171 | + | elseif command == "container" and validation and textAsNumber and textAsNumber >= 100 then | |
| 172 | + | containers[textAsNumber] = 1 | |
| 173 | + | elseif validation then | |
| 174 | + | table.insert(commands, command .. ":" .. text) | |
| 175 | + | end | |
| 176 | + | end | |
| 177 | + | ||
| 178 | + | local itemsToShow = #items + 2 | |
| 179 | + | if itemsToShow % 5 ~= 0 then | |
| 180 | + | itemsToShow = itemsToShow + 5 - itemsToShow % 5 | |
| 181 | + | end | |
| 182 | + | if itemsToShow < 10 then | |
| 183 | + | itemsToShow = 10 | |
| 184 | + | end | |
| 185 | + | ||
| 186 | + | for i=1,itemsToShow do | |
| 187 | + | local widget = g_ui.createWidget("BotItem", ui.items) | |
| 188 | + | local itemId = 0 | |
| 189 | + | if i <= #items then | |
| 190 | + | itemId = items[i] | |
| 191 | + | end | |
| 192 | + | widget:setItemId(itemId) | |
| 193 | + | widget.onItemChange = createNewConfig | |
| 194 | + | end | |
| 195 | + | ||
| 196 | + | for i, widget in ipairs(lootContainers) do | |
| 197 | + | widget:setItemId(0) | |
| 198 | + | end | |
| 199 | + | local containerIndex = 1 | |
| 200 | + | for containerId, i in pairs(containers) do | |
| 201 | + | if lootContainers[containerIndex] then | |
| 202 | + | lootContainers[containerIndex]:setItemId(containerId) | |
| 203 | + | end | |
| 204 | + | containerIndex = containerIndex + 1 | |
| 205 | + | end | |
| 206 | + | for i, widget in ipairs(lootContainers) do | |
| 207 | + | widget.onItemChange = createNewConfig | |
| 208 | + | end | |
| 209 | + | end | |
| 210 | + | ||
| 211 | + | local ignoreOnOptionChange = true | |
| 212 | + | refreshConfig = function(focusIndex) | |
| 213 | + | ignoreOnOptionChange = true | |
| 214 | + | if context.storage.looting.enabled then | |
| 215 | + | ui.enableButton:setText("On") | |
| 216 | + | ui.enableButton:setColor('#00AA00FF') | |
| 217 | + | else | |
| 218 | + | ui.enableButton:setText("Off") | |
| 219 | + | ui.enableButton:setColor('#FF0000FF') | |
| 220 | + | end | |
| 221 | + | ||
| 222 | + | ui.config:clear() | |
| 223 | + | for i, config in ipairs(context.storage.looting.configs) do | |
| 224 | + | local name = getConfigName(config) | |
| 225 | + | if not name then | |
| 226 | + | name = "Unnamed config" | |
| 227 | + | end | |
| 228 | + | ui.config:addOption(name) | |
| 229 | + | end | |
| 230 | + | ||
| 231 | + | if (not context.storage.looting.activeConfig or context.storage.looting.activeConfig == 0) and #context.storage.looting.configs > 0 then | |
| 232 | + | context.storage.looting.activeConfig = 1 | |
| 233 | + | end | |
| 234 | + | ||
| 235 | + | ui.items:destroyChildren() | |
| 236 | + | for i, widget in ipairs(lootContainers) do | |
| 237 | + | widget.onItemChange = nil | |
| 238 | + | widget:setItemId(0) | |
| 239 | + | widget:setItemCount(0) | |
| 240 | + | end | |
| 241 | + | ||
| 242 | + | if context.storage.looting.activeConfig and context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 243 | + | ui.config:setCurrentIndex(context.storage.looting.activeConfig) | |
| 244 | + | parseConfig(context.storage.looting.configs[context.storage.looting.activeConfig]) | |
| 245 | + | end | |
| 246 | + | ||
| 247 | + | context.saveConfig() | |
| 248 | + | if focusIndex and focusIndex > 0 and ui.items:getChildByIndex(focusIndex) then | |
| 249 | + | ui.items:focusChild(ui.items:getChildByIndex(focusIndex)) | |
| 250 | + | end | |
| 251 | + | ||
| 252 | + | ignoreOnOptionChange = false | |
| 253 | + | end | |
| 254 | + | ||
| 255 | + | ui.config.onOptionChange = function(widget) | |
| 256 | + | if not ignoreOnOptionChange then | |
| 257 | + | context.storage.looting.activeConfig = widget.currentIndex | |
| 258 | + | refreshConfig() | |
| 259 | + | end | |
| 260 | + | end | |
| 261 | + | ui.enableButton.onClick = function() | |
| 262 | + | if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 263 | + | return | |
| 264 | + | end | |
| 265 | + | context.storage.looting.enabled = not context.storage.looting.enabled | |
| 266 | + | refreshConfig() | |
| 267 | + | end | |
| 268 | + | ui.add.onClick = function() | |
| 269 | + | modules.client_textedit.multilineEditor("Looting editor", "name:Config name", function(newText) | |
| 270 | + | table.insert(context.storage.looting.configs, newText) | |
| 271 | + | context.storage.looting.activeConfig = #context.storage.looting.configs | |
| 272 | + | refreshConfig() | |
| 273 | + | end) | |
| 274 | + | end | |
| 275 | + | ui.edit.onClick = function() | |
| 276 | + | if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 277 | + | return | |
| 278 | + | end | |
| 279 | + | modules.client_textedit.multilineEditor("Looting editor", context.storage.looting.configs[context.storage.looting.activeConfig], function(newText) | |
| 280 | + | context.storage.looting.configs[context.storage.looting.activeConfig] = newText | |
| 281 | + | refreshConfig() | |
| 282 | + | end) | |
| 283 | + | end | |
| 284 | + | ui.remove.onClick = function() | |
| 285 | + | if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 286 | + | return | |
| 287 | + | end | |
| 288 | + | local questionWindow = nil | |
| 289 | + | local closeWindow = function() | |
| 290 | + | questionWindow:destroy() | |
| 291 | + | end | |
| 292 | + | local removeConfig = function() | |
| 293 | + | closeWindow() | |
| 294 | + | if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then | |
| 295 | + | return | |
| 296 | + | end | |
| 297 | + | context.storage.looting.enabled = false | |
| 298 | + | table.remove(context.storage.looting.configs, context.storage.looting.activeConfig) | |
| 299 | + | context.storage.looting.activeConfig = 0 | |
| 300 | + | refreshConfig() | |
| 301 | + | end | |
| 302 | + | questionWindow = context.displayGeneralBox(tr('Remove config'), tr('Do you want to remove current looting config?'), { | |
| 303 | + | { text=tr('Yes'), callback=removeConfig }, | |
| 304 | + | { text=tr('No'), callback=closeWindow }, | |
| 305 | + | anchor=AnchorHorizontalCenter}, removeConfig, closeWindow) | |
| 306 | + | end | |
| 307 | + | refreshConfig() | |
| 308 | + | ||
| 309 | + | context.onContainerOpen(function(container, prevContainer) | |
| 310 | + | if context.storage.attacking.enabled then | |
| 311 | + | return | |
| 312 | + | end | |
| 313 | + | if prevContainer then | |
| 314 | + | container.autoLooting = prevContainer.autoLooting | |
| 315 | + | else | |
| 316 | + | container.autoLooting = true | |
| 317 | + | end | |
| 318 | + | end) | |
| 319 | + | ||
| 320 | + | context.macro(200, function() | |
| 321 | + | if not context.storage.looting.enabled then | |
| 322 | + | return | |
| 323 | + | end | |
| 324 | + | local candidates = {} | |
| 325 | + | local lootContainersCandidates = {} | |
| 326 | + | for containerId, container in pairs(g_game.getContainers()) do | |
| 327 | + | local containerItem = container:getContainerItem() | |
| 328 | + | if container.autoLooting and container:getItemsCount() > 0 and (not containerItem or containers[containerItem:getId()] == nil) then | |
| 329 | + | table.insert(candidates, container) | |
| 330 | + | elseif containerItem and containers[containerItem:getId()] ~= nil then | |
| 331 | + | table.insert(lootContainersCandidates, container) | |
| 332 | + | end | |
| 333 | + | end | |
| 334 | + | if #lootContainersCandidates == 0 then | |
| 335 | + | for slot = InventorySlotFirst, InventorySlotLast do | |
| 336 | + | local item = context.getInventoryItem(slot) | |
| 337 | + | if item and item:isContainer() and containers[item:getId()] ~= nil then | |
| 338 | + | table.insert(lootContainersCandidates, item) | |
| 339 | + | end | |
| 340 | + | end | |
| 341 | + | if #lootContainersCandidates > 0 then | |
| 342 | + | -- try to open inventory backpack | |
| 343 | + | local target = lootContainersCandidates[math.random(1,#lootContainersCandidates)] | |
| 344 | + | g_game.open(target, nil) | |
| 345 | + | context.delay(200) | |
| 346 | + | end | |
| 347 | + | return | |
| 348 | + | end | |
| 349 | + | ||
| 350 | + | if #candidates == 0 then | |
| 351 | + | return | |
| 352 | + | end | |
| 353 | + | ||
| 354 | + | local container = candidates[math.random(1,#candidates)] | |
| 355 | + | local nextContainers = {} | |
| 356 | + | local foundItem = nil | |
| 357 | + | for i, item in ipairs(container:getItems()) do | |
| 358 | + | if item:isContainer() then | |
| 359 | + | table.insert(nextContainers, item) | |
| 360 | + | elseif itemsByKey[item:getId()] ~= nil then | |
| 361 | + | foundItem = item | |
| 362 | + | break | |
| 363 | + | end | |
| 364 | + | end | |
| 365 | + | ||
| 366 | + | -- found item to loot | |
| 367 | + | if foundItem then | |
| 368 | + | -- find backpack for it, first backpack with same items | |
| 369 | + | for i, container in ipairs(lootContainersCandidates) do | |
| 370 | + | if container:getItemsCount() < container:getCapacity() or foundItem:isStackable() then -- has space | |
| 371 | + | for j, item in ipairs(container:getItems()) do | |
| 372 | + | if item:getId() == foundItem:getId() then | |
| 373 | + | if foundItem:isStackable() then | |
| 374 | + | if item:getCount() ~= 100 then | |
| 375 | + | g_game.move(foundItem, container:getSlotPosition(j - 1), foundItem:getCount()) | |
| 376 | + | return | |
| 377 | + | end | |
| 378 | + | else | |
| 379 | + | g_game.move(foundItem, container:getSlotPosition(container:getItemsCount()), foundItem:getCount()) | |
| 380 | + | return | |
| 381 | + | end | |
| 382 | + | end | |
| 383 | + | end | |
| 384 | + | end | |
| 385 | + | end | |
| 386 | + | -- now any backpack with empty slot | |
| 387 | + | for i, container in ipairs(lootContainersCandidates) do | |
| 388 | + | if container:getItemsCount() < container:getCapacity() then -- has space | |
| 389 | + | g_game.move(foundItem, container:getSlotPosition(container:getItemsCount()), foundItem:getCount()) | |
| 390 | + | return | |
| 391 | + | end | |
| 392 | + | end | |
| 393 | + | ||
| 394 | + | -- can't find backpack, try to open new | |
| 395 | + | for i, container in ipairs(lootContainersCandidates) do | |
| 396 | + | local candidates = {} | |
| 397 | + | for j, item in ipairs(container:getItems()) do | |
| 398 | + | if item:isContainer() and containers[item:getId()] ~= nil then | |
| 399 | + | table.insert(candidates, item) | |
| 400 | + | end | |
| 401 | + | end | |
| 402 | + | if #candidates > 0 then | |
| 403 | + | g_game.open(candidates[math.random(1,#candidates)], container) | |
| 404 | + | return | |
| 405 | + | end | |
| 406 | + | -- full, close it | |
| 407 | + | g_game.close(container) | |
| 408 | + | return | |
| 409 | + | end | |
| 410 | + | return | |
| 411 | + | end | |
| 412 | + | ||
| 413 | + | -- open remaining containers | |
| 414 | + | if #nextContainers == 0 then | |
| 415 | + | return | |
| 416 | + | end | |
| 417 | + | local delay = 1 | |
| 418 | + | for i=2,#nextContainers do | |
| 419 | + | -- if more than 1 container, open them in new window | |
| 420 | + | context.schedule(delay, function() | |
| 421 | + | g_game.open(nextContainers[i], nil) | |
| 422 | + | end) | |
| 423 | + | delay = delay + 250 | |
| 424 | + | end | |
| 425 | + | context.schedule(delay, function() | |
| 426 | + | g_game.open(nextContainers[1], container) | |
| 427 | + | end) | |
| 428 | + | context.delay(150 + delay) | |
| 429 | + | end) | |
| 430 | + | end | |
| 431 | + |
| @@ -0,0 +1,36 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.TradeMessage = function(parent) | |
| 5 | + | context.macro(60000, "Send message on trade", nil, function() | |
| 6 | + | local trade = context.getChannelId("advertising") | |
| 7 | + | if not trade then | |
| 8 | + | trade = context.getChannelId("trade") | |
| 9 | + | end | |
| 10 | + | if context.storage.autoTradeMessage:len() > 0 and trade then | |
| 11 | + | context.sayChannel(trade, context.storage.autoTradeMessage) | |
| 12 | + | end | |
| 13 | + | end, parent) | |
| 14 | + | context.addTextEdit("autoTradeMessage", context.storage.autoTradeMessage or "I'm using OTClientV8 - https://github.com/OTCv8/otclientv8", function(widget, text) | |
| 15 | + | context.storage.autoTradeMessage = text | |
| 16 | + | end, parent) | |
| 17 | + | end | |
| 18 | + | ||
| 19 | + | Panels.AutoStackItems = function(parent) | |
| 20 | + | context.macro(500, "Auto stacking items", nil, function() | |
| 21 | + | local containers = context.getContainers() | |
| 22 | + | for i, container in pairs(containers) do | |
| 23 | + | local toStack = {} | |
| 24 | + | for j, item in ipairs(container:getItems()) do | |
| 25 | + | if item:isStackable() and item:getCount() ~= 100 then | |
| 26 | + | local otherItem = toStack[item:getId()] | |
| 27 | + | if otherItem then | |
| 28 | + | g_game.move(item, otherItem, item:getCount()) | |
| 29 | + | return | |
| 30 | + | end | |
| 31 | + | toStack[item:getId()] = container:getSlotPosition(j - 1) | |
| 32 | + | end | |
| 33 | + | end | |
| 34 | + | end | |
| 35 | + | end, parent) | |
| 36 | + | end |
| @@ -0,0 +1,127 @@ | |||
| 1 | + | local context = G.botContext | |
| 2 | + | local Panels = context.Panels | |
| 3 | + | ||
| 4 | + | Panels.AttackLeaderTarget = function(parent) | |
| 5 | + | local toAttack = nil | |
| 6 | + | context.onMissle(function(missle) | |
| 7 | + | if not context.storage.attackLeader or context.storage.attackLeader:len() == 0 then | |
| 8 | + | return | |
| 9 | + | end | |
| 10 | + | local src = missle:getSource() | |
| 11 | + | if src.z ~= context.posz() then | |
| 12 | + | return | |
| 13 | + | end | |
| 14 | + | local from = g_map.getTile(src) | |
| 15 | + | local to = g_map.getTile(missle:getDestination()) | |
| 16 | + | if not from or not to then | |
| 17 | + | return | |
| 18 | + | end | |
| 19 | + | local fromCreatures = from:getCreatures() | |
| 20 | + | local toCreatures = to:getCreatures() | |
| 21 | + | if #fromCreatures ~= 1 or #toCreatures ~= 1 then | |
| 22 | + | return | |
| 23 | + | end | |
| 24 | + | local c1 = fromCreatures[1] | |
| 25 | + | if c1:getName():lower() == context.storage.attackLeader:lower() then | |
| 26 | + | toAttack = toCreatures[1] | |
| 27 | + | end | |
| 28 | + | end) | |
| 29 | + | context.macro(50, "Attack leader's target", nil, function() | |
| 30 | + | if toAttack and context.storage.attackLeader:len() > 0 and toAttack ~= g_game.getAttackingCreature() then | |
| 31 | + | g_game.attack(toAttack) | |
| 32 | + | toAttack = nil | |
| 33 | + | end | |
| 34 | + | end, parent) | |
| 35 | + | context.addTextEdit("attackLeader", context.storage.attackLeader or "player name", function(widget, text) | |
| 36 | + | context.storage.attackLeader = text | |
| 37 | + | end, parent) | |
| 38 | + | end | |
| 39 | + | ||
| 40 | + | ||
| 41 | + | Panels.LimitFloor = function(parent) | |
| 42 | + | context.onPlayerPositionChange(function(pos) | |
| 43 | + | if context.storage.limitFloor then | |
| 44 | + | local gameMapPanel = modules.game_interface.getMapPanel() | |
| 45 | + | if gameMapPanel then | |
| 46 | + | gameMapPanel:lockVisibleFloor(pos.z) | |
| 47 | + | end | |
| 48 | + | end | |
| 49 | + | end) | |
| 50 | + | ||
| 51 | + | local switch = context.addSwitch("limitFloor", "Don't show higher floors", function(widget) | |
| 52 | + | widget:setOn(not widget:isOn()) | |
| 53 | + | context.storage.limitFloor = widget:isOn() | |
| 54 | + | local gameMapPanel = modules.game_interface.getMapPanel() | |
| 55 | + | if gameMapPanel then | |
| 56 | + | if context.storage.limitFloor then | |
| 57 | + | gameMapPanel:lockVisibleFloor(context.posz()) | |
| 58 | + | else | |
| 59 | + | gameMapPanel:unlockVisibleFloor() | |
| 60 | + | end | |
| 61 | + | end | |
| 62 | + | end, parent) | |
| 63 | + | switch:setOn(context.storage.limitFloor) | |
| 64 | + | end | |
| 65 | + | ||
| 66 | + | Panels.AntiPush = function(parent) | |
| 67 | + | if not parent then | |
| 68 | + | parent = context.panel | |
| 69 | + | end | |
| 70 | + | ||
| 71 | + | local panelName = "antiPushPanel" | |
| 72 | + | local ui = g_ui.createWidget("ItemsPanel", parent) | |
| 73 | + | ui:setId(panelName) | |
| 74 | + | ||
| 75 | + | if not context.storage[panelName] then | |
| 76 | + | context.storage[panelName] = {} | |
| 77 | + | end | |
| 78 | + | ||
| 79 | + | ui.title:setText("Anti push") | |
| 80 | + | ui.title:setOn(context.storage[panelName].enabled) | |
| 81 | + | ui.title.onClick = function(widget) | |
| 82 | + | context.storage[panelName].enabled = not context.storage[panelName].enabled | |
| 83 | + | widget:setOn(context.storage[panelName].enabled) | |
| 84 | + | end | |
| 85 | + | ||
| 86 | + | if type(context.storage[panelName].items) ~= 'table' then | |
| 87 | + | context.storage[panelName].items = {3031, 3035, 0, 0, 0} | |
| 88 | + | end | |
| 89 | + | ||
| 90 | + | for i=1,5 do | |
| 91 | + | ui.items:getChildByIndex(i).onItemChange = function(widget) | |
| 92 | + | context.storage[panelName].items[i] = widget:getItemId() | |
| 93 | + | end | |
| 94 | + | ui.items:getChildByIndex(i):setItemId(context.storage[panelName].items[i]) | |
| 95 | + | end | |
| 96 | + | ||
| 97 | + | context.macro(100, function() | |
| 98 | + | if not context.storage[panelName].enabled then | |
| 99 | + | return | |
| 100 | + | end | |
| 101 | + | local tile = g_map.getTile(context.player:getPosition()) | |
| 102 | + | if not tile then | |
| 103 | + | return | |
| 104 | + | end | |
| 105 | + | local topItem = tile:getTopUseThing() | |
| 106 | + | if topItem and topItem:isStackable() then | |
| 107 | + | topItem = topItem:getId() | |
| 108 | + | else | |
| 109 | + | topItem = 0 | |
| 110 | + | end | |
| 111 | + | local candidates = {} | |
| 112 | + | for i, item in pairs(context.storage[panelName].items) do | |
| 113 | + | if item >= 100 and item ~= topItem and context.findItem(item) then | |
| 114 | + | table.insert(candidates, item) | |
| 115 | + | end | |
| 116 | + | end | |
| 117 | + | if #candidates == 0 then | |
| 118 | + | return | |
| 119 | + | end | |
| 120 | + | if type(context.storage[panelName].lastItem) ~= 'number' or context.storage[panelName].lastItem > #candidates then | |
| 121 | + | context.storage[panelName].lastItem = 1 | |
| 122 | + | end | |
| 123 | + | local item = context.findItem(candidates[context.storage[panelName].lastItem]) | |
| 124 | + | g_game.move(item, context.player:getPosition(), 1) | |
| 125 | + | context.storage[panelName].lastItem = context.storage[panelName].lastItem + 1 | |
| 126 | + | end) | |
| 127 | + | end |