-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathItem.lua
More file actions
1832 lines (1782 loc) · 69.3 KB
/
Item.lua
File metadata and controls
1832 lines (1782 loc) · 69.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Path of Building
--
-- Class: Item
-- Equippable item class
--
local ipairs = ipairs
local t_insert = table.insert
local t_remove = table.remove
local m_min = math.min
local m_max = math.max
local m_floor = math.floor
local dmgTypeList = {"Physical", "Lightning", "Cold", "Fire", "Chaos"}
local catalystList = {"Abrasive", "Accelerating", "Fertile", "Imbued", "Intrinsic", "Noxious", "Prismatic", "Tempering", "Turbulent", "Unstable"}
local catalystTags = {
{ "attack" },
{ "speed" },
{ "life", "mana", "resource" },
{ "caster" },
{ "jewellery_attribute", "attribute" },
{ "physical_damage", "chaos_damage" },
{ "jewellery_resistance", "resistance" },
{ "jewellery_defense", "defences" },
{ "jewellery_elemental" ,"elemental_damage" },
{ "critical" },
}
local function getCatalystScalar(catalystId, tags, quality)
if not catalystId or type(catalystId) ~= "number" or not catalystTags[catalystId] or not tags or type(tags) ~= "table" or #tags == 0 then
return 1
end
if not quality then
quality = 20
end
-- Create a fast lookup table for all provided tags
local tagLookup = {}
for _, curTag in ipairs(tags) do
tagLookup[curTag] = true;
end
-- Find if any of the catalyst's tags match the provided tags
for _, catalystTag in ipairs(catalystTags[catalystId]) do
if tagLookup[catalystTag] then
return (100 + quality) / 100
end
end
return 1
end
local influenceInfo = itemLib.influenceInfo.all
local ItemClass = newClass("Item", function(self, raw, rarity, highQuality)
if raw then
self:ParseRaw(sanitiseText(raw), rarity, highQuality)
end
end)
-- Reset all influence keys to false
function ItemClass:ResetInfluence()
for _, curInfluenceInfo in ipairs(influenceInfo) do
self[curInfluenceInfo.key] = false
end
end
local influenceItemMap = { }
for _, curInfluenceInfo in ipairs(influenceInfo) do
influenceItemMap[curInfluenceInfo.display.." Item"] = curInfluenceInfo.key
end
local lineFlags = {
["crafted"] = true, ["crucible"] = true, ["custom"] = true, ["eater"] = true, ["enchant"] = true,
["exarch"] = true, ["fractured"] = true, ["implicit"] = true, ["scourge"] = true, ["synthesis"] = true,
["mutated"] = true
}
-- Special function to store unique instances of modifier on specific item slots
-- that require special handling for ItemConditions. Only called if line #224 is
-- uncommented
local specialModifierFoundList = {}
local inverseModifierFoundList = {}
local function getTagBasedModifiers(tagName, itemSlotName)
local tag_name = tagName:lower()
local slot_name = itemSlotName:lower():gsub(" ", "_")
-- iterate all the item modifiers
for k,v in pairs(data.itemMods.Item) do
-- iterate across the modifier tags for each modifier
for _,tag in ipairs(v.modTags) do
-- if tag matches the tag_name we are investigating
if tag:lower() == tag_name then
local found = false
-- if there is a valid weightKey table
if #v.weightKey > 0 then
for _,wk in ipairs(v.weightKey) do
-- and it matches the slot_name of the item we are investigating
if wk == slot_name then
for _, dv in ipairs(v) do
-- and the modifier description contains the tag_name keyword
if dv:lower():find(tag_name) then
found = true
break
else
local excluded = false
if data.itemTagSpecial[tagName] and data.itemTagSpecial[tagName][itemSlotName] then
for _, specialMod in ipairs(data.itemTagSpecial[tagName][itemSlotName]) do
if dv:lower():find(specialMod:lower()) then
exclude = true
break
end
end
end
if exclude then
found = true
break
end
end
end
if not found and not specialModifierFoundList[k] then
specialModifierFoundList[k] = true
ConPrintf("[%s] [%s] ENTRY: %s", tagName, itemSlotName, k)
end
end
end
else
for _, dv in ipairs(v) do
if dv:lower():find(tag_name) then
found = true
break
else
local excluded = false
if data.itemTagSpecial[tagName] and data.itemTagSpecial[tagName][itemSlotName] then
for _, specialMod in ipairs(data.itemTagSpecial[tagName][itemSlotName]) do
if dv:lower():find(specialMod:lower()) then
exclude = true
break
end
end
end
if exclude then
found = true
break
end
end
end
if not found and not specialModifierFoundList[k] then
specialModifierFoundList[k] = true
ConPrintf("[%s] ENTRY: %s", tagName, k)
end
end
end
end
for _, dv in ipairs(v) do
if dv:lower():find(tag_name) then
local found_2 = false
if #v.weightKey > 0 then
for _,wk in ipairs(v.weightKey) do
if wk == slot_name then
-- this is useless if the modTags = { } (is empty)
if #v.modTags > 0 then
for _,tag in ipairs(v.modTags) do
if tag:lower() == tag_name then
found_2 = true
break
else
local excluded = false
-- if we have an exclusion pattern list for that tagName and itemSlotName
if data.itemTagSpecialExclusionPattern[tagName] and data.itemTagSpecialExclusionPattern[tagName][itemSlotName] then
-- iterate across the exclusion patterns
for _, specialMod in ipairs(data.itemTagSpecialExclusionPattern[tagName][itemSlotName]) do
-- and if the description matches pattern exclude it
if dv:lower():find(specialMod:lower()) then
excluded = true
break
end
end
end
if excluded then
found_2 = true
break
end
end
end
if not found_2 and not inverseModifierFoundList[k] then
inverseModifierFoundList[k] = true
ConPrintf("[%s] appears in desc but not in tags. [%s] %s", tag_name, k, dv)
break
end
end
end
end
else
-- this is useless if the modTags = { } (is empty)
if #v.modTags > 0 then
for _,tag in ipairs(v.modTags) do
if tag:lower() == tag_name then
found_2 = true
break
else
local excluded = false
-- if we have an exclusion pattern list for that tagName and itemSlotName
if data.itemTagSpecialExclusionPattern[tagName] and data.itemTagSpecialExclusionPattern[tagName][itemSlotName] then
-- iterate across the exclusion patterns
for _, specialMod in ipairs(data.itemTagSpecialExclusionPattern[tagName][itemSlotName]) do
-- and if the description matches pattern exclude it
if dv:lower():find(specialMod:lower()) then
excluded = true
break
end
end
end
if excluded then
found_2 = true
break
end
end
end
if not found_2 and not inverseModifierFoundList[k] then
inverseModifierFoundList[k] = true
ConPrintf("[%s] appears in desc but not in tags. [%s] %s", tag_name, k, dv)
end
end
end
end
end
end
end
-- Iterate over modifiers to see if specific substring is found (for conditional checking)
function ItemClass:FindModifierSubstring(substring, itemSlotName)
local modLines = {}
local substring, explicit = substring:gsub("explicit ", "")
-- The commented out line below is used at GGPK updates to check if any new modifiers
-- have been identified that need to be added to the manually maintained special modifier
-- pool in Data.lua (data.itemTagSpecial and data.itemTagSpecialExclusionPattern tables)
--getTagBasedModifiers(substring, itemSlotName)
-- merge various modifier lines into one table
for _,v in pairs(self.explicitModLines) do t_insert(modLines, v) end
if explicit < 1 then
for _,v in pairs(self.enchantModLines) do t_insert(modLines, v) end
for _,v in pairs(self.scourgeModLines) do t_insert(modLines, v) end
for _,v in pairs(self.implicitModLines) do t_insert(modLines, v) end
for _,v in pairs(self.crucibleModLines) do t_insert(modLines, v) end
end
for _,v in pairs(modLines) do
local currentVariant = false
if v.variantList then
for variant, enabled in pairs(v.variantList) do
if enabled and variant == self.variant then
currentVariant = true
end
end
else
currentVariant = true
end
if currentVariant then
if v.line:lower():find(substring) and not v.line:lower():find(substring .. " modifier") then
local excluded = false
if data.itemTagSpecialExclusionPattern[substring] and data.itemTagSpecialExclusionPattern[substring][itemSlotName] then
for _, specialMod in ipairs(data.itemTagSpecialExclusionPattern[substring][itemSlotName]) do
if v.line:lower():find(specialMod:lower()) then
excluded = true
break
end
end
end
if not excluded then
return true
end
end
if data.itemTagSpecial[substring] and data.itemTagSpecial[substring][itemSlotName] then
for _, specialMod in ipairs(data.itemTagSpecial[substring][itemSlotName]) do
if v.line:lower():find(specialMod:lower()) and (not v.variantList or v.variantList[self.variant]) then
return true
end
end
end
end
end
return false
end
local function specToNumber(s)
local n = s:match("^([%+%-]?[%d%.]+)")
return n and tonumber(n)
end
-- Parse raw item data and extract item name, base type, quality, and modifiers
function ItemClass:ParseRaw(raw, rarity, highQuality)
self.raw = raw
self.name = "?"
self.namePrefix = ""
self.nameSuffix = ""
self.base = nil
self.rarity = rarity or "UNIQUE"
self.quality = nil
self.rawLines = { }
-- Find non-blank lines and trim whitespace
for line in raw:gmatch("%s*([^\n]*%S)") do
t_insert(self.rawLines, line)
end
local mode = rarity and "GAME" or "WIKI"
local l = 1
local itemClass
if self.rawLines[l] then
if self.rawLines[l]:match("^Item Class:") then
itemClass = self.rawLines[l]:gsub("^Item Class: %s+", "%1")
l = l + 1 -- Item class is already determined by the base type
end
local rarity = self.rawLines[l]:match("^Rarity: (%a+)")
if rarity then
mode = "GAME"
if colorCodes[rarity:upper()] then
self.rarity = rarity:upper()
end
if self.rarity == "UNIQUE" or self.rarity == "RELIC" then
-- Hack for relics
for _, line in ipairs(self.rawLines) do
if line:find("Foil Unique") then
self.rarity = "RELIC"
local captured = line:match("%((.-)%)")
self.foilType = captured or "Rainbow"
break
end
end
end
l = l + 1
end
end
if self.rawLines[l] then
self.name = self.rawLines[l]
-- Determine if "Unidentified" item
local unidentified = false
for _, line in ipairs(self.rawLines) do
if line == "Unidentified" then
unidentified = true
break
end
end
-- Found the name for a rare or unique, but let's parse it if it's a magic or normal or Unidentified item to get the base
if not (self.rarity == "NORMAL" or self.rarity == "MAGIC" or unidentified) then
l = l + 1
end
end
self.checkSection = false
self.sockets = { }
self.classRequirementModLines = { }
self.buffModLines = { }
self.enchantModLines = { }
self.scourgeModLines = { }
self.implicitModLines = { }
self.explicitModLines = { }
self.crucibleModLines = { }
local implicitLines = 0
self.variantList = nil
self.prefixes = { }
self.suffixes = { }
self.requirements = { }
self.requirements.str = 0
self.requirements.dex = 0
self.requirements.int = 0
self.baseLines = { }
local importedLevelReq
local flaskBuffLines
local tinctureBuffLines
local deferJewelRadiusIndexAssignment
local gameModeStage = "FINDIMPLICIT"
local foundExplicit, foundImplicit
while self.rawLines[l] do
local line = self.rawLines[l]
if line == "Veiled Prefix" or line == "Veiled Suffix" then
self.veiled = true
end
if flaskBuffLines and flaskBuffLines[line] then
flaskBuffLines[line] = nil
elseif tinctureBuffLines and tinctureBuffLines[line] then
tinctureBuffLines[line] = nil
elseif line == "--------" then
self.checkSection = true
elseif line == "Split" then
self.split = true
elseif line == "Mirrored" then
self.mirrored = true
elseif line == "Corrupted" then
self.corrupted = true
elseif line == "Fractured Item" then
self.fractured = true
elseif line == "Synthesised Item" then
self.synthesised = true
elseif line:match("Foil Unique") then
local captured = line:match("%((.-)%)")
self.foilType = captured or "Rainbow"
elseif influenceItemMap[line] then
self[influenceItemMap[line]] = true
elseif line == "Requirements:" then
-- nothing to do
else
if self.checkSection then
if gameModeStage == "IMPLICIT" then
if foundImplicit then
-- There were definitely implicits, so any following modifiers must be explicits
gameModeStage = "EXPLICIT"
foundExplicit = true
else
gameModeStage = "FINDEXPLICIT"
end
elseif gameModeStage == "EXPLICIT" then
gameModeStage = "DONE"
elseif gameModeStage == "FINDIMPLICIT" and self.itemLevel and not line:match(" %(implicit%)") and
not line:match(" %(enchant%)") and not line:find("Talisman Tier") then
gameModeStage = "EXPLICIT"
foundExplicit = true
end
self.checkSection = false
end
local specName, specVal = line:match("^([%a ]+:?): (.+)$")
if specName then
if specName == "Class:" then
specName = "Requires Class"
end
else
specName, specVal = line:match("^(Requires %a+) (.+)$")
end
if specName then
if specName == "Unique ID" then
self.uniqueID = specVal
elseif specName == "Item Level" then
self.itemLevel = specToNumber(specVal)
elseif specName == "Requires Class" then
self.classRestriction = specVal
elseif specName == "Quality" then
self.quality = specToNumber(specVal)
elseif specName == "Sockets" then
local group = 0
for c in specVal:gmatch(".") do
if c:match("[RGBWA]") then
t_insert(self.sockets, { color = c, group = group })
elseif c == " " then
group = group + 1
end
end
elseif specName == "Radius" and self.type == "Jewel" then
self.jewelRadiusLabel = specVal:match("^%a+")
if specVal:match("^%a+") == "Variable" then
-- Jewel radius is variable and must be read from it's mods instead after they are parsed
deferJewelRadiusIndexAssignment = true
else
for index, data in pairs(data.jewelRadius) do
if specVal:match("^%a+") == data.label then
self.jewelRadiusIndex = index
break
end
end
end
elseif specName == "Limited to" and self.type == "Jewel" then
self.limit = specToNumber(specVal)
elseif specName == "Variant" then
if not self.variantList then
self.variantList = { }
end
-- This has to be kept for backwards compatibility
local ver, name = specVal:match("{([%w_]+)}(.+)")
if ver then
t_insert(self.variantList, name)
else
t_insert(self.variantList, specVal)
end
elseif specName == "Talisman Tier" then
self.talismanTier = specToNumber(specVal)
elseif specName == "Armour" or specName == "Evasion Rating" or specName == "Evasion" or specName == "Energy Shield" or specName == "Ward" then
if specName == "Evasion Rating" then
specName = "Evasion"
if self.baseName == "Two-Toned Boots (Armour/Energy Shield)" then
-- Another hack for Two-Toned Boots
self.baseName = "Two-Toned Boots (Armour/Evasion)"
self.base = data.itemBases[self.baseName]
end
elseif specName == "Energy Shield" then
specName = "EnergyShield"
if self.baseName == "Two-Toned Boots (Armour/Evasion)" then
-- Yet another hack for Two-Toned Boots
self.baseName = "Two-Toned Boots (Evasion/Energy Shield)"
self.base = data.itemBases[self.baseName]
end
end
self.armourData = self.armourData or { }
self.armourData[specName] = specToNumber(specVal)
elseif specName:match("BasePercentile") then
self.armourData = self.armourData or { }
self.armourData[specName] = specToNumber(specVal) or 0
elseif specName == "Requires Level" then
self.requirements.level = specToNumber(specVal)
elseif specName == "Level" then
-- Requirements from imported items can't always be trusted
importedLevelReq = specToNumber(specVal)
elseif specName == "LevelReq" then
self.requirements.level = specToNumber(specVal)
elseif specName == "Has Alt Variant" then
self.hasAltVariant = true
elseif specName == "Has Alt Variant Two" then
self.hasAltVariant2 = true
elseif specName == "Has Alt Variant Three" then
self.hasAltVariant3 = true
elseif specName == "Has Alt Variant Four" then
self.hasAltVariant4 = true
elseif specName == "Has Alt Variant Five" then
self.hasAltVariant5 = true
elseif specName == "Selected Variant" then
self.variant = specToNumber(specVal)
elseif specName == "Selected Alt Variant" then
self.variantAlt = specToNumber(specVal)
elseif specName == "Selected Alt Variant Two" then
self.variantAlt2 = specToNumber(specVal)
elseif specName == "Selected Alt Variant Three" then
self.variantAlt3 = specToNumber(specVal)
elseif specName == "Selected Alt Variant Four" then
self.variantAlt4 = specToNumber(specVal)
elseif specName == "Selected Alt Variant Five" then
self.variantAlt5 = specToNumber(specVal)
elseif specName == "Has Variants" or specName == "Selected Variants" then
-- Need to skip this line for backwards compatibility
-- with builds that used an old Watcher's Eye implementation
l = l + 1
elseif specName == "League" then
self.league = specVal
elseif specName == "Crafted" then
self.crafted = true
elseif specName == "Scourge" then
self.scourge = true
elseif specName == "Crucible" then
self.crucible = true
elseif specName == "Implicit" then
self.implicit = true
elseif specName == "Prefix" then
local range, affix = specVal:match("{range:([%d.]+)}(.+)")
range = range or ((affix or specVal) ~= "None" and main.defaultItemAffixQuality)
t_insert(self.prefixes, {
modId = affix or specVal,
range = tonumber(range),
})
elseif specName == "Suffix" then
local range, affix = specVal:match("{range:([%d.]+)}(.+)")
range = range or ((affix or specVal) ~= "None" and main.defaultItemAffixQuality)
t_insert(self.suffixes, {
modId = affix or specVal,
range = tonumber(range),
})
elseif specName == "Implicits" then
implicitLines = specToNumber(specVal) or 0
gameModeStage = "EXPLICIT"
elseif specName == "Unreleased" then
self.unreleased = (specVal == "true")
elseif specName == "Upgrade" then
self.upgradePaths = self.upgradePaths or { }
t_insert(self.upgradePaths, specVal)
elseif specName == "Source" then
self.source = specVal
elseif specName == "Cluster Jewel Skill" then
if self.clusterJewel and self.clusterJewel.skills[specVal] then
self.clusterJewelSkill = specVal
end
elseif specName == "Cluster Jewel Node Count" then
if self.clusterJewel then
local num = specToNumber(specVal) or self.clusterJewel.maxNodes
self.clusterJewelNodeCount = m_min(m_max(num, self.clusterJewel.minNodes), self.clusterJewel.maxNodes)
end
elseif specName == "Catalyst" then
for i=1, #catalystList do
if specVal == catalystList[i] then
self.catalyst = i
end
end
elseif specName == "CatalystQuality" then
self.catalystQuality = specToNumber(specVal)
elseif specName == "Note" then
self.note = specVal
elseif specName == "Str" or specName == "Strength" or specName == "Dex" or specName == "Dexterity" or
specName == "Int" or specName == "Intelligence" then
self.requirements[specName:sub(1,3):lower()] = specToNumber(specVal)
elseif specName == "Critical Strike Range" or specName == "Attacks per Second" or specName == "Weapon Range" or
specName == "Critical Strike Chance" or specName == "Physical Damage" or specName == "Elemental Damage" or
specName == "Chaos Damage" or specName == "Chance to Block" or specName == "Block chance" or
specName == "Armour" or specName == "Energy Shield" or specName == "Evasion" then
self.hidden_specs = true
-- Anything else is an explicit with a colon in it (Fortress Covenant, Pure Talent, etc) unless it's part of the custom name
elseif not (self.name:match(specName) and self.name:match(specVal)) then
foundExplicit = true
gameModeStage = "EXPLICIT"
end
end
if line == "Prefixes:" then
foundExplicit = true
gameModeStage = "EXPLICIT"
end
if not specName or foundExplicit or foundImplicit then
local modLine = { modTags = {} }
line = line:gsub("{(%a*):?([^}]*)}", function(k,val)
if k == "variant" then
modLine.variantList = { }
for varId in val:gmatch("%d+") do
modLine.variantList[tonumber(varId)] = true
end
elseif k == "tags" then
for tag in val:gmatch("[%a_]+") do
t_insert(modLine.modTags, tag)
end
elseif k == "range" then
modLine.range = tonumber(val)
elseif lineFlags[k] then
modLine[k] = true
end
return ""
end)
line = line:gsub(" %((%l+)%)", function(k)
if lineFlags[k] then
modLine[k] = true
end
return ""
end)
if modLine.enchant then
modLine.crafted = true
modLine.implicit = true
end
local baseName
if not self.base and (self.rarity == "NORMAL" or self.rarity == "MAGIC") then
-- Exact match (affix-less magic and normal items)
if self.name:match("Energy Blade") and itemClass then -- Special handling for energy blade base.
self.name = itemClass:match("One Hand") and "Energy Blade One Handed" or "Energy Blade Two Handed"
end
if data.itemBases[self.name] then
baseName = self.name
else
local bestMatch = {length = -1}
-- Partial match (magic items with affixes)
for itemBaseName, baseData in pairs(data.itemBases) do
local s, e = self.name:find(itemBaseName, 1, true)
if s and e and (e-s > bestMatch.length) then
bestMatch.match = itemBaseName
bestMatch.length = e-s
bestMatch.e = e
bestMatch.s = s
end
end
if bestMatch.match then
self.namePrefix = self.name:sub(1, bestMatch.s - 1)
self.nameSuffix = self.name:sub(bestMatch.e + 1)
baseName = bestMatch.match
end
end
if not baseName then
local s, e = self.name:find("Two-Toned Boots", 1, true)
if s then
-- Hack for Two-Toned Boots
baseName = "Two-Toned Boots"
self.namePrefix = self.name:sub(1, s - 1)
self.nameSuffix = self.name:sub(e + 1)
end
end
self.name = self.name:gsub(" %(.+%)","")
end
if not baseName then
baseName = line:gsub("^Superior ", ""):gsub("^Synthesised ","")
end
if baseName == "Two-Toned Boots" then
baseName = "Two-Toned Boots (Armour/Energy Shield)"
end
local base = data.itemBases[baseName]
if base then
-- Items with variants can have multiple bases
self.baseLines[baseName] = { line = baseName, variantList = modLine.variantList }
-- Set the actual base if variant matches or doesn't have variants
if not self.variant or not modLine.variantList or modLine.variantList[self.variant] then
self.baseName = baseName
if not (self.rarity == "NORMAL" or self.rarity == "MAGIC") then
self.title = self.name
end
if self.title and self.title:find("Foulborn") then
self.foulborn = true
end
self.type = base.type
self.base = base
self.affixes = (self.base.subType and data.itemMods[self.base.type..self.base.subType])
or data.itemMods[self.base.type]
or data.itemMods.Item
if self.base.flask then
if self.base.utility_flask then
self.enchantments = data.enchantments["UtilityFlask"]
else
self.enchantments = data.enchantments["Flask"]
end
else
self.enchantments = data.enchantments[self.base.type]
end
self.corruptible = self.base.type ~= "Flask"
self.canBeInfluenced = self.base.influenceTags ~= nil
self.clusterJewel = data.clusterJewels and data.clusterJewels.jewels[self.baseName]
self.requirements.str = self.base.req.str or 0
self.requirements.dex = self.base.req.dex or 0
self.requirements.int = self.base.req.int or 0
local maxReq = m_max(self.requirements.str, self.requirements.dex, self.requirements.int)
self.defaultSocketColor = (maxReq == self.requirements.dex and "G") or (maxReq == self.requirements.int and "B") or "R"
if self.base.flask and self.base.flask.buff and not flaskBuffLines then
flaskBuffLines = { }
for _, line in ipairs(self.base.flask.buff) do
flaskBuffLines[line] = true
local modList, extra = modLib.parseMod(line)
t_insert(self.buffModLines, { line = line, extra = extra, modList = modList or { } })
end
end
if self.base.tincture and self.base.tincture.buff and not tinctureBuffLines then
tinctureBuffLines = { }
for _, line in ipairs(self.base.tincture.buff) do
tinctureBuffLines[line] = true
local modList, extra = modLib.parseMod(line)
t_insert(self.buffModLines, { line = line, extra = extra, modList = modList or { } })
end
end
end
-- Base lines don't need mod parsing, skip it
goto continue
end
if modLine.implicit then
foundImplicit = true
gameModeStage = "IMPLICIT"
end
local catalystScalar = getCatalystScalar(self.catalyst, modLine.modTags, self.catalystQuality)
local rangedLine = itemLib.applyRange(line, 1, catalystScalar)
local modList, extra = modLib.parseMod(rangedLine)
if (not modList or extra) and self.rawLines[l+1] then
-- Try to combine it with the next line
local nextLine = self.rawLines[l+1]:gsub("%b{}", ""):gsub(" ?%(%l+%)","")
local combLine = line.." "..nextLine
rangedLine = itemLib.applyRange(combLine, 1, catalystScalar)
modList, extra = modLib.parseMod(rangedLine, true)
if modList and not extra then
line = line.."\n"..nextLine
l = l + 1
else
modList, extra = modLib.parseMod(rangedLine)
end
end
local lineLower = line:lower()
if lineLower == "implicit modifiers cannot be changed" then
self.implicitsCannotBeChanged = true
elseif lineLower:match(" prefix modifiers? allowed") then
self.prefixes.limit = (self.prefixes.limit or 0) + (tonumber(lineLower:match("%+(%d+) prefix modifiers? allowed")) or 0) - (tonumber(lineLower:match("%-(%d+) prefix modifiers? allowed")) or 0)
elseif lineLower:match(" suffix modifiers? allowed") then
self.suffixes.limit = (self.suffixes.limit or 0) + (tonumber(lineLower:match("%+(%d+) suffix modifiers? allowed")) or 0) - (tonumber(lineLower:match("%-(%d+) suffix modifiers? allowed")) or 0)
elseif lineLower:find("can be anointed") then -- blight uniques and Cord Belt
self.canBeAnointed = true
elseif lineLower == "can have a second enchantment modifier" then
self.canHaveTwoEnchants = true
elseif lineLower == "can have 1 additional enchantment modifiers" then
self.canHaveTwoEnchants = true
elseif lineLower == "can have 2 additional enchantment modifiers" then
self.canHaveTwoEnchants = true
self.canHaveThreeEnchants = true
elseif lineLower == "can have 3 additional enchantment modifiers" then
self.canHaveTwoEnchants = true
self.canHaveThreeEnchants = true
self.canHaveFourEnchants = true
elseif lineLower == "has elder, shaper and all conqueror influences" then
self.HasElderShaperAndAllConquerorInfluences = true
for _, curInfluenceInfo in ipairs(itemLib.influenceInfo.default) do
self[curInfluenceInfo.key] = true
end
elseif lineLower:match("if the eater of worlds is dominant") then
self.canHaveEldritchInfluence = true
elseif lineLower == "has a crucible passive skill tree with only support passive skills" then
self.canHaveOnlySupportSkillsCrucibleTree = true
elseif lineLower == "has a crucible passive skill tree" then
self.canHaveShieldCrucibleTree = true
elseif lineLower == "has a two handed sword crucible passive skill tree" then
self.canHaveTwoHandedSwordCrucibleTree = true
elseif lineLower == "cannot roll caster modifiers" then
self.restrictTag = true
self.noCaster = true
elseif lineLower == "cannot roll attack modifiers" then
self.restrictTag = true
self.noAttack = true
elseif lineLower == "cannot roll modifiers of non-cold damage types" then
self.restrictDamageType = true
self.onlyColdDamage = true
elseif lineLower == "cannot roll modifiers of non-fire damage types" then
self.restrictDamageType = true
self.onlyFireDamage = true
elseif lineLower == "cannot roll modifiers of non-lightning damage types" then
self.restrictDamageType = true
self.onlyLightningDamage = true
elseif lineLower == "cannot roll modifiers of non-chaos damage types" then
self.restrictDamageType = true
self.onlyChaosDamage = true
elseif lineLower == "cannot roll modifiers of non-physical damage types" then
self.restrictDamageType = true
self.onlyPhysicalDamage = true
end
local modLines
if modLine.enchant or (modLine.crafted and #self.enchantModLines + #self.implicitModLines < implicitLines) then
modLines = self.enchantModLines
elseif modLine.scourge then
modLines = self.scourgeModLines
elseif line:find("Requires Class") then
modLines = self.classRequirementModLines
elseif modLine.implicit or (not modLine.crafted and #self.enchantModLines + #self.scourgeModLines + #self.implicitModLines < implicitLines) then
modLines = self.implicitModLines
elseif modLine.crucible then
modLines = self.crucibleModLines
else
modLines = self.explicitModLines
end
modLine.line = line
if modList then
modLine.modList = modList
modLine.extra = extra
modLine.valueScalar = catalystScalar
modLine.range = modLine.range or main.defaultItemAffixQuality
t_insert(modLines, modLine)
if mode == "GAME" then
if gameModeStage == "FINDIMPLICIT" then
gameModeStage = "IMPLICIT"
elseif gameModeStage == "FINDEXPLICIT" then
foundExplicit = true
gameModeStage = "EXPLICIT"
elseif gameModeStage == "EXPLICIT" then
foundExplicit = true
end
else
foundExplicit = true
end
elseif mode == "GAME" then
if gameModeStage == "IMPLICIT" or gameModeStage == "EXPLICIT" or (gameModeStage == "FINDIMPLICIT" and (not data.itemBases[line]) and not (self.name == line) and not line:find("Two%-Toned") and not (self.base and (line == self.base.type or self.base.subType and line == self.base.subType .. " " .. self.base.type))) then
modLine.modList = { }
modLine.extra = line
t_insert(modLines, modLine)
elseif gameModeStage == "FINDEXPLICIT" then
gameModeStage = "DONE"
end
elseif foundExplicit or (not foundExplicit and gameModeStage == "EXPLICIT") then
modLine.modList = { }
modLine.extra = line
t_insert(modLines, modLine)
end
end
end
::continue::
l = l + 1
end
if self.baseName and self.title then
self.name = self.title .. ", " .. self.baseName:gsub(" %(.+%)","")
end
if self.base and not self.requirements.level then
if importedLevelReq and #self.sockets == 0 then
-- Requirements on imported items can only be trusted for items with no sockets
self.requirements.level = importedLevelReq
else
self.requirements.level = self.base.req.level
end
end
self.affixLimit = 0
if self.crafted then
if not self.affixes then
self.crafted = false
elseif self.rarity == "MAGIC" then
if self.prefixes.limit or self.suffixes.limit then
self.prefixes.limit = m_max(m_min((self.prefixes.limit or 0) + 1, 2), 0)
self.suffixes.limit = m_max(m_min((self.suffixes.limit or 0) + 1, 2), 0)
self.affixLimit = self.prefixes.limit + self.suffixes.limit
else
self.affixLimit = 2
end
elseif self.rarity == "RARE" then
self.affixLimit = (((self.type == "Jewel" and not (self.base.subType == "Abyss" and self.corrupted)) or self.type == "Graft") and 4 or 6)
if self.prefixes.limit or self.suffixes.limit then
self.prefixes.limit = m_max(m_min((self.prefixes.limit or 0) + self.affixLimit / 2, self.affixLimit), 0)
self.suffixes.limit = m_max(m_min((self.suffixes.limit or 0) + self.affixLimit / 2, self.affixLimit), 0)
self.affixLimit = self.prefixes.limit + self.suffixes.limit
end
else
self.crafted = false
end
if self.crafted then
for _, list in ipairs({self.prefixes,self.suffixes}) do
for i = 1, (list.limit or (self.affixLimit / 2)) do
if not list[i] then
list[i] = { modId = "None" }
elseif list[i].modId ~= "None" and not self.affixes[list[i].modId] then
for modId, mod in pairs(self.affixes) do
if list[i].modId == mod.affix then
list[i].modId = modId
break
end
end
if not self.affixes[list[i].modId] then
list[i].modId = "None"
end
end
end
end
end
end
if self.base and self.base.socketLimit then
if #self.sockets == 0 then
for i = 1, self.base.socketLimit do
t_insert(self.sockets, {
color = self.defaultSocketColor,
group = 0,
})
end
end
end
self.abyssalSocketCount = 0
if self.variantList then
self.variant = m_min(#self.variantList, self.variant or #self.variantList)
if self.hasAltVariant then
self.variantAlt = m_min(#self.variantList, self.variantAlt or #self.variantList)
end
if self.hasAltVariant2 then
self.variantAlt2 = m_min(#self.variantList, self.variantAlt2 or #self.variantList)
end
if self.hasAltVariant3 then
self.variantAlt3 = m_min(#self.variantList, self.variantAlt3 or #self.variantList)
end
if self.hasAltVariant4 then
self.variantAlt4 = m_min(#self.variantList, self.variantAlt4 or #self.variantList)
end
if self.hasAltVariant5 then
self.variantAlt5 = m_min(#self.variantList, self.variantAlt5 or #self.variantList)
end
end
if not self.quality then
self:NormaliseQuality()
if highQuality then
-- Behavior of NormaliseQuality should be looked at because calling it twice has different results.
-- Leaving it alone for now. Just moving it here from Main.lua so BuildAndParseRaw doesn't need to be called.
self:NormaliseQuality()
end
end
self:BuildModList()
if deferJewelRadiusIndexAssignment then
self.jewelRadiusIndex = self.jewelData.radiusIndex
end
end
function ItemClass:NormaliseQuality()
if self.base and (self.base.armour or self.base.weapon or self.base.flask or self.base.tincture) then
if not self.quality then
self.quality = 0
elseif not self.uniqueID and not self.corrupted and not self.split and not self.mirrored and self.quality < 20 then
self.quality = 20
end
end
end
function ItemClass:GetModSpawnWeight(mod, includeTags, excludeTags)
local weight = 0
if self.base then
local function HasInfluenceTag(key)
if self.base.influenceTags then
for _, curInfluenceInfo in ipairs(influenceInfo) do
if self[curInfluenceInfo.key] and self.base.influenceTags[curInfluenceInfo.key] == key then
return true
end
end
end
return false
end
local function HasMavenInfluence(modAffix)
return modAffix:match("Elevated")
end
if self.restrictTag then
for _, key in ipairs(mod.modTags) do
local flagName = "no" .. key:gsub("^%l", string.upper)
if flagName and self[flagName] then
return 0
end
end
end
if self.restrictDamageType then
local required, restricted = false, {}
for _, element in ipairs({ "fire", "cold", "lightning", "chaos", "physical" }) do
local flagName = "only" .. element:gsub("^%l", string.upper) .. "Damage"
if self[flagName] then
required = true
else
restricted[element] = true
end
end
if required then