Skip to content

Commit 9c1495a

Browse files
committed
Add item parsing handling, fix corruptItem(), and apply range in formatModLine()
1 parent 5316569 commit 9c1495a

3 files changed

Lines changed: 38 additions & 23 deletions

File tree

src/Classes/Item.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
701701
end
702702
elseif k == "range" then
703703
modLine.range = tonumber(val)
704+
elseif k == "corruptedRange" then
705+
modLine.corruptedRange = tonumber(val)
704706
elseif lineFlags[k] then
705707
modLine[k] = true
706708
end
@@ -892,13 +894,13 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
892894
modLine.range = bestPrecisionRange
893895
end
894896
end
895-
local rangedLine = itemLib.applyRange(line, 1, catalystScalar)
897+
local rangedLine = itemLib.applyRange(line, 1, catalystScalar, modLine.corruptedRange)
896898
local modList, extra = modLib.parseMod(rangedLine)
897899
if (not modList or extra) and self.rawLines[l+1] then
898900
-- Try to combine it with the next line
899901
local nextLine = self.rawLines[l+1]:gsub("%b{}", ""):gsub(" ?%(%l+%)","")
900902
local combLine = line.." "..nextLine
901-
rangedLine = itemLib.applyRange(combLine, 1, catalystScalar)
903+
rangedLine = itemLib.applyRange(combLine, 1, catalystScalar, modLine.corruptedRange)
902904
modList, extra = modLib.parseMod(rangedLine, true)
903905
if modList and not extra then
904906
line = line.."\n"..nextLine
@@ -1262,10 +1264,14 @@ function ItemClass:BuildRaw()
12621264
t_insert(rawLines, "Item Level: " .. self.itemLevel)
12631265
end
12641266
local function writeModLine(modLine)
1265-
local line = modLine.line
1267+
local displayValueScalar = modLine.displayValueScalar and (modLine.valueScalar or 1) * modLine.displayValueScalar
1268+
local line = displayValueScalar and itemLib.applyRange(modLine.line, modLine.range or main.defaultItemAffixQuality, displayValueScalar, modLine.corruptedRange) or modLine.line
12661269
if modLine.range and line:match("%(%-?[%d%.]+%-%-?[%d%.]+%)") then
12671270
line = "{range:" .. round(modLine.range, 3) .. "}" .. line
12681271
end
1272+
if modLine.corruptedRange then
1273+
line = "{corruptedRange:" .. round(modLine.corruptedRange, 2) .. "}" .. line
1274+
end
12691275
if modLine.crafted then
12701276
line = "{crafted}" .. line
12711277
end
@@ -1867,7 +1873,7 @@ function ItemClass:BuildModList()
18671873
local strippedModeLine = modLine.line:gsub("\n"," ")
18681874
local catalystScalar = getCatalystScalar(self.catalyst, modLine, self.catalystQuality)
18691875
-- Put the modified value into the string
1870-
local line = itemLib.applyRange(strippedModeLine, modLine.range, catalystScalar)
1876+
local line = itemLib.applyRange(strippedModeLine, modLine.range, catalystScalar, modLine.corruptedRange)
18711877
-- Check if we can parse it before adding the mods
18721878
local list, extra = modLib.parseMod(line)
18731879
if list and not extra then

