Skip to content
Open
Changes from all commits
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
42 changes: 32 additions & 10 deletions src/Classes/SkillsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,28 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont
local item = getSelectedItem()
return not not item
end
self.controls.optimiseSockets = new("ButtonControl", { "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "^7Optimise Sockets", function()
local function getSocketCounts(item)
local abyssalSocketCount = 0
for _, socket in ipairs(item.sockets) do
if socket.color == "A" then
abyssalSocketCount = abyssalSocketCount + 1
end
end
local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount
return maxSockets, abyssalSocketCount
end
self.controls.optimiseSockets = new("ButtonControl", { "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "Optimise Sockets", function()
local item, groupSlot = getSelectedItem()
if not item or not groupSlot or not item.base then
return
end

self.build.itemsTab:AddUndoState()

-- save count of abyssal sockets
local abyssalSocketCount = 0
for _, socket in ipairs(item.sockets) do
if socket.color == "A" then
abyssalSocketCount = abyssalSocketCount + 1
end
end
local maxSockets, abyssalSocketCount = getSocketCounts(item)

local groupCount = 0
item.sockets = {}
local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount
for _, group in ipairs(self.socketGroupList) do
local colours = { "R", "G", "B" }
if group.slot == groupSlot.slotName then
Expand All @@ -272,7 +275,6 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont
groupCount = groupCount + 1
end
end

for _ = 0, abyssalSocketCount - 1 do
groupCount = groupCount + 1
table.insert(item.sockets, { color = "A", group = groupCount })
Expand All @@ -285,6 +287,26 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont
local item = getSelectedItem()
return item and (item.base.socketLimit ~= nil)
end
self.controls.optimiseSockets.enabled = function()
local item, groupSlot = getSelectedItem()
if not item or not groupSlot or not item.base then
return false
end
local maxSockets = getSocketCounts(item)
for _, group in ipairs(self.socketGroupList) do
if group.slot == groupSlot.slotName then
for _, gem in ipairs(group.gemList) do
if (gem.grantedEffect or (gem.gemData and gem.gemData.grantedEffect)) and maxSockets > 0 then
if not gem.matchesSocket then
return true
end
maxSockets -= 1
end
end
end
end
return false
end
self.controls.optimiseSockets.tooltipText = "Rebuild the item's sockets to match the groups assigned to it."
-- self.imbuedSupportBySlot is used by CalcSetup to add an ExtraSupport mod of the selected gem
-- Each displayGroup has its own "imbuedSupport" and is saved to the xml to load when changing sockets or loading a build
Expand Down
Loading