Skip to content

Commit b7c8136

Browse files
committed
Add support for finding correct conqueror mod
1 parent 553509e commit b7c8136

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

spec/System/TestItemParse_spec.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ describe("TestAdvancedItemParse #item", function()
560560
assert.are.equals(20, item.baseModList[1].value.mod.value)
561561
end)
562562

563+
it("correctly matches conqueror mod", function()
564+
local item = new("Item", raw([[
565+
{ Suffix Modifier "of the Conquest" (Tier: 1) — Elemental, Cold }
566+
10(8-10)% chance to Avoid Cold Damage from Hits
567+
(No chance to avoid damage can be higher than 75%)
568+
Warlord Item
569+
]]))
570+
assert.are.equals(10, item.baseModList[1].value)
571+
assert.are.equals(1, item.explicitModLines[1].range)
572+
end)
573+
563574
it("parses junk", function()
564575
local godTestItem = new("Item", [[
565576
Item Class: Sceptres

src/Classes/Item.lua

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,30 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
425425
fullModName = line:match("^{ (.-) }$")
426426
end
427427
local modName = fullModName:match("^.*Modifier \"(.*)\"")
428-
if modName and modName ~= "" then
428+
if modName and modName ~= "" then
429+
self.pendingAffixList = { }
430+
local backupAffixList = { }
429431
for modId, modData in pairs(self.affixes) do
430-
if modData.affix == modName and self:CanHaveMod(modData) then
431-
if modData.type == "Prefix" then
432-
self.pendingAffix = { modId = modId, table = self.prefixes }
433-
elseif modData.type == "Suffix" then
434-
self.pendingAffix = { modId = modId, table = self.suffixes }
432+
if modData.affix == modName then
433+
if self:CanHaveMod(modData) then
434+
if modData.type == "Prefix" then
435+
t_insert(self.pendingAffixList, { modId = modId, table = self.prefixes })
436+
elseif modData.type == "Suffix" then
437+
t_insert(self.pendingAffixList, { modId = modId, table = self.suffixes })
438+
end
439+
else
440+
-- Conqueror mods can't natively spawn on items, so we'll use those if we don't find a match otherwise
441+
if modData.type == "Prefix" then
442+
t_insert(backupAffixList, { modId = modId, table = self.prefixes })
443+
elseif modData.type == "Suffix" then
444+
t_insert(backupAffixList, { modId = modId, table = self.suffixes })
445+
end
435446
end
436447
end
437448
end
449+
if #self.pendingAffixList == 0 and #backupAffixList > 0 then
450+
self.pendingAffixList = backupAffixList
451+
end
438452
end
439453
local possibleLineFlags = fullModName:match("(.*)Modifier.*")
440454
if possibleLineFlags then
@@ -796,7 +810,21 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
796810
else
797811
catalystScalar = getCatalystScalar(self.catalyst, modLine, self.catalystQuality)
798812
end
799-
if self.pendingAffix then
813+
if self.pendingAffixList and #self.pendingAffixList > 0 then
814+
if #self.pendingAffixList > 1 then
815+
-- Probably a conqueror mod since the mod name is the same for all of them
816+
-- Try to match the line against one of the mods there
817+
local valueStrippedLine = line:gsub("%-?%d+%.?%d*%(", "("):gsub("%-?%d+%.?%d*", "#")
818+
for _, pendingAffix in ipairs(self.pendingAffixList) do
819+
local modData = self.affixes[pendingAffix.modId]
820+
for _, modDataLine in ipairs(modData) do
821+
if valueStrippedLine == modDataLine:gsub("%-?%d+%.?%d*", "#") then
822+
self.pendingAffixList = { pendingAffix }
823+
break
824+
end
825+
end
826+
end
827+
end
800828
local bestPrecisionDelta = 0
801829
local bestPrecisionRange = 0
802830
for value, range in line:gmatch("(%-?%d+%.?%d*)%((%-?%d+%.?%d*%-%-?%d+%.?%d*)%)") do
@@ -809,11 +837,11 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
809837
bestPrecisionDelta = delta
810838
end
811839
end
812-
t_insert(self.pendingAffix.table, {
813-
modId = self.pendingAffix.modId,
840+
t_insert(self.pendingAffixList[1].table, {
841+
modId = self.pendingAffixList[1].modId,
814842
range = tonumber(bestPrecisionRange),
815843
})
816-
self.pendingAffix = nil
844+
self.pendingAffixList = {}
817845
else
818846
local bestPrecisionDelta = 0
819847
local bestPrecisionRange = 0

0 commit comments

Comments
 (0)