-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathCalcOffence.lua
5557 lines (5372 loc) · 307 KB
/
CalcOffence.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 Offence
-- Performs offence calculations.
--
local calcs = ...
local pairs = pairs
local ipairs = ipairs
local unpack = unpack
local t_insert = table.insert
local t_remove = table.remove
local m_abs = math.abs
local m_floor = math.floor
local m_ceil = math.ceil
local m_min = math.min
local m_max = math.max
local m_sqrt = math.sqrt
local m_pow = math.pow
local m_huge = math.huge
local bor = bit.bor
local band = bit.band
local bnot = bit.bnot
local s_format = string.format
local tempTable1 = { }
local tempTable2 = { }
local tempTable3 = { }
local isElemental = { Fire = true, Cold = true, Lightning = true }
-- List of all damage types, ordered according to the conversion sequence
local dmgTypeList = {"Physical", "Lightning", "Cold", "Fire", "Chaos"}
local dmgTypeFlags = {
Physical = 0x01,
Lightning = 0x02,
Cold = 0x04,
Fire = 0x08,
Elemental = 0x0E,
Chaos = 0x10,
}
-- List of all ailments
local ailmentTypeList = data.ailmentTypeList
-- List of elemental ailments
local elementalAilmentTypeList = data.elementalAilmentTypeList
-- Magic table for caching the modifier name sets used in calcDamage()
local damageStatsForTypes = setmetatable({ }, { __index = function(t, k)
local modNames = { "Damage" }
for type, flag in pairs(dmgTypeFlags) do
if band(k, flag) ~= 0 then
t_insert(modNames, type.."Damage")
end
end
t[k] = modNames
return modNames
end })
local globalOutput = nil
local globalBreakdown = nil
-- Calculate min/max damage for the given damage type
local function calcDamage(activeSkill, output, cfg, breakdown, damageType, typeFlags, convDst)
local skillModList = activeSkill.skillModList
typeFlags = bor(typeFlags, dmgTypeFlags[damageType])
-- Calculate conversions
local addMin, addMax = 0, 0
local conversionTable = activeSkill.conversionTable
for _, otherType in ipairs(dmgTypeList) do
if otherType == damageType then
-- Damage can only be converted from damage types that precede this one in the conversion sequence, so stop here
break
end
local convMult = conversionTable[otherType][damageType]
if convMult > 0 then
-- Damage is being converted/gained from the other damage type
local min, max = calcDamage(activeSkill, output, cfg, breakdown, otherType, typeFlags, damageType)
addMin = addMin + min * convMult
addMax = addMax + max * convMult
end
end
if addMin ~= 0 and addMax ~= 0 then
addMin = round(addMin)
addMax = round(addMax)
end
local baseMin = output[damageType.."MinBase"]
local baseMax = output[damageType.."MaxBase"]
if baseMin == 0 and baseMax == 0 then
-- No base damage for this type, don't need to calculate modifiers
if breakdown and (addMin ~= 0 or addMax ~= 0) then
t_insert(breakdown.damageTypes, {
source = damageType,
convSrc = (addMin ~= 0 or addMax ~= 0) and (addMin .. " to " .. addMax),
total = addMin .. " to " .. addMax,
convDst = convDst and s_format("%d%% to %s", conversionTable[damageType][convDst] * 100, convDst),
})
end
return addMin, addMax
end
-- Combine modifiers
local modNames = damageStatsForTypes[typeFlags]
local inc = 1 + skillModList:Sum("INC", cfg, unpack(modNames)) / 100
local more = skillModList:More(cfg, unpack(modNames))
local genericMoreMinDamage = skillModList:More(cfg, "MinDamage")
local genericMoreMaxDamage = skillModList:More(cfg, "MaxDamage")
local moreMinDamage = skillModList:More(cfg, "Min"..damageType.."Damage")
local moreMaxDamage = skillModList:More(cfg, "Max"..damageType.."Damage")
if breakdown then
t_insert(breakdown.damageTypes, {
source = damageType,
base = baseMin .. " to " .. baseMax,
inc = (inc ~= 1 and "x "..inc),
more = (more ~= 1 and "x "..more),
convSrc = (addMin ~= 0 or addMax ~= 0) and (addMin .. " to " .. addMax),
total = (round(baseMin * inc * more) + addMin) .. " to " .. (round(baseMax * inc * more) + addMax),
convDst = convDst and conversionTable[damageType][convDst] > 0 and s_format("%d%% to %s", conversionTable[damageType][convDst] * 100, convDst),
})
end
return round(((baseMin * inc * more) * genericMoreMinDamage + addMin) * moreMinDamage),
round(((baseMax * inc * more) * genericMoreMaxDamage + addMax) * moreMaxDamage)
end
local function calcAilmentSourceDamage(activeSkill, output, cfg, breakdown, damageType, typeFlags)
local min, max = calcDamage(activeSkill, output, cfg, breakdown, damageType, typeFlags)
local convMult = activeSkill.conversionTable[damageType].mult
if breakdown and convMult ~= 1 then
t_insert(breakdown, "Source damage:")
t_insert(breakdown, s_format("%d to %d ^8(total damage)", min, max))
t_insert(breakdown, s_format("x %g ^8(%g%% converted to other damage types)", convMult, (1-convMult)*100))
t_insert(breakdown, s_format("= %d to %d", min * convMult, max * convMult))
end
return min * convMult, max * convMult
end
---Calculates skill radius
---@param baseRadius number
---@param areaMod number
---@return number
local function calcRadius(baseRadius, areaMod)
return m_floor(baseRadius * m_floor(100 * m_sqrt(areaMod)) / 100)
end
---Calculates the tertiary radius for Molten Strike, correctly handling the deadzone.
---@param baseRadius number
---@param deadzoneRadius number
---@param areaMod number
---@param speedMod number
local function calcMoltenStrikeTertiaryRadius(baseRadius, deadzoneRadius, areaMod, speedMod)
-- For now, we assume that PoE only rounds at the end.
local maxDistIgnoringSpeed = m_sqrt(baseRadius * baseRadius * areaMod - deadzoneRadius * deadzoneRadius * (areaMod - 1))
local maxDist = m_floor((maxDistIgnoringSpeed - deadzoneRadius) * speedMod + deadzoneRadius)
return maxDist
end
---Calculates modifiers needed to reach the next and previous radius breakpoints
---@param baseRadius number
---@param incArea number @Additive modifier
---@param moreArea number @Multiplicative modifier
---@return number, number, number, number @Next breakpoint: increased, more; Previous breakpoint: reduced, less
local function calcRadiusBreakpoints(baseRadius, incArea, moreArea)
local radius = calcRadius(baseRadius, round(round(incArea * moreArea, 10), 2))
local incAreaBreakpoint, redAreaBreakpoint, moreAreaBreakpoint, lessAreaBreakpoint
if radius > 0 then
incAreaBreakpoint = 0
repeat
incAreaBreakpoint = incAreaBreakpoint + 1
local newRadius = calcRadius(baseRadius, round(round((incArea + incAreaBreakpoint / 100) * moreArea, 10), 2))
until (newRadius > radius)
redAreaBreakpoint = 0
repeat
redAreaBreakpoint = redAreaBreakpoint + 1
local newRadius = calcRadius(baseRadius, round(round((incArea - redAreaBreakpoint / 100) * moreArea, 10), 2))
until (newRadius < radius)
moreAreaBreakpoint = 0
repeat
moreAreaBreakpoint = moreAreaBreakpoint + 1
local newRadius = calcRadius(baseRadius, round(round(incArea * moreArea * (1 + moreAreaBreakpoint / 100), 10), 2))
until (newRadius > radius)
lessAreaBreakpoint = 0
repeat
lessAreaBreakpoint = lessAreaBreakpoint + 1
local newRadius = calcRadius(baseRadius, round(round(incArea * moreArea * (1 - lessAreaBreakpoint / 100), 10), 2))
until (newRadius < radius)
end
return incAreaBreakpoint, moreAreaBreakpoint, redAreaBreakpoint, lessAreaBreakpoint
end
---Computes and sets the breakdown for Molten Strike's tertiary radius.
---@param breakdown table
---@param deadzoneRadius number min ball landing distance (cannot be changed by any mods)
---@param baseRadius number default max landing distance with no aoe or proj. speed modifiers
---@param label string top level label to use for the breakdown
---@param incArea number current net increased area modifier
---@param moreArea number current product of all "more" and "less" area modifiers
---@param incSpd number current net increased projectile speed modifier
---@param moreSpd number current product of all "more" and "less" projectile speed modifiers
local function setMoltenStrikeTertiaryRadiusBreakdown(breakdown, deadzoneRadius, baseRadius, label, incArea, moreArea, incSpd, moreSpd)
-- nil -> 1 (no multiplier)
incArea = incArea or 1
moreArea = moreArea or 1
incSpd = incSpd or 1
moreSpd = moreSpd or 1
---Helper that calculates the tertiary radius with incremental modifiers to the 4 relevant pools.
---This helps declutter the code below.
local function calc(extraIncAoePct, extraMoreAoePct, extraIncSpdPct, extraMoreSpdPct)
local areaMod = round(round((incArea + extraIncAoePct / 100) * moreArea * (1 + extraMoreAoePct / 100), 10), 2)
local speedMod = round(round((incSpd + extraIncSpdPct / 100) * moreSpd * (1 + extraMoreSpdPct / 100), 10), 2)
local dist = calcMoltenStrikeTertiaryRadius(baseRadius, deadzoneRadius, areaMod, speedMod)
return dist, areaMod, speedMod
end
-- Current settings.
local currentDist, currentAreaMod, currentSpeedMod = calc(0, 0, 0, 0)
-- Create the detailed breakdown. This includes:
-- * the complete formula as an algebraic expression (ignoring rounding),
-- * the final value,
-- * breakpoints on the 4 modifier pools (increased vs. more crossed with aoe and projectile speed), and
-- * the input variables for the algebraic expression.
local breakdownRadius = breakdown.AreaOfEffectRadiusTertiary or { }
breakdown.AreaOfEffectRadiusTertiary = breakdownRadius
t_insert(breakdownRadius, label)
t_insert(breakdownRadius, " = (sqrt(R*R*a - r*r*(a-1)) - r) * s + r")
t_insert(breakdownRadius, s_format(" = %d", currentDist))
if currentDist > 0 then
---Helper for finding one tertiary radius breakpoint value. This is a little slower than what
---we do in the generic calcRadiusBreakpoints, but this approach requires a lot less code and
---should be more maintainable given that we need to search for 8 different breakpoints.
---@param sign number +1 (for increased and more breakpoints) or -1 (for reduced and less breakpoints)
---@param argIdx number which argument to the calc function we're modifying
local function findBreakpoint(sign, argIdx)
local args = {0, 0, 0, 0} -- starter args for the calc function
repeat
args[argIdx] = args[argIdx] + sign -- increment or decrement the desired arg
local newDist, _, _ = calc(unpack(args))
until (newDist ~= currentDist) or (newDist == 0) -- stop once we've hit a new radius breakpoint
return args[argIdx] * sign -- remove the sign since we want all positive numbers
end
t_insert(breakdownRadius, s_format("^8Next AoE breakpoint: %d%% increased or %d%% more", findBreakpoint(1, 1), findBreakpoint(1, 2)))
t_insert(breakdownRadius, s_format("^8Next Proj. Speed breakpoint: %d%% increased or %d%% more", findBreakpoint(1, 3), findBreakpoint(1, 4)))
t_insert(breakdownRadius, s_format("^8Previous AoE breakpoint: %d%% increased or %d%% more", findBreakpoint(-1, 1), findBreakpoint(-1, 2)))
t_insert(breakdownRadius, s_format("^8Previous Proj. Speed breakpoint: %d%% increased or %d%% more", findBreakpoint(-1, 3), findBreakpoint(-1, 4)))
end
-- This is the input variable table.
breakdownRadius.label = "Inputs"
breakdownRadius.rowList = { }
breakdownRadius.colList = {
{ label = "Variable", key = "name" },
{ label = "Value", key = "value"},
{ label = "Description", key = "description" }
}
t_insert(breakdownRadius.rowList, { name = "r", value = s_format("%d", deadzoneRadius), description = "fixed deadzone radius" })
t_insert(breakdownRadius.rowList, { name = "R", value = s_format("%d", baseRadius), description = "base outer radius" })
t_insert(breakdownRadius.rowList, { name = "a", value = s_format("%.2f", currentAreaMod), description = "net AoE multiplier (scales area)" })
t_insert(breakdownRadius.rowList, { name = "s", value = s_format("%.2f", currentSpeedMod), description = "net projectile speed multiplier (scales range)" })
-- Trigger the inclusion of the radius display.
breakdownRadius.radius = currentDist
end
function calcSkillCooldown(skillModList, skillCfg, skillData)
local cooldownOverride = skillModList:Override(skillCfg, "CooldownRecovery")
local addedCooldown = skillModList:Sum("BASE", skillCfg, "CooldownRecovery")
local cooldown = cooldownOverride or ((skillData.cooldown or 0) + addedCooldown) / m_max(0, calcLib.mod(skillModList, skillCfg, "CooldownRecovery"))
-- If a skill can store extra uses and has a cooldown, it doesn't round the cooldown value to server ticks
local rounded = false
if (skillData.storedUses and skillData.storedUses > 1) or (skillData.VaalStoredUses and skillData.VaalStoredUses > 1) or skillModList:Sum("BASE", skillCfg, "AdditionalCooldownUses") > 0 then
return cooldown, rounded
else
cooldown = m_ceil(cooldown * data.misc.ServerTickRate) / data.misc.ServerTickRate
rounded = true
return cooldown, rounded, addedCooldown
end
end
local function calcWarcryCastTime(skillModList, skillCfg, skillData, actor)
local baseSpeed = 1 / skillModList:Sum("BASE", skillCfg, "WarcryCastTime")
local warcryCastTime = baseSpeed * calcLib.mod(skillModList, skillCfg, "WarcrySpeed") * calcs.actionSpeedMod(actor)
warcryCastTime = m_min(warcryCastTime, data.misc.ServerTickRate)
warcryCastTime = 1 / warcryCastTime
if skillModList:Flag(skillCfg, "InstantWarcry") or skillData.SupportedByAutoexertion then
warcryCastTime = 0
end
return warcryCastTime
end
function calcSkillDuration(skillModList, skillCfg, skillData, env, enemyDB)
local durationMod = calcLib.mod(skillModList, skillCfg, "Duration", "PrimaryDuration", "SkillAndDamagingAilmentDuration", skillData.mineDurationAppliesToSkill and "MineDuration" or nil)
durationMod = m_max(durationMod, 0)
local durationBase = (skillData.duration or 0) + skillModList:Sum("BASE", skillCfg, "Duration", "PrimaryDuration")
local duration = durationBase * durationMod
local debuffDurationMult = 1
if env.mode_effective then
debuffDurationMult = 1 / m_max(data.misc.BuffExpirationSlowCap, calcLib.mod(enemyDB, skillCfg, "BuffExpireFaster"))
end
if skillData.debuff then
duration = duration * debuffDurationMult
end
return duration
end
-- Performs all offensive calculations
function calcs.offence(env, actor, activeSkill)
local modDB = actor.modDB
local enemyDB = actor.enemy.modDB
local output = actor.output
local breakdown = actor.breakdown
local skillModList = activeSkill.skillModList
local skillData = activeSkill.skillData
local skillFlags = activeSkill.skillFlags
local skillCfg = activeSkill.skillCfg
if skillData.showAverage then
skillFlags.showAverage = true
else
skillFlags.notAverage = true
end
if skillFlags.disable then
-- Skill is disabled
output.CombinedDPS = 0
return
end
local function calcAreaOfEffect(skillModList, skillCfg, skillData, skillFlags, output, breakdown)
local incArea, moreArea = calcLib.mods(skillModList, skillCfg, "AreaOfEffect", "AreaOfEffectPrimary")
output.AreaOfEffectMod = round(round(incArea * moreArea, 10), 2)
if skillData.radiusIsWeaponRange then
local range = 0
if skillFlags.weapon1Attack then
range = m_max(range, actor.weaponRange1)
end
if skillFlags.weapon2Attack then
range = m_max(range, actor.weaponRange2)
end
skillData.radius = range + 2
end
if skillData.radius then
skillFlags.area = true
local baseRadius = skillData.radius + (skillData.radiusExtra or 0) + skillModList:Sum("BASE", skillCfg, "AreaOfEffect")
output.AreaOfEffectRadius = calcRadius(baseRadius, output.AreaOfEffectMod)
output.AreaOfEffectRadiusMetres = output.AreaOfEffectRadius / 10
if breakdown then
local incAreaBreakpoint, moreAreaBreakpoint, redAreaBreakpoint, lessAreaBreakpoint = calcRadiusBreakpoints(baseRadius, incArea, moreArea)
breakdown.AreaOfEffectRadius = breakdown.area(baseRadius, output.AreaOfEffectMod, output.AreaOfEffectRadius, incAreaBreakpoint, moreAreaBreakpoint, redAreaBreakpoint, lessAreaBreakpoint, skillData.radiusLabel)
end
if skillData.radiusSecondary then
local incAreaSecondary, moreAreaSecondary = calcLib.mods(skillModList, skillCfg, "AreaOfEffect", "AreaOfEffectSecondary")
output.AreaOfEffectModSecondary = round(round(incAreaSecondary * moreAreaSecondary, 10), 2)
baseRadius = skillData.radiusSecondary + (skillData.radiusExtra or 0)
output.AreaOfEffectRadiusSecondary = calcRadius(baseRadius, output.AreaOfEffectModSecondary)
output.AreaOfEffectRadiusSecondaryMetres = output.AreaOfEffectRadiusSecondary / 10
if breakdown then
local incAreaBreakpointSecondary, moreAreaBreakpointSecondary, redAreaBreakpointSecondary, lessAreaBreakpointSecondary
if not skillData.projectileSpeedAppliesToMSAreaOfEffect then
incAreaBreakpointSecondary, moreAreaBreakpointSecondary, redAreaBreakpointSecondary, lessAreaBreakpointSecondary = calcRadiusBreakpoints(baseRadius, incAreaSecondary, moreAreaSecondary)
end
breakdown.AreaOfEffectRadiusSecondary = breakdown.area(baseRadius, output.AreaOfEffectModSecondary, output.AreaOfEffectRadiusSecondary, incAreaBreakpointSecondary, moreAreaBreakpointSecondary, redAreaBreakpointSecondary, lessAreaBreakpointSecondary, skillData.radiusSecondaryLabel)
end
end
if skillData.radiusTertiary then
local incAreaTertiary, moreAreaTertiary = calcLib.mods(skillModList, skillCfg, "AreaOfEffect", "AreaOfEffectTertiary")
output.AreaOfEffectModTertiary = round(round(incAreaTertiary * moreAreaTertiary, 10), 2)
baseRadius = skillData.radiusTertiary + (skillData.radiusExtra or 0)
if skillData.projectileSpeedAppliesToMSAreaOfEffect then
local incSpeedTertiary, moreSpeedTertiary = calcLib.mods(skillModList, skillCfg, "ProjectileSpeed")
output.SpeedModTertiary = round(round(incSpeedTertiary * moreSpeedTertiary, 10), 2)
output.AreaOfEffectRadiusTertiary = calcMoltenStrikeTertiaryRadius(baseRadius, skillData.radiusSecondary, output.AreaOfEffectModTertiary, output.SpeedModTertiary)
if breakdown then
setMoltenStrikeTertiaryRadiusBreakdown(
breakdown, skillData.radiusSecondary, baseRadius, skillData.radiusTertiaryLabel,
incAreaTertiary, moreAreaTertiary, incSpeedTertiary, moreSpeedTertiary
)
end
elseif skillData.radiusTertiaryBaseMargin then -- Currently only on explosive trap in the form of "Smaller explosions have between 30% reduced and 30% increased base radius at random"
local margin = skillData.radiusTertiaryBaseMargin / 100
local marginWidth = skillData.radiusTertiaryBaseMargin * 2 + 1
-- Calculate all the possible base radii
local baseRadiiOccurrences = {}
for deviation = 1 - margin, 1 + margin + 0.01, 0.01 do
local radiusForDeviation = math.floor(baseRadius * deviation)
baseRadiiOccurrences[radiusForDeviation] = (baseRadiiOccurrences[radiusForDeviation] or 0) + 1
end
-- Calculate the modified radius for each base radius
local sumOfRandomRadii = 0
local radiusForBaseRadius = {}
local radiiOccurrences = {}
for adjustedBaseRadius, occurrenceCount in pairs(baseRadiiOccurrences) do
local radiusForDeviation = calcRadius(adjustedBaseRadius, output.AreaOfEffectModTertiary)
radiusForBaseRadius[adjustedBaseRadius] = radiusForDeviation
sumOfRandomRadii = sumOfRandomRadii + radiusForDeviation * occurrenceCount
radiiOccurrences[radiusForDeviation] = (radiiOccurrences[radiusForDeviation] or 0) + occurrenceCount
end
output.AreaOfEffectRadiusTertiary = sumOfRandomRadii / marginWidth
output.AreaOfEffectRadiusTertiaryOccurrences = radiiOccurrences
if breakdown then
local out = {}
local incAreaBreakpointTertiary, moreAreaBreakpointTertiary, redAreaBreakpointTertiary, lessAreaBreakpointTertiary = math.huge, math.huge, math.huge, math.huge
t_insert(out, skillData.radiusTertiaryLabel)
t_insert(out, s_format("R ^8(base radius)^7 x %.2f ^8(square root of area of effect modifier)", m_floor(100 * m_sqrt(output.AreaOfEffectModTertiary)) / 100))
local baseRadii = {}
for adjustedBaseRadius in pairs(baseRadiiOccurrences) do
t_insert(baseRadii, adjustedBaseRadius)
end
table.sort(baseRadii, function(a,b) return a < b end)
for _, adjustedBaseRadius in ipairs(baseRadii) do
t_insert(out, s_format("%.1f%% ^8chance of^7 %.1fm ^8base radius resulting in^7 %.1fm ^8final radius", baseRadiiOccurrences[adjustedBaseRadius] / marginWidth * 100, adjustedBaseRadius / 10, radiusForBaseRadius[adjustedBaseRadius] / 10))
local incAreaBreakpointTertiaryIntermediate, moreAreaBreakpointTertiaryIntermediate, redAreaBreakpointTertiaryIntermediate, lessAreaBreakpointTertiaryIntermediate = calcRadiusBreakpoints(adjustedBaseRadius, incAreaTertiary, moreAreaTertiary)
incAreaBreakpointTertiary = math.min(incAreaBreakpointTertiary, incAreaBreakpointTertiaryIntermediate)
moreAreaBreakpointTertiary = math.min(moreAreaBreakpointTertiary, moreAreaBreakpointTertiaryIntermediate)
redAreaBreakpointTertiary = math.min(redAreaBreakpointTertiary, redAreaBreakpointTertiaryIntermediate)
lessAreaBreakpointTertiary = math.min(lessAreaBreakpointTertiary, lessAreaBreakpointTertiaryIntermediate)
end
t_insert(out, s_format("^8Next closest 0.1m breakpoint: %d%% increased AoE / a %d%% more AoE multiplier", incAreaBreakpointTertiary, moreAreaBreakpointTertiary))
t_insert(out, s_format("^8Previous closest 0.1m breakpoint: %d%% reduced AoE / a %d%% less AoE multiplier", redAreaBreakpointTertiary, lessAreaBreakpointTertiary))
t_insert(out, s_format("On average, the radius is %.2fm", output.AreaOfEffectRadiusTertiary / 10))
breakdown.AreaOfEffectRadiusTertiary = out
end
else
output.AreaOfEffectRadiusTertiary = calcRadius(baseRadius, output.AreaOfEffectModTertiary)
if breakdown then
local incAreaBreakpointTertiary, moreAreaBreakpointTertiary, redAreaBreakpointTertiary, lessAreaBreakpointTertiary = calcRadiusBreakpoints(baseRadius, incAreaTertiary, moreAreaTertiary)
breakdown.AreaOfEffectRadiusTertiary = breakdown.area(baseRadius, output.AreaOfEffectModTertiary, output.AreaOfEffectRadiusTertiary, incAreaBreakpointTertiary, moreAreaBreakpointTertiary, redAreaBreakpointTertiary, lessAreaBreakpointTertiary, skillData.radiusTertiaryLabel)
end
end
output.AreaOfEffectRadiusTertiaryMetres = output.AreaOfEffectRadiusTertiary / 10
end
end
if breakdown then
breakdown.AreaOfEffectMod = { }
if output.AreaOfEffectMod ~= 1 then
breakdown.multiChain(breakdown.AreaOfEffectMod, {
{ "%.2f ^8(increased/reduced)", 1 + skillModList:Sum("INC", skillCfg, "AreaOfEffect") / 100 },
{ "%.2f ^8(more/less)", skillModList:More(skillCfg, "AreaOfEffect") },
total = s_format("= %.2f", output.AreaOfEffectMod),
})
end
end
end
local function calcResistForType(damageType, cfg)
local resist = enemyDB:Override(cfg, damageType.."Resist")
local maxResist = enemyDB:Flag(nil, "DoNotChangeMaxResFromConfig") and data.misc.EnemyMaxResist or m_min(m_max(env.configInput["enemy"..damageType.."Resist"] or data.misc.EnemyMaxResist, data.misc.EnemyMaxResist), data.misc.MaxResistCap)
if not resist then
if env.modDB:Flag(nil, "Enemy"..damageType.."ResistEqualToYours") then
resist = env.player.output[damageType.."Resist"]
elseif env.partyMembers.modDB:Flag(nil, "Enemy"..damageType.."ResistEqualToYours") then
resist = env.partyMembers.output[damageType.."Resist"]
else
resist = enemyDB:Sum("BASE", cfg, damageType.."Resist", isElemental[damageType] and "ElementalResist" or nil) * m_max(calcLib.mod(enemyDB, cfg, damageType.."Resist", isElemental[damageType] and "ElementalResist" or nil), 0)
end
end
return m_max(m_min(resist, maxResist), data.misc.ResistFloor)
end
local function runSkillFunc(name)
local func = activeSkill.activeEffect.grantedEffect[name]
if func then
func(activeSkill, output, breakdown)
end
end
runSkillFunc("initialFunc")
skillCfg.skillCond["SkillIsTriggered"] = skillData.triggered
if skillCfg.skillCond["SkillIsTriggered"] then
skillFlags.triggered = true
end
skillCfg.skillCond["SkillIsFocused"] = skillData.chanceToTriggerOnFocus
if skillCfg.skillCond["SkillIsFocused"] then
skillFlags.focused = true
end
-- Update skill data
for _, value in ipairs(skillModList:List(skillCfg, "SkillData")) do
if value.merge == "MAX" then
skillData[value.key] = m_max(value.value, skillData[value.key] or 0)
else
skillData[value.key] = value.value
end
end
-- Add addition stat bonuses
if skillModList:Flag(nil, "IronGrip") then
skillModList:NewMod("PhysicalDamage", "INC", actor.strDmgBonus or 0, "Strength", bor(ModFlag.Attack, ModFlag.Projectile))
end
if skillModList:Flag(nil, "IronWill") then
skillModList:NewMod("Damage", "INC", actor.strDmgBonus or 0, "Strength", ModFlag.Spell)
end
if skillModList:Flag(nil, "TransfigurationOfBody") then
skillModList:NewMod("Damage", "INC", m_floor(skillModList:Sum("INC", nil, "Life") * data.misc.Transfiguration), "Transfiguration of Body", ModFlag.Attack)
end
if skillModList:Flag(nil, "TransfigurationOfMind") then
skillModList:NewMod("Damage", "INC", m_floor(skillModList:Sum("INC", nil, "Mana") * data.misc.Transfiguration), "Transfiguration of Mind")
end
if skillModList:Flag(nil, "TransfigurationOfSoul") then
skillModList:NewMod("Damage", "INC", m_floor(skillModList:Sum("INC", nil, "EnergyShield") * data.misc.Transfiguration), "Transfiguration of Soul", ModFlag.Spell)
end
if modDB:Flag(nil, "Elusive") and skillModList:Flag(nil, "SupportedByNightblade") then
local elusiveEffect = output.ElusiveEffectMod / 100
local nightbladeMulti = skillModList:Sum("BASE", nil, "NightbladeElusiveCritMultiplier")
skillModList:NewMod("CritMultiplier", "BASE", m_floor(nightbladeMulti * elusiveEffect), "Nightblade")
end
-- set other limits
output.ActiveTrapLimit = skillModList:Sum("BASE", skillCfg, "ActiveTrapLimit")
output.ActiveMineLimit = skillModList:Sum("BASE", skillCfg, "ActiveMineLimit")
-- set flask scaling
output.LifeFlaskRecovery = env.itemModDB.multipliers["LifeFlaskRecovery"]
if modDB.conditions["AffectedByEnergyBlade"] then
local dmgMod = calcLib.mod(skillModList, skillCfg, "EnergyBladeDamage")
local speedMod = calcLib.mod(skillModList, skillCfg, "EnergyBladeAttackSpeed")
for slotName, weaponData in pairs({ ["Weapon 1"] = "weaponData1", ["Weapon 2"] = "weaponData2" }) do
if actor.itemList[slotName] and actor.itemList[slotName].weaponData and actor.itemList[slotName].weaponData[1] and actor[weaponData].name and data.itemBases[actor[weaponData].name] then
local weaponBaseData = data.itemBases[actor[weaponData].name].weapon
actor[weaponData].CritChance = weaponBaseData.CritChanceBase
actor[weaponData].AttackRate = weaponBaseData.AttackRateBase * speedMod
actor[weaponData].Range = weaponBaseData.Range
for _, damageType in ipairs(dmgTypeList) do
actor[weaponData][damageType.."Min"] = (weaponBaseData[damageType.."Min"] or 0) + m_floor(skillModList:Sum("BASE", skillCfg, "EnergyBladeMin"..damageType) * dmgMod)
actor[weaponData][damageType.."Max"] = (weaponBaseData[damageType.."Max"] or 0) + m_floor(skillModList:Sum("BASE", skillCfg, "EnergyBladeMax"..damageType) * dmgMod)
end
end
end
end
-- account for Battlemage
-- Note: we check conditions of Main Hand weapon using actor.itemList as actor.weaponData1 is populated with unarmed values when no weapon slotted.
if skillModList:Flag(nil, "Battlemage") and actor.itemList["Weapon 1"] and actor.itemList["Weapon 1"].weaponData and actor.itemList["Weapon 1"].weaponData[1] then
local multiplier = (skillModList:Max(skillCfg, "MainHandWeaponDamageAppliesToSpells") or 100) / 100
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", m_floor((actor.weaponData1[damageType.."Min"] or 0) * multiplier), "Battlemage", ModFlag.Spell)
skillModList:NewMod(damageType.."Max", "BASE", m_floor((actor.weaponData1[damageType.."Max"] or 0) * multiplier), "Battlemage", ModFlag.Spell)
end
end
local weapon1info = env.data.weaponTypeInfo[actor.weaponData1.type]
local weapon2info = env.data.weaponTypeInfo[actor.weaponData2.type]
-- -- account for Spellblade
-- Note: we check conditions of Main Hand weapon using actor.itemList as actor.weaponData1 is populated with unarmed values when no weapon slotted.
local spellbladeMulti = skillModList:Max(skillCfg, "OneHandWeaponDamageAppliesToSpells")
if spellbladeMulti and actor.itemList["Weapon 1"] and actor.itemList["Weapon 1"].weaponData and actor.itemList["Weapon 1"].weaponData[1] and weapon1info.melee and weapon1info.oneHand then
local multiplier = spellbladeMulti / 100 * (weapon2info and 0.6 or 1)
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", m_floor((actor.weaponData1[damageType.."Min"] or 0) * multiplier), "Spellblade Main Hand", ModFlag.Spell)
skillModList:NewMod(damageType.."Max", "BASE", m_floor((actor.weaponData1[damageType.."Max"] or 0) * multiplier), "Spellblade Main Hand", ModFlag.Spell)
end
if weapon2info then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", m_floor((actor.weaponData2[damageType.."Min"] or 0) * multiplier), "Spellblade Off Hand", ModFlag.Spell)
skillModList:NewMod(damageType.."Max", "BASE", m_floor((actor.weaponData2[damageType.."Max"] or 0) * multiplier), "Spellblade Off Hand", ModFlag.Spell)
end
end
end
if skillModList:Flag(nil, "MinionDamageAppliesToPlayer") or skillModList:Flag(skillCfg, "MinionDamageAppliesToPlayer") then
-- Minion Damage conversion from Spiritual Aid and The Scourge
local multiplier = (skillModList:Max(skillCfg, "ImprovedMinionDamageAppliesToPlayer") or 100) / 100
for _, value in ipairs(skillModList:List(skillCfg, "MinionModifier")) do
if value.mod.name == "Damage" and value.mod.type == "INC" then
local mod = value.mod
local modifiers = calcLib.getConvertedModTags(mod, multiplier, true)
skillModList:NewMod("Damage", "INC", mod.value * multiplier, mod.source, mod.flags, mod.keywordFlags, unpack(modifiers))
end
end
end
if skillModList:Flag(nil, "MinionAttackSpeedAppliesToPlayer") then
-- Minion Damage conversion from Spiritual Command
local multiplier = (skillModList:Max(skillCfg, "ImprovedMinionAttackSpeedAppliesToPlayer") or 100) / 100
-- Minion Attack Speed conversion from Spiritual Command
for _, value in ipairs(skillModList:List(skillCfg, "MinionModifier")) do
if value.mod.name == "Speed" and value.mod.type == "INC" and (value.mod.flags == 0 or band(value.mod.flags, ModFlag.Attack) ~= 0) then
local modifiers = calcLib.getConvertedModTags(value.mod, multiplier, true)
skillModList:NewMod("Speed", "INC", value.mod.value * multiplier, value.mod.source, ModFlag.Attack, value.mod.keywordFlags, unpack(modifiers))
end
end
end
if skillModList:Flag(nil, "SpellDamageAppliesToAttacks") then
-- Spell Damage conversion from Crown of Eyes, Kinetic Bolt, and the Wandslinger notable
local multiplier = (skillModList:Max(skillCfg, "ImprovedSpellDamageAppliesToAttacks") or 100) / 100
for i, value in ipairs(skillModList:Tabulate("INC", { flags = ModFlag.Spell }, "Damage")) do
local mod = value.mod
if band(mod.flags, ModFlag.Spell) ~= 0 then
local modifiers = calcLib.getConvertedModTags(mod, multiplier)
skillModList:NewMod("Damage", "INC", mod.value * multiplier, mod.source, bor(band(mod.flags, bnot(ModFlag.Spell)), ModFlag.Attack), mod.keywordFlags, unpack(modifiers))
if mod.source == "Strength" then -- Prevent double-dipping from converted strength's damage bonus
skillModList:ReplaceMod("PhysicalDamage", "INC", 0, "Strength", ModFlag.Melee)
end
end
end
end
if skillModList:Flag(nil, "CastSpeedAppliesToAttacks") then
-- Get all increases for this; assumption is that multiple sources would not stack, so find the max
local multiplier = (skillModList:Max(skillCfg, "ImprovedCastSpeedAppliesToAttacks") or 100) / 100
for i, value in ipairs(skillModList:Tabulate("INC", { flags = ModFlag.Cast }, "Speed")) do
local mod = value.mod
-- Add a new mod for all mods that are cast only
-- Replace this with a single mod for the sum?
if band(mod.flags, ModFlag.Cast) ~= 0 then
local modifiers = calcLib.getConvertedModTags(mod, multiplier)
skillModList:NewMod("Speed", "INC", mod.value * multiplier, mod.source, bor(band(mod.flags, bnot(ModFlag.Cast)), ModFlag.Attack), mod.keywordFlags, unpack(modifiers))
end
end
end
if skillModList:Flag(nil, "ProjectileSpeedAppliesToBowDamage") then
-- Bow mastery projectile speed to damage with bows conversion
for i, value in ipairs(skillModList:Tabulate("INC", { }, "ProjectileSpeed")) do
local mod = value.mod
skillModList:NewMod("Damage", mod.type, mod.value, mod.source, bor(ModFlag.Bow, ModFlag.Hit), mod.keywordFlags, unpack(mod))
end
end
if skillModList:Flag(nil, "ClawDamageAppliesToUnarmed") then
-- Claw Damage conversion from Rigwald's Curse
for i, value in ipairs(skillModList:Tabulate("INC", { flags = bor(ModFlag.Claw, ModFlag.Hit), keywordFlags = KeywordFlag.Hit }, "Damage")) do
local mod = value.mod
if band(mod.flags, ModFlag.Claw) ~= 0 then
skillModList:NewMod("Damage", mod.type, mod.value, mod.source, bor(band(mod.flags, bnot(ModFlag.Claw)), ModFlag.Unarmed, ModFlag.Melee), mod.keywordFlags, unpack(mod))
end
end
end
if skillModList:Flag(nil, "ClawAttackSpeedAppliesToUnarmed") then
-- Claw Attack Speed conversion from Rigwald's Curse
for i, value in ipairs(skillModList:Tabulate("INC", { flags = bor(ModFlag.Claw, ModFlag.Attack, ModFlag.Hit) }, "Speed")) do
local mod = value.mod
if band(mod.flags, ModFlag.Claw) ~= 0 and band(mod.flags, ModFlag.Attack) ~= 0 then
skillModList:NewMod("Speed", mod.type, mod.value, mod.source, bor(band(mod.flags, bnot(ModFlag.Claw)), ModFlag.Unarmed), mod.keywordFlags, unpack(mod))
end
end
end
if skillModList:Flag(nil, "ClawCritChanceAppliesToUnarmed") then
-- Claw Crit Chance conversion from Rigwald's Curse
for i, value in ipairs(skillModList:Tabulate("INC", { flags = bor(ModFlag.Claw, ModFlag.Hit) }, "CritChance")) do
local mod = value.mod
if band(mod.flags, ModFlag.Claw) ~= 0 then
skillModList:NewMod("CritChance", mod.type, mod.value, mod.source, bor(band(mod.flags, bnot(ModFlag.Claw)), ModFlag.Unarmed), mod.keywordFlags, unpack(mod))
end
end
end
if skillModList:Flag(nil, "ClawCritChanceAppliesToMinions") then
-- Claw Crit Chance conversion from Law of the Wilds
for i, value in ipairs(skillModList:Tabulate("INC", { flags = bor(ModFlag.Claw, ModFlag.Hit) }, "CritChance")) do
local mod = value.mod
if band(mod.flags, ModFlag.Claw) ~= 0 then
env.minion.modDB:NewMod("CritChance", mod.type, mod.value, mod.source)
end
end
end
if skillModList:Flag(nil, "ClawCritMultiplierAppliesToMinions") then
-- Claw Crit Multi conversion from Law of the Wilds
for i, value in ipairs(skillModList:Tabulate("BASE", { flags = bor(ModFlag.Claw, ModFlag.Hit) }, "CritMultiplier")) do
local mod = value.mod
if band(mod.flags, ModFlag.Claw) ~= 0 then
env.minion.modDB:NewMod("CritMultiplier", mod.type, mod.value, mod.source)
end
end
end
if skillModList:Flag(nil, "CritChanceIncreasedByUncappedLightningRes") then
for i, value in ipairs(modDB:Tabulate("FLAG", nil, "CritChanceIncreasedByUncappedLightningRes")) do
local mod = value.mod
skillModList:NewMod("CritChance", "INC", output.LightningResistTotal, mod.source)
break
end
end
if skillModList:Flag(nil, "CritChanceIncreasedByLightningRes") then
for i, value in ipairs(modDB:Tabulate("FLAG", nil, "CritChanceIncreasedByLightningRes")) do
local mod = value.mod
skillModList:NewMod("CritChance", "INC", output.LightningResist, mod.source)
break
end
end
if skillModList:Flag(nil, "CritChanceIncreasedByOvercappedLightningRes") then
for i, value in ipairs(modDB:Tabulate("FLAG", nil, "CritChanceIncreasedByOvercappedLightningRes")) do
local mod = value.mod
skillModList:NewMod("CritChance", "INC", output.LightningResistOverCap, mod.source)
break
end
end
if skillModList:Flag(nil, "CritChanceIncreasedBySpellSuppressChance") then
for i, value in ipairs(modDB:Tabulate("FLAG", nil, "CritChanceIncreasedBySpellSuppressChance")) do
local mod = value.mod
skillModList:NewMod("CritChance", "INC", output.SpellSuppressionChance, mod.source)
break
end
end
if skillModList:Flag(nil, "LightRadiusAppliesToAccuracy") then
-- Light Radius conversion from Corona Solaris
for i, value in ipairs(skillModList:Tabulate("INC", { }, "LightRadius")) do
local mod = value.mod
skillModList:NewMod("Accuracy", "INC", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
if skillModList:Flag(nil, "LightRadiusAppliesToAreaOfEffect") then
-- Light Radius conversion from Wreath of Phrecia
for i, value in ipairs(skillModList:Tabulate("INC", { }, "LightRadius")) do
local mod = value.mod
skillModList:NewMod("AreaOfEffect", "INC", math.floor(mod.value / 2), mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
if skillModList:Flag(nil, "LightRadiusAppliesToDamage") then
-- Light Radius conversion from Wreath of Phrecia
for i, value in ipairs(skillModList:Tabulate("INC", { }, "LightRadius")) do
local mod = value.mod
skillModList:NewMod("Damage", "INC", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
if skillModList:Flag(nil, "CastSpeedAppliesToTrapThrowingSpeed") then
-- Cast Speed conversion from Slavedriver's Hand
for i, value in ipairs(skillModList:Tabulate("INC", { flags = ModFlag.Cast }, "Speed")) do
local mod = value.mod
if (mod.flags == 0 or band(mod.flags, ModFlag.Cast) ~= 0) then
skillModList:NewMod("TrapThrowingSpeed", "INC", mod.value, mod.source, band(mod.flags, bnot(ModFlag.Cast), bnot(ModFlag.Attack)), mod.keywordFlags, unpack(mod))
end
end
end
if skillData.arrowSpeedAppliesToAreaOfEffect then
-- Arrow Speed conversion for Galvanic Arrow
for i, value in ipairs(skillModList:Tabulate("INC", { flags = ModFlag.Bow }, "ProjectileSpeed")) do
local mod = value.mod
skillModList:NewMod("AreaOfEffect", "INC", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
if skillModList:Flag(nil, "SequentialProjectiles") and not skillModList:Flag(nil, "OneShotProj") and not skillModList:Flag(nil,"NoAdditionalProjectiles") and not skillModList:Flag(nil, "TriggeredBySnipe") then
-- Applies DPS multiplier based on projectile count
skillData.dpsMultiplier = skillModList:Sum("BASE", skillCfg, "ProjectileCount")
end
output.Repeats = 1 + (skillModList:Sum("BASE", skillCfg, "RepeatCount") or 0)
if output.Repeats > 1 then
output.RepeatCount = output.Repeats
-- handle all the multipliers from Repeats
if env.configInput.repeatMode ~= "NONE" then
for i, value in ipairs(skillModList:Tabulate("INC", skillCfg, "RepeatFinalAreaOfEffect")) do
local mod = value.mod
local modValue = mod.value
if env.configInput.repeatMode == "AVERAGE" then
modValue = modValue / output.Repeats
end
skillModList:NewMod("AreaOfEffect", "INC", modValue, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
for i, value in ipairs(skillModList:Tabulate("INC", skillCfg, "RepeatPerRepeatAreaOfEffect")) do
local mod = value.mod
local modValue = mod.value * (output.Repeats - 1)
if env.configInput.repeatMode == "AVERAGE" then
modValue = modValue / 2
end
skillModList:NewMod("AreaOfEffect", "INC", modValue, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
for i, value in ipairs(skillModList:Tabulate("BASE", skillCfg, "RepeatFinalDoubleDamageChance")) do
local mod = value.mod
local modValue = mod.value
if env.configInput.repeatMode == "AVERAGE" then
modValue = modValue / output.Repeats
end
skillModList:NewMod("DoubleDamageChance", "BASE", modValue, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
local DamageFinalMoreValueTotal = 1
local DamageMoreValueTotal = 0
for i, value in ipairs(skillModList:Tabulate("MORE", skillCfg, "RepeatFinalDamage")) do
local mod = value.mod
local modValue = mod.value
DamageFinalMoreValueTotal = DamageFinalMoreValueTotal * (1 + modValue / 100)
DamageMoreValueTotal = DamageMoreValueTotal + modValue
if env.configInput.repeatMode == "AVERAGE" and not skillModList:Flag(nil, "OnlyFinalRepeat") then
modValue = modValue / output.Repeats
end
skillModList:NewMod("Damage", "MORE", modValue, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
for i, value in ipairs(skillModList:Tabulate("MORE", skillCfg, "RepeatPerRepeatDamage")) do
local mod = value.mod
local modValue = mod.value * (output.Repeats - 1)
if env.configInput.repeatMode == "AVERAGE" then
if DamageFinalMoreValueTotal ~= 1 then
-- sum from 0 to num Repeats the damage each one does, multiplied by the other repeat multipliers,
-- divide the total by the average other repeat multipliers and divide by number of repeats
-- eg greater echo with 20Q div echo is (100 + 130 + 160 + 190*1.6)/1.15/4 - 100 = 50.87% more damage
modValue = ((100 + mod.value * (output.Repeats - 2) / 2) * (output.Repeats - 1) + (100 + mod.value * (output.Repeats - 1)) * DamageFinalMoreValueTotal) / (output.Repeats + DamageMoreValueTotal / 100) - 100
else
modValue = modValue / 2
end
end
skillModList:NewMod("Damage", "MORE", modValue, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
local lastMod = nil
DamageFinalMoreValueTotal = DamageMoreValueTotal
for _, repeatCount in ipairs({{2, "One"}, {3, "Two"}, {4, "Three"}}) do
if repeatCount[1] > output.Repeats then
break
elseif env.configInput.repeatMode == "AVERAGE" then
for i, value in ipairs(skillModList:Tabulate("MORE", skillCfg, "Repeat"..repeatCount[2].."Damage")) do
DamageMoreValueTotal = DamageMoreValueTotal + value.mod.value
lastMod = value.mod
end
elseif repeatCount[1] == output.Repeats then
for i, value in ipairs(skillModList:Tabulate("MORE", skillCfg, "Repeat"..repeatCount[2].."Damage")) do
skillModList:NewMod("Damage", "MORE", value.mod.value, value.mod.source, value.mod.flags, value.mod.keywordFlags, unpack(value.mod))
end
end
end
if env.configInput.repeatMode == "AVERAGE" then
if lastMod then
skillModList:NewMod("Damage", "MORE", (DamageMoreValueTotal / output.Repeats + 100) / (1 + DamageFinalMoreValueTotal / output.Repeats / 100) - 100, lastMod.source, lastMod.flags, lastMod.keywordFlags, unpack(lastMod))
end
end
if skillModList:Flag(nil, "FinalRepeatSumsDamage") then
for i, value in ipairs(skillModList:Tabulate("FLAG", skillCfg, "FinalRepeatSumsDamage")) do
skillModList:NewMod("Damage", "MORE", (100 * output.Repeats + DamageFinalMoreValueTotal) / (1 + DamageFinalMoreValueTotal / 100) - 100, value.mod.source, value.mod.flags, value.mod.keywordFlags, unpack(value.mod))
end
end
end
end
if skillData.gainPercentBaseWandDamage then
local mult = skillData.gainPercentBaseWandDamage / 100
if actor.weaponData1.type == "Wand" and actor.weaponData2.type == "Wand" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", ((actor.weaponData1[damageType.."Min"] or 0) + (actor.weaponData2[damageType.."Min"] or 0)) / 2 * mult, "Spellslinger")
skillModList:NewMod(damageType.."Max", "BASE", ((actor.weaponData1[damageType.."Max"] or 0) + (actor.weaponData2[damageType.."Max"] or 0)) / 2 * mult, "Spellslinger")
end
elseif actor.weaponData1.type == "Wand" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", (actor.weaponData1[damageType.."Min"] or 0) * mult, "Spellslinger")
skillModList:NewMod(damageType.."Max", "BASE", (actor.weaponData1[damageType.."Max"] or 0) * mult, "Spellslinger")
end
elseif actor.weaponData2.type == "Wand" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", (actor.weaponData2[damageType.."Min"] or 0) * mult, "Spellslinger")
skillModList:NewMod(damageType.."Max", "BASE", (actor.weaponData2[damageType.."Max"] or 0) * mult, "Spellslinger")
end
end
end
if skillData.gainPercentBaseDaggerDamage then
local mult = skillData.gainPercentBaseDaggerDamage / 100
if actor.weaponData1.type == "Dagger" and actor.weaponData2.type == "Dagger" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", ((actor.weaponData1[damageType.."Min"] or 0) + (actor.weaponData2[damageType.."Min"] or 0)) / 2 * mult, "Blade Blast of Dagger Detonation")
skillModList:NewMod(damageType.."Max", "BASE", ((actor.weaponData1[damageType.."Max"] or 0) + (actor.weaponData2[damageType.."Max"] or 0)) / 2 * mult, "Blade Blast of Dagger Detonation")
end
elseif actor.weaponData1.type == "Dagger" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", (actor.weaponData1[damageType.."Min"] or 0) * mult, "Blade Blast of Dagger Detonation")
skillModList:NewMod(damageType.."Max", "BASE", (actor.weaponData1[damageType.."Max"] or 0) * mult, "Blade Blast of Dagger Detonation")
end
elseif actor.weaponData2.type == "Dagger" then
for _, damageType in ipairs(dmgTypeList) do
skillModList:NewMod(damageType.."Min", "BASE", (actor.weaponData2[damageType.."Min"] or 0) * mult, "Blade Blast of Dagger Detonation")
skillModList:NewMod(damageType.."Max", "BASE", (actor.weaponData2[damageType.."Max"] or 0) * mult, "Blade Blast of Dagger Detonation")
end
end
end
if skillModList:Flag(nil, "HasSeals") and activeSkill.skillTypes[SkillType.CanRapidFire] and not skillModList:Flag(nil, "NoRepeatBonuses") then
-- Applies DPS multiplier based on seals count
output.SealCooldown = skillModList:Sum("BASE", skillCfg, "SealGainFrequency") / calcLib.mod(skillModList, skillCfg, "SealGainFrequency")
output.SealMax = skillModList:Sum("BASE", skillCfg, "SealCount")
output.AverageBurstHits = output.SealMax
output.TimeMaxSeals = output.SealCooldown * output.SealMax
if not skillData.hitTimeOverride then
if skillModList:Flag(nil, "UseMaxUnleash") then
for i, value in ipairs(skillModList:Tabulate("INC", { }, "MaxSealCrit")) do
local mod = value.mod
skillModList:NewMod("CritChance", "INC", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
env.player.mainSkill.skillData.dpsMultiplier = (1 + output.SealMax * calcLib.mod(skillModList, skillCfg, "SealRepeatPenalty"))
env.player.mainSkill.skillData.hitTimeOverride = m_max(output.TimeMaxSeals, (1 / activeSkill.activeEffect.grantedEffect.castTime * 1.1 * calcLib.mod(skillModList, skillCfg, "Speed") * output.ActionSpeedMod))
else
env.player.mainSkill.skillData.dpsMultiplier = 1 + 1 / output.SealCooldown / (1 / activeSkill.activeEffect.grantedEffect.castTime * 1.1 * calcLib.mod(skillModList, skillCfg, "Speed") * output.ActionSpeedMod) * calcLib.mod(skillModList, skillCfg, "SealRepeatPenalty")
end
end
if breakdown then
breakdown.SealGainTime = { }
breakdown.multiChain(breakdown.SealGainTime, {
label = "Gain frequency:",
base = { "%.2fs ^8(base gain frequency)", skillModList:Sum("BASE", skillCfg, "SealGainFrequency") },
{ "%.2f ^8(increased/reduced gain frequency)", 1 + skillModList:Sum("INC", skillCfg, "SealGainFrequency") / 100 },
{ "%.2f ^8(action speed modifier)", output.ActionSpeedMod },
total = s_format("= %.2fs ^8per Seal", output.SealCooldown),
})
end
end
if skillModList:Sum("BASE", skillCfg, "PhysicalDamageGainAsRandom", "PhysicalDamageConvertToRandom", "PhysicalDamageGainAsColdOrLightning") > 0 then
skillFlags.randomPhys = true
local physMode = env.configInput.physMode or "AVERAGE"
for i, value in ipairs(skillModList:Tabulate("BASE", skillCfg, "PhysicalDamageGainAsRandom")) do
local mod = value.mod
local effVal = mod.value / 3
if physMode == "AVERAGE" then
skillModList:NewMod("PhysicalDamageGainAsFire", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
skillModList:NewMod("PhysicalDamageGainAsCold", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
skillModList:NewMod("PhysicalDamageGainAsLightning", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "FIRE" then
skillModList:NewMod("PhysicalDamageGainAsFire", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "COLD" then
skillModList:NewMod("PhysicalDamageGainAsCold", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "LIGHTNING" then
skillModList:NewMod("PhysicalDamageGainAsLightning", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
for i, value in ipairs(skillModList:Tabulate("BASE", skillCfg, "PhysicalDamageConvertToRandom")) do
local mod = value.mod
local effVal = mod.value / 3
if physMode == "AVERAGE" then
skillModList:NewMod("PhysicalDamageConvertToFire", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
skillModList:NewMod("PhysicalDamageConvertToCold", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
skillModList:NewMod("PhysicalDamageConvertToLightning", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "FIRE" then
skillModList:NewMod("PhysicalDamageConvertToFire", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "COLD" then
skillModList:NewMod("PhysicalDamageConvertToCold", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "LIGHTNING" then
skillModList:NewMod("PhysicalDamageConvertToLightning", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
for i, value in ipairs(skillModList:Tabulate("BASE", skillCfg, "PhysicalDamageGainAsColdOrLightning")) do
local mod = value.mod
local effVal = mod.value / 2
if physMode == "AVERAGE" or physMode == "FIRE" then
skillModList:NewMod("PhysicalDamageGainAsCold", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
skillModList:NewMod("PhysicalDamageGainAsLightning", "BASE", effVal, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "COLD" then
skillModList:NewMod("PhysicalDamageGainAsCold", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
elseif physMode == "LIGHTNING" then
skillModList:NewMod("PhysicalDamageGainAsLightning", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
end
end
end
-- momentum stacks
if skillModList:Flag(nil, "SupportedByMomentum") then
local maxMomentumStacks = skillModList:Sum("BASE", skillCfg, "MomentumStacksMax")
local extraMomentumStacks = skillModList:Sum("BASE", skillCfg, "MomentumStacksExtra")
if maxMomentumStacks > 0 then
if not modDB:HasMod("BASE", nil, "Multiplier:MomentumStacks") then
modDB:NewMod("Multiplier:MomentumStacks", "BASE", m_min((maxMomentumStacks + extraMomentumStacks) / 2, maxMomentumStacks), "Config", { type = "Condition", var = "Combat" })
elseif modDB:Sum("BASE", nil, "Multiplier:MomentumStacks") > maxMomentumStacks then
modDB:ReplaceMod("Multiplier:MomentumStacks", "BASE", maxMomentumStacks, "Config", { type = "Condition", var = "Combat" })
end
elseif modDB:HasMod("BASE", nil, "Multiplier:MomentumStacks") then
modDB:ReplaceMod("Multiplier:MomentumStacks", "BASE", 0, "Config")
end
end
local isAttack = skillFlags.attack
runSkillFunc("preSkillTypeFunc")
-- Calculate skill type stats
if skillFlags.minion then
if activeSkill.minion and activeSkill.minion.minionData.limit then
output.ActiveMinionLimit = m_floor(env.modDB:Override(nil, activeSkill.minion.minionData.limit) or calcLib.val(skillModList, activeSkill.minion.minionData.limit, skillCfg))
end
output.SummonedMinionsPerCast = m_floor(calcLib.val(skillModList, "MinionPerCastCount", skillCfg))
if output.SummonedMinionsPerCast == 0 then
output.SummonedMinionsPerCast = 1
end
end
if skillFlags.chaining then
if skillModList:Flag(skillCfg, "CannotChain") or skillModList:Flag(skillCfg, "NoAdditionalChains")then
output.ChainMaxString = "Cannot chain"
else
output.ChainMax = skillModList:Sum("BASE", skillCfg, "ChainCountMax", not skillFlags.projectile and "BeamChainCountMax" or nil)
if skillModList:Flag(skillCfg, "AdditionalProjectilesAddChainsInstead") then
output.ChainMax = output.ChainMax + m_floor((skillModList:Sum("BASE", skillCfg, "ProjectileCount") - 1) * skillModList:More(skillCfg, "ProjectileCount"))
end
output.ChainMaxString = output.ChainMax
output.Chain = m_min(output.ChainMax, skillModList:Sum("BASE", skillCfg, "ChainCount"))
output.ChainRemaining = m_max(0, output.ChainMax - output.Chain)
end
end
if skillFlags.projectile then
if skillModList:Flag(nil, "PointBlank") then
skillModList:NewMod("Damage", "MORE", 30, "Point Blank", bor(ModFlag.Attack, ModFlag.Projectile), { type = "DistanceRamp", ramp = {{10,1},{35,0},{120,-1}} })
end
if skillModList:Flag(nil, "FarShot") then
skillModList:NewMod("Damage", "MORE", 100, "Far Shot", bor(ModFlag.Attack, ModFlag.Projectile), { type = "DistanceRamp", ramp = {{10, -0.2}, {25, 0}, {70, 0.6}} })
end
if skillModList:Flag(skillCfg, "NoAdditionalProjectiles") then
output.ProjectileCount = 1
else
local projBase = skillModList:Sum("BASE", skillCfg, "ProjectileCount")
local projMore = skillModList:More(skillCfg, "ProjectileCount")
output.ProjectileCount = m_floor(projBase * projMore)
end
if skillModList:Flag(skillCfg, "AdditionalProjectilesAddBouncesInstead") then
local projBase = skillModList:Sum("BASE", skillCfg, "ProjectileCount") + skillModList:Sum("BASE", skillCfg, "BounceCount") - 1
local projMore = skillModList:More(skillCfg, "ProjectileCount")
output.BounceCount = m_floor(projBase * projMore)
end
if skillModList:Flag(skillCfg, "CannotSplit") or activeSkill.skillTypes[SkillType.ProjectileNumber] then
if breakdown then
local SplitCount = skillModList:Sum("BASE", skillCfg, "SplitCount") + enemyDB:Sum("BASE", skillCfg, "SelfSplitCount")
if SplitCount > 0 then
output.SplitCountString = "Cannot split"