Skip to content

Commit 746c116

Browse files
authored
Merge pull request #140 from QuickStick123/improve-rune-handling
Improve rune handling
2 parents 2586684 + 75bb20c commit 746c116

File tree

15 files changed

+474
-90
lines changed

15 files changed

+474
-90
lines changed

src/Classes/ImportTab.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ function ImportTabClass:ImportItem(itemData, slotName)
910910
end
911911
end
912912
item.enchantModLines = { }
913+
item.runeModLines = { }
913914
item.classRequirementModLines = { }
914915
item.implicitModLines = { }
915916
item.explicitModLines = { }
@@ -921,6 +922,14 @@ function ImportTabClass:ImportItem(itemData, slotName)
921922
end
922923
end
923924
end
925+
if itemData.runeMods then
926+
for _, line in ipairs(itemData.runeMods) do
927+
for line in line:gmatch("[^\n]+") do
928+
local modList, extra = modLib.parseMod(line)
929+
t_insert(item.runeModLines, { line = line, extra = extra, mods = modList or { }, enchant = true, rune = true })
930+
end
931+
end
932+
end
924933
if itemData.implicitMods then
925934
for _, line in ipairs(itemData.implicitMods) do
926935
for line in line:gmatch("[^\n]+") do

src/Classes/Item.lua

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,12 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
332332
end
333333
self.checkSection = false
334334
self.sockets = { }
335+
self.runes = { }
335336
self.itemSocketCount = 0
336337
self.classRequirementModLines = { }
337338
self.buffModLines = { }
338339
self.enchantModLines = { }
340+
self.runeModLines = { }
339341
self.implicitModLines = { }
340342
self.explicitModLines = { }
341343
local implicitLines = 0
@@ -417,6 +419,8 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
417419
end
418420
end
419421
self.itemSocketCount = #self.sockets
422+
elseif specName == "Rune" then
423+
t_insert(self.runes, specVal)
420424
elseif specName == "Radius" and self.type == "Jewel" then
421425
self.jewelRadiusLabel = specVal:match("^[%a ]+")
422426
if specVal:match("^%a+") == "Variable" then
@@ -739,11 +743,13 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
739743
end
740744

