-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluator.pluto
1016 lines (932 loc) · 34.5 KB
/
evaluator.pluto
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
-- @pluto_warnings enable-non-portable-bytecode
export data = {}
export function is_inited(): bool
return data.powersuits ~= nil
end
export function init(new_data: ?table)
if not new_data then
new_data = dofile("data.json.lua")
end
data.mods = new_data.mods
data.sub_upgrades = new_data.sub_upgrades
data.modsets = new_data.modsets
data.powersuits = new_data.powersuits
data.weapons = new_data.weapons
data.resistances = new_data.resistances
data.enemies = new_data.enemies
end
local function get_num_mods_from_set(mods, set)
local n = 0
for pairs(mods) as mod do
if (data.mods[mod.name] or error("Unknown mod: "..mod.name)).data.ModSet == set then
++n
end
end
return n
end
local function stat_addOperation(stat, type, value)
if type == "ADD_BASE" then
stat.base += value
elseif type == "ADD" then
stat.add = (stat.add or 0) + value
else
assert(type == "STACKING_MULTIPLY")
stat.stacking_multiply_base = (stat.stacking_multiply_base or 1) + value
end
end
local function stat_addConditional(stat, conditional)
if not stat.conditionals then
stat.conditionals = {}
end
conditional.name = switch conditional.type do
case "/Lotus/Upgrades/CosmeticEnhancers/Offensive/OnComboTierCondition", "PM_HEAVY_MELEE", "CC_SLIDING" -> conditional.type
default -> conditional.source
end
stat.conditionals[#stat.conditionals + 1] = conditional
end
local function stat_getValue(stat)
return stat.base * (stat.stacking_multiply_base or 1) + (stat.add or 0)
end
local function build_applyStatConditionals(build, stat, to_apply)
local tmp = {
base = stat.base,
stacking_multiply_base = stat.stacking_multiply_base,
add = stat.add,
}
if stat.conditionals then
for pairs(stat.conditionals) as conditional do
if conditional.consteval then
assert(conditional.type:sub(1, 7) == "power>=")
if build.powersuit then
if stat_getValue(build.powersuit.power) >= tonumber(conditional.type:sub(8)) then
stat_addOperation(tmp, conditional.operation, conditional.value)
end
end
elseif to_apply[conditional.name] ~= nil then
stat_addOperation(tmp, conditional.operation, conditional.value * to_apply[conditional.name])
end
end
end
return stat_getValue(tmp)
end
local function upgrade_type_to_gear_name(upgradeType): ?string
if upgradeType:sub(1, 7) == "AVATAR_" then
return "powersuit"
end
if upgradeType:sub(1, 13) == "WEAPON_MELEE_" then
return "melee"
end
return nil
end
local function valid_type_to_gear_name(validType): ?string
return switch validType do
case "/Lotus/Weapons/Tenno/LotusLongGun" -> "primary"
case "/Lotus/Weapons/Tenno/LotusPistol" -> "secondary"
case "/Lotus/Types/Game/LotusMeleeWeapon" -> "melee"
case "/Lotus/Weapons/Tenno/Melee/PlayerMeleeWeapon" -> "melee"
end
end
local function gear_getStats(gear, upgrade): table
return switch upgrade.UpgradeType do
case "AVATAR_HEALTH_MAX" -> { "health" }
case "AVATAR_ARMOUR" -> { "armor" }
case "AVATAR_POWER_MAX" -> { "power" }
case "AVATAR_ABILITY_DURATION" -> { "ability_duration" }
case "AVATAR_ABILITY_EFFICIENCY" -> { "ability_efficiency" }
case "AVATAR_ABILITY_RANGE" -> { "ability_range" }
case "AVATAR_ABILITY_STRENGTH" -> { "ability_strength" }
case "AVATAR_HEAL_RATE" -> { "heal_rate" }
case "AVATAR_AURA_STRENGTH" -> { "aura_strength" }
case "AVATAR_AURA_EFFECTIVENESS_ON_ME" -> { "aura_effectiveness" }
case "GAMEPLAY_POWER_TO_HEALTH_ON_DEATH" -> { "power_to_health_efficiency" }
case "AVATAR_MOVEMENT_SPEED" -> { "movement_speed", "sprint_speed" }
case "AVATAR_SPRINT_SPEED" -> { "sprint_speed" }
case "WEAPON_DAMAGE_AMOUNT", "WEAPON_MELEE_DAMAGE" -> { "dmg_impact", "dmg_puncture", "dmg_slash", "dmg_heat", "dmg_cold", "dmg_electricity", "dmg_toxin", "dmg_blast", "dmg_radiation", "dmg_gas", "dmg_magnetic", "dmg_viral", "dmg_corrosive" }
case "WEAPON_PERCENT_BASE_DAMAGE_ADDED" -> switch upgrade.DamageType do
case "DT_IMPACT" -> { "dmgadd_impact" }
case "DT_PUNCTURE" -> { "dmgadd_puncture" }
case "DT_SLASH" -> { "dmgadd_slash" }
case "DT_FIRE" -> { "dmgadd_heat" }
case "DT_FREEZE" -> { "dmgadd_cold" }
case "DT_ELECTRICITY" -> { "dmgadd_electricity" }
case "DT_POISON" -> { "dmgadd_toxin" }
case "DT_EXPLOSION" -> { "dmgadd_blast" }
case "DT_RADIATION" -> { "dmgadd_radiation" }
case "DT_GAS" -> { "dmgadd_gas" }
case "DT_MAGNETIC" -> { "dmgadd_magnetic" }
case "DT_VIRAL" -> { "dmgadd_viral" }
case "DT_CORROSIVE" -> { "dmgadd_corrosive" }
default -> --[[print("Silently ignoring WEAPON_PERCENT_BASE_DAMAGE_ADDED with "..upgrade.DamageType) or]] {}
end
case "WEAPON_CRIT_CHANCE" -> { "crit_chance" }
case "WEAPON_CRIT_DAMAGE" -> { "crit_damage" }
case "WEAPON_DOUBLE_CRIT_CHANCE" -> { "crit_enhance_chance" }
case "WEAPON_FIRE_RATE" -> { "fire_rate" }
case "WEAPON_MELEE_COMBO_DURATION_BONUS" -> { "combo_duration" }
default -> --[[print("Silently ignoring "..upgradeType) or]] {}
end
end
local function gear_getPrimaryElementalAdd(gear)
local elementals = {}
if gear.dmgadd_heat.add then
elementals[#elementals + 1] = "heat"
end
if gear.dmgadd_cold.add then
elementals[#elementals + 1] = "cold"
end
if gear.dmgadd_electricity.add then
elementals[#elementals + 1] = "electricity"
end
if gear.dmgadd_toxin.add then
elementals[#elementals + 1] = "toxin"
end
return elementals
end
local elemental_mix <const> = {
heat = {
cold = "blast",
electricity = "radiation",
toxin = "gas",
},
cold = {
heat = "blast",
electricity = "magnetic",
toxin = "viral",
},
electricity = {
heat = "radiation",
cold = "magnetic",
toxin = "corrosive",
},
toxin = {
heat = "gas",
cold = "viral",
electricity = "corrosive",
}
}
local function gear_addStatOperation(gear, stat_name, operation_type, value)
if gear.redirects?[stat_name] then
stat_name = gear.redirects[stat_name]
end
stat_addOperation(gear[stat_name], operation_type, value)
if stat_name == "dmgadd_heat" or stat_name == "dmgadd_cold" or stat_name == "dmgadd_electricity" or stat_name == "dmgadd_toxin" then
assert(operation_type == "ADD")
local this_elemental = stat_name:sub(8)
for pairs(gear_getPrimaryElementalAdd(gear)) as elemental do
if elemental ~= this_elemental then
local combined = elemental_mix[this_elemental][elemental]
gear["dmgadd_"..combined].add = gear[stat_name].add + gear["dmgadd_"..elemental].add
gear[stat_name].add = nil
gear["dmgadd_"..elemental].add = nil
gear.redirects[stat_name] = "dmgadd_"..combined
gear.redirects["dmgadd_"..elemental] = "dmgadd_"..combined
break
end
end
end
end
local function build_getStats(build, gear_name, upgrade)
local applies = false
local stats = gear_getStats(build[gear_name], upgrade)
for pairs(stats) as stat_name do
if build[gear_name]?[stat_name] then
applies = true
break
end
end
if not applies then
if upgrade_gear_name := upgrade_type_to_gear_name(upgrade.UpgradeType) or valid_type_to_gear_name(upgrade.ValidType) then
return upgrade_gear_name, gear_getStats(build[upgrade_gear_name], upgrade)
end
end
return gear_name, stats
end
local function build_addConditionalUpgrade(build, conditional: string, upgrade)
if upgrade_gear_name := upgrade_type_to_gear_name(upgrade.UpgradeType) then
local stats = gear_getStats(build[upgrade_gear_name], upgrade)
for pairs(stats) as stat_name do
if stat := build[upgrade_gear_name]?[stat_name] then
stat_addConditional(stat, {
type = conditional,
source = conditional,
operation = upgrade.OperationType,
value = upgrade.Value,
})
end
end
end
end
local function fusion_level_to_rank(qa): int
return switch qa do
case "QA_VERY_HIGH" -> 10
case "QA_HIGH" -> 5
case "QA_MEDIUM" -> 3
default -> 0
end
end
local function get_script_prop(mod, prop)
repeat
if mod.data.Script[prop] then
return mod.data.Script[prop]
end
mod = data.mods[mod.parent]
until mod == nil
end
local function build_applyMod(build, gear_name: ?string, mod_name, mod, rank = 0, value_multiplier = 1)
local upgrades = mod.data.Upgrades
if upgrades == nil then
upgrades = data.mods[mod.parent]?.data?.Upgrades
end
if upgrades then
if mod.data.ConditionalUpgrades then
for pairs(upgrades) as upgrade do
local upgrade_gear_name, stats = build_getStats(build, gear_name, upgrade)
for pairs(stats) as stat_name do
if stat := build[upgrade_gear_name]?[stat_name] then
stat_addConditional(stat, {
type = mod.data.ConditionalUpgrades[1],
source = mod_name,
proc_chance = mod.data.UpgradeChance,
max_stacks = mod.data.MaxConditionalStacks,
operation = upgrade.OperationType,
value = upgrade.Value * value_multiplier,
})
end
end
end
else
for pairs(upgrades) as upgrade do
local upgrade_gear_name, stats = build_getStats(build, gear_name, upgrade)
for pairs(stats) as stat_name do
if stat := build[upgrade_gear_name]?[stat_name] then
if upgrade.ValidModifiers and #upgrade.ValidModifiers ~= 0 then
stat_addConditional(stat, {
type = upgrade.ValidModifiers[1],
source = mod_name,
max_stacks = 1,
operation = upgrade.OperationType,
value = upgrade.Value * value_multiplier
})
elseif upgrade.SymbolFilter and upgrade.SymbolFilter ~= "" then
if upgrade.SymbolFilter ~= "CC_SLIDING_PVP" then
stat_addConditional(stat, {
type = upgrade.SymbolFilter,
source = mod_name,
max_stacks = 1,
operation = upgrade.OperationType,
value = upgrade.Value * value_multiplier
})
end
else
gear_addStatOperation(build[upgrade_gear_name], stat_name, upgrade.OperationType, upgrade.Value * value_multiplier)
end
end
end
end
end
end
if mod.data.ExtraUpgrades and rank >= fusion_level_to_rank(mod.data.ExtraUpgradeFusionLevel) then
for pairs(mod.data.ExtraUpgrades) as upgrade do
if upgrade.ValidType ~= "" then
assert(upgrade.ValidType == "/Lotus/Weapons/Tenno/Melee/PlayerMeleeWeapon")
local stats = gear_getStats(build.melee, upgrade)
for pairs(stats) as stat_name do
if build.melee?[stat_name] then
gear_addStatOperation(build.melee, stat_name, upgrade.OperationType, upgrade.Value)
end
end
else
local stats = gear_getStats(build[gear_name], upgrade)
for pairs(stats) as stat_name do
if build[gear_name][stat_name] then
gear_addStatOperation(build[gear_name], stat_name, upgrade.OperationType, upgrade.Value)
end
end
end
end
end
if mod.data.SubUpgrades then
for pairs(mod.data.SubUpgrades) as sub_upgrade do
if sub_mod := data.sub_upgrades[sub_upgrade] then
build_applyMod(build, gear_name, mod_name, sub_mod, rank, value_multiplier)
end
end
end
if mod.data.Script then
local script = get_script_prop(mod, "Script")
if script == "MeleeDamageForActiveShields.lua" then
if build.melee then
local stats = gear_getStats(build.melee, { UpgradeType = "WEAPON_MELEE_DAMAGE" })
for pairs(stats) as stat_name do
local value = get_script_prop(mod, "_meleeDamagePerBonus") * value_multiplier
stat_addConditional(build.melee[stat_name], {
type = script,
source = mod_name,
max_stacks = get_script_prop(mod, "_meleeDamageLimit") / value + 1,
operation = "STACKING_MULTIPLY",
value = value
})
end
end
elseif script == "/Lotus/Scripts/Mods/UpgradeStackAfterEnergyThreshold.lua" then
local upgrade_gear_name, stats = build_getStats(build, gear_name, { UpgradeType = get_script_prop(mod, "_upgradeType"), ValidType = get_script_prop(mod, "_objectType") })
for pairs(stats) as stat_name do
for pairs(get_script_prop(mod, "_thresholds")) as threshold do
if stat := build[upgrade_gear_name]?[stat_name] then
stat_addConditional(stat, {
type = "power>="..threshold,
source = mod_name,
consteval = true,
operation = get_script_prop(mod, "_operationType"),
value = get_script_prop(mod, "_value")
})
end
end
end
end
end
end
local function build_initGear(build, gear_name, gear_data)
build[gear_name] = {
redirects = {},
dmg_impact = { base = gear_data.damagePerShot[1] },
dmg_puncture = { base = gear_data.damagePerShot[2] },
dmg_slash = { base = gear_data.damagePerShot[3] },
dmg_heat = { base = gear_data.damagePerShot[4] },
dmg_cold = { base = gear_data.damagePerShot[5] },
dmg_electricity = { base = gear_data.damagePerShot[6] },
dmg_toxin = { base = gear_data.damagePerShot[7] },
dmg_blast = { base = gear_data.damagePerShot[8] },
dmg_radiation = { base = gear_data.damagePerShot[9] },
dmg_gas = { base = gear_data.damagePerShot[10] },
dmg_magnetic = { base = gear_data.damagePerShot[11] },
dmg_viral = { base = gear_data.damagePerShot[12] },
dmg_corrosive = { base = gear_data.damagePerShot[13] },
dmgadd_impact = { base = 0 },
dmgadd_puncture = { base = 0 },
dmgadd_slash = { base = 0 },
dmgadd_heat = { base = 0 },
dmgadd_cold = { base = 0 },
dmgadd_electricity = { base = 0 },
dmgadd_toxin = { base = 0 },
dmgadd_blast = { base = 0 },
dmgadd_radiation = { base = 0 },
dmgadd_gas = { base = 0 },
dmgadd_magnetic = { base = 0 },
dmgadd_viral = { base = 0 },
dmgadd_corrosive = { base = 0 },
crit_chance = { base = gear_data.criticalChance },
crit_damage = { base = gear_data.criticalMultiplier },
crit_enhance_chance = { base = 0 },
fire_rate = { base = gear_data.fireRate },
}
if gear_data.EquippedBonuses then
for pairs(gear_data.EquippedBonuses) as upgrade do
build_addConditionalUpgrade(build, gear_data.uniqueName, upgrade)
end
end
end
export function parse_build(inbuild)
if not is_inited() then init() end
local build = {}
if inbuild.powersuit?.name then
local pe_data = data.powersuits[inbuild.powersuit.name] or error("Unknown powersuit: "..inbuild.powersuit.name)
build.powersuit = {
health = { base = pe_data.health },
shield = { base = pe_data.shield },
armor = { base = pe_data.armor },
power = { base = pe_data.power },
movement_speed = { base = pe_data.speed },
sprint_speed = { base = pe_data.speed },
ability_duration = { base = 1 },
ability_efficiency = { base = 1 },
ability_range = { base = 1 },
ability_strength = { base = 1, stacking_multiply_base = 1 },
heal_rate = { base = 0 },
aura_strength = { base = 1 },
aura_effectiveness = { base = 1 },
power_to_health_efficiency = { base = 0 },
}
local rank = inbuild.powersuit.rank or 30
switch pe_data.parentName do
case "/Lotus/Powersuits/Sandman/SandmanBaseSuit": -- Inaros
case "/Lotus/Powersuits/Devourer/DevourerBaseSuit": -- Grendel
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.health.base += (rank + 1) // 3 * 10
build.powersuit.power.base += rank // 3 * 5
break
case "/Lotus/Powersuits/Infestation/InfestationBaseSuit": -- Nidus
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.armor.base += (rank + 4) // 6 * 20
build.powersuit.ability_strength.stacking_multiply_base += (rank + 3) // 6 * 0.03
build.powersuit.power.base += rank // 6 * 10
build.powersuit.heal_rate.base = 5
build.powersuit.heal_rate.base += rank // 6 * 2
break
case "/Lotus/Powersuits/PaxDuviricus/PaxDuviricusBaseSuit": -- Kullervo
build.powersuit.health.base += (rank + 2) // 3 * 20
build.powersuit.armor.base += (rank + 1) // 3 * 10
build.powersuit.power.base += rank // 3 * 5
break
case "/Lotus/Powersuits/IronFrame/IronFrameBaseSuit": -- Hildryn
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.shield.base += (rank + 1) // 3 * 25
build.powersuit.shield.base += rank // 3 * 25
break
case "/Lotus/Powersuits/BrokenFrame/BrokenFrameBaseSuit": -- Xaku
build.powersuit.health.base += (rank + 2) // 3 * 9
build.powersuit.shield.base += (rank + 1) // 3 * 9
build.powersuit.power.base += rank // 3 * 7
break
case "/Lotus/Powersuits/Alchemist/AlchemistBaseSuit": -- Lavos
build.powersuit.health.base += (rank + 2) // 3 * 20
build.powersuit.shield.base += (rank + 1) // 3 * 10
build.powersuit.armor.base += rank // 3 * 10
break
case "/Lotus/Powersuits/Berserker/BerserkerBaseSuit": -- Valkyr
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.shield.base += (rank + 1) // 3 * 5
build.powersuit.power.base += rank // 3 * 5
break
case "/Lotus/Powersuits/Pacifist/PacifistBaseSuit": -- Baruuk
case "/Lotus/Powersuits/Garuda/GarudaBaseSuit": -- Garuda
case "/Lotus/Powersuits/Wisp/WispBaseSuit": -- Wisp
case "/Lotus/Powersuits/Yareli/YareliBaseSuit": -- Yareli
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.shield.base += (rank + 1) // 3 * 10
build.powersuit.power.base += rank // 3 * 10
break
default:
build.powersuit.health.base += (rank + 2) // 3 * 10
build.powersuit.shield.base += (rank + 1) // 3 * 10
build.powersuit.power.base += rank // 3 * 5
end
end
if inbuild.primary?.name then
build_initGear(build, "primary", data.weapons[inbuild.primary.name] or error("Unknown primary: "..inbuild.primary.name))
end
if inbuild.secondary?.name then
build_initGear(build, "secondary", data.weapons[inbuild.secondary.name] or error("Unknown secondary: "..inbuild.secondary.name))
end
if inbuild.melee?.name then
local gear_data = data.weapons[inbuild.melee.name] or error("Unknown melee: "..inbuild.melee.name)
build_initGear(build, "melee", gear_data)
build.melee.combo_duration = { base = gear_data.comboDuration }
end
local phoenix_talons_bonus = 0
if inbuild.operator?.phoenix_talons then
phoenix_talons_bonus = switch inbuild.operator?.phoenix_talons do
case 0 -> 0.5
case 1 -> 0.10
case 2 -> 0.20
case 3 -> 0.30
default -> error("Invalid phoenix_talons value")
end
end
local sets = {}
if inbuild.powersuit then
if inbuild.powersuit.mods then
local aura_mod
for pairs(inbuild.powersuit.mods) as mod do
local mod_obj = (data.mods[mod.name] or error("Unknown mod: "..mod.name))
local set_bonus = 1
if mod_obj.data.ModSetValues then
local n = get_num_mods_from_set(inbuild.powersuit.mods, mod_obj.data.ModSet)
if n > 1 then
set_bonus += mod_obj.data.ModSetValues[n - 1]
end
elseif mod_obj.data.ModSet then
sets[mod_obj.data.ModSet] = (sets[mod_obj.data.ModSet] or 0) + 1
end
local value_multiplier = ((mod.rank or 0) + 1) * set_bonus
if data.mods[mod.name].type == "AURA" then
-- Save aura mod for later so aura strength can be applied
aura_mod = { name = mod.name, obj = mod_obj, rank = mod.rank, mult = value_multiplier }
else
build_applyMod(build, "powersuit", mod.name, mod_obj, rank, value_multiplier)
end
end
if aura_mod then
build_applyMod(build, "powersuit", aura_mod.name, aura_mod.obj, aura_mod.rank, aura_mod.mult * stat_getValue(build.powersuit.aura_strength) * stat_getValue(build.powersuit.aura_effectiveness))
end
end
if build.powersuit then
build.powersuit.redirects = nil
build.powersuit.aura_strength = nil
build.powersuit.aura_effectiveness = nil
end
end
if inbuild.primary then
if inbuild.primary.mods then
for pairs(inbuild.primary.mods) as mod do
local mod_obj = (data.mods[mod.name] or error("Unknown mod: "..mod.name))
if mod_obj.data.ModSet then
sets[mod_obj.data.ModSet] = (sets[mod_obj.data.ModSet] or 0) + 1
end
build_applyMod(build, "primary", mod.name, mod_obj, mod.rank, (mod.rank or 0) + 1)
end
end
if build.primary then
if phoenix_talons_bonus ~= 0 then
stat_addOperation(build.primary.dmg_impact, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.primary.dmg_puncture, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.primary.dmg_slash, "STACKING_MULTIPLY", phoenix_talons_bonus)
end
build.primary.redirects = nil
end
end
if inbuild.secondary then
if inbuild.secondary.mods then
for pairs(inbuild.secondary.mods) as mod do
local mod_obj = (data.mods[mod.name] or error("Unknown mod: "..mod.name))
if mod_obj.data.ModSet then
sets[mod_obj.data.ModSet] = (sets[mod_obj.data.ModSet] or 0) + 1
end
build_applyMod(build, "secondary", mod.name, mod_obj, mod.rank, (mod.rank or 0) + 1)
end
end
if build.secondary then
if phoenix_talons_bonus ~= 0 then
stat_addOperation(build.secondary.dmg_impact, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.secondary.dmg_puncture, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.secondary.dmg_slash, "STACKING_MULTIPLY", phoenix_talons_bonus)
end
build.secondary.redirects = nil
end
end
if inbuild.melee then
if inbuild.melee.mods then
for pairs(inbuild.melee.mods) as mod do
local mod_obj = (data.mods[mod.name] or error("Unknown mod: "..mod.name))
local set_bonus = 1
if mod_obj.data.ModSetValues then
local n = get_num_mods_from_set(inbuild.melee.mods, mod_obj.data.ModSet)
if n > 1 then
set_bonus += mod_obj.data.ModSetValues[n - 1]
end
elseif mod_obj.data.ModSet then
sets[mod_obj.data.ModSet] = (sets[mod_obj.data.ModSet] or 0) + 1
end
build_applyMod(build, "melee", mod.name, mod_obj, mod.rank, ((mod.rank or 0) + 1) * set_bonus)
end
end
if build.melee then
if phoenix_talons_bonus ~= 0 then
stat_addOperation(build.melee.dmg_impact, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.melee.dmg_puncture, "STACKING_MULTIPLY", phoenix_talons_bonus)
stat_addOperation(build.melee.dmg_slash, "STACKING_MULTIPLY", phoenix_talons_bonus)
end
build.melee.redirects = nil
end
end
for set, n in pairs(sets) do
build_applyMod(build, nil, set, data.modsets[set], n, n)
end
return build
end
export function build_getConditionals(build)
local conditionals = {}
for pairs(build) as gear do
for pairs(gear) as stat do
if stat.conditionals then
for pairs(stat.conditionals) as conditional do
if not conditionals[conditional.name] and not conditional.consteval then
conditionals[conditional.name] = {
type = conditional.type,
source = conditional.source,
proc_chance = conditional.proc_chance or 1,
max_stacks = conditional.max_stacks or 1
}
end
end
end
end
end
return conditionals
end
local function finalise_dmg(gear)
local base_dmg = gear.dmg_impact + gear.dmg_puncture + gear.dmg_slash + gear.dmg_heat + gear.dmg_cold + gear.dmg_electricity + gear.dmg_toxin + gear.dmg_blast + gear.dmg_radiation + gear.dmg_gas + gear.dmg_magnetic + gear.dmg_viral + gear.dmg_corrosive
if gear.dmgadd_gas ~= 0 then
gear.dmg_gas += base_dmg * gear.dmgadd_gas
end
if gear_dmgadd_impact ~= 0 then
gear.dmg_impact += base_dmg * gear.dmgadd_impact
end
if gear_dmgadd_puncture ~= 0 then
gear.dmg_puncture += base_dmg * gear.dmgadd_puncture
end
if gear_dmgadd_slash ~= 0 then
gear.dmg_slash += base_dmg * gear.dmgadd_slash
end
if gear_dmgadd_heat ~= 0 then
gear.dmg_heat += base_dmg * gear.dmgadd_heat
end
if gear_dmgadd_cold ~= 0 then
gear.dmg_cold += base_dmg * gear.dmgadd_cold
end
if gear_dmgadd_electricity ~= 0 then
gear.dmg_electricity += base_dmg * gear.dmgadd_electricity
end
if gear_dmgadd_toxin ~= 0 then
gear.dmg_toxin += base_dmg * gear.dmgadd_toxin
end
if gear_dmgadd_blast ~= 0 then
gear.dmg_blast += base_dmg * gear.dmgadd_blast
end
if gear_dmgadd_radiation ~= 0 then
gear.dmg_radiation += base_dmg * gear.dmgadd_radiation
end
if gear_dmgadd_gas ~= 0 then
gear.dmg_gas += base_dmg * gear.dmgadd_gas
end
if gear_dmgadd_magnetic ~= 0 then
gear.dmg_magnetic += base_dmg * gear.dmgadd_magnetic
end
if gear_dmgadd_viral ~= 0 then
gear.dmg_viral += base_dmg * gear.dmgadd_viral
end
if gear_dmgadd_corrosive ~= 0 then
gear.dmg_corrosive += base_dmg * gear.dmgadd_corrosive
end
gear.crit_fail_tier = gear.crit_chance // 1
gear.crit_tier = gear.crit_fail_tier + 1
gear.crit_tier_damage = 1 + (gear.crit_tier * (gear.crit_damage - 1))
gear.crit_tier_chance = gear.crit_chance % 1
gear.crit_fail_tier_damage = 1 + (gear.crit_fail_tier * (gear.crit_damage - 1))
gear.crit_fail_tier_chance = 1 - gear.crit_tier_chance
gear.crit_enhance_tier = gear.crit_tier + 1
gear.crit_enhance_tier_damage = 1 + (gear.crit_enhance_tier * (gear.crit_damage - 1))
-- crit_enhance_tier_chance takes from crit_tier_chance
gear.crit_enhance_tier_chance = gear.crit_tier_chance * gear.crit_enhance_chance
gear.crit_tier_chance -= gear.crit_enhance_tier_chance
if gear.crit_fail_tier ~= 0 then
-- crit_enhance_chance takes from crit_fail_tier_chance to add to crit_tier_chance
local enhanced_fail_crit_chance = gear.crit_fail_tier_chance * gear.crit_enhance_chance
gear.crit_tier_chance += enhanced_fail_crit_chance
gear.crit_fail_tier_chance = gear.crit_fail_tier_chance * (1 - gear.crit_enhance_chance)
end
gear.crit_damage_avg = (gear.crit_tier_chance * gear.crit_tier_damage) + (gear.crit_fail_tier_chance * gear.crit_fail_tier_damage) + (gear.crit_enhance_chance * gear.crit_enhance_tier_damage)
gear.dmgadd_impact = nil
gear.dmgadd_puncture = nil
gear.dmgadd_slash = nil
gear.dmgadd_heat = nil
gear.dmgadd_cold = nil
gear.dmgadd_electricity = nil
gear.dmgadd_toxin = nil
gear.dmgadd_blast = nil
gear.dmgadd_radiation = nil
gear.dmgadd_gas = nil
gear.dmgadd_magnetic = nil
gear.dmgadd_viral = nil
gear.dmgadd_corrosive = nil
end
export function build_applyConditionals(build, to_apply)
local outbuild = {}
for gear_name, gear in pairs(build) do
outbuild[gear_name] = {}
for stat_name, stat in pairs(gear) do
outbuild[gear_name][stat_name] = build_applyStatConditionals(build, stat, to_apply)
end
end
if outbuild.powersuit then
outbuild.powersuit.power_health = outbuild.powersuit.power * outbuild.powersuit.power_to_health_efficiency
outbuild.powersuit.armor_damage_reduction = outbuild.powersuit.armor / (outbuild.powersuit.armor + 300)
outbuild.powersuit.effective_health = outbuild.powersuit.health / (1 - outbuild.powersuit.armor_damage_reduction)
outbuild.powersuit.effective_power_health = outbuild.powersuit.power_health / (1 - outbuild.powersuit.armor_damage_reduction)
outbuild.powersuit.effective_health_incl_power = outbuild.powersuit.effective_health + outbuild.powersuit.effective_power_health
outbuild.powersuit.movement_speed_mps = outbuild.powersuit.movement_speed * 6
outbuild.powersuit.sprint_speed_mps = outbuild.powersuit.sprint_speed * 7.5
end
if outbuild.primary then
finalise_dmg(outbuild.primary)
end
if outbuild.secondary then
finalise_dmg(outbuild.secondary)
end
if outbuild.melee then
finalise_dmg(outbuild.melee)
end
return outbuild
end
export function build_applyNoConditionals(build)
return build_applyConditionals(build, {})
end
export function build_applyAllConditionals(build)
local to_apply = {}
for conditional_type, conditional in pairs(build_getConditionals(build)) do
to_apply[conditional_type] = conditional.max_stacks
end
return build_applyConditionals(build, to_apply)
end
export function evaluate_build(build)
return build_applyNoConditionals(parse_build(build))
end
-- Evaluation for damage against enemies
local function level_scaling_trans(base_level, start, _end, level)
if level - base_level < start then
return 0
end
if level - base_level > _end then
return 1
end
local T = (level - base_level - start) / (_end - start)
return 3 * T ^ 2 - 2 * T ^ 3
end
local function enemy_getArmor(enemy, level)
if level < enemy.base_level then
level = enemy.base_level
end
local old_armor = 1 + 0.005 * (level - enemy.base_level) ^ 1.75
local new_armor = 1 + 0.40 * (level - enemy.base_level) ^ 0.75
local armor_mult = old_armor * (1 - level_scaling_trans(enemy.base_level, 70, 80, level)) + new_armor * level_scaling_trans(enemy.base_level, 70, 80, level)
return enemy.armor * armor_mult
end
local function enemy_getEffectiveDamageOfType(enemy, level, damage_type, amount)
local health_offset = (data.resistances[enemy.health_resistance][damage_type] or 0) * -1
local armor_offset = (data.resistances[enemy.armor_resistance][damage_type] or 0) * -1
local armor = enemy_getArmor(enemy, level)
return amount * (1 + health_offset) * (1 + armor_offset) * 300 / (300 + armor * (1 - armor_offset))
end
local function enemy_getEffectiveDamage(enemy, level, gear, dmg_multiplier)
return enemy_getEffectiveDamageOfType(enemy, level, "DT_IMPACT", gear.dmg_impact * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_PUNCTURE", gear.dmg_puncture * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_SLASH", gear.dmg_slash * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_FIRE", gear.dmg_heat * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_FREEZE", gear.dmg_cold * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_ELECTRICITY", gear.dmg_electricity * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_POISON", gear.dmg_toxin * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_EXPLOSION", gear.dmg_blast * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_RADIATION", gear.dmg_radiation * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_GAS", gear.dmg_gas * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_MAGNETIC", gear.dmg_magnetic * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_VIRAL", gear.dmg_viral * dmg_multiplier)
+ enemy_getEffectiveDamageOfType(enemy, level, "DT_CORROSIVE", gear.dmg_corrosive * dmg_multiplier)
end
export function calculate_damage(enemy, level, gear)
enemy = data.enemies[enemy] or error("Unknown enemy: "..enemy)
return {
worst = enemy_getEffectiveDamage(enemy, level, gear, gear.crit_fail_tier_damage),
best = enemy_getEffectiveDamage(enemy, level, gear, gear.crit_enhance_chance > 0 ? gear.crit_enhance_tier_damage : gear.crit_tier_damage),
avg = enemy_getEffectiveDamage(enemy, level, gear, gear.crit_damage_avg),
}
end
-- Compact Share
local function joaat(str)
local hash = 0
if str ~= nil then
for i = 1, #str do
hash = (hash + str:byte(i)) & 0xff_ff_ff_ff
hash = (hash + (hash << 10)) & 0xff_ff_ff_ff
hash = (hash ~ (hash >> 6)) & 0xff_ff_ff_ff
end
hash = (hash + (hash << 3)) & 0xff_ff_ff_ff
hash = (hash ~ (hash >> 11)) & 0xff_ff_ff_ff
hash = (hash + (hash << 15)) & 0xff_ff_ff_ff
end
return hash
end
export function powersuit_name_to_id(name)
return joaat(name) & 0xff_ff
end
export function powersuit_id_to_name(id)
if id ~= 0 then
for key in pairs(data.powersuits) do
if powersuit_name_to_id(key) == id then
return key
end
end
end
return nil
end
export function weapon_name_to_id(name)
return joaat(name) & 0xf_ff_ff
end
export function weapon_id_to_name(id)
if id ~= 0 then
for key in pairs(data.weapons) do
if weapon_name_to_id(key) == id then
return key
end
end
end
return nil
end
export function mod_name_to_id(name)
return joaat(name) & 0xf_ff_ff
end
export function mod_id_to_name(id)
if id ~= 0 then
for key in pairs(data.mods) do
if mod_name_to_id(key) == id then
return key
end
end
end
return nil
end
-- We use the name 'data' here to refer to the binary data, not our data table.
-- @pluto_warnings disable-var-shadow
local function export_mods(mods)
local data = ""
if mods then
for mods as mod do
local id = mod_name_to_id(mod.name)
data ..= string.pack("I3", (id << 4) | (mod.rank or 0))
end
end
return string.pack("s1", data)
end
export function export_build(inbuild)
if not is_inited() then init() end
local data = (inbuild.operator?.phoenix_talons ? "\x01" : "\x00")
local id = powersuit_name_to_id(inbuild.powersuit?.name)
data ..= string.pack("I2", id)
if id ~= 0 then
data ..= string.pack("I1", inbuild.powersuit?.rank or 30)
end
data ..= export_mods(inbuild.powersuit.mods)
data ..= string.pack("I3", weapon_name_to_id(inbuild.primary?.name))
data ..= export_mods(inbuild.primary.mods)
data ..= string.pack("I3", weapon_name_to_id(inbuild.secondary?.name))
data ..= export_mods(inbuild.secondary?.mods)
data ..= string.pack("I3", weapon_name_to_id(inbuild.melee?.name))
data ..= export_mods(inbuild.melee?.mods)
if inbuild.operator?.phoenix_talons then
data ..= string.pack("I1", inbuild.operator.phoenix_talons + 1)
end
return data
end
local function import_mods(data, i)
local mods = {}
local ret_i
data, ret_i = string.unpack("s1", data, i)
i = 1
while i < #data do
local val
val, i = string.unpack("I3", data, i)
local mod = {
name = mod_id_to_name(val >> 4),
rank = val & 0xf
}
assert(mod.name)
mods[#mods + 1] = mod
end
return mods, ret_i
end
export function import_build(data)
if not is_inited() then init() end
local format = data:byte(1)
assert(format == 0 or format == 1)
local inbuild = {}
local i = 2
local id, mods, name
do
local rank
id, i = string.unpack("I2", data, i)
if id ~= 0 then
name = powersuit_id_to_name(id)
rank, i = string.unpack("I1", data, i)
end
mods, i = import_mods(data, i)
if name or #mods ~= 0 then
inbuild.powersuit = {
name = name,
rank = rank,
mods = mods
}
end
end
id, i = string.unpack("I3", data, i)
mods, i = import_mods(data, i)
name = weapon_id_to_name(id)
if name or #mods ~= 0 then
inbuild.primary = {
name = name,
mods = mods
}
end
id, i = string.unpack("I3", data, i)
mods, i = import_mods(data, i)
name = weapon_id_to_name(id)
if name or #mods ~= 0 then
inbuild.secondary = {
name = name,
mods = mods
}
end
id, i = string.unpack("I3", data, i)
mods, i = import_mods(data, i)