Skip to content
Closed
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion spec/System/TestSkills_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,25 @@ describe("TestSkills", function()

assert.True(build.calcsTab.calcsOutput.Cooldown == 10)
end)
end)

it("Test active gem DPS sorting estimates replacement skills", function()
build.itemsTab:CreateDisplayItemFromRaw([[
New Item
Bombard Crossbow
Quality: 0
]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")

build.skillsTab:PasteSocketGroup("Oil Grenade 20/0 1")
runCallback("OnFrame")

build.skillsTab.sortGemsByDPS = true
build.skillsTab.sortGemsByDPSField = "CombinedDPS"
local activeGemSelect = build.skillsTab.gemSlots[1].nameSpec
activeGemSelect:UpdateSortCache()

local _, explosiveGrenade = build.skillsTab:FindSkillGem("Explosive Grenade")
assert.True(activeGemSelect.sortCache.dpsCalculated["Default:" .. explosiveGrenade.id])
end)
end)
15 changes: 12 additions & 3 deletions src/Classes/GemSelectControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ function GemSelectClass:UpdateSortCache()
canSupport = { },
dps = { },
dpsColor = { },
dpsCalculated = { },
sortType = self.skillsTab.sortGemsByDPSField
}
self.sortCache = sortCache
Expand Down Expand Up @@ -300,14 +301,19 @@ function GemSelectClass:UpdateSortCache()
local calcFunc, calcBase = self.skillsTab.build.calcsTab:GetMiscCalculator(self.build)
-- Check for nil because some fields may not be populated, default to 0
local baseDPS = (dpsField == "FullDPS" and calcBase[dpsField] ~= nil and calcBase[dpsField]) or (calcBase.Minion and calcBase.Minion.CombinedDPS) or (calcBase[dpsField] ~= nil and calcBase[dpsField]) or 0
sortCache.baseDPS = baseDPS

for gemId, gemData in pairs(self.gems) do
sortCache.dps[gemId] = baseDPS
-- Ignore gems that don't support the active skill
if sortCache.canSupport[gemId] or (gemData.grantedEffect.hasGlobalEffect and not gemData.grantedEffect.support) then
local canEstimateDPS = sortCache.canSupport[gemId]
or (gemData.grantedEffect.hasGlobalEffect and not gemData.grantedEffect.support)
or (self.index == 1 and not gemData.grantedEffect.support)
-- Ignore gems that cannot affect the active skill or replace the active gem
if canEstimateDPS then
local output = self:CalcOutputWithThisGem(calcFunc, gemData, useFullDPS, fastCalcOptions, calcBase)
-- Check for nil because some fields may not be populated, default to 0
sortCache.dps[gemId] = (dpsField == "FullDPS" and output[dpsField] ~= nil and output[dpsField]) or (output.Minion and output.Minion.CombinedDPS) or (output[dpsField] ~= nil and output[dpsField]) or 0
sortCache.dpsCalculated[gemId] = true
end
-- Color based on the DPS
if sortCache.dps[gemId] > baseDPS then
Expand Down Expand Up @@ -438,6 +444,9 @@ function GemSelectClass:Draw(viewPort, noTooltip)
elseif gemData.grantedEffect.hasGlobalEffect then
SetDrawColor(self.sortCache.dpsColor[gemId])
DrawString(width - 4 - height / 2 - (scrollBar.enabled and 18 or 0), y - 2, "CENTER_X", height, "VAR", "+")
elseif self.sortCache.dpsCalculated[gemId] and self.sortCache.dps[gemId] ~= self.sortCache.baseDPS then
SetDrawColor(self.sortCache.dpsColor[gemId])
DrawString(width - 4 - height / 2 - (scrollBar.enabled and 18 or 0), y - 2, "CENTER_X", height, "VAR", "+")
end
end
end
Expand Down Expand Up @@ -907,4 +916,4 @@ function GemSelectClass:OnKeyUp(key)
end
local newSel = self.EditControl:OnKeyUp(key)
return newSel == self.EditControl and self or newSel
end
end