Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion modules/game_bot/default_configs/vBot_4.8/targetbot/looting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ TargetBot.Looting.setup = function()
UI.Container(TargetBot.Looting.onContainersUpdate, true, nil, ui.containers)
ui.everyItem.onClick = function()
ui.everyItem:setOn(not ui.everyItem:isOn())
if ui.labelToLoot then
if ui.everyItem:isOn() then
ui.labelToLoot:setText("Items to ignore")
else
ui.labelToLoot:setText("Items to loot")
end
end
Comment on lines +17 to +23
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label update logic is duplicated in the onClick handler and the update function. Consider extracting this into a separate function to improve maintainability and reduce code duplication. For example, create a function like updateLootLabel() that checks the state and updates the label text accordingly.

Copilot uses AI. Check for mistakes.
TargetBot.save()
end
ui.maxDangerPanel.value.onTextChange = function()
Expand Down Expand Up @@ -52,6 +59,13 @@ TargetBot.Looting.update = function(data)
ui.items:setItems(data['items'] or {})
ui.containers:setItems(data['containers'] or {})
ui.everyItem:setOn(data['everyItem'])
if ui.labelToLoot then
if ui.everyItem:isOn() then
ui.labelToLoot:setText("Items to ignore")
else
ui.labelToLoot:setText("Items to loot")
end
end
Comment on lines +62 to +68
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for updating the label text based on the everyItem toggle state is duplicated between the setup function (lines 17-23) and the update function (lines 62-68). Consider extracting this into a separate helper function like updateLabelText() to improve maintainability and reduce code duplication.

Copilot uses AI. Check for mistakes.
ui.maxDangerPanel.value:setText(data['maxDanger'] or 10)
ui.minCapacityPanel.value:setText(data['minCapacity'] or 100)
TargetBot.Looting.updateItemsAndContainers()
Expand Down Expand Up @@ -224,7 +238,7 @@ TargetBot.Looting.lootContainer = function(lootContainers, container)
for i, item in ipairs(container:getItems()) do
if item:isContainer() and not itemsById[item:getId()] then
nextContainer = item
elseif itemsById[item:getId()] or (ui.everyItem:isOn() and not item:isContainer()) then
elseif (not ui.everyItem:isOn() and itemsById[item:getId()]) or (ui.everyItem:isOn() and (not item:isContainer() and not itemsById[item:getId()])) then
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boolean logic on this line is complex and difficult to understand at a glance. Consider extracting this into a helper function with a descriptive name like shouldLootItem(item) or adding a comment explaining the two modes: whitelist mode (everyItem OFF - loot only items in list) and blacklist mode (everyItem ON - loot everything except items in list and containers).

Copilot uses AI. Check for mistakes.
item.lootTries = (item.lootTries or 0) + 1
Comment on lines 240 to 242
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The looting condition is correct but hard to read/maintain as a single boolean expression with repeated lookups. Consider computing local flags (e.g., blacklistMode, isContainer, inList) and using a small if/else to decide whether to loot, so future changes don’t accidentally invert the logic.

Copilot uses AI. Check for mistakes.
if item.lootTries < 5 then -- if can't be looted within 0.5s then skip it
return TargetBot.Looting.lootItem(lootContainers, item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TargetBotLootingPanel < Panel
margin-top: 5

Label
id: labelToLoot
margin-top: 5
text: Items to loot
text-align: center
Expand All @@ -17,8 +18,9 @@ TargetBotLootingPanel < Panel

BotSwitch
id: everyItem
!text: tr("Loot every item")
!text: tr("Loot every item, except these")
margin-top: 2
font: small-9px

Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The font size has been reduced to small-9px to accommodate the longer button text. This smaller font size may impact readability and accessibility, particularly for users with visual impairments. Consider if the text can be made more concise to avoid needing a smaller font, or if the UI layout can be adjusted to accommodate the standard font size.

Suggested change
!text: tr("Loot every item, except these")
margin-top: 2
font: small-9px
!text: tr("Loot all except listed")
margin-top: 2

Copilot uses AI. Check for mistakes.
Label
margin-top: 5
Expand Down Expand Up @@ -66,4 +68,4 @@ TargetBotLootingPanel < Panel
anchors.left: parent.left
anchors.verticalCenter: prev.verticalCenter
text: Min. capacity:
margin-left: 5
margin-left: 5