Repository navigation
Expand file tree
/
Copy pathModParser.lua
More file actions
728 lines (689 loc) · 27.8 KB
/
Copy pathModParser.lua
File metadata and controls
728 lines (689 loc) · 27.8 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
-- Last Epoch Planner
--
-- Module: Mod Parser for 3.0
-- Parser function for modifier names
--
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local band = bit.band
local bor = bit.bor
local bnot = bit.bnot
local m_huge = math.huge
local function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
-- List of modifier forms
local formList = {
["^([%+%-]?[%d%.]+)%% increased"] = "INC",
["^([%+%-]?[%d%.]+)%% (%w+) increased"] = "INC",
["^([%+%-]?[%d%.]+)%% reduced"] = "RED",
["^([%+%-]?[%d%.]+)%% (%w+) reduced"] = "RED",
["^([%+%-]?[%d%.]+)%% more"] = "MORE",
["^([%+%-]?[%d%.]+)%% (%w+) more"] = "MORE",
["^([%+%-]?[%d%.]+)%% less"] = "LESS",
["^([%+%-]?[%d%.]+)%% (%w+) less"] = "LESS",
["^(%d+)%% faster"] = "INC",
["^(%d+)%% slower"] = "RED",
["^([%+%-]?[%d%.]+)%%"] = "BASE_MORE",
["^([%+%-]?[%d%.]+)"] = "BASE",
["^([%+%-][%d%.]+)%%? to"] = "BASE",
["^([%+%-]?[%d%.]+)%%? of"] = "BASE",
["^([%+%-][%d%.]+)%%? base"] = "BASE",
["^([%+%-]?[%d%.]+)%%? additional"] = "BASE",
["^you gain ([%d%.]+)"] = "GAIN",
["^gains? ([%d%.]+)%% of"] = "GAIN",
["^gain ([%d%.]+)"] = "GAIN",
["^gain %+(%d+)%% to"] = "GAIN",
["^you lose ([%d%.]+)"] = "LOSE",
["^loses? ([%d%.]+)%% of"] = "LOSE",
["^lose ([%d%.]+)"] = "LOSE",
["^lose %+(%d+)%% to"] = "LOSE",
["^(%d+)"] = "BASE",
["^([%+%-]?%d+)%% chance"] = "CHANCE",
["^([%+%-]?%d+)%% chance to gain "] = "FLAG",
["^([%+%-]?%d+)%% additional chance"] = "CHANCE",
["^you have "] = "FLAG",
["^have "] = "FLAG",
["^you are "] = "FLAG",
["^are "] = "FLAG",
["^gain "] = "FLAG",
["^you gain "] = "FLAG",
}
-- Map of modifier names
local modNameList = {
-- Attributes
["all attributes"] = Attributes,
-- Life/mana
["health"] = "Life",
["health regen"] = "LifeRegen",
["health regeneration"] = "LifeRegen",
["healing effectiveness"] = "HealingEffectiveness",
["maximum health"] = "Life",
["mana"] = "Mana",
["maximum mana"] = "Mana",
["mana regen"] = "ManaRegen",
["mana cost"] = "ManaCost",
-- Primary defences
["armour"] = "Armour",
["armor"] = "Armour",
["dodge rating"] = "Evasion",
["ward"] = "Ward",
["endurance"] = "Endurance",
["endurance threshold"] = "EnduranceThreshold",
["ward decay threshold"] = "WardDecayThreshold",
["ward per second"] = "WardPerSecond",
["ward retention"] = "WardRetention",
-- Resistances
["elemental resistance"] = { "FireResist", "LightningResist", "ColdResist" },
["elemental resistances"] = { "FireResist", "LightningResist", "ColdResist" },
["all resistances"] = { "FireResist", "LightningResist", "ColdResist", "PhysicalResist", "PoisonResist", "NecroticResist", "VoidResist" },
-- Damage taken
["damage taken"] = "DamageTaken",
["damage over time taken"] = "DamageTakenOverTime",
["elemental damage taken"] = "ElementalDamageTaken",
["elemental damage taken over time"] = "ElementalDamageTakenOverTime",
-- Other defences
["block chance"] = "BlockChance",
["block effectiveness"] = "BlockEffectiveness",
["health gained on block"] = "LifeOnBlock",
["health gain on block"] = "LifeOnBlock",
["mana gained on block"] = "ManaOnBlock",
["mana gain on block"] = "ManaOnBlock",
["ward gained on block"] = "WardOnBlock",
["ward gain on block"] = "WardOnBlock",
-- Stun/knockback modifiers
["stun duration on you"] = "StunDuration",
["stun duration"] = "EnemyStunDuration",
["stun avoidance"] = "StunAvoidance",
["knockback distance"] = "EnemyKnockbackDistance",
-- Auras/curses/buffs
["buff effect"] = "BuffEffect",
-- On hit/kill/leech effects
["health gain on kill"] = "LifeOnKill",
["health gain on hit"] = { "LifeOnHit", flags = ModFlag.Hit },
-- Projectile modifiers
["extra projectiles"] = "ProjectileCount",
["projectiles"] = "ProjectileCount",
["projectile speed"] = "ProjectileSpeed",
-- Explicitly cast (non-triggered) extra instances
["number of (%a[%a ]*) for direct casts"] = function (cap1)
-- Using a static "number of .* for direct casts" pattern would consume the entire phrase (including the skill name) from `line`, because scan() removes matched text.
-- The subsequent skillNameList scan would then find nothing and attach no SkillName tag.
-- Instead, we capture the skill name here via regex and attach the tag ourselves.
local lowerCap = cap1:lower():gsub("%s+$", "")
for _, skill in pairs(data.skills) do
local skillLower = skill.name:lower()
if lowerCap == skillLower or lowerCap == skillLower .. "s" then
return { "InstanceCountOnDirectCast", tag = { type = "SkillName", skillName = skill.name } }
end
end
return "InstanceCountOnDirectCast"
end,
-- Totem/trap/mine/brand modifiers
["totem duration"] = "TotemDuration",
-- Other skill modifiers
["radius"] = "AreaOfEffect",
["area"] = "AreaOfEffect",
["area of effect"] = "AreaOfEffect",
["duration"] = "Duration",
["active duration"] = "Duration",
["cooldown duration"] = "CooldownRecovery",
["cooldown recovery"] = "CooldownRecovery",
["cooldown recovery speed"] = "CooldownRecovery",
["melee range"] = "MeleeWeaponRange",
["to deal double damage"] = "DoubleDamageChance",
-- Basic damage types
["damage"] = "Damage",
["elemental damage"] = { "FireDamage", "ColdDamage", "LightningDamage" },
["damage over time"] = { "Damage", flags = ModFlag.Dot },
-- Crit/speed modifiers
["crit chance"] = "CritChance",
["critical chance"] = "CritChance",
["critical strike chance"] = "CritChance",
["critical strike multiplier"] = "CritMultiplier",
["critical multiplier"] = "CritMultiplier",
["attack speed"] = { "Speed", flags = ModFlag.Attack },
["cast speed"] = { "Speed", flags = ModFlag.Cast },
["attack and cast speed"] = "Speed",
["freeze duration"] = "EnemyFreezeDuration",
-- Misc modifiers
["movespeed"] = "MovementSpeed",
["movement speed"] = "MovementSpeed",
["(%w+) and (%w+) resistance"] = function (d1, d2) return { d1:capitalize() .. "Resist", d2:capitalize() .. "Resist" } end,
["base damage converted to (%a+)"] = function (damageType)
return "BaseDamageConvertTo" .. damageType:capitalize()
end,
}
for i, stat in ipairs(LongAttributes) do
modNameList[stat:lower()] = Attributes[i]
end
for skillId, skill in pairs(data.skills) do
-- The player cannot trigger a minion skill and cannot trigger "Stacking" variants of skills
if not skill.fromMinion and not skillId:find("Stacking") then
modNameList["to " .. skill.name:lower()] = { "ChanceToTriggerOnHit_" .. skillId, flags = ModFlag.Hit }
modNameList[skill.name:lower() .. " chance"] = { "ChanceToTriggerOnHit_" .. skillId, flags = ModFlag.Hit }
if skill.altName then
modNameList[skill.altName:lower() .. " chance"] = { "ChanceToTriggerOnHit_" .. skillId, flags = ModFlag.Hit }
end
modNameList["to cast " .. skill.name:lower()] = "ChanceToTriggerOnHit_" .. skillId
if skill.baseFlags.ailment then
modNameList["to apply " .. skill.name:lower()] = "ChanceToTriggerOnHit_" .. skillId
modNameList["to inflict " .. skill.name:lower()] = "ChanceToTriggerOnHit_" .. skillId
end
modNameList[skill.name:lower() .. " stacks"] = { "ChanceToTriggerOnHit_" .. skillId, flags = ModFlag.Hit, mult = 100 }
modNameList[skill.name:lower() .. " stacks applied"] = { "ChanceToTriggerOnHit_" .. skillId, flags = ModFlag.Hit, mult = 100 }
end
end
for _, damageType in ipairs(DamageTypes) do
modNameList[damageType:lower() .. " penetration"] = damageType .. "Penetration"
modNameList[damageType:lower() .. " damage"] = damageType .. "Damage"
modNameList[damageType:lower() .. " resistance"] = damageType .. "Resist"
modNameList[damageType:lower() .. " damage taken"] = damageType .. "DamageTaken"
modNameList[damageType:lower() .. " damage over time taken"] = damageType .. "DamageTakenOverTime"
modNameList[damageType:lower() .. " damage over time"] = {
damageType .. "Damage",
flags = ModFlag.Dot +
ModFlag[damageType]
}
for _, damageSourceType in ipairs(DamageSourceTypes) do
modNameList[damageType:lower() .. " " .. damageSourceType:lower() .. " damage"] = {
damageType .. "Damage",
keywordFlags = KeywordFlag[damageSourceType]
}
end
end
modNameList["penetration"] = "Penetration"
-- List of modifier flags
local modFlagList = {
-- Skill types
["elemental"] = { keywordFlags = bor(KeywordFlag.Fire, KeywordFlag.Cold, KeywordFlag.Lightning) },
["on melee hit"] = { flags = bor(ModFlag.Melee, ModFlag.Hit) },
["on hit"] = { flags = ModFlag.Hit },
["hit"] = { flags = ModFlag.Hit },
["minion skills"] = { tag = { type = "SkillType", skillType = SkillType.Minion } },
["with elemental spells"] = { keywordFlags = bor(KeywordFlag.Lightning, KeywordFlag.Cold, KeywordFlag.Fire) },
["minion"] = { addToMinion = true },
["shared"] = { addToMinion = true, shared = true },
-- can be ignored since the cooldown is already part of the triggered skill data
["%(%d+ second cooldown%)"] = {},
-- Other
["global"] = { tag = { type = "Global" } },
}
for _, damageType in ipairs(DamageTypes) do
modFlagList["on " .. damageType:lower() .. " hit"] = { keywordFlags = KeywordFlag[damageType], flags = ModFlag.Hit }
modFlagList["with " .. damageType:lower() .. " skills"] = { keywordFlags = KeywordFlag[damageType] }
modFlagList["when you directly use a " .. damageType:lower() .. " spell"] = { keywordFlags = KeywordFlag[damageType] }
end
for _, damageSourceType in ipairs(DamageSourceTypes) do
modFlagList[damageSourceType:lower()] = { keywordFlags = ModFlag[damageSourceType] }
modFlagList["with " .. damageSourceType:lower() .. " attacks"] = {
keywordFlags = ModFlag[damageSourceType],
flags =
ModFlag.Hit
}
end
for _, damageType in ipairs(DamageTypes) do
modFlagList[damageType:lower()] = { keywordFlags = ModFlag[damageType] }
end
-- List of modifier flags/tags that appear at the start of a line
local preFlagList = {}
-- List of modifier tags
local modTagList = {
[". this effect is doubled if you have (%d+) or more maximum mana."] = function (num) return { tag = { type = "StatThreshold", stat = "Mana", threshold = num, mult = 2 } } end,
["for (%d+) seconds"] = {},
[" on critical strike"] = { tag = { type = "Condition", var = "CriticalStrike" } },
["from critical strikes"] = { tag = { type = "Condition", var = "CriticalStrike" } },
-- Multipliers
["per level"] = { tag = { type = "Multiplier", var = "Level" } },
-- Per stat
["per (%d+) total attributes"] = function (num) return { tag = { type = "PerStat", statList = Attributes, div = num } } end,
["per (%d+) maximum mana"] = function (num) return { tag = { type = "PerStat", stat = "Mana", div = num } } end,
["per (%d+)%% block chance"] = function (num) return { tag = { type = "PerStat", stat = "BlockChance", div = num } } end,
["per totem"] = { tag = { type = "PerStat", stat = "TotemsSummoned" } },
-- Slot conditions
["while dual wielding"] = { tag = { type = "Condition", var = "DualWielding" } },
["while wielding a two handed melee weapon"] = { tagList = { { type = "Condition", var = "UsingTwoHandedWeapon" }, { type = "Condition", var = "UsingMeleeWeapon" } } },
["while unarmed"] = { tag = { type = "Condition", var = "Unarmed" } },
["while moving"] = { tag = { type = "Condition", var = "Moving" } },
["while channell?ing"] = { tag = { type = "Condition", var = "Channelling" } },
["while leeching"] = { tag = { type = "Condition", var = "Leeching" } },
["while frozen"] = { tag = { type = "Condition", var = "Frozen" } },
["while cursed"] = { tag = { type = "Condition", var = "Cursed" } },
["if you[' ]h?a?ve dealt a critical strike recently"] = { tag = { type = "Condition", var = "CritRecently" } },
["on kill"] = { tag = { type = "Condition", var = "KilledRecently" } },
["on melee kill"] = { flags = ModFlag.WeaponMelee, tag = { type = "Condition", var = "KilledRecently" } },
["when you kill an enemy"] = { tag = { type = "Condition", var = "KilledRecently" } },
["if you[' ]h?a?ve stunned an enemy recently"] = { tag = { type = "Condition", var = "StunnedEnemyRecently" } },
["if you[' ]h?a?ve been hit recently"] = { tag = { type = "Condition", var = "BeenHitRecently" } },
["if you have ?n[o']t been hit recently"] = { tag = { type = "Condition", var = "BeenHitRecently", neg = true } },
["when you summon a totem"] = { tag = { type = "Condition", var = "SummonedTotemRecently" } },
-- Enemy status conditions
["against poisoned enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Poisoned" } },
["to poisoned enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Poisoned" } },
["against blinded enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Blinded" } },
["against ignited enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Ignited" } },
["to ignited enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Ignited" } },
["against shocked enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Shocked" } },
["to shocked enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Shocked" } },
["against frozen enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Frozen" } },
["to frozen enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Frozen" } },
["against chilled enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Chilled" } },
["to chilled enemies"] = { tag = { type = "ActorCondition", actor = "enemy", var = "Chilled" } },
["against chilled or frozen enemies"] = { tag = { type = "ActorCondition", actor = "enemy", varList = { "Chilled", "Frozen" } } },
}
for i, stat in ipairs(LongAttributes) do
modTagList["per " .. stat:lower()] = { tag = { type = "PerStat", stat = Attributes[i] } }
modTagList["per point of " .. stat:lower()] = { tag = { type = "PerStat", stat = Attributes[i] } }
modTagList["per player " .. stat:lower()] = { tag = { type = "PerStat", stat = Attributes[i], actor = "parent" } }
modTagList["per (%d+) " .. stat:lower()] = function (num) return { tag = { type = "PerStat", stat = Attributes[i], div = num } } end
modTagList["per (%d+) " .. Attributes[i]:lower()] = function (num) return { tag = { type = "PerStat", stat = Attributes[i], div = num } } end
modTagList["w?h?i[lf]e? you have at least (%d+) " .. stat:lower()] = function (num) return { tag = { type = "StatThreshold", stat = Attributes[i], threshold = num } } end
end
for _, weapon in ipairs(DamageSourceWeapons) do
modTagList["with an? " .. weapon:lower()] = { tag = { type = "Condition", var = "Using" .. weapon } }
modTagList["while wielding a " .. weapon:lower()] = { tag = { type = "Condition", var = "Using" .. weapon } }
modTagList["per equipped " .. weapon:lower()] = { tag = { type = "Multiplier", var = weapon .. "Item" } }
modTagList["per " .. weapon:lower()] = { tag = { type = "Multiplier", var = weapon .. "Item" } }
end
local mod = modLib.createMod
local function flag(name, ...)
return mod(name, "FLAG", true, ...)
end
local explodeFunc = function (chance, amount, type, ...)
local amountNumber = tonumber(amount) or (amount == "tenth" and 10) or (amount == "quarter" and 25)
if not amountNumber then
return
end
local amounts = {}
amounts[type] = amountNumber
return {
mod("ExplodeMod", "LIST",
{ type = firstToUpper(type), chance = chance / 100, amount = amountNumber, keyOfScaledMod = "chance" }, ...),
flag("CanExplode")
}
end
-- List of special modifiers
local specialQuickFixModList = {
["^([%+%-]?[%d%.]+%%) Cast Speed"] = "%1 increased Cast Speed",
["^([%+%-]?[%d%.]+%%) Cooldown Recovery Speed"] = "%1 increased Cooldown Recovery Speed",
["^([%+%-]?[%d%.]+%%) Duration"] = "%1 increased Duration",
["^([%+%-]?[%d%.]+%%) Movespeed"] = "%1 increased Movespeed",
["Duration %(S?s?econds%)"] = "Duration"
}
for _, damageType in ipairs(DamageTypes) do
specialQuickFixModList[damageType .. " Shred Chance"] = "Shred " .. damageType .. " Resistance Chance"
end
local specialModList = {
["no cooldown"] = { flag("NoCooldown") },
[" ?always crits?.* above (%d+) mana"] = function (num)
num = tonumber(num)
return { mod("CritChance", "OVERRIDE", 100, { type = "StatThreshold", stat = "Mana", threshold = num }) }
end,
-- The actual text that they can hit the same target is in the flavour text, not mods, so we detect it via shurikens in line instead
["^ ?shurikens in line$"] = { flag("SequentialProjectiles", { type = "SkillName", skillName = "Shurikens" }) },
["^ base (%a+) damage %-> (%a+)$"] = function (fromType, toType)
return { mod(fromType:capitalize() .. "BaseDamageConvertTo" .. toType:capitalize(), "BASE", 100) }
end,
["^ base (%a+) damage converted to (%a+)$"] = function (fromType, toType)
return { mod(fromType:capitalize() .. "BaseDamageConvertTo" .. toType:capitalize(), "BASE", 100) }
end,
["^ base damage %-> (%a+)$"] = function (damageType)
return { mod("BaseDamageConvertTo" .. damageType:capitalize(), "BASE", 100) }
end,
["^ base damage converted to (%a+)$"] = function (damageType)
return { mod("BaseDamageConvertTo" .. damageType:capitalize(), "BASE", 100) }
end,
["^ (%a+) conversion$"] = function (damageType)
return { mod("BaseDamageConvertTo" .. damageType:capitalize(), "BASE", 100) }
end,
}
for _, skillId in ipairs(data.treeSkills) do
local skill = data.skills[skillId]
specialModList["^+(%d+) to " .. skill.name:lower() .. "$"] = function (num)
num = tonumber(num)
return { mod(skill.id .. "Level", "BASE",
num) }
end
end
-- Modifiers that are recognised but unsupported
local unsupportedModList = {}
-- Special lookups used for various modifier forms
local suffixTypes = { ["as fire"] = "AsFire", }
for _, damageType in ipairs(DamageTypes) do
suffixTypes["converted to " .. damageType:lower()] = "ConvertTo" .. damageType
end
local function appendMod(inputTable, string)
local table = {}
for subLine, mods in pairs(inputTable) do
if type(mods) == "string" then
table[subLine] = mods .. string
else
table[subLine] = {}
for _, mod in ipairs(mods) do
t_insert(table[subLine], mod .. string)
end
end
end
return table
end
local flagTypes = { ["frenzy"] = "Condition:Frenzy", }
-- Build active skill name lookup
local skillNameList = {}
for _, skill in pairs(data.skills) do
skillNameList[skill.name:lower()] = { tag = { type = "SkillName", skillName = skill.name } }
skillNameList["for " .. skill.name:lower()] = { tag = { type = "SkillName", skillName = skill.name } }
end
local preSkillNameList = {}
-- Scan a line for the earliest and longest match from the pattern list
-- If a match is found, returns the corresponding value from the pattern list, plus the remainder of the line and a table of captures
local function scan(line, patternList, plain, matchAll)
local bestIndex, bestEndIndex
local bestPattern = ""
local bestVal, bestStart, bestEnd, bestCaps
local lineLower = line:lower()
for pattern, patternVal in pairs(patternList) do
local index, endIndex, cap1, cap2, cap3, cap4, cap5 = lineLower:find(pattern, 1, plain)
if index and (not bestIndex or index < bestIndex or (index == bestIndex and (endIndex > bestEndIndex or (endIndex == bestEndIndex and #pattern > #bestPattern)))) then
bestIndex = index
bestEndIndex = endIndex
bestPattern = pattern
bestVal = patternVal
bestStart = index
bestEnd = endIndex
bestCaps = { cap1, cap2, cap3, cap4, cap5 }
end
end
if bestVal then
local lineRemainder = line:sub(1, bestStart - 1) .. line:sub(bestEnd + 1, -1)
if matchAll then
local results, lineRemainderFinal = scan(lineRemainder, patternList, plain, true)
t_insert(results, bestVal)
return results, lineRemainderFinal
else
return bestVal, lineRemainder, bestCaps
end
else
if matchAll then
return { nil }, line
else
return nil, line
end
end
end
local function parseMod(line, order)
-- Check if this is a special modifier
local lineLower = line:lower()
if unsupportedModList[lineLower] then
return {}, line
end
local specialMod, specialLine, cap = scan(line, specialModList)
if specialMod and not specialLine:match("%S") then
if type(specialMod) == "function" then
return specialMod(unpack(cap))
else
return copyTable(specialMod)
end
end
for pattern, replacement in pairs(specialQuickFixModList) do
line = line:gsub(pattern, replacement)
end
line = line .. " "
-- Check for a flag/tag specification at the start of the line
local preFlag, preFlagCap
preFlag, line, preFlagCap = scan(line, preFlagList)
if type(preFlag) == "function" then
preFlag = preFlag(unpack(preFlagCap))
end
-- Check for skill name at the start of the line
local skillTag
skillTag, line = scan(line, preSkillNameList)
-- Scan for modifier form
local modForm, formCap
modForm, line, formCap = scan(line, formList)
if not modForm then
return nil, line
end
if formCap[2] then
line = formCap[2] .. line
end
-- Check for tags (per-charge, conditionals)
local modTag, modTag2, tagCap
modTag, line, tagCap = scan(line, modTagList)
if type(modTag) == "function" then
if tagCap[1]:match("%d+") then
modTag = modTag(tonumber(tagCap[1]), unpack(tagCap))
else
modTag = modTag(tagCap[1], unpack(tagCap))
end
end
if modTag then
modTag2, line, tagCap = scan(line, modTagList)
if type(modTag2) == "function" then
if tagCap[1]:match("%d+") then
modTag2 = modTag2(tonumber(tagCap[1]), unpack(tagCap))
else
modTag2 = modTag2(tagCap[1], unpack(tagCap))
end
end
end
-- Scan for modifier name and skill name
local modName, nameCap
if order == 2 and not skillTag then
skillTag, line = scan(line, skillNameList)
end
if modForm == "FLAG" then
formCap[1], line = scan(line, flagTypes, false)
if not formCap[1] then
return nil, line
end
modName, line = scan(line, modNameList, true)
else
modName, line, nameCap = scan(line, modNameList)
if type(modName) == "function" then
modName = modName(unpack(nameCap))
end
end
if order == 1 and not skillTag then
skillTag, line = scan(line, skillNameList)
end
-- Scan for flags
local modFlags
modFlags, line = scan(line, modFlagList, false, true)
if #modFlags > 1 then
line = line:gsub(" And ", "")
end
-- Find modifier value and type according to form
local keywordFlags
local modValue = tonumber(formCap[1]) or formCap[1]
local modType = "BASE"
local modSuffix
local modExtraTags
if modForm == "INC" then
modType = "INC"
elseif modForm == "SHARED_INC" then
modType = "INC"
elseif modForm == "RED" then
modValue = -modValue
modType = "INC"
elseif modForm == "MORE" then
modType = "MORE"
elseif modForm == "LESS" then
modValue = -modValue
modType = "MORE"
elseif modForm == "BASE" then
modSuffix, line = scan(line, suffixTypes, true)
elseif modForm == "GAIN" then
modType = "BASE"
modSuffix, line = scan(line, suffixTypes, true)
elseif modForm == "LOSE" then
modValue = -modValue
modType = "BASE"
modSuffix, line = scan(line, suffixTypes, true)
elseif modForm == "GRANTS" then -- local
modType = "BASE"
modExtraTags = { tag = { type = "Condition", var = "{Hand}Attack" } }
modSuffix, line = scan(line, suffixTypes, true)
elseif modForm == "REMOVES" then -- local
modValue = -modValue
modType = "BASE"
modExtraTags = { tag = { type = "Condition", var = "{Hand}Attack" } }
modSuffix, line = scan(line, suffixTypes, true)
elseif modForm == "FLAG" then
modName = type(modValue) == "table" and modValue.name or modValue
modType = type(modValue) == "table" and modValue.type or "FLAG"
modValue = type(modValue) == "table" and modValue.value or true
elseif modForm == "OVERRIDE" then
modType = "OVERRIDE"
end
if not modName then
return {}, line
end
-- differentiate when a % should be more vs base. e.g. +30% fire resist = base, but +30% damage = more
if modForm == "BASE_MORE" and modName ~= nil then
local modNameStr = type(modName) == "table" and modName[1] or modName
if modNameStr:match("Damage$") or modName == "Duration" or modName == "ProjectileCount" then
modType = "MORE"
else
modType = "BASE"
end
end
-- Combine flags and tags
local flags = 0
local baseKeywordFlags = 0
local tagList = {}
local misc = {}
local dataList = { modName, preFlag, modTag, modTag2, skillTag, modExtraTags }
tableInsertAll(dataList, modFlags)
for _, data in pairs(dataList) do
if type(data) == "table" then
flags = bor(flags, data.flags or 0)
baseKeywordFlags = bor(baseKeywordFlags, data.keywordFlags or 0)
if data.tag then
t_insert(tagList, copyTable(data.tag))
elseif data.tagList then
for _, tag in ipairs(data.tagList) do
t_insert(tagList, copyTable(tag))
end
end
for k, v in pairs(data) do
misc[k] = v
end
end
end
-- Generate modifier list
local nameList = modName
local modList = {}
for i, name in ipairs(type(nameList) == "table" and nameList or { nameList }) do
local value = type(modValue) == "table" and modValue[i] or modValue
if modName.mult then
value = value * modName.mult
end
modList[i] = {
name = name .. (modSuffix or misc.modSuffix or ""),
type = modType,
value = value,
flags = flags,
keywordFlags = bor(type(keywordFlags) == "table" and keywordFlags[i] or 0, baseKeywordFlags),
unpack(tagList)
}
end
if modList[1] then
-- Special handling for various modifier types
if misc.addToAura then
-- Modifiers that add effects to your auras
for i, effectMod in ipairs(modList) do
modList[i] = mod("ExtraAuraEffect", "LIST", { mod = effectMod })
end
elseif misc.newAura then
-- Modifiers that add extra auras
for i, effectMod in ipairs(modList) do
local tagList = {}
for i, tag in ipairs(effectMod) do
tagList[i] = tag
effectMod[i] = nil
end
modList[i] = mod("ExtraAura", "LIST", { mod = effectMod, onlyAllies = misc.newAuraOnlyAllies },
unpack(tagList))
end
elseif misc.addToMinion then
-- Minion modifiers
local newModList = {}
for i, effectMod in ipairs(modList) do
local tagList = {}
local modTagList = copyTable(effectMod)
if misc.playerTag then t_insert(tagList, misc.playerTag) end
if misc.addToMinionTag then t_insert(tagList, misc.addToMinionTag) end
if misc.playerTagList then
for _, tag in ipairs(misc.playerTagList) do
t_insert(tagList, tag)
end
end
-- Until proven otherwise, "PerStat" mods are always relative to the player
for _, tag in ipairs(modTagList) do
if tag.type == "PerStat" then
tag.actor = "parent"
end
end
local newMod = mod("MinionModifier", "LIST", { mod = modTagList }, unpack(tagList))
t_insert(newModList, newMod)
end
if misc.shared then
for _, newMod in ipairs(newModList) do
t_insert(modList, newMod)
end
else
modList = newModList
end
elseif misc.addToSkill then
-- Skill enchants or socketed gem modifiers that add additional effects
for i, effectMod in ipairs(modList) do
modList[i] = mod("ExtraSkillMod", "LIST", { mod = effectMod }, misc.addToSkill)
end
elseif misc.applyToEnemy then
for i, effectMod in ipairs(modList) do
local tagList = {}
if misc.playerTag then t_insert(tagList, misc.playerTag) end
if misc.playerTagList then
for _, tag in ipairs(misc.playerTagList) do
t_insert(tagList, tag)
end
end
local newMod = effectMod
if effectMod[1] and type(effectMod) == "table" and misc.actorEnemy then
newMod = copyTable(effectMod)
newMod[1]["actor"] = "enemy"
end
modList[i] = mod("EnemyModifier", "LIST", { mod = newMod }, unpack(tagList))
end
end
end
return modList, line:match("%S") and line
end
local cache = {}
local unsupported = {}
local count = 0
--local foo = io.open("../unsupported.txt", "w")
--foo:close()
return function (line, isComb)
if not cache[line] then
local modList, extra = parseMod(line, 1)
if modList and extra then
-- TODO: No need currently, to be removed?
-- modList, extra = parseMod(line, 2)
end
cache[line] = { modList, extra }
if foo and not isComb and not cache[line][1] then
local form = line:gsub("[%+%-]?%d+%.?%d*", "{num}")
if not unsupported[form] then
unsupported[form] = true
count = count + 1
foo = io.open("../unsupported.txt", "a+")
foo:write(count, ': ', form,
(cache[line][2] and #cache[line][2] < #line and (' {' .. cache[line][2]) .. '}') or "", '\n')
foo:close()
end
end
end
return unpack(copyTable(cache[line]))
end, cache