-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathCalcDefence.lua
2259 lines (2178 loc) · 107 KB
/
CalcDefence.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 Defence
-- Performs defence calculations.
--
local calcs = ...
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local m_min = math.min
local m_max = math.max
local m_floor = math.floor
local m_huge = math.huge
local s_format = string.format
local tempTable1 = { }
local isElemental = { Fire = true, Cold = true, Lightning = true }
-- List of all damage types, ordered according to the conversion sequence
local hitSourceList = {"Attack", "Spell"}
local dmgTypeList = {"Physical", "Lightning", "Cold", "Fire", "Chaos"}
local resistTypeList = { "Fire", "Cold", "Lightning", "Chaos" }
-- Calculate hit chance
function calcs.hitChance(evasion, accuracy)
if accuracy < 0 then
return 5
end
local rawChance = accuracy / (accuracy + (evasion / 5) ^ 0.9) * 125
return m_max(m_min(round(rawChance), 100), 5)
end
-- Calculate damage reduction from armour, float
function calcs.armourReductionF(armour, raw)
if armour == 0 and raw == 0 then
return 0
end
return (armour / (armour + raw * 5) * 100)
end
-- Calculate damage reduction from armour, int
function calcs.armourReduction(armour, raw)
return round(calcs.armourReductionF(armour, raw))
end
-- Performs all defensive calculations
function calcs.defence(env, actor)
local modDB = actor.modDB
local enemyDB = actor.enemy.modDB
local output = actor.output
local breakdown = actor.breakdown
local condList = modDB.conditions
-- Action Speed
output.ActionSpeedMod = calcs.actionSpeedMod(actor)
-- Resistances
output.DamageReductionMax = modDB:Override(nil, "DamageReductionMax") or data.misc.DamageReductionCap
output.BasePhysicalDamageReduction = m_min(m_max(0, modDB:Sum("BASE", nil, "PhysicalDamageReduction")), output.DamageReductionMax)
output.BasePhysicalDamageReductionWhenHit = m_min(m_max(0, output.BasePhysicalDamageReduction + modDB:Sum("BASE", nil, "PhysicalDamageReductionWhenHit")), output.DamageReductionMax)
modDB:NewMod("ArmourAppliesToPhysicalDamageTaken", "BASE", 100)
output["PhysicalResist"] = 0
-- Highest Maximum Elemental Resistance for Melding of the Flesh
if modDB:Flag(nil, "ElementalResistMaxIsHighestResistMax") then
local highestResistMax = 0;
local highestResistMaxType = "";
for _, elem in ipairs(resistTypeList) do
local resistMax = modDB:Override(nil, elem.."ResistMax") or m_min(data.misc.MaxResistCap, modDB:Sum("BASE", nil, elem.."ResistMax", isElemental[elem] and "ElementalResistMax"))
if resistMax > highestResistMax and isElemental[elem] then
highestResistMax = resistMax;
highestResistMaxType = elem;
end
end
for _, elem in ipairs(resistTypeList) do
if isElemental[elem] then
modDB:NewMod(elem.."ResistMax", "OVERRIDE", highestResistMax, highestResistMaxType.." Melding of the Flesh");
end
end
end
for _, elem in ipairs(resistTypeList) do
local min, max, total
min = data.misc.ResistFloor
max = modDB:Override(nil, elem.."ResistMax") or m_min(data.misc.MaxResistCap, modDB:Sum("BASE", nil, elem.."ResistMax", isElemental[elem] and "ElementalResistMax"))
totemMax = modDB:Override(nil, "Totem"..elem.."ResistMax") or m_min(data.misc.MaxResistCap, modDB:Sum("BASE", nil, "Totem"..elem.."ResistMax", isElemental[elem] and "TotemElementalResistMax"))
total = modDB:Override(nil, elem.."Resist")
totemTotal = modDB:Override(nil, "Totem"..elem.."Resist")
if not total then
local base = modDB:Sum("BASE", nil, elem.."Resist", isElemental[elem] and "ElementalResist")
total = base * calcLib.mod(modDB, nil, elem.."Resist", isElemental[elem] and "ElementalResist")
end
if not totemTotal then
local base = modDB:Sum("BASE", nil, "Totem"..elem.."Resist", isElemental[elem] and "TotemElementalResist")
totemTotal = base * calcLib.mod(modDB, nil, "Totem"..elem.."Resist", isElemental[elem] and "TotemElementalResist")
end
local final = m_max(m_min(total, max), min)
local totemFinal = m_max(m_min(totemTotal, totemMax), min)
output["Base"..elem.."DamageReduction"] = 0
output[elem.."Resist"] = final
output[elem.."ResistTotal"] = total
output[elem.."ResistOverCap"] = m_max(0, total - max)
output[elem.."ResistOver75"] = m_max(0, final - 75)
output["Missing"..elem.."Resist"] = m_max(0, totemMax - final)
output["Totem"..elem.."Resist"] = totemFinal
output["Totem"..elem.."ResistTotal"] = totemTotal
output["Totem"..elem.."ResistOverCap"] = m_max(0, totemTotal - totemMax)
output["MissingTotem"..elem.."Resist"] = m_max(0, totemMax - totemFinal)
if breakdown then
breakdown[elem.."Resist"] = {
"Min: "..min.."%",
"Max: "..max.."%",
"Total: "..total.."%",
}
breakdown["Totem"..elem.."Resist"] = {
"Min: "..min.."%",
"Max: "..totemMax.."%",
"Total: "..totemTotal.."%",
}
end
end
-- Block
output.BlockChanceMax = modDB:Sum("BASE", nil, "BlockChanceMax")
output.BlockChanceOverCap = 0
output.SpellBlockChanceOverCap = 0
local baseBlockChance = 0
if actor.itemList["Weapon 2"] and actor.itemList["Weapon 2"].armourData then
baseBlockChance = baseBlockChance + actor.itemList["Weapon 2"].armourData.BlockChance
end
if actor.itemList["Weapon 3"] and actor.itemList["Weapon 3"].armourData then
baseBlockChance = baseBlockChance + actor.itemList["Weapon 3"].armourData.BlockChance
end
output.ShieldBlockChance = baseBlockChance
if modDB:Flag(nil, "MaxBlockIfNotBlockedRecently") then
output.BlockChance = output.BlockChanceMax
else
local totalBlockChance = (baseBlockChance + modDB:Sum("BASE", nil, "BlockChance")) * calcLib.mod(modDB, nil, "BlockChance")
output.BlockChance = m_min(totalBlockChance, output.BlockChanceMax)
output.BlockChanceOverCap = m_max(0, totalBlockChance - output.BlockChanceMax)
end
output.ProjectileBlockChance = m_min(output.BlockChance + modDB:Sum("BASE", nil, "ProjectileBlockChance") * calcLib.mod(modDB, nil, "BlockChance"), output.BlockChanceMax)
if modDB:Flag(nil, "SpellBlockChanceMaxIsBlockChanceMax") then
output.SpellBlockChanceMax = output.BlockChanceMax
else
output.SpellBlockChanceMax = modDB:Sum("BASE", nil, "SpellBlockChanceMax")
end
if modDB:Flag(nil, "SpellBlockChanceIsBlockChance") then
output.SpellBlockChance = output.BlockChance
output.SpellProjectileBlockChance = output.ProjectileBlockChance
output.SpellBlockChanceOverCap = output.BlockChanceOverCap
else
local totalSpellBlockChance = modDB:Sum("BASE", nil, "SpellBlockChance") * calcLib.mod(modDB, nil, "SpellBlockChance")
output.SpellBlockChance = m_min(totalSpellBlockChance, output.SpellBlockChanceMax)
output.SpellBlockChanceOverCap = m_max(0, totalSpellBlockChance - output.SpellBlockChanceMax)
output.SpellProjectileBlockChance = output.SpellBlockChance
end
if breakdown then
breakdown.BlockChance = {
"Base: "..baseBlockChance.."%",
"Max: "..output.BlockChanceMax.."%",
"Total: "..output.BlockChance+output.BlockChanceOverCap.."%",
}
breakdown.SpellBlockChance = {
"Max: "..output.SpellBlockChanceMax.."%",
"Total: "..output.SpellBlockChance+output.SpellBlockChanceOverCap.."%",
}
end
if modDB:Flag(nil, "CannotBlockAttacks") then
output.BlockChance = 0
output.ProjectileBlockChance = 0
end
if modDB:Flag(nil, "CannotBlockSpells") then
output.SpellBlockChance = 0
output.SpellProjectileBlockChance = 0
end
output.AverageBlockChance = (output.BlockChance + output.ProjectileBlockChance + output.SpellBlockChance + output.SpellProjectileBlockChance) / 4
output.BlockEffect = m_max(100 - modDB:Sum("BASE", nil, "BlockEffect"), 0)
if output.BlockEffect == 0 then
output.BlockEffect = 100
else
output.ShowBlockEffect = true
output.DamageTakenOnBlock = 100 - output.BlockEffect
end
if modDB:Flag(nil, "ArmourAppliesToEnergyShieldRecharge") then
-- Armour to ES Recharge conversion from Armour and Energy Shield Mastery
local multiplier = (modDB:Max(nil, "ImprovedArmourAppliesToEnergyShieldRecharge") or 100) / 100
for _, value in ipairs(modDB:Tabulate("INC", nil, "Armour", "ArmourAndEvasion", "Defences")) do
local mod = value.mod
local modifiers = calcLib.getConvertedModTags(mod, multiplier)
modDB:NewMod("EnergyShieldRecharge", "INC", m_floor(mod.value * multiplier), mod.source, mod.flags, mod.keywordFlags, unpack(modifiers))
end
end
-- Primary defences: Energy shield, evasion and armour
do
local ironReflexes = modDB:Flag(nil, "IronReflexes")
local ward = 0
local energyShield = 0
local armour = 0
local evasion = 0
if breakdown then
breakdown.Ward = { slots = { } }
breakdown.EnergyShield = { slots = { } }
breakdown.Armour = { slots = { } }
breakdown.Evasion = { slots = { } }
end
local energyShieldBase, armourBase, evasionBase, wardBase
local gearWard = 0
local gearEnergyShield = 0
local gearArmour = 0
local gearEvasion = 0
local slotCfg = wipeTable(tempTable1)
for _, slot in pairs({"Helmet","Body Armour","Gloves","Boots","Weapon 2","Weapon 3"}) do
local armourData = actor.itemList[slot] and actor.itemList[slot].armourData
if armourData then
slotCfg.slotName = slot
wardBase = armourData.Ward or 0
if wardBase > 0 then
output["WardOn"..slot] = wardBase
if modDB:Flag(nil, "EnergyShieldToWard") then
local inc = modDB:Sum("INC", slotCfg, "Ward", "Defences", "EnergyShield")
local more = modDB:More(slotCfg, "Ward", "Defences")
ward = ward + wardBase * (1 + inc / 100) * more
gearWard = gearWard + wardBase
if breakdown then
t_insert(breakdown["Ward"].slots, {
base = wardBase,
inc = (inc ~= 0) and s_format(" x %.2f", 1 + inc/100),
more = (more ~= 1) and s_format(" x %.2f", more),
total = s_format("%.2f", wardBase * (1 + inc / 100) * more),
source = slot,
item = actor.itemList[slot],
})
end
else
ward = ward + wardBase * calcLib.mod(modDB, slotCfg, "Ward", "Defences")
gearWard = gearWard + wardBase
if breakdown then
breakdown.slot(slot, nil, slotCfg, wardBase, nil, "Ward", "Defences")
end
end
end
energyShieldBase = armourData.EnergyShield or 0
if energyShieldBase > 0 then
output["EnergyShieldOn"..slot] = energyShieldBase
if modDB:Flag(nil, "EnergyShieldToWard") then
local more = modDB:More(slotCfg, "EnergyShield", "Defences")
energyShield = energyShield + energyShieldBase * more
gearEnergyShield = gearEnergyShield + energyShieldBase
if breakdown then
t_insert(breakdown["EnergyShield"].slots, {
base = energyShieldBase,
more = (more ~= 1) and s_format(" x %.2f", more),
total = s_format("%.2f", energyShieldBase * more),
source = slot,
item = actor.itemList[slot],
})
end
else
energyShield = energyShield + energyShieldBase * calcLib.mod(modDB, slotCfg, "EnergyShield", "Defences")
gearEnergyShield = gearEnergyShield + energyShieldBase
if breakdown then
breakdown.slot(slot, nil, slotCfg, energyShieldBase, nil, "EnergyShield", "Defences")
end
end
end
armourBase = armourData.Armour or 0
if armourBase > 0 then
output["ArmourOn"..slot] = armourBase
if slot == "Body Armour" and modDB:Flag(nil, "Unbreakable") then
armourBase = armourBase * 2
end
armour = armour + armourBase * calcLib.mod(modDB, slotCfg, "Armour", "ArmourAndEvasion", "Defences")
gearArmour = gearArmour + armourBase
if breakdown then
breakdown.slot(slot, nil, slotCfg, armourBase, nil, "Armour", "ArmourAndEvasion", "Defences")
end
end
evasionBase = armourData.Evasion or 0
if evasionBase > 0 then
output["EvasionOn"..slot] = evasionBase
gearEvasion = gearEvasion + evasionBase
if breakdown then
breakdown.slot(slot, nil, slotCfg, evasionBase, nil, "Evasion", "ArmourAndEvasion", "Defences")
end
if ironReflexes then
armour = armour + evasionBase * calcLib.mod(modDB, slotCfg, "Armour", "Evasion", "ArmourAndEvasion", "Defences")
else
evasion = evasion + evasionBase * calcLib.mod(modDB, slotCfg, "Evasion", "ArmourAndEvasion", "Defences")
end
end
end
end
wardBase = modDB:Sum("BASE", nil, "Ward")
if wardBase > 0 then
if modDB:Flag(nil, "EnergyShieldToWard") then
local inc = modDB:Sum("INC", slotCfg, "Ward", "Defences", "EnergyShield")
local more = modDB:More(slotCfg, "Ward", "Defences")
ward = ward + wardBase * (1 + inc / 100) * more
if breakdown then
t_insert(breakdown["Ward"].slots, {
base = wardBase,
inc = (inc ~= 0) and s_format(" x %.2f", 1 + inc/100),
more = (more ~= 1) and s_format(" x %.2f", more),
total = s_format("%.2f", wardBase * (1 + inc / 100) * more),
source = "Global",
item = actor.itemList["Global"],
})
end
else
ward = ward + wardBase * calcLib.mod(modDB, nil, "Ward", "Defences")
if breakdown then
breakdown.slot("Global", nil, nil, wardBase, nil, "Ward", "Defences")
end
end
end
energyShieldBase = modDB:Sum("BASE", nil, "EnergyShield")
if energyShieldBase > 0 then
if modDB:Flag(nil, "EnergyShieldToWard") then
energyShield = energyShield + energyShieldBase * modDB:More(slotCfg, "EnergyShield", "Defences")
else
energyShield = energyShield + energyShieldBase * calcLib.mod(modDB, nil, "EnergyShield", "Defences")
end
if breakdown then
local inc = modDB:Sum("INC", slotCfg, "Defences", "EnergyShield")
local more = modDB:More(slotCfg, "EnergyShield", "Defences")
t_insert(breakdown["EnergyShield"].slots, {
base = energyShieldBase,
inc = (inc ~= 0) and s_format(" x %.2f", 1 + inc/100),
more = (more ~= 1) and s_format(" x %.2f", more),
total = s_format("%.2f", energyShieldBase * (1 + inc / 100) * more),
source = "Global",
item = actor.itemList["Global"],
})
end
end
armourBase = modDB:Sum("BASE", nil, "Armour", "ArmourAndEvasion")
if armourBase > 0 then
armour = armour + armourBase * calcLib.mod(modDB, nil, "Armour", "ArmourAndEvasion", "Defences")
if breakdown then
breakdown.slot("Global", nil, nil, armourBase, nil, "Armour", "ArmourAndEvasion", "Defences")
end
end
evasionBase = modDB:Sum("BASE", nil, "Evasion", "ArmourAndEvasion")
if evasionBase > 0 then
if ironReflexes then
armour = armour + evasionBase * calcLib.mod(modDB, nil, "Armour", "Evasion", "ArmourAndEvasion", "Defences")
if breakdown then
breakdown.slot("Conversion", "Evasion to Armour", nil, evasionBase, nil, "Armour", "Evasion", "ArmourAndEvasion", "Defences")
end
else
evasion = evasion + evasionBase * calcLib.mod(modDB, nil, "Evasion", "ArmourAndEvasion", "Defences")
if breakdown then
breakdown.slot("Global", nil, nil, evasionBase, nil, "Evasion", "ArmourAndEvasion", "Defences")
end
end
end
local convManaToArmour = modDB:Sum("BASE", nil, "ManaConvertToArmour")
if convManaToArmour > 0 then
armourBase = 2 * modDB:Sum("BASE", nil, "Mana") * convManaToArmour / 100
local total = armourBase * calcLib.mod(modDB, nil, "Mana", "Armour", "ArmourAndEvasion", "Defences")
armour = armour + total
if breakdown then
breakdown.slot("Conversion", "Mana to Armour", nil, armourBase, total, "Armour", "ArmourAndEvasion", "Defences", "Mana")
end
end
local convManaToES = modDB:Sum("BASE", nil, "ManaGainAsEnergyShield")
if convManaToES > 0 then
energyShieldBase = modDB:Sum("BASE", nil, "Mana") * convManaToES / 100
energyShield = energyShield + energyShieldBase * calcLib.mod(modDB, nil, "Mana", "EnergyShield", "Defences")
if breakdown then
breakdown.slot("Conversion", "Mana to Energy Shield", nil, energyShieldBase, nil, "EnergyShield", "Defences", "Mana")
end
end
local convLifeToArmour = modDB:Sum("BASE", nil, "LifeGainAsArmour")
if convLifeToArmour > 0 then
armourBase = modDB:Sum("BASE", nil, "Life") * convLifeToArmour / 100
local total
if modDB:Flag(nil, "ChaosInoculation") then
total = 1
else
total = armourBase * calcLib.mod(modDB, nil, "Life", "Armour", "ArmourAndEvasion", "Defences")
end
armour = armour + total
if breakdown then
breakdown.slot("Conversion", "Life to Armour", nil, armourBase, total, "Armour", "ArmourAndEvasion", "Defences", "Life")
end
end
local convLifeToES = modDB:Sum("BASE", nil, "LifeConvertToEnergyShield", "LifeGainAsEnergyShield")
if convLifeToES > 0 then
energyShieldBase = modDB:Sum("BASE", nil, "Life") * convLifeToES / 100
local total
if modDB:Flag(nil, "ChaosInoculation") then
total = 1
else
total = energyShieldBase * calcLib.mod(modDB, nil, "Life", "EnergyShield", "Defences")
end
energyShield = energyShield + total
if breakdown then
breakdown.slot("Conversion", "Life to Energy Shield", nil, energyShieldBase, total, "EnergyShield", "Defences", "Life")
end
end
local convEvasionToArmour = modDB:Sum("BASE", nil, "EvasionGainAsArmour")
if convEvasionToArmour > 0 then
armourBase = (modDB:Sum("BASE", nil, "Evasion", "ArmourAndEvasion") + gearEvasion) * convEvasionToArmour / 100
local total = armourBase * calcLib.mod(modDB, nil, "Evasion", "Armour", "ArmourAndEvasion", "Defences")
armour = armour + total
if breakdown then
breakdown.slot("Conversion", "Evasion to Armour", nil, armourBase, total, "Armour", "ArmourAndEvasion", "Defences", "Evasion")
end
end
output.EnergyShield = modDB:Override(nil, "EnergyShield") or m_max(round(energyShield), 0)
output.Armour = m_max(round(armour), 0)
output.ArmourDefense = (modDB:Max(nil, "ArmourDefense") or 0) / 100
output.RawArmourDefense = output.ArmourDefense > 0 and ((1 + output.ArmourDefense) * 100) or nil
output.Evasion = m_max(round(evasion), 0)
output.MeleeEvasion = m_max(round(evasion * calcLib.mod(modDB, nil, "MeleeEvasion")), 0)
output.ProjectileEvasion = m_max(round(evasion * calcLib.mod(modDB, nil, "ProjectileEvasion")), 0)
output.LowestOfArmourAndEvasion = m_min(output.Armour, output.Evasion)
output.Ward = m_max(round(ward), 0)
output["Gear:Ward"] = gearWard
output["Gear:EnergyShield"] = gearEnergyShield
output["Gear:Armour"] = gearArmour
output["Gear:Evasion"] = gearEvasion
output.CappingES = modDB:Flag(nil, "ArmourESRecoveryCap") and output.Armour < output.EnergyShield or modDB:Flag(nil, "EvasionESRecoveryCap") and output.Evasion < output.EnergyShield or env.configInput["conditionLowEnergyShield"]
if output.CappingES then
output.EnergyShieldRecoveryCap = modDB:Flag(nil, "ArmourESRecoveryCap") and modDB:Flag(nil, "EvasionESRecoveryCap") and m_min(output.Armour, output.Evasion) or modDB:Flag(nil, "ArmourESRecoveryCap") and output.Armour or modDB:Flag(nil, "EvasionESRecoveryCap") and output.Evasion or output.EnergyShield or 0
output.EnergyShieldRecoveryCap = env.configInput["conditionLowEnergyShield"] and m_min(output.EnergyShield * data.misc.LowPoolThreshold, output.EnergyShieldRecoveryCap) or output.EnergyShieldRecoveryCap
else
output.EnergyShieldRecoveryCap = output.EnergyShield or 0
end
if modDB:Flag(nil, "CannotEvade") then
output.EvadeChance = 0
output.MeleeEvadeChance = 0
output.ProjectileEvadeChance = 0
else
local enemyAccuracy = round(calcLib.val(enemyDB, "Accuracy"))
local evadeChance = modDB:Sum("BASE", nil, "EvadeChance")
local hitChance = calcLib.mod(enemyDB, nil, "HitChance")
output.EvadeChance = 100 - (calcs.hitChance(output.Evasion, enemyAccuracy) - evadeChance) * hitChance
output.MeleeEvadeChance = m_max(0, m_min(data.misc.EvadeChanceCap, (100 - (calcs.hitChance(output.MeleeEvasion, enemyAccuracy) - evadeChance) * hitChance) * calcLib.mod(modDB, nil, "EvadeChance", "MeleeEvadeChance")))
output.ProjectileEvadeChance = m_max(0, m_min(data.misc.EvadeChanceCap, (100 - (calcs.hitChance(output.ProjectileEvasion, enemyAccuracy) - evadeChance) * hitChance) * calcLib.mod(modDB, nil, "EvadeChance", "ProjectileEvadeChance")))
-- Condition for displaying evade chance only if melee or projectile evade chance have the same values
if output.MeleeEvadeChance ~= output.ProjectileEvadeChance then
output.splitEvade = true
else
output.EvadeChance = output.MeleeEvadeChance
output.dontSplitEvade = true
end
if breakdown then
breakdown.EvadeChance = {
s_format("Enemy level: %d ^8(%s the Configuration tab)", env.enemyLevel, env.configInput.enemyLevel and "overridden from" or "can be overridden in"),
s_format("Average enemy accuracy: %d", enemyAccuracy),
s_format("Approximate evade chance: %d%%", output.EvadeChance),
}
breakdown.MeleeEvadeChance = {
s_format("Enemy level: %d ^8(%s the Configuration tab)", env.enemyLevel, env.configInput.enemyLevel and "overridden from" or "can be overridden in"),
s_format("Average enemy accuracy: %d", enemyAccuracy),
s_format("Effective Evasion: %d", output.MeleeEvasion),
s_format("Approximate melee evade chance: %d%%", output.MeleeEvadeChance),
}
breakdown.ProjectileEvadeChance = {
s_format("Enemy level: %d ^8(%s the Configuration tab)", env.enemyLevel, env.configInput.enemyLevel and "overridden from" or "can be overridden in"),
s_format("Average enemy accuracy: %d", enemyAccuracy),
s_format("Effective Evasion: %d", output.ProjectileEvasion),
s_format("Approximate projectile evade chance: %d%%", output.ProjectileEvadeChance),
}
end
end
end
-- Dodge
-- Acrobatics Spell Suppression to Spell Dodge Chance conversion.
if modDB:Flag(nil, "ConvertSpellSuppressionToSpellDodge") then
local SpellSuppressionChance = modDB:Sum("BASE", nil, "SpellSuppressionChance")
modDB:NewMod("SpellDodgeChance", "BASE", SpellSuppressionChance / 2, "Acrobatics")
end
local totalSpellSuppressionChance = modDB:Override(nil, "SpellSuppressionChance") or modDB:Sum("BASE", nil, "SpellSuppressionChance")
output.SpellSuppressionChance = m_min(totalSpellSuppressionChance, data.misc.SuppressionChanceCap)
output.SpellSuppressionEffect = data.misc.SuppressionEffect + modDB:Sum("BASE", nil, "SpellSuppressionEffect")
if env.mode_effective and modDB:Flag(nil, "SpellSuppressionChanceIsUnlucky") then
output.SpellSuppressionChance = output.SpellSuppressionChance / 100 * output.SpellSuppressionChance
elseif env.mode_effective and modDB:Flag(nil, "SpellSuppressionChanceIsLucky") then
output.SpellSuppressionChance = (1 - (1 - output.SpellSuppressionChance / 100) ^ 2) * 100
end
output.SpellSuppressionChanceOverCap = m_max(0, totalSpellSuppressionChance - data.misc.SuppressionChanceCap)
if actor.itemList["Weapon 3"] and actor.itemList["Weapon 3"].armourData then
baseBlockChance = baseBlockChance + actor.itemList["Weapon 3"].armourData.BlockChance
end
output.ShieldBlockChance = baseBlockChance
if modDB:Flag(nil, "MaxBlockIfNotBlockedRecently") then
output.BlockChance = output.BlockChanceMax
else
output.BlockChance = m_min((baseBlockChance + modDB:Sum("BASE", nil, "BlockChance")) * calcLib.mod(modDB, nil, "BlockChance"), output.BlockChanceMax)
end
output.ProjectileBlockChance = m_min(output.BlockChance + modDB:Sum("BASE", nil, "ProjectileBlockChance") * calcLib.mod(modDB, nil, "BlockChance"), output.BlockChanceMax)
if modDB:Flag(nil, "SpellBlockChanceMaxIsBlockChanceMax") then
output.SpellBlockChanceMax = output.BlockChanceMax
else
output.SpellBlockChanceMax = modDB:Sum("BASE", nil, "SpellBlockChanceMax")
end
if modDB:Flag(nil, "SpellBlockChanceIsBlockChance") then
output.SpellBlockChance = output.BlockChance
output.SpellProjectileBlockChance = output.ProjectileBlockChance
else
output.SpellBlockChance = m_min(modDB:Sum("BASE", nil, "SpellBlockChance") * calcLib.mod(modDB, nil, "SpellBlockChance"), output.SpellBlockChanceMax)
output.SpellProjectileBlockChance = output.SpellBlockChance
end
if breakdown then
breakdown.BlockChance = breakdown.simple(baseBlockChance, nil, output.BlockChance, "BlockChance")
breakdown.SpellBlockChance = breakdown.simple(0, nil, output.SpellBlockChance, "SpellBlockChance")
end
if modDB:Flag(nil, "CannotBlockAttacks") then
output.BlockChance = 0
output.ProjectileBlockChance = 0
end
if modDB:Flag(nil, "CannotBlockSpells") then
output.SpellBlockChance = 0
output.SpellProjectileBlockChance = 0
end
output.AverageBlockChance = (output.BlockChance + output.ProjectileBlockChance + output.SpellBlockChance + output.SpellProjectileBlockChance) / 4
output.BlockEffect = m_max(100 - modDB:Sum("BASE", nil, "BlockEffect"), 0)
if output.BlockEffect == 0 or output.BlockEffect == 100 then
output.BlockEffect = 100
else
output.ShowBlockEffect = true
output.DamageTakenOnBlock = 100 - output.BlockEffect
end
output.LifeOnBlock = modDB:Sum("BASE", nil, "LifeOnBlock")
output.ManaOnBlock = modDB:Sum("BASE", nil, "ManaOnBlock")
output.EnergyShieldOnBlock = modDB:Sum("BASE", nil, "EnergyShieldOnBlock")
-- Dodge
local baseDodgeChance = 0
local totalAttackDodgeChance = modDB:Sum("BASE", nil, "AttackDodgeChance")
local totalSpellDodgeChance = modDB:Sum("BASE", nil, "SpellDodgeChance")
local attackDodgeChanceMax = data.misc.DodgeChanceCap
local spellDodgeChanceMax = modDB:Override(nil, "SpellDodgeChanceMax") or modDB:Sum("BASE", nil, "SpellDodgeChanceMax")
output.AttackDodgeChance = m_min(totalAttackDodgeChance, attackDodgeChanceMax)
output.SpellDodgeChance = m_min(totalSpellDodgeChance, spellDodgeChanceMax)
if env.mode_effective and modDB:Flag(nil, "DodgeChanceIsUnlucky") then
output.AttackDodgeChance = output.AttackDodgeChance / 100 * output.AttackDodgeChance
output.SpellDodgeChance = output.SpellDodgeChance / 100 * output.SpellDodgeChance
end
output.AttackDodgeChanceOverCap = m_max(0, totalAttackDodgeChance - attackDodgeChanceMax)
output.SpellDodgeChanceOverCap = m_max(0, totalSpellDodgeChance - spellDodgeChanceMax)
if breakdown then
breakdown.AttackDodgeChance = {
"Base: "..baseDodgeChance.."%",
"Max: "..attackDodgeChanceMax.."%",
"Total: "..output.AttackDodgeChance+output.AttackDodgeChanceOverCap.."%",
}
breakdown.SpellDodgeChance = {
"Base: "..baseDodgeChance.."%",
"Max: "..spellDodgeChanceMax.."%",
"Total: "..output.SpellDodgeChance+output.SpellDodgeChanceOverCap.."%",
}
end
-- Recovery modifiers
output.LifeRecoveryRateMod = calcLib.mod(modDB, nil, "LifeRecoveryRate")
output.ManaRecoveryRateMod = calcLib.mod(modDB, nil, "ManaRecoveryRate")
output.EnergyShieldRecoveryRateMod = calcLib.mod(modDB, nil, "EnergyShieldRecoveryRate")
-- Leech caps
output.MaxLifeLeechInstance = output.Life * calcLib.val(modDB, "MaxLifeLeechInstance") / 100
output.MaxLifeLeechRatePercent = calcLib.val(modDB, "MaxLifeLeechRate")
output.MaxLifeLeechRate = output.Life * output.MaxLifeLeechRatePercent / 100
if breakdown then
breakdown.MaxLifeLeechRate = {
s_format("%d ^8(maximum life)", output.Life),
s_format("x %d%% ^8(percentage of life to maximum leech rate)", output.MaxLifeLeechRatePercent),
s_format("= %.1f", output.MaxLifeLeechRate)
}
end
output.MaxEnergyShieldLeechInstance = output.EnergyShield * calcLib.val(modDB, "MaxEnergyShieldLeechInstance") / 100
output.MaxEnergyShieldLeechRate = output.EnergyShield * calcLib.val(modDB, "MaxEnergyShieldLeechRate") / 100
if breakdown then
breakdown.MaxEnergyShieldLeechRate = {
s_format("%d ^8(maximum energy shield)", output.EnergyShield),
s_format("x %d%% ^8(percentage of energy shield to maximum leech rate)", calcLib.val(modDB, "MaxEnergyShieldLeechRate")),
s_format("= %.1f", output.MaxEnergyShieldLeechRate)
}
end
output.MaxManaLeechInstance = output.Mana * calcLib.val(modDB, "MaxManaLeechInstance") / 100
output.MaxManaLeechRate = output.Mana * calcLib.val(modDB, "MaxManaLeechRate") / 100
if breakdown then
breakdown.MaxManaLeechRate = {
s_format("%d ^8(maximum mana)", output.Mana),
s_format("x %d%% ^8(percentage of mana to maximum leech rate)", modDB:Sum("BASE", nil, "MaxManaLeechRate")),
s_format("= %.1f", output.MaxManaLeechRate)
}
end
-- Mana, life, energy shield, and rage regen
if modDB:Flag(nil, "NoManaRegen") then
output.ManaRegen = 0
output.ManaRegenRecovery = - modDB:Sum("BASE", nil, "ManaDegen")
else
local base = modDB:Sum("BASE", nil, "ManaRegen") + output.Mana * modDB:Sum("BASE", nil, "ManaRegenPercent") / 100
output.ManaRegenInc = modDB:Sum("INC", nil, "ManaRegen")
local more = modDB:More(nil, "ManaRegen")
if modDB:Flag(nil, "ManaRegenToRageRegen") then
output.ManaRegenInc = 0
end
local regen = base * (1 + output.ManaRegenInc/100) * more
local regenRate = round(regen * output.ManaRecoveryRateMod, 1)
local degen = modDB:Sum("BASE", nil, "ManaDegen")
output.ManaRegen = regenRate
output.ManaRegenRecovery = (modDB:Flag(nil, "UnaffectedByManaRegen") and 0 or output.ManaRegen) - degen
if breakdown then
breakdown.ManaRegenRecovery = { }
breakdown.multiChain(breakdown.ManaRegenRecovery, {
label = "Mana Regeneration:",
base = s_format("%.1f ^8(base)", base),
{ "%.2f ^8(increased/reduced)", 1 + output.ManaRegenInc/100 },
{ "%.2f ^8(more/less)", more },
total = s_format("= %.1f ^8per second", regen),
})
breakdown.multiChain(breakdown.ManaRegenRecovery, {
label = "Effective Mana Regeneration:",
base = s_format("%.1f", regen),
{ "%.2f ^8(recovery rate modifier)", output.ManaRecoveryRateMod },
total = s_format("= %.1f ^8per second", regenRate),
})
if degen ~= 0 then
t_insert(breakdown.ManaRegenRecovery, s_format("- %d", degen))
t_insert(breakdown.ManaRegenRecovery, s_format("= %.1f ^8per second", output.ManaRegenRecovery))
end
end
end
if modDB:Flag(nil, "NoLifeRegen") then
output.LifeRegen = 0
elseif modDB:Flag(nil, "ZealotsOath") then
output.LifeRegen = 0
local lifeBase = modDB:Sum("BASE", nil, "LifeRegen")
if lifeBase > 0 then
modDB:NewMod("EnergyShieldRegen", "BASE", lifeBase, "Zealot's Oath")
end
local lifePercent = modDB:Sum("BASE", nil, "LifeRegenPercent")
if lifePercent > 0 then
modDB:NewMod("EnergyShieldRegenPercent", "BASE", lifePercent, "Zealot's Oath")
end
else
local lifeBase = modDB:Sum("BASE", nil, "LifeRegen")
local lifePercent = modDB:Sum("BASE", nil, "LifeRegenPercent")
if lifePercent > 0 then
lifeBase = lifeBase + output.Life * lifePercent / 100
end
if lifeBase > 0 then
output.LifeRegen = lifeBase * output.LifeRecoveryRateMod * modDB:More(nil, "LifeRegen") * (1 + modDB:Sum("INC", nil, "LifeRegen") / 100)
else
output.LifeRegen = 0
end
-- Don't add life recovery mod for this
if output.LifeRegen and modDB:Flag(nil, "LifeRegenerationRecoversEnergyShield") and output.EnergyShield > 0 then
modDB:NewMod("EnergyShieldRecovery", "BASE",output.LifeRegen / output.LifeRecoveryRateMod, "Life Regeneration Recovers Energy Shield")
end
end
output.LifeRegenRecovery = (modDB:Flag(nil, "UnaffectedByLifeRegen") and 0 or output.LifeRegen) - modDB:Sum("BASE", nil, "LifeDegen") + modDB:Sum("BASE", nil, "LifeRecovery") * output.LifeRecoveryRateMod
output.LifeRegenPercent = round(output.LifeRegenRecovery / output.Life * 100, 1)
if modDB:Flag(nil, "NoEnergyShieldRegen") then
output.EnergyShieldRegenRecovery = 0 - modDB:Sum("BASE", nil, "EnergyShieldDegen")
output.EnergyShieldRegenPercent = round(output.EnergyShieldRegenRecovery / output.EnergyShield * 100, 1)
else
local esBase = modDB:Sum("BASE", nil, "EnergyShieldRegen")
local esPercent = modDB:Sum("BASE", nil, "EnergyShieldRegenPercent")
if esPercent > 0 then
esBase = esBase + output.EnergyShield * esPercent / 100
end
if esBase > 0 then
output.EnergyShieldRegenRecovery = esBase * output.EnergyShieldRecoveryRateMod * calcLib.mod(modDB, nil, "EnergyShieldRegen") - modDB:Sum("BASE", nil, "EnergyShieldDegen")
output.EnergyShieldRegenPercent = round(output.EnergyShieldRegenRecovery / output.EnergyShield * 100, 1)
else
output.EnergyShieldRegenRecovery = 0 - modDB:Sum("BASE", nil, "EnergyShieldDegen")
end
end
output.EnergyShieldRegenRecovery = output.EnergyShieldRegenRecovery + modDB:Sum("BASE", nil, "EnergyShieldRecovery") * output.EnergyShieldRecoveryRateMod
output.EnergyShieldRegenPercent = round(output.EnergyShieldRegenRecovery / output.EnergyShield * 100, 1)
if modDB:Sum("BASE", nil, "RageRegen") > 0 then
modDB:NewMod("Condition:CanGainRage", "FLAG", true, "RageRegen")
local base = modDB:Sum("BASE", nil, "RageRegen")
if modDB:Flag(nil, "ManaRegenToRageRegen") then
local mana = modDB:Sum("INC", nil, "ManaRegen")
modDB:NewMod("RageRegen", "INC", mana, "Mana Regen to Rage Regen")
end
local inc = modDB:Sum("INC", nil, "RageRegen")
local more = modDB:More(nil, "RageRegen")
output.RageRegen = base * (1 + inc /100) * more
if breakdown then
breakdown.RageRegen = { }
breakdown.multiChain(breakdown.RageRegen, {
base = s_format("%.1f ^8(base)", base),
{ "%.2f ^8(increased/reduced)", 1 + inc/100 },
{ "%.2f ^8(more/less)", more },
total = s_format("= %.1f ^8per second", output.RageRegen),
})
end
end
-- Energy Shield Recharge
if modDB:Flag(nil, "NoEnergyShieldRecharge") then
output.EnergyShieldRecharge = 0
else
local inc = modDB:Sum("INC", nil, "EnergyShieldRecharge")
local more = modDB:More(nil, "EnergyShieldRecharge")
if modDB:Flag(nil, "EnergyShieldRechargeAppliesToLife") then
output.EnergyShieldRechargeAppliesToLife = true
local recharge = output.Life * data.misc.EnergyShieldRechargeBase * (1 + inc/100) * more
output.LifeRecharge = round(recharge * output.LifeRecoveryRateMod)
if breakdown then
breakdown.LifeRecharge = { }
breakdown.multiChain(breakdown.LifeRecharge, {
label = "Recharge rate:",
base = s_format("%.1f ^8(33%% per second)", output.Life * data.misc.EnergyShieldRechargeBase),
{ "%.2f ^8(increased/reduced)", 1 + inc/100 },
{ "%.2f ^8(more/less)", more },
total = s_format("= %.1f ^8per second", recharge),
})
breakdown.multiChain(breakdown.LifeRecharge, {
label = "Effective Recharge rate:",
base = s_format("%.1f", recharge),
{ "%.2f ^8(recovery rate modifier)", output.LifeRecoveryRateMod },
total = s_format("= %.1f ^8per second", output.LifeRecharge),
})
end
else
output.EnergyShieldRechargeAppliesToEnergyShield = true
local recharge = output.EnergyShield * data.misc.EnergyShieldRechargeBase * (1 + inc/100) * more
output.EnergyShieldRecharge = round(recharge * output.EnergyShieldRecoveryRateMod)
if breakdown then
breakdown.EnergyShieldRecharge = { }
breakdown.multiChain(breakdown.EnergyShieldRecharge, {
label = "Recharge rate:",
base = s_format("%.1f ^8(33%% per second)", output.EnergyShield * data.misc.EnergyShieldRechargeBase),
{ "%.2f ^8(increased/reduced)", 1 + inc/100 },
{ "%.2f ^8(more/less)", more },
total = s_format("= %.1f ^8per second", recharge),
})
breakdown.multiChain(breakdown.EnergyShieldRecharge, {
label = "Effective Recharge rate:",
base = s_format("%.1f", recharge),
{ "%.2f ^8(recovery rate modifier)", output.EnergyShieldRecoveryRateMod },
total = s_format("= %.1f ^8per second", output.EnergyShieldRecharge),
})
end
end
output.EnergyShieldRechargeDelay = data.misc.EnergyShieldRechargeDelay / (1 + modDB:Sum("INC", nil, "EnergyShieldRechargeFaster") / 100)
if breakdown then
if output.EnergyShieldRechargeDelay ~= data.misc.EnergyShieldRechargeDelay then
breakdown.EnergyShieldRechargeDelay = {
s_format("%.2fs ^8(base)", data.misc.EnergyShieldRechargeDelay),
s_format("/ %.2f ^8(faster start)", 1 + modDB:Sum("INC", nil, "EnergyShieldRechargeFaster") / 100),
s_format("= %.2fs", output.EnergyShieldRechargeDelay)
}
end
end
end
-- recoup
do
local quickRecoup = modDB:Flag(nil, "3SecondRecoup")
local recoupTypeList = {"Life", "Mana", "EnergyShield"}
for _, recoupType in ipairs(recoupTypeList) do
local baseRecoup = modDB:Sum("BASE", nil, recoupType.."Recoup")
output[recoupType.."Recoup"] = baseRecoup * output[recoupType.."RecoveryRateMod"]
if breakdown then
if output[recoupType.."RecoveryRateMod"] ~= 1 then
breakdown[recoupType.."Recoup"] = {
s_format("%d%% ^8(base)", baseRecoup),
s_format("* %.2f ^8(recovery rate modifier)", output[recoupType.."RecoveryRateMod"]),
s_format("= %.1f%% over %d seconds", output[recoupType.."Recoup"], quickRecoup and 3 or 4)
}
else
breakdown[recoupType.."Recoup"] = { s_format("%d%% over %d seconds", output[recoupType.."Recoup"], quickRecoup and 3 or 4) }
end
end
end
if modDB:Flag(nil, "UsePowerCharges") and modDB:Flag(nil, "PowerChargesConvertToAbsorptionCharges") then
local ElementalEnergyShieldRecoupPerAbsorptionCharges = modDB:Sum("BASE", nil, "PerAbsorptionElementalEnergyShieldRecoup")
modDB:NewMod("ElementalEnergyShieldRecoup", "BASE", ElementalEnergyShieldRecoupPerAbsorptionCharges, "Absorption Charges", { type = "Multiplier", var = "AbsorptionCharge" } )
end
local ElementalEnergyShieldRecoup = modDB:Sum("BASE", nil, "ElementalEnergyShieldRecoup")
output.ElementalEnergyShieldRecoup = ElementalEnergyShieldRecoup * output.EnergyShieldRecoveryRateMod
if breakdown then
if output.EnergyShieldRecoveryRateMod ~= 1 then
breakdown.ElementalEnergyShieldRecoup = {
s_format("%d%% ^8(base)", ElementalEnergyShieldRecoup),
s_format("* %.2f ^8(recovery rate modifier)", output.EnergyShieldRecoveryRateMod),
s_format("= %.1f%% over %d seconds", output.ElementalEnergyShieldRecoup, quickRecoup and 3 or 4)
}
else
breakdown.ElementalEnergyShieldRecoup = { s_format("%d%% over %d seconds", output.ElementalEnergyShieldRecoup, quickRecoup and 3 or 4) }
end
end
for _, damageType in ipairs(dmgTypeList) do
local LifeRecoup = modDB:Sum("BASE", nil, damageType.."LifeRecoup")
output[damageType.."LifeRecoup"] = LifeRecoup * output.LifeRecoveryRateMod
if breakdown then
if output.LifeRecoveryRateMod ~= 1 then
breakdown[damageType.."LifeRecoup"] = {
s_format("%d%% ^8(base)", LifeRecoup),
s_format("* %.2f ^8(recovery rate modifier)", output.LifeRecoveryRateMod),
s_format("= %.1f%% over %d seconds", output[damageType.."LifeRecoup"], quickRecoup and 3 or 4)
}
else
breakdown[damageType.."LifeRecoup"] = { s_format("%d%% over %d seconds", output[damageType.."LifeRecoup"], quickRecoup and 3 or 4) }
end
end
end
end
-- Ward recharge
output.WardRechargeDelay = data.misc.WardRechargeDelay / (1 + modDB:Sum("INC", nil, "WardRechargeFaster") / 100)
if breakdown then
if output.WardRechargeDelay ~= data.misc.WardRechargeDelay then
breakdown.WardRechargeDelay = {
s_format("%.2fs ^8(base)", data.misc.WardRechargeDelay),
s_format("/ %.2f ^8(faster start)", 1 + modDB:Sum("INC", nil, "WardRechargeFaster") / 100),
s_format("= %.2fs", output.WardRechargeDelay)
}
end
end
-- Miscellaneous: move speed, avoidance
output.MovementSpeedMod = modDB:Override(nil, "MovementSpeed") or calcLib.mod(modDB, nil, "MovementSpeed")
if modDB:Flag(nil, "MovementSpeedCannotBeBelowBase") then
output.MovementSpeedMod = m_max(output.MovementSpeedMod, 1)
end
output.EffectiveMovementSpeedMod = output.MovementSpeedMod * output.ActionSpeedMod
if breakdown then
breakdown.EffectiveMovementSpeedMod = { }
breakdown.multiChain(breakdown.EffectiveMovementSpeedMod, {
{ "%.2f ^8(movement speed modifier)", output.MovementSpeedMod },
{ "%.2f ^8(action speed modifier)", output.ActionSpeedMod },
total = s_format("= %.2f ^8(effective movement speed modifier)", output.EffectiveMovementSpeedMod)
})
end
if enemyDB:Flag(nil, "Blind") then
output.BlindEffectMod = calcLib.mod(enemyDB, nil, "BlindEffect", "BuffEffectOnSelf") * 100
end
-- recovery on block, needs to be after primary defences
output.LifeOnBlock = modDB:Sum("BASE", nil, "LifeOnBlock")
output.ManaOnBlock = modDB:Sum("BASE", nil, "ManaOnBlock")
output.EnergyShieldOnBlock = modDB:Sum("BASE", nil, "EnergyShieldOnBlock")
output.EnergyShieldOnSpellBlock = modDB:Sum("BASE", nil, "EnergyShieldOnSpellBlock")
output.EnergyShieldOnSuppress = modDB:Sum("BASE", nil, "EnergyShieldOnSuppress")
output.LifeOnSuppress = modDB:Sum("BASE", nil, "LifeOnSuppress")
-- damage avoidances
output.specificTypeAvoidance = false
for _, damageType in ipairs(dmgTypeList) do
output["Avoid"..damageType.."DamageChance"] = m_min(modDB:Sum("BASE", nil, "Avoid"..damageType.."DamageChance"), data.misc.AvoidChanceCap)
if output["Avoid"..damageType.."DamageChance"] > 0 then
output.specificTypeAvoidance = true
end
end
output.AvoidProjectilesChance = m_min(modDB:Sum("BASE", nil, "AvoidProjectilesChance"), data.misc.AvoidChanceCap)
-- hit avoidance
output.AvoidAllDamageFromHitsChance = m_min(modDB:Sum("BASE", nil, "AvoidAllDamageFromHitsChance"), data.misc.AvoidChanceCap)
-- other avoidances etc
output.BlindAvoidChance = m_min(modDB:Sum("BASE", nil, "AvoidBlind"), 100)
for _, ailment in ipairs(data.ailmentTypeList) do
output[ailment.."AvoidChance"] = m_min(modDB:Sum("BASE", nil, "Avoid"..ailment), 100)
end
output.CritExtraDamageReduction = m_min(modDB:Sum("BASE", nil, "ReduceCritExtraDamage"), 100)
output.LightRadiusMod = calcLib.mod(modDB, nil, "LightRadius")
if breakdown then
breakdown.LightRadiusMod = breakdown.mod(modDB, nil, "LightRadius")
end
output.CurseEffectOnSelf = modDB:More(nil, "CurseEffectOnSelf") * (100 + modDB:Sum("INC", nil, "CurseEffectOnSelf"))
-- Ailment duration on self
output.DebuffExpirationRate = modDB:Sum("BASE", nil, "SelfDebuffExpirationRate")
output.DebuffExpirationModifier = 10000 / (100 + output.DebuffExpirationRate)
output.showDebuffExpirationModifier = (output.DebuffExpirationModifier ~= 100)
output.SelfBlindDuration = modDB:More(nil, "SelfBlindDuration") * (100 + modDB:Sum("INC", nil, "SelfBlindDuration")) * output.DebuffExpirationModifier / 100
for _, ailment in ipairs(data.ailmentTypeList) do
output["Self"..ailment.."Duration"] = modDB:More(nil, "Self"..ailment.."Duration") * (100 + modDB:Sum("INC", nil, "Self"..ailment.."Duration")) * 100 / (100 + output.DebuffExpirationRate + modDB:Sum("BASE", nil, "Self"..ailment.."DebuffExpirationRate"))
end
output.SelfChillEffect = modDB:More(nil, "SelfChillEffect") * (100 + modDB:Sum("INC", nil, "SelfChillEffect"))
output.SelfShockEffect = modDB:More(nil, "SelfShockEffect") * (100 + modDB:Sum("INC", nil, "SelfShockEffect"))
--Enemy damage input and modifications
do
output["totalEnemyDamage"] = 0
output["totalEnemyDamageIn"] = 0
if breakdown then
breakdown["totalEnemyDamage"] = {
label = "Total damage from the enemy",
rowList = { },
colList = {
{ label = "Type", key = "type" },
{ label = "Value", key = "value" },
{ label = "Mult", key = "mult" },
{ label = "Crit", key = "crit" },
{ label = "Final", key = "final" },
{ label = "From", key = "from" },
},
}
end
local enemyCritChance = env.configInput["enemyCritChance"] or env.configPlaceholder["enemyCritChance"] or 0
local enemyCritDamage = env.configInput["enemyCritDamage"] or env.configPlaceholder["enemyCritDamage"] or 0
output["EnemyCritEffect"] = 1 + enemyCritChance / 100 * (enemyCritDamage / 100) * (1 - output.CritExtraDamageReduction / 100)
local enemyCfg = {keywordFlags = bit.bnot(KeywordFlag.MatchAll)} -- Match all keywordFlags parameter for enemy min-max damage mods
for _, damageType in ipairs(dmgTypeList) do
local enemyDamageMult = calcLib.mod(enemyDB, nil, "Damage", damageType.."Damage", isElemental[damageType] and "ElementalDamage" or nil) -- missing taunt from allies
local enemyDamage = tonumber(env.configInput["enemy"..damageType.."Damage"])
local enemyPen = tonumber(env.configInput["enemy"..damageType.."Pen"])
local enemyOverwhelm = tonumber(env.configInput["enemy"..damageType.."Overwhelm"])
local sourceStr = enemyDamage == nil and "Default" or "Config"
if enemyDamage == nil then
enemyDamage = tonumber(env.configPlaceholder["enemy"..damageType.."Damage"]) or 0
end
if enemyPen == nil then
enemyPen = tonumber(env.configPlaceholder["enemy"..damageType.."Pen"]) or 0
end
if enemyOverwhelm == nil then
enemyOverwhelm = tonumber(env.configPlaceholder["enemy"..damageType.."enemyOverwhelm"]) or 0
end
-- Add min-max enemy damage from mods
enemyDamage = enemyDamage + (enemyDB:Sum("BASE", enemyCfg, (damageType.."Min")) + enemyDB:Sum("BASE", enemyCfg, (damageType.."Max"))) / 2
output[damageType.."EnemyPen"] = enemyPen
output[damageType.."EnemyOverwhelm"] = enemyOverwhelm
output["totalEnemyDamageIn"] = output["totalEnemyDamageIn"] + enemyDamage
output[damageType.."EnemyDamage"] = enemyDamage * enemyDamageMult * output["EnemyCritEffect"]
output["totalEnemyDamage"] = output["totalEnemyDamage"] + output[damageType.."EnemyDamage"]
if breakdown then
breakdown[damageType.."EnemyDamage"] = {
s_format("from %s: %d", sourceStr, enemyDamage),
s_format("* %.2f (modifiers to enemy damage)", enemyDamageMult),
s_format("* %.3f (enemy crit effect)", output["EnemyCritEffect"]),
s_format("= %d", output[damageType.."EnemyDamage"]),
}
t_insert(breakdown["totalEnemyDamage"].rowList, {
type = s_format("%s", damageType),
value = s_format("%d", enemyDamage),
mult = s_format("%.2f", enemyDamageMult),
crit = s_format("%.2f", output["EnemyCritEffect"]),
final = s_format("%d", output[damageType.."EnemyDamage"]),
from = s_format("%s", sourceStr),
})
end
end
end
--Damage Taken as
do
actor.damageShiftTable = wipeTable(actor.damageShiftTable)
for _, damageType in ipairs(dmgTypeList) do
-- Build damage shift table
local shiftTable = { }
local destTotal = 0
for _, destType in ipairs(dmgTypeList) do
if destType ~= damageType then
shiftTable[destType] = modDB:Sum("BASE", nil, damageType.."DamageTakenAs"..destType, isElemental[damageType] and "ElementalDamageTakenAs"..destType or nil)
destTotal = destTotal + shiftTable[destType]
end
end
if destTotal > 100 then
local factor = 100 / destTotal
for destType, portion in pairs(shiftTable) do
shiftTable[destType] = portion * factor
end
destTotal = 100
end
shiftTable[damageType] = 100 - destTotal
actor.damageShiftTable[damageType] = shiftTable
--add same type damage
output[damageType.."TakenDamage"] = output[damageType.."EnemyDamage"] * actor.damageShiftTable[damageType][damageType] / 100
if breakdown then
breakdown[damageType.."TakenDamage"] = {
label = "Taken",
rowList = { },
colList = {
{ label = "Type", key = "type" },
{ label = "Value", key = "value" },