forked from PathOfBuildingCommunity/PathOfBuilding-PoE2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcSetup.lua
1846 lines (1738 loc) · 75.1 KB
/
CalcSetup.lua
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.
--
local calcs = ...
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 tempTable1 = { }
-- Initialise modifier database with stats and conditions common to all actors
function calcs.initModDB(env, modDB)
modDB:NewMod("FireResistMax", "BASE", 75, "Base")
modDB:NewMod("ColdResistMax", "BASE", 75, "Base")
modDB:NewMod("LightningResistMax", "BASE", 75, "Base")
modDB:NewMod("ChaosResistMax", "BASE", 75, "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("BlockChanceMax", "BASE", 75, "Base")
modDB:NewMod("SpellBlockChanceMax", "BASE", 75, "Base")
modDB:NewMod("SpellDodgeChanceMax", "BASE", 75, "Base")
modDB:NewMod("ChargeDuration", "BASE", 10, "Base")
modDB:NewMod("PowerChargesMax", "BASE", 3, "Base")
modDB:NewMod("FrenzyChargesMax", "BASE", 3, "Base")
modDB:NewMod("EnduranceChargesMax", "BASE", 3, "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("ActiveTotemLimit", "BASE", 1, "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("DamageTaken", "INC", 10, "Base", ModFlag.Attack, { type = "Condition", var = "Intimidated"})
modDB:NewMod("DamageTaken", "INC", 10, "Base", ModFlag.Attack, { 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("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("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("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.conditions["Buffed"] = env.mode_buffs
modDB.conditions["Combat"] = env.mode_combat
modDB.conditions["Effective"] = env.mode_effective
end
-- ATD has a special case with variant/variantAlt but other jewels have a fairly simple iterative list
local function setStats(jewel, radiusJewelStats, index, alternate)
local variant = (alternate and jewel.variantAlt or jewel.variant) or index
local range = jewel.explicitModLines[variant].range
local line = jewel.explicitModLines[variant].line
local value = 0
line:gsub("%((%d+)%-(%d+)%)",
function(num1, num2)
value = round(num1 + (num2-num1) * range)
end
)
radiusJewelStats[index] = {
isNotable = (line:match("^(%S+)") == "Notable"),
toAdd = (line:find("also% grant")~= nil), -- only add mods with the "also grant" text to radiusNodes
sdLine = line:gsub(".*grant ", ""):gsub("%(.-%)", value)
}
if line:lower():match("increased effect of small passive skills in radius") then
return tonumber(line:match("%d+"))
end
end
local function mergeStats(node, sd, spec)
-- copy the original tree node so we ignore the mods being added from the jewel
local nodeCopy = copyTable(spec.tree.nodes[node.id], true)
local nodeNumber = 0
local nodeString = ""
local modToAddNumber = 0
local modToAddString = ""
-- loop the original node mods and compare to the jewel mod we want to add
-- if the strings without the numbers are identical, the mods should be identical
-- if so, update the node's version of the mod and do not add the jewel mods to the list
-- otherwise, add the jewel mod because it's unique/new to the node
for index, nodeSd in ipairs(nodeCopy.sd) do
nodeString = nodeSd:gsub("(%d+)", function(number)
nodeNumber = number
return ""
end)
modToAddString = sd:gsub("(%d+)", function(number)
modToAddNumber = number
return ""
end)
if nodeString == modToAddString then
node.sd[index] = node.sd[index]:gsub("(%d+)", (nodeNumber + modToAddNumber))
return
end
end
t_insert(node.sd, sd)
end
-- grab the stat lines from the selected variants on the jewel to add to the nodes
-- e.g. Against the Darkness or Time-Lost jewels
local function setRadiusJewelStats(radiusJewel, radiusJewelStats)
local jewel = radiusJewel.item
local incEffect
if jewel.baseName:find("Time%-Lost") ~= nil then
radiusJewelStats.source = radiusJewel.data.modSource
if jewel.title == "Against the Darkness" then
setStats(jewel, radiusJewelStats, 1, false)
setStats(jewel, radiusJewelStats, 2, true)
else
local jewelModLines = copyTable(jewel.explicitModLines, true)
-- sanitize mods in case of line breaks
for id, mod in ipairs(jewelModLines) do
local line1, line2 = mod.line:match("^(.-)\n(.*)$")
-- if a line break is found, copy the modLineTable, modify the original with the first string
-- and add the table with second string to the end
if line1 and line2 then
jewel.explicitModLines[id].line = line1
local linebreakMod = copyTable(jewel.explicitModLines[id])
linebreakMod.line = line2
t_insert(jewel.explicitModLines, linebreakMod)
end
end
for modIndex, _ in ipairs(jewelModLines) do
incEffect = setStats(jewel, radiusJewelStats, modIndex, false) or incEffect
end
end
end
return incEffect
end
local function addStats(jewel, node, spec)
local incEffect
-- short term to avoid running the logic on AddItemTooltip
if not spec.build.treeTab.skipTimeLostJewelProcessing then
-- reset node stats to base or override for attributes
if spec.hashOverrides and spec.hashOverrides[node.id] then
node.sd = copyTable(spec.hashOverrides[node.id].sd, true)
else
node.sd = copyTable(spec.tree.nodes[node.id].sd, true)
end
local radiusJewelStats = { }
incEffect = setRadiusJewelStats(jewel, radiusJewelStats)
for _, stat in ipairs(radiusJewelStats) do
-- the node and stat types match, add sd to node if it's not already there and it's an 'also grant' mod
if not isValueInTable(node.sd, stat.sdLine) and ((node.type == "Notable" and stat.isNotable) or (node.type == "Normal" and not stat.isNotable))
and stat.toAdd then
mergeStats(node, stat.sdLine, spec)
end
end
-- if there's an incEffect of Small Passives mod on the jewel and the node is small, scale all numbers
-- we've already checked this isn't an attribute node
if incEffect and node.type == "Normal" then
for index, sd in ipairs(node.sd) do
node.sd[index] = sd:gsub("(%d+)", function(num)
return tostring(round(tonumber(num) * (1 + incEffect/100)))
end)
end
end
end
end
local function addStatsFromJewelToNode(jewel, node, spec)
-- attribute nodes do not count as Small Passives
if not node.isAttribute then
local itemsTab = spec.build.itemsTab
-- if the Time-Lost jewel is socketed, add the stat
if itemsTab.activeSocketList then
for _, nodeId in pairs(itemsTab.activeSocketList) do
local _, socketedJewel = itemsTab:GetSocketAndJewelForNodeID(nodeId)
if socketedJewel and socketedJewel.baseName:find("Time%-Lost") == 1 then
addStats(jewel, node, spec)
end
end
-- activeSocketList isn't init on Load, need to run once
elseif itemsTab.initSockets then
addStats(jewel, node, spec)
end
end
end
function calcs.buildModListForNode(env, node, incSmallPassiveSkill)
local modList = new("ModList")
if node.type == "Keystone" then
modList:AddMod(node.keystoneMod)
else
modList:AddList(node.modList)
end
-- Run first pass radius jewels
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 then
rad.func(node, modList, rad.data)
else
addStatsFromJewelToNode(rad, node, env.build.spec)
env.build.spec.tree:ProcessStats(node)
modList = node.modList
end
end
end
if modList:Flag(nil, "PassiveSkillHasNoEffect") or (env.allocNodes[node.id] and modList:Flag(nil, "AllocatedPassiveSkillHasNoEffect")) then
wipeTable(modList)
end
-- Apply effect scaling
local scale = calcLib.mod(modList, nil, "PassiveSkillEffect")
if scale ~= 1 then
local scaledList = new("ModList")
scaledList:ScaleAddList(modList, scale)
modList = scaledList
end
-- Run second pass radius jewels
for _, rad in pairs(env.radiusJewelList) do
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
if rad.item.baseName:find("Time%-Lost") == nil then
rad.func(node, modList, rad.data)
else
addStatsFromJewelToNode(rad, node, env.build.spec)
env.build.spec.tree:ProcessStats(node)
modList = node.modList
end
end
end
if modList:Flag(nil, "PassiveSkillHasOtherEffect") then
for i, mod in ipairs(modList:List(skillCfg, "NodeModifier")) do
if i == 1 then wipeTable(modList) end
modList:AddMod(mod.mod)
end
end
node.grantedSkills = { }
for _, skill in ipairs(modList:List(nil, "ExtraSkill")) do
if skill.name ~= "Unknown" then
t_insert(node.grantedSkills, {
skillId = skill.skillId,
level = skill.level,
noSupports = true,
source = "Tree:"..node.id
})
end
end
if modList:Flag(nil, "CanExplode") then
t_insert(env.explodeSources, node)
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 conditional 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 })
end
end
-- Apply Inc Node scaling from Hulking Form
if incSmallPassiveSkill > 0 and node.type == "Normal" and not node.isAttribute and not node.ascendancyName then
local scale = 1 + incSmallPassiveSkill / 100
local scaledList = new("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)
-- 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")
for _, node in pairs(nodeList) do
local nodeModList = calcs.buildModListForNode(env, node, inc)
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, inc)
if env.mode == "MAIN" then
node.finalModList = nodeModList
end
end
-- Finalise radius jewels
for _, rad in pairs(env.radiusJewelList) do
if rad.item.baseName:find("Time%-Lost") == nil then
rad.func(nil, modList, rad.data)
end
if env.mode == "MAIN" then
if not rad.item.jewelRadiusData then
rad.item.jewelRadiusData = { }
end
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.aegisModList then
wipeTable(env.aegisModList)
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)
-- 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.gemData, keyword, true) then
match = false
break
end
end
elseif not calcLib.gemIsType(effect.gemData, value.keyword, true) then
match = false
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.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
-- 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)
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
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.spec = override.spec or build.spec
env.classId = env.spec.curClassId
modDB = new("ModDB")
env.modDB = modDB
enemyDB = new("ModDB")
env.enemyDB = enemyDB
env.itemModDB = new("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", 12, "Base", { type = "Multiplier", var = "Level", base = 16 })
modDB:NewMod("Mana", "BASE", 4, "Base", { type = "Multiplier", var = "Level", base = 30 })
modDB:NewMod("ManaRegen", "BASE", 0.04, "Base", { type = "PerStat", stat = "Mana", div = 1 })
modDB:NewMod("Spirit", "BASE", 0, "Base")
modDB:NewMod("Devotion", "BASE", 0, "Base")
modDB:NewMod("Evasion", "BASE", 3, "Base", { type = "Multiplier", var = "Level", base = 27 })
modDB:NewMod("Accuracy", "BASE", 3, "Base", { type = "Multiplier", var = "Level", base = -3 })
modDB:NewMod("CritMultiplier", "BASE", 100, "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("MaximumRage", "BASE", 30, "Base")
modDB:NewMod("MaximumFortification", "BASE", 20, "Base")
modDB:NewMod("MaximumValour", "BASE", 50, "Base")
modDB:NewMod("SoulEaterMax", "BASE", 45, "Base")
modDB:NewMod("Multiplier:IntensityLimit", "BASE", 3, "Base")
modDB:NewMod("Damage", "INC", 2, "Base", { type = "Multiplier", var = "Rampage", limit = 50, div = 20 })
modDB:NewMod("MovementSpeed", "INC", 1, "Base", { type = "Multiplier", var = "Rampage", limit = 50, 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", 15, "Base")
modDB:NewMod("ActiveMineLimit", "BASE", 15, "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("Speed", "MORE", 10, "Base", ModFlag.Attack, { type = "Condition", var = "DualWielding" }, { type = "Condition", var = "DoubledInherentDualWieldingSpeed", neg = true })
modDB:NewMod("Speed", "MORE", 20, "Base", ModFlag.Attack, { type = "Condition", var = "DualWielding" }, { type = "Condition", var = "DoubledInherentDualWieldingSpeed"})
modDB:NewMod("BlockChance", "BASE", 20, "Base", { type = "Condition", var = "DualWielding" }, { type = "Condition", var = "NoInherentBlock", neg = true}, { type = "Condition", var = "DoubledInherentDualWieldingBlock", neg = true})
modDB:NewMod("BlockChance", "BASE", 40, "Base", { type = "Condition", var = "DualWielding" }, { type = "Condition", var = "NoInherentBlock", neg = true}, { type = "Condition", var = "DoubledInherentDualWieldingBlock"})
modDB:NewMod("AilmentMagnitude", "MORE", 100, "Base", 0, KeywordFlag.Bleed, { type = "ActorCondition", actor = "enemy", var = "Moving" }, { type = "Condition", var = "NoExtraBleedDamageToMovingEnemy", neg = true })
modDB:NewMod("Condition:BloodStance", "FLAG", true, "Base", { type = "Condition", var = "SandStance", neg = true })
modDB:NewMod("Condition:PrideMinEffect", "FLAG", true, "Base", { type = "Condition", var = "PrideMaxEffect", neg = true })
modDB:NewMod("PerBrutalTripleDamageChance", "BASE", 3, "Base")
modDB:NewMod("PerAfflictionAilmentDamage", "BASE", 8, "Base")
modDB:NewMod("PerAfflictionNonDamageEffect", "BASE", 8, "Base")
modDB:NewMod("PerAbsorptionElementalEnergyShieldRecoup", "BASE", 12, "Base")
modDB:NewMod("CharmLimit", "BASE", 0, "Base")
modDB:NewMod("ManaDegenPercent", "BASE", 1, "Base", { type = "Multiplier", var = "EffectiveManaBurnStacks" })
modDB:NewMod("LifeDegenPercent", "BASE", 1, "Base", { type = "Multiplier", var = "WeepingWoundsStacks" })
modDB:NewMod("WeaponSwapSpeed", "BASE", 250, "Base") -- 250ms
modDB:NewMod("Speed", "INC", 3, "Base", ModFlag.Attack, { type = "Multiplier", var = "Tailwind", limit = 10 })
modDB:NewMod("Speed", "INC", 3, "Base", ModFlag.Cast, { type = "Multiplier", var = "Tailwind", limit = 10 })
modDB:NewMod("MovementSpeed", "INC", 1, "Base", { type = "Multiplier", var = "Tailwind", limit = 10 })
modDB:NewMod("Evasion", "INC", 15, "Base", { type = "Multiplier", var = "Tailwind", limit = 10 })
modDB:NewMod("SkillSlots", "BASE", 9, "Base")
-- Initialise enemy modifier database
calcs.initModDB(env, enemyDB)
enemyDB:NewMod("Accuracy", "BASE", env.data.monsterAccuracyTable[env.enemyLevel], "Base")
enemyDB:NewMod("Condition:AgainstDamageOverTime", "FLAG", true, "Base", ModFlag.Dot, { type = "ActorCondition", actor = "player", var = "Combat" })
-- Add mods from the config tab
env.modDB:AddList(build.configTab.modList)
env.enemyDB:AddList(build.configTab.enemyModList)
-- Add mods from the party tab
env.enemyDB:AddList(build.partyTab.enemyModList)
cachedPlayerDB, cachedEnemyDB, cachedMinionDB = specCopy(env)
else
env.modDB.parent = cachedPlayerDB
env.enemyDB.parent = cachedEnemyDB
if cachedMinionDB and env.minion then
env.minion.modDB.parent = cachedMinionDB
end
end
if override.conditions then
for _, flag in ipairs(override.conditions) do
modDB.conditions[flag] = true
end
end
local allocatedNotableCount = env.spec.allocatedNotableCount
local allocatedMasteryCount = env.spec.allocatedMasteryCount
local allocatedMasteryTypeCount = env.spec.allocatedMasteryTypeCount
local allocatedMasteryTypes = copyTable(env.spec.allocatedMasteryTypes)
if not accelerate.nodeAlloc then
-- Build list of passive nodes
local nodes
if override.addNodes or override.removeNodes then
nodes = { }
if override.addNodes then
for node in pairs(override.addNodes) do
nodes[node.id] = node
if node.type == "Mastery" then
allocatedMasteryCount = allocatedMasteryCount + 1
if not allocatedMasteryTypes[node.name] then
allocatedMasteryTypes[node.name] = 1
allocatedMasteryTypeCount = allocatedMasteryTypeCount + 1
else
local prevCount = allocatedMasteryTypes[node.name]
allocatedMasteryTypes[node.name] = prevCount + 1
if prevCount == 0 then
allocatedMasteryTypeCount = allocatedMasteryTypeCount + 1
end
end
elseif node.type == "Notable" then
allocatedNotableCount = allocatedNotableCount + 1
end
end
end
for _, node in pairs(env.spec.allocNodes) do
if not override.removeNodes or not override.removeNodes[node] then
nodes[node.id] = node
elseif override.removeNodes[node] then
if node.type == "Mastery" then
allocatedMasteryCount = allocatedMasteryCount - 1
allocatedMasteryTypes[node.name] = allocatedMasteryTypes[node.name] - 1
if allocatedMasteryTypes[node.name] == 0 then
allocatedMasteryTypeCount = allocatedMasteryTypeCount - 1
end
elseif node.type == "Notable" then
allocatedNotableCount = allocatedNotableCount - 1
end
end
end
else
nodes = copyTable(env.spec.allocNodes, true)
end
env.allocNodes = nodes
end
local nodesModsList = calcs.buildModListForNodeList(env, env.allocNodes, true)
if allocatedNotableCount and allocatedNotableCount > 0 then
modDB:NewMod("Multiplier:AllocatedNotable", "BASE", allocatedNotableCount)
end
if allocatedMasteryCount and allocatedMasteryCount > 0 then
modDB:NewMod("Multiplier:AllocatedMastery", "BASE", allocatedMasteryCount)
end
if allocatedMasteryTypeCount and allocatedMasteryTypeCount > 0 then
modDB:NewMod("Multiplier:AllocatedMasteryType", "BASE", allocatedMasteryTypeCount)
end
if allocatedMasteryTypes["Life Mastery"] and allocatedMasteryTypes["Life Mastery"] > 0 then
modDB:NewMod("Multiplier:AllocatedLifeMastery", "BASE", allocatedMasteryTypes["Life Mastery"])
end
-- add Conditional WeaponSet# base on weapon set from item
modDB:NewMod("Condition:WeaponSet" .. (build.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1) , "FLAG", true, "Weapon Set")
-- Build and merge item modifiers, and create list of radius jewels
if not accelerate.requirementsItems then
local items = {}
local jewelLimits = {}
for _, slot in pairs(build.itemsTab.orderedSlots) do
local slotName = slot.slotName
local item
if slotName == override.repSlotName then
item = override.repItem
elseif override.repItem and override.repSlotName:match("^Weapon 1") and slotName:match("^Weapon 2") and
(override.repItem.base.type == "Staff" or override.repItem.base.type == "Two Handed Sword" or override.repItem.base.type == "Two Handed Axe" or override.repItem.base.type == "Two Handed Mace"
or (override.repItem.base.type == "Bow" and item and item.base.type ~= "Quiver")) then
goto continue
elseif slot.nodeId and override.spec then
item = build.itemsTab.items[env.spec.jewels[slot.nodeId]]
else
item = build.itemsTab.items[slot.selItemId]
end
if item and item.grantedSkills then
-- Find skills granted by this item
for _, skill in ipairs(item.grantedSkills) do
local skillData = env.data.skills[skill.skillId]
local grantedSkill = copyTable(skill)
grantedSkill.nameSpec = skillData and skillData.name or nil
grantedSkill.sourceItem = item
grantedSkill.slotName = slotName
t_insert(env.grantedSkillsItems, grantedSkill)
end
end
if item and item.baseModList and item.baseModList:Flag(nil, "CanExplode") then
t_insert(env.explodeSources, item)
end
if slot.weaponSet and slot.weaponSet ~= (build.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1) then
goto continue
end
if slot.weaponSet == 2 and build.itemsTab.activeItemSet.useSecondWeaponSet then
slotName = slotName:gsub(" Swap","")
end
if slot.nodeId then
-- Slot is a jewel socket, check if socket is allocated
if not env.allocNodes[slot.nodeId] then
goto continue
elseif item then
if item.jewelData then
item.jewelData.limitDisabled = nil
end
if item and item.type == "Jewel" and item.name:match("The Adorned, Diamond") then
env.modDB.multipliers["CorruptedMagicJewelEffect"] = item.jewelData.corruptedMagicJewelIncEffect / 100
end
if item.limit and not env.configInput.ignoreJewelLimits then
local limitKey = item.base.subType == "Timeless" and "Historic" or item.title
if jewelLimits[limitKey] and jewelLimits[limitKey] >= item.limit then
if item.jewelData then
item.jewelData.limitDisabled = true
end
env.itemWarnings.jewelLimitWarning = env.itemWarnings.jewelLimitWarning or { }
t_insert(env.itemWarnings.jewelLimitWarning, limitKey)
goto continue
else
jewelLimits[limitKey] = (jewelLimits[limitKey] or 0) + 1
end
end
if item and ( item.jewelRadiusIndex or (override and override.extraJewelFuncs and #override.extraJewelFuncs > 0) ) then
-- Jewel has a radius, add it to the list
local funcList = (item.jewelData and item.jewelData.funcList) or { { type = "Self", func = function(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 } }
for _, func in ipairs(funcList) do
local node = env.spec.nodes[slot.nodeId]
t_insert(env.radiusJewelList, {
nodes = node.nodesInRadius and node.nodesInRadius[item.jewelRadiusIndex] or { },
func = func.func,
type = func.type,
item = item,
nodeId = slot.nodeId,
attributes = node.attributesInRadius and node.attributesInRadius[item.jewelRadiusIndex] or { },
data = { }
})
if func.type ~= "Self" and node.nodesInRadius then
-- Add nearby unallocated nodes to the extra node list
for nodeId, node in pairs(node.nodesInRadius[item.jewelRadiusIndex]) do
if not env.allocNodes[nodeId] then
env.extraRadiusNodeList[nodeId] = env.spec.nodes[nodeId]
end
end
end
end
for _, funcData in ipairs(override and override.extraJewelFuncs and override.extraJewelFuncs:List({item = item}, "ExtraJewelFunc") or {}) do
local node = env.spec.nodes[slot.nodeId]
local radius
for index, data in pairs(data.jewelRadius) do
if funcData.radius == data.label then
radius = index
break
end
end
t_insert(env.radiusJewelList, {
nodes = node.nodesInRadius and node.nodesInRadius[radius] or { },
func = funcData.func,
type = funcData.type,
item = item,
nodeId = slot.nodeId,
attributes = node.attributesInRadius and node.attributesInRadius[radius] or { },
data = { }
})
if funcData.type ~= "Self" and node.nodesInRadius then
-- Add nearby unallocated nodes to the extra node list
for nodeId, node in pairs(node.nodesInRadius[radius]) do
if not env.allocNodes[nodeId] then
env.extraRadiusNodeList[nodeId] = env.spec.nodes[nodeId]
end
end
end
end
end
end
end
items[slotName] = item
::continue::
end
if not env.configInput.ignoreItemDisablers then
local itemDisabled = {}
local itemDisablers = {}
if modDB:Flag(nil, "CanNotUseHelm") then
itemDisabled["Helmet"] = { disabled = true, size = 1 }
end
for _, slot in pairs(build.itemsTab.orderedSlots) do
local slotName = slot.slotName
if items[slotName] then
local srcList = items[slotName].modList or items[slotName].slotModList[slot.slotNum]
for _, mod in ipairs(srcList) do
-- checks if it disables another slot
for _, tag in ipairs(mod) do
if tag.type == "DisablesItem" then
-- e.g. Tincture in Flask 5 while using a Micro-Distillery Belt
if tag.excludeItemType and items[tag.slotName] and items[tag.slotName].type == tag.excludeItemType then
break
end
itemDisablers[slotName] = tag.slotName
itemDisabled[tag.slotName] = slotName
break
end
end
end
end
end
local visited = {}
local trueDisabled = {}
for slot in pairs(itemDisablers) do
if not visited[slot] then
-- find chain start
local curChain = { slot = true }
while itemDisabled[slot] do
slot = itemDisabled[slot]
if curChain[slot] then break end -- detect cycles
curChain[slot] = true
end
-- step through the chain of disabled items, disabling every other one
repeat
visited[slot] = true
slot = itemDisablers[slot]
if not slot then break end
visited[slot] = true
trueDisabled[slot] = true
slot = itemDisablers[slot]
until(not slot or visited[slot])
end
end
for slot in pairs(trueDisabled) do
items[slot] = nil
end
end
for _, slot in pairs(build.itemsTab.orderedSlots) do
local slotName = slot.slotName
local item = items[slotName]
if item and item.type == "Flask" then
if slot.active then
env.flasks[item] = true
end
if item.base.subType == "Life" then
local highestLifeRecovery = env.itemModDB.multipliers["LifeFlaskRecovery"] or 0
if item.flaskData.lifeTotal > highestLifeRecovery then
env.itemModDB.multipliers["LifeFlaskRecovery"] = item.flaskData.lifeTotal
end
end
item = nil
elseif item and item.type == "Charm" then
if slot.active then
env.charms[item] = true
end
item = nil
end
local scale = 1