src/Classes/ItemsTab.lua

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,28 +2748,37 @@ function ItemsTabClass:CorruptDisplayItem(modType)
27482748
if controls.implicit3 then controls.implicit3:UpdateSearch() end
27492749
if controls.implicit4 then controls.implicit4:UpdateSearch() end
27502750
end
2751-
local function corruptItem()
2751+
local function corruptItem(addingImplicits)
27522752
local item = new("Item"):Item(self.displayItem:BuildRaw())
27532753
item.id = self.displayItem.id
27542754
item.corrupted = true
2755-
local newImplicit = { }
2756-
for _, control in ipairs { controls.implicit1, controls.implicit2, controls.implicit3, controls.implicit4 } do
2757-
if control.selIndex > 1 then
2758-
local mod = control.list[control.selIndex].mod
2759-
for _, modLine in ipairs(mod) do
2760-
modLine = (currentModType == "ScourgeUpside" and "{scourge}" or "") .. modLine
2761-
if mod.modTags[1] then
2762-
t_insert(newImplicit, { line = "{tags:" .. table.concat(mod.modTags, ",") .. "}" .. modLine })
2763-
else
2764-
t_insert(newImplicit, { line = modLine })
2755+
-- either add implicits or roll ranges. if in the future it is possible
2756+
-- to double corrupt an item, this needs to be changed to not remove
2757+
-- implicits, like in pob2
2758+
if addingImplicits then
2759+
local newImplicit = {}
2760+
for _, control in ipairs { controls.implicit1, controls.implicit2, controls.implicit3, controls.implicit4 } do
2761+
if control.selIndex > 1 then
2762+
local mod = control.list[control.selIndex].mod
2763+
for _, modLine in ipairs(mod) do
2764+
modLine = (currentModType == "ScourgeUpside" and "{scourge}" or "") .. modLine
2765+
if mod.modTags[1] then
2766+
t_insert(newImplicit, { line = "{tags:" .. table.concat(mod.modTags, ",") .. "}" .. modLine })
2767+
else
2768+
t_insert(newImplicit, { line = modLine })
2769+
end
27652770
end
27662771
end
27672772
end
2768-
end
2769-
if #newImplicit > 0 then
2770-
wipeTable(currentModType == "Corrupted" and item.implicitModLines or item.scourgeModLines)
2771-
for i, implicit in ipairs(newImplicit) do
2772-
t_insert(currentModType == "Corrupted" and item.implicitModLines or item.scourgeModLines, i, implicit)
2773+
if #newImplicit > 0 then
2774+
wipeTable(currentModType == "Corrupted" and item.implicitModLines or item.scourgeModLines)
2775+
for i, implicit in ipairs(newImplicit) do
2776+
t_insert(currentModType == "Corrupted" and item.implicitModLines or item.scourgeModLines, i, implicit)
2777+
end
2778+
end
2779+
else
2780+
for i, modLine in ipairs(item.explicitModLines) do
2781+
if corruptedRanges[i] ~= 1 then modLine.corruptedRange = corruptedRanges[i] end
27732782
end
27742783
end
27752784
item:BuildAndParseRaw()
@@ -2964,12 +2973,12 @@ function ItemsTabClass:CorruptDisplayItem(modType)
29642973
end
29652974
end
29662975
controls.save = new("ButtonControl"):ButtonControl({ "BOTTOM", nil, "BOTTOM" }, { -45, -4, 80, 20 }, modType, function()
2967-
self:SetDisplayItem(corruptItem())
2976+
self:SetDisplayItem(corruptItem(controls.implicit1.shown))
29682977
main:ClosePopup()
29692978
end)
29702979
controls.save.tooltipFunc = function(tooltip)
29712980
tooltip:Clear()
2972-
self:AddItemTooltip(tooltip, corruptItem(), nil, true)
2981+
self:AddItemTooltip(tooltip, corruptItem(controls.implicit1.shown), nil, false)
29732982
end
29742983
controls.close = new("ButtonControl"):ButtonControl({ "BOTTOM", nil, "BOTTOM" }, { 45, -4, 80, 20 }, "Cancel", function()
29752984
main:ClosePopup()

src/Modules/ItemTools.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ function itemLib.applyRange(line, range, valueScalar, baseValueScalar)
337337
end
338338

339339
function itemLib.formatModLine(modLine, dbMode)
340-
local line = (not dbMode and modLine.range and itemLib.applyRange(modLine.line, modLine.range, modLine.valueScalar)) or modLine.line
340+
local line = (not dbMode and modLine.range and itemLib.applyRange(modLine.line, modLine.range, modLine.valueScalar, modLine.corruptedRange)) or modLine.line
341341
if line:match("^%+?0%%? ") or (line:match(" %+?0%%? ") and not line:match("0 to [1-9]")) or line:match(" 0%-0 ") or line:match(" 0 to 0 ") then -- Hack to hide 0-value modifiers
342342
return
343343
end

0 commit comments

Comments
 (0)