Skip to content

Commit 1910eef

Browse files
LocalIdentityLocalIdentity
andauthored
Fix Mageblood mods merging in item crafter (#2186)
We currently only check if a variant is active to add the variants mod which is why selecting the same variant twice only shows 1 mod on the item Added a flag that overwrites this behaviour so they don't get merged on Mageblood Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 0d07111 commit 1910eef

6 files changed

Lines changed: 103 additions & 8 deletions

File tree

spec/System/TestItemMods_spec.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ describe("TetsItemMods", function()
77
-- newBuild() takes care of resetting everything in setup()
88
end)
99

10+
it("shows duplicate selected variants in item tooltips when enabled", function()
11+
local item = new("Item", [[
12+
Rarity: Unique
13+
Mageblood
14+
Utility Belt
15+
Has Alt Variant: true
16+
Selected Variant: 1
17+
Selected Alt Variant: 1
18+
Allow Duplicate Variants: true
19+
Variant: Legacy of Amethyst
20+
Implicits: 0
21+
{variant:1}Legacy of Amethyst
22+
]])
23+
local tooltip = new("Tooltip")
24+
25+
build.itemsTab:AddItemTooltip(tooltip, item)
26+
27+
local legacyLines = 0
28+
for _, line in ipairs(tooltip.lines) do
29+
if line.text and line.text:find("Legacy of Amethyst", 1, true) then
30+
legacyLines = legacyLines + 1
31+
end
32+
end
33+
assert.are.equals(2, legacyLines)
34+
end)
35+
1036
it("aggregates matching ring item rarity lines before applying ring bonus effect", function()
1137
build.configTab.input.customMods = "30% increased bonuses gained from left Equipped Ring"
1238
build.configTab:BuildModList()

spec/System/TestItemParse_spec.lua

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,45 @@ describe("TestItemParse", function()
8585
--it("Variant name", function()
8686
--end)
8787

88-
--it("variant", function()
89-
--end)
88+
it("allows duplicate selected variants when enabled", function()
89+
local item = new("Item", [[
90+
Rarity: Unique
91+
Mageblood
92+
Utility Belt
93+
Has Alt Variant: true
94+
Has Alt Variant Two: true
95+
Has Alt Variant Three: true
96+
Selected Variant: 1
97+
Selected Alt Variant: 1
98+
Selected Alt Variant Two: 2
99+
Selected Alt Variant Three: 2
100+
Allow Duplicate Variants: true
101+
Variant: Legacy of Amethyst
102+
Variant: Legacy of Basalt
103+
Implicits: 0
104+
{variant:1}Legacy of Amethyst
105+
{variant:2}Legacy of Basalt
106+
]])
107+
108+
assert.are.equals(2, item.baseModList:Sum("BASE", nil, "LegacyOfAmethyst"))
109+
assert.are.equals(2, item.baseModList:Sum("BASE", nil, "LegacyOfBasalt"))
110+
end)
111+
112+
it("does not duplicate selected variants by default", function()
113+
local item = new("Item", [[
114+
Rarity: Unique
115+
Mageblood
116+
Utility Belt
117+
Has Alt Variant: true
118+
Selected Variant: 1
119+
Selected Alt Variant: 1
120+
Variant: Legacy of Amethyst
121+
Implicits: 0
122+
{variant:1}Legacy of Amethyst
123+
]])
124+
125+
assert.are.equals(1, item.baseModList:Sum("BASE", nil, "LegacyOfAmethyst"))
126+
end)
90127

91128
--TODO: Alt variants for POB2
92129
--it("Alt Variant", function()

src/Classes/Item.lua

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
630630
self.variantAlt4 = specToNumber(specVal)
631631
elseif specName == "Selected Alt Variant Five" then
632632
self.variantAlt5 = specToNumber(specVal)
633+
elseif specName == "Allow Duplicate Variants" then
634+
self.allowDuplicateVariants = specVal == "true"
633635
elseif specName == "Has Variants" or specName == "Selected Variants" then
634636
-- Need to skip this line for backwards compatibility
635637
-- with builds that used an old Watcher's Eye implementation
@@ -1462,6 +1464,9 @@ function ItemClass:BuildRaw()
14621464
t_insert(rawLines, "Has Alt Variant Five: true")
14631465
t_insert(rawLines, "Selected Alt Variant Five: " .. self.variantAlt5)
14641466
end
1467+
if self.allowDuplicateVariants then
1468+
t_insert(rawLines, "Allow Duplicate Variants: true")
1469+
end
14651470
end
14661471
if self.quality then
14671472
t_insert(rawLines, "Quality: " .. self.quality)
@@ -1683,6 +1688,24 @@ function ItemClass:CheckModLineVariant(modLine)
16831688
or (self.hasAltVariant5 and modLine.variantList[self.variantAlt5])
16841689
end
16851690

1691+
function ItemClass:GetModLineVariantCount(modLine)
1692+
if not self.allowDuplicateVariants or not modLine.variantList then
1693+
return self:CheckModLineVariant(modLine) and 1 or 0
1694+
end
1695+
1696+
-- Mageblood can intentionally select the same variant more than once.
1697+
local variantList = modLine.variantList
1698+
local count = variantList[self.variant] and 1 or 0
1699+
for i = 1, 5 do
1700+
local suffix = i == 1 and "" or i
1701+
local variant = self["variantAlt" .. suffix]
1702+
if self["hasAltVariant" .. suffix] and variant and variantList[variant] then
1703+
count = count + 1
1704+
end
1705+
end
1706+
return count
1707+
end
1708+
16861709
-- Return the name of the slot this item is equipped in
16871710
function ItemClass:GetPrimarySlot()
16881711
if self.base.weapon or self.base.type == "Wand" or self.base.type == "Sceptre" or self.base.type == "Staff" then
@@ -2027,7 +2050,8 @@ function ItemClass:BuildModList()
20272050
end
20282051
end
20292052
local function processModLine(modLine)
2030-
if self:CheckModLineVariant(modLine) then
2053+
local variantCount = self:GetModLineVariantCount(modLine)
2054+
if variantCount > 0 then
20312055
-- special section for variant over-ride of pre-modifier item parameters
20322056
if modLine.line:find("Requires Class") then
20332057
self.classRestriction = modLine.line:gsub("{variant:([%d,]+)}", ""):match("Requires Class (.+)")
@@ -2054,8 +2078,9 @@ function ItemClass:BuildModList()
20542078
end
20552079
end
20562080
for _, mod in ipairs(modLine.modList) do
2057-
mod = modLib.setSource(mod, self.modSource)
2058-
baseList:AddMod(mod)
2081+
for _ = 1, variantCount do
2082+
baseList:AddMod(modLib.setSource(mod, self.modSource))
2083+
end
20592084
end
20602085
if modLine.modTags and #modLine.modTags > 0 then
20612086
self.hasModTags = true

src/Classes/ItemsTab.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,10 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
35343534
for _, modList in ipairs{item.enchantModLines, item.runeModLines, item.implicitModLines, item.explicitModLines} do
35353535
if modList[1] then
35363536
for _, modLine in ipairs(modList) do
3537-
if item:CheckModLineVariant(modLine) then
3537+
local variantCount = item:GetModLineVariantCount(modLine)
3538+
if variantCount > 0 then
35383539
local bg = modLine.desecrated and "HoverModBgAbyss" or nil
3540+
local formattedModLine
35393541
if scale ~= 1 then
35403542
local copyModLine = copyTable(modLine)
35413543
local modsList = copyTable(modLine.modList)
@@ -3556,9 +3558,12 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
35563558
copyModLine.line = copyModLine.line:gsub("%d*%.?%d+", math.abs(newValue), 1) -- Only scale first number in line
35573559
end
35583560
end
3559-
tooltip:AddLine(fontSizeBig, itemLib.formatModLine(copyModLine, dbMode), "FONTIN SC", bg)
3561+
formattedModLine = itemLib.formatModLine(copyModLine, dbMode)
35603562
else
3561-
tooltip:AddLine(fontSizeBig, itemLib.formatModLine(modLine, dbMode), "FONTIN SC", bg)
3563+
formattedModLine = itemLib.formatModLine(modLine, dbMode)
3564+
end
3565+
for _ = 1, variantCount do
3566+
tooltip:AddLine(fontSizeBig, formattedModLine, "FONTIN SC", bg)
35623567
end
35633568

35643569
-- Show mods from granted Notables

src/Data/Uniques/belt.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Selected Variant: 1
169169
Selected Alt Variant: 2
170170
Selected Alt Variant Two: 3
171171
Selected Alt Variant Three: 4
172+
Allow Duplicate Variants: true
172173
Variant: Legacy of Amethyst
173174
Variant: Legacy of Basalt
174175
Variant: Legacy of Bismuth

src/Export/Uniques/belt.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Selected Variant: 1
169169
Selected Alt Variant: 2
170170
Selected Alt Variant Two: 3
171171
Selected Alt Variant Three: 4
172+
Allow Duplicate Variants: true
172173
Variant: Legacy of Amethyst
173174
Variant: Legacy of Basalt
174175
Variant: Legacy of Bismuth

0 commit comments

Comments
 (0)