Repository navigation
Expand file tree
/
Copy pathCalcSetup.lua
More file actions
2604 lines (2458 loc) · 111 KB
/
Copy pathCalcSetup.lua
File metadata and controls
2604 lines (2458 loc) · 111 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
--
-- Module: Calc Setup
-- Initialises the environment for calculations.
--
---@class Calcs
local calcs = require("Modules.CalcBase")
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local t_remove = table.remove
local m_min = math.min
local m_max = math.max
local band = AND64
local tempTable1 = { }
local function addGrantedPassiveNode(env, node)
env.allocNodes[node.id] = env.spec.nodes[node.id] or node -- use the conquered node data, if available
env.grantedPassives[node.id] = true
env.extraRadiusNodeList[node.id] = nil
end
-- Initialise modifier database with stats and conditions common to all actors
function calcs.initModDB(env, modDB)
modDB:NewMod("FireResistMax", "BASE", data.characterConstants["base_maximum_all_resistances_%"], "Base")
modDB:NewMod("ColdResistMax", "BASE", data.characterConstants["base_maximum_all_resistances_%"], "Base")
modDB:NewMod("LightningResistMax", "BASE", data.characterConstants["base_maximum_all_resistances_%"], "Base")
modDB:NewMod("ChaosResistMax", "BASE", data.characterConstants["base_maximum_all_resistances_%"], "Base")
modDB:NewMod("TotemFireResistMax", "BASE", 75, "Base")
modDB:NewMod("TotemColdResistMax", "BASE", 75, "Base")
modDB:NewMod("TotemLightningResistMax", "BASE", 75, "Base")
modDB:NewMod("TotemChaosResistMax", "BASE", 75, "Base")
modDB:NewMod("BaseBlockChanceMax", "BASE", data.characterConstants["object_inherent_base_maximum_block_%_from_ot"], "Base")
modDB:NewMod("BaseSpellBlockChanceMax", "BASE", data.characterConstants["object_inherent_base_maximum_block_%_from_ot"], "Base")
modDB:NewMod("SpellDodgeChanceMax", "BASE", 75, "Base")
modDB:NewMod("ChargeDuration", "BASE", 15, "Base")
modDB:NewMod("PowerChargesMax", "BASE", data.characterConstants["max_power_charges"], "Base")
modDB:NewMod("FrenzyChargesMax", "BASE", data.characterConstants["max_frenzy_charges"], "Base")
modDB:NewMod("EnduranceChargesMax", "BASE", data.characterConstants["max_endurance_charges"], "Base")
modDB:NewMod("MaximumRage", "BASE", data.gameConstants["BaseMaximumRage"], "Base")
modDB:NewMod("SiphoningChargesMax", "BASE", 0, "Base")
modDB:NewMod("ChallengerChargesMax", "BASE", 0, "Base")
modDB:NewMod("BlitzChargesMax", "BASE", 0, "Base")
modDB:NewMod("InspirationChargesMax", "BASE", 5, "Base")
modDB:NewMod("CrabBarriersMax", "BASE", 0, "Base")
modDB:NewMod("BrutalChargesMax", "BASE", 0, "Base")
modDB:NewMod("AbsorptionChargesMax", "BASE", 0, "Base")
modDB:NewMod("AfflictionChargesMax", "BASE", 0, "Base")
modDB:NewMod("BloodChargesMax", "BASE", 5, "Base")
modDB:NewMod("MaxLifeLeechRate", "BASE", 20, "Base")
modDB:NewMod("MaxManaLeechRate", "BASE", 20, "Base")
modDB:NewMod("ImpaleStacksMax", "BASE", 5, "Base")
modDB:NewMod("IgniteStacksMax", "BASE", 1, "Base")
modDB:NewMod("BleedStacksMax", "BASE", 1, "Base")
modDB:NewMod("PoisonStacksMax", "BASE", 1, "Base")
modDB:NewMod("MaxEnergyShieldLeechRate", "BASE", 10, "Base")
modDB:NewMod("MaxLifeLeechInstance", "BASE", 10, "Base")
modDB:NewMod("MaxManaLeechInstance", "BASE", 10, "Base")
modDB:NewMod("MaxEnergyShieldLeechInstance", "BASE", 10, "Base")
modDB:NewMod("TrapThrowingTime", "BASE", 0.6, "Base")
modDB:NewMod("MineLayingTime", "BASE", 0.3, "Base")
modDB:NewMod("WarcryCastTime", "BASE", 0.8, "Base")
modDB:NewMod("TotemPlacementTime", "BASE", 0.6, "Base")
modDB:NewMod("BallistaPlacementTime", "BASE", 0.35, "Base")
modDB:NewMod("ShockStacksMax", "BASE", 1, "Base")
modDB:NewMod("ChillStacksMax", "BASE", 1, "Base")
modDB:NewMod("ScorchStacksMax", "BASE", 1, "Base")
modDB:NewMod("MovementSpeed", "INC", -30, "Base", { type = "Condition", var = "Maimed" })
modDB:NewMod("Evasion", "INC", -15, "Base", { type = "Condition", var = "Maimed" })
modDB:NewMod("MovementSpeed", "INC", -30, "Base", { type = "Condition", var = "Hindered" })
modDB:NewMod("AilmentThreshold", "BASE", 50, "Base", { type = "PercentStat", stat = "Life", percent = 1 })
modDB:NewMod("PoiseThreshold", "BASE", 50, "Base", { type = "PercentStat", stat = "Life", percent = 1 })
modDB:NewMod("DamageTaken", "INC", 10, "Base", { type = "Condition", var = "Intimidated"})
modDB:NewMod("DamageTaken", "INC", 10, "Base", { type = "Condition", var = "Intimidated", neg = true}, { type = "Condition", var = "Party:Intimidated"})
modDB:NewMod("Damage", "INC", -10, "Base", { type = "Condition", var = "Intimidated"})
modDB:NewMod("Damage", "INC", -10, "Base", { type = "Condition", var = "Intimidated", neg = true}, { type = "Condition", var = "Party:Intimidated"})
modDB:NewMod("DamageTaken", "INC", 10, "Base", ModFlag.Spell, { type = "Condition", var = "Unnerved"})
modDB:NewMod("DamageTaken", "INC", 10, "Base", ModFlag.Spell, { type = "Condition", var = "Unnerved", neg = true}, { type = "Condition", var = "Party:Unnerved"})
modDB:NewMod("Damage", "MORE", -10, "Base", { type = "Condition", var = "Debilitated"})
modDB:NewMod("DamageGainAsRandom", "BASE", 2, "Faerie Fire", { type = "Multiplier", var = "FaerieFireStack", limit = 10, actor = "enemy" })
modDB:NewMod("Condition:Burning", "FLAG", true, "Base", { type = "IgnoreCond" }, { type = "Condition", var = "Ignited" })
modDB:NewMod("Condition:Poisoned", "FLAG", true, "Base", { type = "IgnoreCond" }, { type = "MultiplierThreshold", var = "PoisonStack", threshold = 1 })
modDB:NewMod("ShockBase", "BASE", data.gameConstants["BaseShockMagnitude"], "Base", { type = "ActorCondition", actor = "enemy", var = "Shocked" })
modDB:NewMod("ChillBase", "BASE", 30, "Base", { type = "ActorCondition", actor = "enemy", var = "Chilled" })
modDB:NewMod("Blind", "FLAG", true, "Base", { type = "Condition", var = "Blinded" })
modDB:NewMod("Chill", "FLAG", true, "Base", { type = "Condition", var = "Chilled" })
modDB:NewMod("Freeze", "FLAG", true, "Base", { type = "Condition", var = "Frozen" })
modDB:NewMod("Fortify", "FLAG", true, "Base", { type = "Condition", var = "Fortify" })
modDB:NewMod("Fortified", "FLAG", true, "Base", { type = "Condition", var = "Fortified" })
modDB:NewMod("Fanaticism", "FLAG", true, "Base", { type = "Condition", var = "Fanaticism" })
modDB:NewMod("Onslaught", "FLAG", true, "Base", { type = "Condition", var = "Onslaught" })
modDB:NewMod("UnholyMight", "FLAG", true, "Base", { type = "Condition", var = "UnholyMight" })
modDB:NewMod("ChaoticMight", "FLAG", true, "Base", { type = "Condition", var = "ChaoticMight" })
modDB:NewMod("Adrenaline", "FLAG", true, "Base", { type = "Condition", var = "Adrenaline" })
modDB:NewMod("LesserMassiveShrine", "FLAG", true, "Base", { type = "Condition", var = "LesserMassiveShrine" })
modDB:NewMod("LesserBrutalShrine", "FLAG", true, "Base", { type = "Condition", var = "LesserBrutalShrine" })
modDB:NewMod("DiamondShrine", "FLAG", true, "Base", { type = "Condition", var = "DiamondShrine" })
modDB:NewMod("MassiveShrine", "FLAG", true, "Base", { type = "Condition", var = "MassiveShrine" })
modDB:NewMod("AlchemistsGenius", "FLAG", true, "Base", { type = "Condition", var = "AlchemistsGenius" })
modDB:NewMod("LuckyHits", "FLAG", true, "Base", { type = "Condition", var = "LuckyHits" })
modDB:NewMod("HeavyStunBuildup", "MORE", 50, "Base", { type = "Condition", var = "Dazed"})
modDB:NewMod("ColdCannotHeavyStun", "FLAG", true)
modDB:NewMod("Convergence", "FLAG", true, "Base", { type = "Condition", var = "Convergence" })
modDB:NewMod("PhysicalDamageReduction", "BASE", -15, "Base", { type = "Condition", var = "Crushed" })
modDB:NewMod("CritChanceCap", "BASE", 100, "Base")
modDB:NewMod("PresenceRadius", "BASE", data.characterConstants["base_presence_radius"], "Base")
modDB:NewMod("SurroundedRadius", "BASE", data.misc.SurroundedRadiusBase, "Base")
modDB:NewMod("SurroundedMinimum", "BASE", data.gameConstants["BaseRequiredEnemiesToBeConsideredSurrounded"], "Base")
modDB.conditions["Buffed"] = env.mode_buffs
modDB.conditions["Combat"] = env.mode_combat
modDB.conditions["Effective"] = env.mode_effective
end
local function capitaliseWord(a, b)
return a .. string.lower(b)
end
local function getCorruptedJewelEffect(env, item, node)
if not item or item.type ~= "Jewel" or not item.corrupted or not node or node.containJewelSocket or node.sinister or item.base.subType == "Charm" then
return 0
end
local rarity = item.rarity:gsub("(%a)(%u*)", capitaliseWord)
return env.modDB.multipliers["Corrupted" .. rarity .. "JewelEffect"] or 0
end
local function runRadiusJewelFunc(rad, node, out, data)
local scale = rad.effectScale
if not scale or scale == 1 then
rad.func(node, out, data)
return
end
local start = #out
rad.func(node, out, data)
if #out == start then
return
end
local scaledList = new("ModList"):ModList()
for i = start + 1, #out do
scaledList:AddMod(out[i])
end
for i = #out, start + 1, -1 do
t_remove(out, i)
end
out:ScaleAddList(scaledList, scale)
for i = start + 1, #out do
local mod = out[i]
if mod.parsedLine then
local value = mod.value
while type(value) == "table" and value.mod do
value = value.mod.value
end
if type(value) == "table" then
value = value.value
end
if type(value) == "number" then
mod.parsedLine = mod.parsedLine:gsub("%d*%.?%d+", math.abs(value), 1)
end
end
end
end
local function refreshJewelStatCache(env)
local normalNode = { type = "Normal" }
local attributeNode = { type = "Normal", isAttribute = true }
local notableNode = { type = "Notable" }
GlobalCache.cachedData[env.mode].radiusJewelData = { }
for _, rad in pairs(env.radiusJewelList) do
if not GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId] then
GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId] = { }
GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].hash = rad.jewelHash
GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].smallModList = new("ModList"):ModList()
GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].attributeModList = new("ModList"):ModList()
GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].notableModList = new("ModList"):ModList()
end
runRadiusJewelFunc(rad, normalNode, GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].smallModList, rad.data)
runRadiusJewelFunc(rad, attributeNode, GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].attributeModList, rad.data)
runRadiusJewelFunc(rad, notableNode, GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId].notableModList, rad.data)
end
end
-- Recycle a modlist so that we do not allocate many tables for each node.
local function resetModList(list)
for i = #list, 1, -1 do
list[i] = nil
end
list.multipliers = wipeTable(list.multipliers)
list.conditions = wipeTable(list.conditions)
list.actor = wipeTable(list.actor)
list.parent = false
return list
end
---@param reuse table|nil A ModList to recycle instead of allocating. Only safe when the caller discards the result.
function calcs.buildModListForNode(env, node, reuse, incSmallPassiveSkill, includeKeystoneMods)
local localSmallIncEffect = 0
local localNotableIncEffect = 0
local modList = reuse and resetModList(reuse) or new("ModList"):ModList()
if node.type == "Keystone" then
if includeKeystoneMods then
modList:AddList(node.modList)
end
if node.keystoneMod then
modList:AddMod(node.keystoneMod)
end
else
modList:AddList(node.modList)
end
if #env.radiusJewelList > 0 and not GlobalCache.cachedData[env.mode].radiusJewelData then
refreshJewelStatCache(env)
end
-- Run first pass radius jewels // jewel functions caught by jewelOtherFuncs
for _, rad in pairs(env.radiusJewelList) do
if rad.type == "Other" and rad.nodes[node.id] and rad.nodes[node.id].type ~= "Mastery" then
if rad.item.baseName:find("Time%-Lost") == nil and rad.item.baseName:find("Timeless Jewel") == nil then
runRadiusJewelFunc(rad, node, modList, rad.data)
elseif node.type == "Normal" or node.type == "Notable" then
local cache = GlobalCache.cachedData[env.mode].radiusJewelData[rad.nodeId]
if not cache or (cache.hash ~= rad.jewelHash) then
refreshJewelStatCache(env)
end
if node.type == "Normal" and node.isAttribute and cache and #cache.attributeModList > 0 then
modList:CopyList(cache.attributeModList)
elseif node.type == "Normal" and not node.isAttribute and cache and #cache.smallModList > 0 then
modList:CopyList(cache.smallModList)
elseif node.type == "Notable" and cache and #cache.notableModList > 0 then
modList:CopyList(cache.notableModList)
end
break
end
end
end
-- prefilter the modlist so that every :Flag() call does not have to go through the entire mod list
local hasNoEffect, hasAllocNoEffect, hasScale, hasOtherEffect, hasExtraSkill, hasExplode
for i = 1, #modList do
local name = modList[i].name
if name == "PassiveSkillHasNoEffect" then
hasNoEffect = true
elseif name == "AllocatedPassiveSkillHasNoEffect" then
hasAllocNoEffect = true
elseif name == "PassiveSkillEffect" then
hasScale = true
elseif name == "PassiveSkillHasOtherEffect" then
hasOtherEffect = true
elseif name == "ExtraSkill" then
hasExtraSkill = true
elseif name == "CanExplode" then
hasExplode = true
end
end
if (hasNoEffect and modList:Flag(nil, "PassiveSkillHasNoEffect")) or (env.allocNodes[node.id] and (hasAllocNoEffect and modList:Flag(nil, "AllocatedPassiveSkillHasNoEffect"))) then
wipeTable(modList)
hasScale = false
hasOtherEffect = nil
hasExtraSkill = nil
hasExplode = nil
end
-- Apply effect scaling
if hasScale then
local scale = calcLib.mod(modList, nil, "PassiveSkillEffect")
if scale ~= 1 then
local scaledList = new("ModList"):ModList()
scaledList:ScaleAddList(modList, scale)
modList = scaledList
end
end
-- Run second pass radius jewels
local rescan = false
for i = 1, #env.radiusJewelList do
local rad = env.radiusJewelList[i]
if rad.nodes[node.id] and rad.nodes[node.id].type ~= "Mastery" and (rad.type == "Threshold" or (rad.type == "Self" and env.allocNodes[node.id]) or (rad.type == "SelfUnalloc" and not env.allocNodes[node.id])) then
runRadiusJewelFunc(rad, node, modList, rad.data)
rescan = true
hasOtherEffect = nil
hasExtraSkill = nil
hasExplode = nil
end
end
if rescan then
for i = 1, #modList do
local name = modList[i].name
if name == "PassiveSkillHasOtherEffect" then
hasOtherEffect = true
elseif name == "ExtraSkill" then
hasExtraSkill = true
elseif name == "CanExplode" then
hasExplode = true
end
end
end
if hasOtherEffect and modList:Flag(nil, "PassiveSkillHasOtherEffect") then
local newMods = modList:List(nil, "NodeModifier")
for i = 1, #newMods do
local mod = newMods[i].mod
if i == 1 then
wipeTable(modList)
hasExtraSkill = nil
hasExplode = nil
end
if mod.name == "ExtraSkill" then
hasExtraSkill = true
elseif mod.name == "CanExplode" then
hasExplode = true
end
modList:AddMod(mod)
end
end
node.grantedSkills = wipeTable(node.grantedSkills)
if hasExtraSkill then
local list = modList:List(nil, "ExtraSkill")
for i = 1, #list do
local skill = list[i]
if skill.name ~= "Unknown" then
t_insert(node.grantedSkills, {
skillId = skill.skillId,
level = skill.level,
noSupports = skill.noSupports,
source = "Tree:" .. node.id
})
end
end
end
if hasExplode then
if modList:Flag(nil, "CanExplode") then
t_insert(env.explodeSources, node)
end
end
for i, mod in ipairs(modList) do
local added = false
for j = #mod, 1, -1 do
if mod[j].type == "Condition" and mod[j].var and mod[j].var:match("^WeaponSet") then
added = true
if node.allocMode ~= 0 then -- only update the conditional for WS1/WS2
mod[j].var = "WeaponSet".. node.allocMode
else -- if normal and condition exists, remove it
t_remove(mod, j)
end
end
end
-- only add the conditional for WS1/WS2
if not added and node.allocMode ~= 0 then
table.insert(mod, { type = "Condition", var = "WeaponSet".. node.allocMode })
elseif mod.parsedLine then
local jewelSource = tonumber(mod.source:match("%d+"))
if env.build.spec.nodes[jewelSource].allocMode ~= 0 then
table.insert(mod, { type = "Condition", var = "WeaponSet".. env.build.spec.nodes[jewelSource].allocMode })
end
end
local hasWSCondition = false
-- if the jewelMod has a WS Condition, only add the incEffect given it matches the activeWeaponSet
-- otherwise the mod came from a jewel that is allocMode 0, so it always applies
if mod.name == "JewelSmallPassiveSkillEffect" then
for _, modCriteria in ipairs(mod) do
if modCriteria.type == "Condition" and modCriteria.var and modCriteria.var:match("^WeaponSet") then
if tonumber(modCriteria.var:match("(%d)")) == env.weaponSet then
localSmallIncEffect = mod.value
end
hasWSCondition = true
end
end
if not hasWSCondition then
localSmallIncEffect = mod.value
end
end
if mod.name == "JewelNotablePassiveSkillEffect" then
for _, modCriteria in ipairs(mod) do
if modCriteria.type == "Condition" and modCriteria.var and modCriteria.var:match("^WeaponSet") then
if tonumber(modCriteria.var:match("(%d)")) == env.weaponSet then
localNotableIncEffect = mod.value
end
hasWSCondition = true
end
end
if not hasWSCondition then
localNotableIncEffect = mod.value
end
end
end
-- Apply Inc Node scaling from Hulking Form
if (incSmallPassiveSkill + localSmallIncEffect) > 0 and node.type == "Normal" and not node.isAttribute and not node.ascendancyName then
local scale = 1 + (incSmallPassiveSkill + localSmallIncEffect) / 100
local scaledList = new("ModList"):ModList()
scaledList:ScaleAddList(modList, scale)
modList = scaledList
end
if localNotableIncEffect > 0 and node.type == "Notable" and not node.isAttribute and not node.ascendancyName then
local scale = 1 + localNotableIncEffect / 100
local scaledList = new("ModList"):ModList()
scaledList:ScaleAddList(modList, scale)
modList = scaledList
end
return modList
end
-- Build list of modifiers from the listed tree nodes
function calcs.buildModListForNodeList(env, nodeList, finishJewels, includeKeystoneMods)
-- Initialise radius jewels
for _, rad in pairs(env.radiusJewelList) do
wipeTable(rad.data)
rad.data.modSource = "Tree:"..rad.nodeId
end
-- calculate inc from SmallPassiveSkillEffect
local inc = 0
for _, node in pairs(nodeList) do
inc = inc + node.modList:Sum("INC", nil ,"SmallPassiveSkillEffect")
end
-- Add node modifiers
local modList = new("ModList"):ModList()
-- Outside MAIN mode the per-node list is merged into modList and then
-- dropped, so a single list can be recycled for every node instead of
-- allocating one each time.
local scratch = env.mode ~= "MAIN" and new("ModList"):ModList() or nil
for _, node in pairs(nodeList) do
local nodeModList = calcs.buildModListForNode(env, node, scratch, inc, includeKeystoneMods)
modList:AddList(nodeModList)
if env.mode == "MAIN" then
node.finalModList = nodeModList
end
end
if finishJewels then
-- Process extra radius nodes; these are unallocated nodes near conversion or threshold jewels that need to be processed
for _, node in pairs(env.extraRadiusNodeList) do
local nodeModList = calcs.buildModListForNode(env, node, scratch, inc)
if env.mode == "MAIN" then
node.finalModList = nodeModList
end
end
-- Finalise radius jewels
for _, rad in pairs(env.radiusJewelList) do
runRadiusJewelFunc(rad, nil, modList, rad.data)
if env.mode == "MAIN" then
if not rad.item.jewelRadiusData then
rad.item.jewelRadiusData = { }
end -- used to calc Attributes in radius in itemsTab
rad.item.jewelRadiusData[rad.nodeId] = rad.data
end
end
end
return modList
end
function wipeEnv(env, accelerate)
-- Always wipe the below as we will be pushing in the modifiers,
-- multipliers and conditions for player and enemy DBs via `parent`
-- extensions of those DBs later which allow us to do a table-pointer
-- link and save time on having to do a copyTable() function.
wipeTable(env.modDB.mods)
wipeTable(env.modDB.conditions)
wipeTable(env.modDB.multipliers)
wipeTable(env.enemyDB.mods)
wipeTable(env.enemyDB.conditions)
wipeTable(env.enemyDB.multipliers)
if env.minion then
wipeTable(env.minion.modDB.mods)
wipeTable(env.minion.modDB.conditions)
wipeTable(env.minion.modDB.multipliers)
end
if accelerate.everything then
return
end
-- Passive tree node allocations
-- Also in a further pass tracks Legion influenced mods
if not accelerate.nodeAlloc then
wipeTable(env.allocNodes)
-- Usually states: `Allocates <NAME>` (e.g., amulet anointment)
wipeTable(env.grantedPassives)
wipeTable(env.grantedSkillsNodes)
end
if not accelerate.requirementsItems then
-- Item-related tables
wipeTable(env.itemModDB.mods)
wipeTable(env.itemModDB.conditions)
wipeTable(env.itemModDB.multipliers)
-- 1) Jewels and Jewel-Radius related node modifications
-- 2) Player items
-- 3) Granted Skill from items (e.g., Curse on Hit rings)
-- 4) Flasks
wipeTable(env.radiusJewelList)
wipeTable(env.extraRadiusNodeList)
wipeTable(env.player.itemList)
wipeTable(env.grantedSkillsItems)
wipeTable(env.flasks)
wipeTable(env.charms)
-- Special / Unique Items that have their own ModDB()
if env.talismanModList then
wipeTable(env.talismanModList)
end
if env.theIronMass then
wipeTable(env.theIronMass)
end
if env.weaponModList1 then
wipeTable(env.weaponModList1)
end
-- Requirements from Items (Str, Dex, Int)
wipeTable(env.requirementsTableItems)
end
-- Requirements from Gems (Str, Dex, Int)
if not accelerate.requirementsGems then
wipeTable(env.requirementsTableGems)
end
if not accelerate.skills then
-- Player Active Skills generation
wipeTable(env.player.activeSkillList)
env.sourceGemPropertyInfo = { }
-- Enhances Active Skills with skill ModFlags, KeywordFlags
-- and modifiers that affect skill scaling (e.g., global buffs/effects)
wipeTable(env.auxSkillList)
end
end
local function getGemModList(env, groupCfg, socketColor, socketNum)
local gemCfg = copyTable(groupCfg, true)
gemCfg.socketColor = socketColor
gemCfg.socketNum = socketNum
return env.modDB:Tabulate("LIST", gemCfg, "GemProperty")
end
local function applyGemMods(effect, modList)
for _, mod in ipairs(modList) do
local match = true
local value = mod.value
if value.keywordList then
for _, keyword in ipairs(value.keywordList) do
if not calcLib.gemIsType(effect, keyword, true) then
match = false
break
end
end
elseif not calcLib.gemIsType(effect, value.keyword, true) then
match = false
end
if value.gemRequirements then
for req, val in pairs(value.gemRequirements) do
match = match and effect.gemData[req] > val
end
end
if match then
effect[value.key] = (effect[value.key] or 0) + value.value
effect.gemPropertyInfo = effect.gemPropertyInfo or {}
t_insert(effect.gemPropertyInfo, mod)
end
end
end
local function applySocketMods(env, gem, groupCfg, socketNum, modSource)
local socketCfg = copyTable(groupCfg, true)
socketCfg.skillGem = gem
socketCfg.socketNum = socketNum
for _, value in ipairs(env.modDB:List(socketCfg, "SocketProperty")) do
env.player.modDB:AddMod(modLib.setSource(value.value, modSource or groupCfg.slotName or ""))
end
end
local function addBestSupport(supportEffect, appliedSupportList, mode)
local add = true
for index, otherSupport in ipairs(appliedSupportList) do
-- Check if there's another better support already present
if supportEffect.grantedEffect == otherSupport.grantedEffect then
add = false
if supportEffect.level > otherSupport.level or (supportEffect.level == otherSupport.level and supportEffect.quality > otherSupport.quality) then
if mode == "MAIN" then
otherSupport.superseded = true
end
appliedSupportList[index] = supportEffect
else
supportEffect.superseded = true
end
break
elseif supportEffect.grantedEffect.gemFamily and otherSupport.grantedEffect.gemFamily then
for _, family in ipairs(supportEffect.grantedEffect.gemFamily) do
for _, otherFamily in ipairs(otherSupport.grantedEffect.gemFamily) do
if family == otherFamily then
add = false
if mode == "MAIN" then
otherSupport.superseded = true
end
appliedSupportList[index] = supportEffect
break
end
end
end
elseif supportEffect.grantedEffect.plusVersionOf == otherSupport.grantedEffect.id then
add = false
if mode == "MAIN" then
otherSupport.superseded = true
end
appliedSupportList[index] = supportEffect
elseif otherSupport.grantedEffect.plusVersionOf == supportEffect.grantedEffect.id then
add = false
supportEffect.superseded = true
end
end
if add then
t_insert(appliedSupportList, supportEffect)
end
end
local function processGrantedEffect(grantedEffect, gemInstance, env, groupCfg, gemIndex, propertyModList, processedSockets, targetListList)
if not grantedEffect or not grantedEffect.support then
return
end
local supportEffect = {
grantedEffect = grantedEffect,
level = gemInstance.level,
quality = gemInstance.quality,
srcInstance = gemInstance,
gemData = gemInstance.gemData,
superseded = false,
isSupporting = {},
}
if env.mode == "MAIN" then
gemInstance.displayEffect = supportEffect
gemInstance.supportEffect = supportEffect
end
if gemInstance.gemData then
local playerItems = env.player.itemList
local socketedIn = playerItems[groupCfg.slotName] and playerItems[groupCfg.slotName].sockets and playerItems[groupCfg.slotName].sockets[gemIndex]
applyGemMods(supportEffect, socketedIn and getGemModList(env, groupCfg, socketedIn.color, gemIndex) or propertyModList)
if not processedSockets[gemInstance] then
processedSockets[gemInstance] = true
applySocketMods(env, gemInstance.gemData, groupCfg, gemIndex, playerItems[groupCfg.slotName] and playerItems[groupCfg.slotName].name)
-- Keep track of the gem count for each color socketed in this group
groupCfg.intelligenceGems = (groupCfg.intelligenceGems or 0) + (gemInstance.gemData.tags.intelligence and 1 or 0)
groupCfg.dexterityGems = (groupCfg.dexterityGems or 0) + (gemInstance.gemData.tags.dexterity and 1 or 0)
groupCfg.strengthGems = (groupCfg.strengthGems or 0) + (gemInstance.gemData.tags.strength and 1 or 0)
end
end
-- Validate support gem level in case there is no active skill (and no full calculation)
calcLib.validateGemLevel(supportEffect)
for _, targetList in ipairs(targetListList) do
addBestSupport(supportEffect, targetList, env.mode)
end
end
local function getNormalizedSkillLevel(grantedSkill)
-- Levels in socketGroup.gemList[1].level are normalized
-- grantedSkill.level is not causing group match miss which causes all things that rely on group order to fail
local normalizedGrantedSkill = {
grantedEffect = data.skills[grantedSkill.skillId],
level = grantedSkill.level
}
calcLib.validateGemLevel(normalizedGrantedSkill)
return normalizedGrantedSkill.level
end
local function getGrantedSkillLevel(gemData, maxLevel, characterLevel, modDB)
local str, dex, int
if modDB then
str = m_max(round(calcLib.val(modDB, "Str")), 0)
dex = m_max(round(calcLib.val(modDB, "Dex")), 0)
int = m_max(round(calcLib.val(modDB, "Int")), 0)
end
for level = maxLevel, 1, -1 do
local levelData = gemData.grantedEffect.levels[level]
local levelRequirement = levelData and levelData.levelRequirement
if levelRequirement and levelRequirement <= characterLevel and (not modDB
or calcLib.getGemStatRequirement(levelRequirement, gemData.reqStr, false) <= str
and calcLib.getGemStatRequirement(levelRequirement, gemData.reqDex, false) <= dex
and calcLib.getGemStatRequirement(levelRequirement, gemData.reqInt, false) <= int) then
return level
end
end
-- Some granted skills only define higher levels (Pinnacle of Power has only 20)
local lowest
for level in pairs(gemData.grantedEffect.levels) do
if type(level) == "number" and (not lowest or level < lowest) then
lowest = level
end
end
return lowest or 1
end
local defaultAttackSlots = {
{ "Weapon 1", "Weapon 2" },
{ "Weapon 1 Swap", "Weapon 2 Swap" },
}
local function getCharacterMeleeSkillClass(item)
if item and item.base then
if item.base.tags.buckler then
return "Buckler"
elseif item.base.weapon then
return item.base.subType or item.base.type
end
end
return "Unarmed"
end
local thornsStats = { "PhysicalMin", "PhysicalMax", "FireMin", "FireMax", "ColdMin", "ColdMax", "LightningMin", "LightningMax", "ChaosMin", "ChaosMax" }
local function modDBHasThornsDamage(modDB)
for _, stat in ipairs(thornsStats) do
local mods = modDB.mods[stat]
if mods then
for _, mod in ipairs(mods) do
if mod.type == "BASE" and band(mod.flags or 0, ModFlag.Thorns) ~= 0 then
return true
end
end
end
end
return modDB.parent and modDBHasThornsDamage(modDB.parent)
end
local function defaultRadiusJewelFunc(node, out, data)
-- Default function just tallies all stats in radius
if node then
for _, stat in pairs({ "Str", "Dex", "Int" }) do
data[stat] = (data[stat] or 0) + out:Sum("BASE", nil, stat)
end
end
end
local function replaceWeaponSetActiveSkills(targetEnv, sourceEnv, sourceSet)
local replacements = { }
for _, activeSkill in ipairs(sourceEnv.player.activeSkillList) do
local group = activeSkill.socketGroup
if group and group.usingSkillSet == sourceSet then
if not replacements[group] then
replacements[group] = { }
end
t_insert(replacements[group], activeSkill)
end
end
local replaced = { }
local activeSkillList = { }
for _, activeSkill in ipairs(targetEnv.player.activeSkillList) do
local group = activeSkill.socketGroup
if replacements[group] then
if not replaced[group] then
replaced[group] = true
for _, replacement in ipairs(replacements[group]) do
t_insert(activeSkillList, replacement)
end
end
else
t_insert(activeSkillList, activeSkill)
end
end
targetEnv.player.activeSkillList = activeSkillList
end
local function socketGroupHasGem(socketGroup, gemInstance)
for _, existing in ipairs(socketGroup.gemList) do
if gemInstance.gemId and existing.gemId == gemInstance.gemId
or gemInstance.skillId and existing.skillId == gemInstance.skillId
or not gemInstance.gemId and not gemInstance.skillId and existing.nameSpec == gemInstance.nameSpec then
return true
end
end
return false
end
local function migrateLegacySlotSupports(socketGroup, legacyGroups, migratedGroups)
for _, legacyGroup in ipairs(legacyGroups) do
for _, gemInstance in ipairs(legacyGroup.gemList) do
local grantedEffect = gemInstance.grantedEffect or gemInstance.gemData and gemInstance.gemData.grantedEffect
if grantedEffect and grantedEffect.support then
migratedGroups[legacyGroup] = true
if not socketGroupHasGem(socketGroup, gemInstance) then
t_insert(socketGroup.gemList, copyTable(gemInstance, true))
end
end
end
end
end
local function getGrantedSkillGroupKey(source, slot, skillId)
return (source or "") .. "\0" .. (slot or "") .. "\0" .. (skillId or "")
end
local grantedSkillGroupStateFields = { "label", "enabled", "includeInFullDPS", "groupCount", "set1", "set2", "mainActiveSkill", "mainActiveSkillCalcs" }
local function cacheGrantedSkillGroupState(build, group)
local sourceSlot = (group.sourceItem or group.source == "Default Attack") and group.slot and build.itemsTab.slots[group.slot]
local customized = #group.gemList > 1 or group.label and group.label:match("%S") or group.enabled == false
or group.includeInFullDPS or group.groupCount and group.groupCount ~= 1
or not (sourceSlot and sourceSlot.weaponSet) and (group.set1 == false or group.set2 == false)
or group.mainActiveSkill and group.mainActiveSkill ~= 1 or group.mainActiveSkillCalcs and group.mainActiveSkillCalcs ~= 1
if not customized then
return
end
local state = { gemList = { } }
for _, field in ipairs(grantedSkillGroupStateFields) do
state[field] = group[field]
end
for index = 2, #group.gemList do
local support = copyTable(group.gemList[index], true)
support.displayEffect = nil
support.supportEffect = nil
t_insert(state.gemList, support)
end
return state
end
---@alias CalcEnvMode "MAIN"|"CALCS"|"CALCULATOR"
-- Initialise environment:
-- 1. Initialises the player and enemy modifier databases
-- 2. Merges modifiers for all items
-- 3. Builds a list of jewels with radius functions
-- 4. Merges modifiers for all allocated passive nodes
-- 5. Builds a list of active skills and their supports (calcs.createActiveSkill)
-- 6. Builds modifier lists for all active skills (calcs.buildActiveSkillModList)
---@param build Build
---@param mode CalcEnvMode
---@param override CalcOverride?
---@param specEnv any?
---@return Env
---@return ModDB? cachedPlayerDB
---@return ModDB? cachedEnemyDB
---@return ModDB? cachedMinionDB
function calcs.initEnv(build, mode, override, specEnv)
-- accelerator variables
local cachedPlayerDB = specEnv and specEnv.cachedPlayerDB or nil
local cachedEnemyDB = specEnv and specEnv.cachedEnemyDB or nil
local cachedMinionDB = specEnv and specEnv.cachedMinionDB or nil
---@type Env?
local env = specEnv and specEnv.env or nil
local accelerate = specEnv and specEnv.accelerate or { }
-- environment variables
local override = override or { }
local modDB = nil
local enemyDB = nil
local classStats = nil
if not env then
env = { }
env.build = build
env.data = build.data
env.configInput = build.configTab.input
env.configPlaceholder = build.configTab.placeholder
env.calcsInput = build.calcsTab.input
env.mode = mode
env.buildBreakdown = mode == "MAIN" or mode == "CALCS"
env.spec = override.spec or build.spec
env.classId = env.spec.curClassId
modDB = new("ModDB"):ModDB()
env.modDB = modDB
enemyDB = new("ModDB"):ModDB()
env.enemyDB = enemyDB
env.itemModDB = new("ModDB"):ModDB()
env.enemyLevel = build.configTab.enemyLevel or m_min(data.misc.MaxEnemyLevel, build.characterLevel)
-- Create player/enemy actors
env.player = {
modDB = env.modDB,
level = build.characterLevel,
}
env.modDB.actor = env.player
env.enemy = {
modDB = env.enemyDB,
level = env.enemyLevel,
}
enemyDB.actor = env.enemy
env.player.enemy = env.enemy
env.enemy.enemy = env.player
enemyDB.actor.player = env.player
env.modDB.actor.player = env.player
-- Set up requirements tracking
env.requirementsTableItems = { }
env.requirementsTableGems = { }
-- Prepare item, skill, flask tables
env.radiusJewelList = wipeTable(env.radiusJewelList)
env.extraRadiusNodeList = wipeTable(env.extraRadiusNodeList)
env.player.itemList = { }
env.grantedSkills = { }
env.grantedSkillsNodes = { }
env.grantedSkillsItems = { }
env.explodeSources = { }
env.itemWarnings = { }
env.flasks = { }
env.charms = { }
-- tree based
env.grantedPassives = { }
-- skill-related
env.player.activeSkillList = { }
env.auxSkillList = { }
--elseif accelerate.everything then
-- local minionDB = nil
-- env.modDB.parent, env.enemyDB.parent, minionDB = specCopy(env)
-- if minionDB then
-- env.minion.modDB.parent = minionDB
-- end
-- wipeEnv(env, accelerate)
else
wipeEnv(env, accelerate)
modDB = env.modDB
enemyDB = env.enemyDB
end
-- Set buff mode
local buffMode
if mode == "CALCS" then
buffMode = env.calcsInput.misc_buffMode
else
buffMode = "EFFECTIVE"
end
if buffMode == "EFFECTIVE" then
env.mode_buffs = true
env.mode_combat = true
env.mode_effective = true
elseif buffMode == "COMBAT" then
env.mode_buffs = true
env.mode_combat = true
env.mode_effective = false
elseif buffMode == "BUFFED" then
env.mode_buffs = true
env.mode_combat = false
env.mode_effective = false
else
env.mode_buffs = false
env.mode_combat = false
env.mode_effective = false
end
classStats = env.spec.tree.characterData and env.spec.tree.characterData[env.classId] or env.spec.tree.classes[env.classId]
if not cachedPlayerDB then
-- Initialise modifier database with base values
for _, stat in pairs({"Str","Dex","Int"}) do
modDB:NewMod(stat, "BASE", classStats["base_"..stat:lower()], "Base")
end
modDB.multipliers["Level"] = m_max(1, m_min(100, build.characterLevel))
calcs.initModDB(env, modDB)
modDB:NewMod("Life", "BASE", data.characterConstants["life_per_level"], "Base", { type = "Multiplier", var = "Level", base = 16 })
modDB:NewMod("Mana", "BASE", data.characterConstants["mana_per_level"], "Base", { type = "Multiplier", var = "Level", base = 30 })
modDB:NewMod("ManaRegen", "BASE", env.data.misc.ManaRegenBase, "Base", { type = "PerStat", stat = "Mana", div = 1 }, { type = "Condition", var = "NoInherentManaRegen", neg = true })
modDB:NewMod("WardRegenPercent", "BASE", data.gameConstants["BaseWardRegenerationPercentPerMinute"]/60, "Base" )
modDB:NewMod("Spirit", "BASE", 0, "Base")
modDB:NewMod("Devotion", "BASE", 0, "Base")
modDB:NewMod("Tribute", "BASE", 0, "Base")
modDB:NewMod("Evasion", "BASE", data.characterConstants["base_evasion_rating"], "Base")
modDB:NewMod("Accuracy", "BASE", data.characterConstants["accuracy_rating_per_level"], "Base", { type = "Multiplier", var = "Level", base = -data.characterConstants["accuracy_rating_per_level"] })
modDB:NewMod("CritMultiplier", "BASE", data.characterConstants["base_critical_hit_damage_bonus"], "Base")
modDB:NewMod("DotMultiplier", "BASE", 50, "Base", { type = "Condition", var = "CriticalStrike" })
modDB:NewMod("FireResist", "BASE", env.configInput.resistancePenalty or -60, "Base")
modDB:NewMod("ColdResist", "BASE", env.configInput.resistancePenalty or -60, "Base")
modDB:NewMod("LightningResist", "BASE", env.configInput.resistancePenalty or -60, "Base")
modDB:NewMod("ChaosResist", "BASE", 0, "Base")
modDB:NewMod("TotemFireResist", "BASE", 40, "Base")
modDB:NewMod("TotemColdResist", "BASE", 40, "Base")
modDB:NewMod("TotemLightningResist", "BASE", 40, "Base")
modDB:NewMod("TotemChaosResist", "BASE", 20, "Base")
modDB:NewMod("MaximumFortification", "BASE", data.characterConstants["base_max_fortification"], "Base")
modDB:NewMod("MaximumValour", "BASE", 50, "Base")
modDB:NewMod("SoulEaterMax", "BASE", 45, "Base")
modDB:NewMod("Multiplier:IntensityLimit", "BASE", 3, "Base")
modDB:NewMod("Multiplier:DemonFlameMaximum", "BASE", 10, "Base")
modDB:NewMod("Damage", "INC", data.characterConstants["damage_+%_per_10_rampage_stacks"], "Base", { type = "Multiplier", var = "Rampage", limit = data.characterConstants["max_rampage_stacks"] / 20, div = 20 })
modDB:NewMod("MovementSpeed", "INC", data.characterConstants["movement_velocity_+%_per_10_rampage_stacks"], "Base", { type = "Multiplier", var = "Rampage", limit = data.characterConstants["max_rampage_stacks"] / 20, div = 20 })
modDB:NewMod("Speed", "INC", 5, "Base", ModFlag.Attack, { type = "Multiplier", var = "SoulEater"})
modDB:NewMod("Speed", "INC", 5, "Base", ModFlag.Cast, { type = "Multiplier", var = "SoulEater" })
modDB:NewMod("ActiveTrapLimit", "BASE", data.characterConstants["base_number_of_traps_allowed"], "Base")
modDB:NewMod("ActiveMineLimit", "BASE", data.characterConstants["base_number_of_remote_mines_allowed"], "Base")
modDB:NewMod("MineThrowCount", "BASE", 1, "Base")
modDB:NewMod("TrapThrowCount", "BASE", 1, "Base")
modDB:NewMod("ActiveBrandLimit", "BASE", 3, "Base")
modDB:NewMod("EnemyCurseLimit", "BASE", 1, "Base")
modDB:NewMod("EnemyMarkLimit", "BASE", 1, "Base")
modDB:NewMod("SocketedCursesHexLimitValue", "BASE", 1, "Base")
modDB:NewMod("ProjectileCount", "BASE", 1, "Base")
modDB:NewMod("PhysicalHeavyStunBuildup", "MORE", data.characterConstants["physical_hit_damage_stun_multiplier_+%_final_from_ot"], "Physical Damage")
modDB:NewMod("EnemyHeavyStunBuildup", "MORE", data.characterConstants["melee_hit_damage_stun_multiplier_+%_final_from_ot"], "Melee Damage", ModFlag.Melee)
modDB:NewMod("AilmentMagnitude", "MORE", 100, "Base", 0, KeywordFlag.Bleed, { type = "ActorCondition", actor = "enemy", varList = { "Moving", "BleedAggravated" } }, { type = "Condition", var = "NoExtraBleedDamageToMovingEnemy", neg = true })