741745
local modLines
742-
if modLine.enchant then
746+
if modLine.rune then
747+
modLines = self.runeModLines
748+
elseif modLine.enchant then
743749
modLines = self.enchantModLines
744750
elseif line:find("Requires Class") then
745751
modLines = self.classRequirementModLines
746-
elseif modLine.implicit or #self.enchantModLines + #self.implicitModLines < implicitLines then
752+
elseif modLine.implicit or #self.runeModLines + #self.enchantModLines + #self.implicitModLines < implicitLines then
747753
modLines = self.implicitModLines
748754
else
749755
modLines = self.explicitModLines
@@ -788,6 +794,37 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
788794
if self.baseName and self.title then
789795
self.name = self.title .. ", " .. self.baseName:gsub(" %(.+%)","")
790796
end
797+
-- this will need more advanced logic for jewel sockets in items to work properly but could just be removed as items like this was only introduced during development.
798+
if self.base then
799+
if self.base.weapon or self.base.armour then
800+
if #self.runes == 0 then
801+
for i, modLine in ipairs(self.runeModLines) do
802+
local value
803+
local strippedModeLine = modLine.line:gsub("(%d%.?%d*)", function(val)
804+
value = val
805+
return "#"
806+
end)
807+
for name, runeMods in pairs(data.itemMods.Runes) do
808+
local runeValue
809+
local runeStrippedModeLine = (self.base.weapon and runeMods.weapon or runeMods.armour)[1]:gsub("(%d%.?%d*)", function(val)
810+
runeValue = val
811+
return "#"
812+
end)
813+
if strippedModeLine == runeStrippedModeLine then
814+
for i = 1, round(value/runeValue) do
815+
t_insert(self.runes, name)
816+
end
817+
end
818+
end
819+
end
820+
end
821+
else
822+
self.sockets = { }
823+
self.itemSocketCount = 0
824+
self.runes = { }
825+
end
826+
end
827+
791828
if self.base and not self.requirements.level then
792829
if importedLevelReq and #self.sockets == 0 then
793830
-- Requirements on imported items can only be trusted for items with no sockets
@@ -838,14 +875,6 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
838875
end
839876
end
840877
end
841-
if self.base and self.base.socketLimit and (self.base.weapon or self.base.armour) then -- must be a martial weapon/armour
842-
if #self.sockets == 0 then
843-
for i = 1, self.base.socketLimit do
844-
t_insert(self.sockets, { group = 0 })
845-
end
846-
self.itemSocketCount = #self.sockets
847-
end
848-
end
849878
if self.variantList then
850879
self.variant = m_min(#self.variantList, self.variant or #self.variantList)
851880
if self.hasAltVariant then
@@ -975,6 +1004,9 @@ function ItemClass:BuildRaw()
9751004
if modLine.corruptedRange then
9761005
line = "{corruptedRange:" .. round(modLine.corruptedRange, 2) .. "}" .. line
9771006
end
1007+
if modLine.rune then
1008+
line = "{rune}" .. line
1009+
end
9781010
if modLine.enchant then
9791011
line = "{enchant}" .. line
9801012
end
@@ -1028,13 +1060,16 @@ function ItemClass:BuildRaw()
10281060
if self.quality then
10291061
t_insert(rawLines, "Quality: " .. self.quality)
10301062
end
1031-
if self.itemSocketCount and self.itemSocketCount > 0 then
1063+
if self.itemSocketCount and self.itemSocketCount > 0 and (self.base.weapon or self.base.armour) then
10321064
local socketString = ""
10331065
for _ = 1, self.itemSocketCount do
10341066
socketString = socketString .. "S "
10351067
end
10361068
socketString = socketString:gsub(" $", "")
10371069
t_insert(rawLines, "Sockets: " .. socketString)
1070+
for i = 1, self.itemSocketCount do
1071+
t_insert(rawLines, "Rune: "..(self.runes[i] or "None"))
1072+
end
10381073
end
10391074
if self.requirements and self.requirements.level then
10401075
t_insert(rawLines, "LevelReq: " .. self.requirements.level)
@@ -1048,7 +1083,10 @@ function ItemClass:BuildRaw()
10481083
if self.classRestriction then
10491084
t_insert(rawLines, "Requires Class " .. self.classRestriction)
10501085
end
1051-
t_insert(rawLines, "Implicits: " .. (#self.enchantModLines + #self.implicitModLines))
1086+
t_insert(rawLines, "Implicits: " .. (#self.runeModLines + #self.enchantModLines + #self.implicitModLines))
1087+
for _, modLine in ipairs(self.runeModLines) do
1088+
writeModLine(modLine)
1089+
end
10521090
for _, modLine in ipairs(self.enchantModLines) do
10531091
writeModLine(modLine)
10541092
end
@@ -1075,6 +1113,39 @@ function ItemClass:BuildAndParseRaw()
10751113
self:ParseRaw(raw)
10761114
end
10771115

1116+
-- Rebuild rune modifiers using the item's runes
1117+
function ItemClass:UpdateRunes()
1118+
wipeTable(self.runeModLines)
1119+
local statOrder = {}
1120+
for _, name in ipairs(self.runes) do
1121+
if name ~= "None" then
1122+
local mod = self.base.weapon and data.itemMods.Runes[name].weapon or self.base.armour and data.itemMods.Runes[name].armour or { }
1123+
for i, line in ipairs(mod) do
1124+
local order = mod.statOrder[i]
1125+
if statOrder[order] then
1126+
-- Combine stats
1127+
local start = 1
1128+
statOrder[order].line = statOrder[order].line:gsub("%d+", function(num)
1129+
local s, e, other = line:find("(%d+)", start)
1130+
start = e + 1
1131+
return tonumber(num) + tonumber(other)
1132+
end)
1133+
else
1134+
local modLine = { line = line, order = order, rune = true, enchant = true }
1135+
for l = 1, #self.runeModLines + 1 do
1136+
if not self.runeModLines[l] or self.runeModLines[l].order > order then
1137+
t_insert(self.runeModLines, l, modLine)
1138+
break
1139+
end
1140+
end
1141+
statOrder[order] = modLine
1142+
end
1143+
end
1144+
end
1145+
end
1146+
1147+
end
1148+
10781149
-- Rebuild explicit modifiers using the item's affixes
10791150
function ItemClass:Craft()
10801151
-- Save off any custom mods so they can be re-added at the end
@@ -1503,6 +1574,9 @@ function ItemClass:BuildModList()
15031574
for _, modLine in ipairs(self.enchantModLines) do
15041575
processModLine(modLine)
15051576
end
1577+
for _, modLine in ipairs(self.runeModLines) do
1578+
processModLine(modLine)
1579+
end
15061580
for _, modLine in ipairs(self.classRequirementModLines) do
15071581
processModLine(modLine)
15081582
end

src/Classes/ItemDBControl.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ function ItemDBClass:DoesItemMatchFilters(item)
150150
break
151151
end
152152
end
153+
for _, line in pairs(item.runeModLines) do
154+
local err, match = PCall(string.matchOrPattern, line.line:lower(), searchStr)
155+
if not err and match then
156+
found = true
157+
break
158+
end
159+
end
153160
for _, line in pairs(item.implicitModLines) do
154161
local err, match = PCall(string.matchOrPattern, line.line:lower(), searchStr)
155162
if not err and match then

src/Classes/ItemListControl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function ItemListClass:FindSocketedJewel(jewelId, excludeActiveSpec)
9191
end
9292

9393
function ItemListClass:FindEquippedItemSocket(socketId, excludeActiveSet)
94-
if not self.itemsTab.items[socketId] or self.itemsTab.items[socketId].type ~= "Rune" or self.itemsTab.items[socketId].type ~= "SoulCore" then
94+
if not self.itemsTab.items[socketId] then
9595
return nil
9696
end
9797
local equipSet = nil

src/Classes/ItemSlotControl.lua

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ function ItemSlotClass:Populate()
100100
if not self.selItemId or not self.itemsTab.items[self.selItemId] or not self.itemsTab:IsItemValidForSlot(self.itemsTab.items[self.selItemId], self.slotName) then
101101
self:SetSelItemId(0)
102102
end
103-
104-
-- Update Rune / Soul Core Sockets
105-
local socketCount = 0
106-
if self.selItemId > 0 then
107-
local selItem = self.itemsTab.items[self.selItemId]
108-
socketCount = selItem.itemSocketCount or 0
109-
end
110-
for i, socket in ipairs(self.socketList) do
111-
socket.inactive = i > socketCount
112-
113-
end
114103
end
115104

116105
function ItemSlotClass:CanReceiveDrag(type, value)

0 commit comments

Comments
 (0)