-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHelperFunctions.lua
985 lines (828 loc) · 34.5 KB
/
HelperFunctions.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
require('logger')
extdata = require('extdata')
equip_slots = {'main','sub','range','ammo','head','neck','left_ear','right_ear','body','hands','left_ring','right_ring','back','waist','legs','feet'}
augment_cache = setmetatable({}, {
__index = function(t, item)
return type(item) == 'table' and item.id and item.extdata and rawget(t, item.id .. item.extdata) or rawget(t, item)
end,
__newindex = function(t, item, value)
if not value or not value.type or not value.augments then return end
if value.type ~= 'Augmented Equipment' then
rawset(t, item.id .. item.extdata, false)
else
local augments = T(extdata_parse.augments):filter(function(a) return a ~= 'none' end)
rawset(t, item.id .. item.extdata, augments)
end
end,
})
cache = {
get_info
}
function calculate_enhancing_duration(player, spell, target, equipment, buffs)
--local spell_info, equipment, player, buffs = get_basic_info(spell, equipment)
if not (player or spell or target or equipment or buffs) then return end
local composure_modifier = get_base_enhancing_composure_modifier(player, spell, target, buffs)
local composure_count = 0
local base_duration = spell.duration or 0
local duration_modifier = 1
local duration_bonus = get_enhancing_duration_bonus(spell, player, buffs)
local augment_duration_modifier = 1
local perpetuance_modifier = buffs.Perpetuance and 2 or 1
local embolden_modifier = buffs.Embolden and (target.id == player.id and -0.5) or 1
for _, slot in ipairs(equip_slots) do
local item = windower.ffxi.get_items(equipment[slot .. '_bag'], equipment[slot])
local modifiers = enhancing_modifiers[item.id]
if modifiers then
for index, value in pairs(modifiers) do
if index == 1 then
duration_modifier = duration_modifier + value
elseif index == 'augment' then
augment_duration_modifier = augment_duration_modifier + value
elseif index == 'perpetuance' and buffs.Perpetuance then
perpetuance_modifier = perpetuance_modifier + value
elseif index == 'embolden' and buffs.Embolden then
embolden_modifier = embolden_modifier + value
elseif spell.english:startswith(index) then
duration_bonus = duration_bonus + value
end
end
end
if enhancing_relic_bonus[item.id] then
duration_bonus = duration_bonus + (player.merits.enhancing_magic_duration and (player.merits.enhancing_magic_duration * 3) or 0)
end
if composure_gear[item.id] then
composure_count = composure_count + 1
end
end
if buffs.Composure and target.id ~= player.id then
composure_modifier = composure_modifier + (composure_modifiers[composure_count] or 0)
end
-- TODO: Implement RUN Embolden. Be sure to account for Evasionist's Cape aug (variable)
local enhancing_duration = base_duration + duration_bonus
for _, modifier in ipairs({duration_modifier, augment_duration_modifier, perpetuance_modifier, embolden_modifier}) do
enhancing_duration = enhancing_duration * modifier
end
if enhancing_duration < (60 * 30) then
enhancing_duration = enhancing_duration * composure_modifier
if enhancing_duration > (60 * 30) then
enhancing_duration = 60 * 30
end
end
local modifiers = {
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier,
["Composure"] = composure_modifier,
["Perpetuance"] = perpetuance_modifier,
["Embolden"] = embolden_modifier
}
return enhancing_duration, modifiers
end
function calculate_enfeebling_duration(player, spell, target, equipment, buffs)
if not (player or spell or target or equipment or buffs) then return end
local current_time = socket.gettime()
local composure_modifier = 1
local composure_count = 0
local saboteur_modifier = get_base_saboteur_modifier(spell, target, buffs, mob_data.NMs or L{})
local duration_modifier = 1
local augment_duration_modifier = 1
local base_duration = (spell.duration or 0)
local duration_bonus = (player.main_job == "RDM" and player.merits.enfeebling_magic_duration and (player.merits.enfeebling_magic_duration * 6) or 0)
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].enfeebling_magic_duration or 0)
if buffs.Stymie then
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].stymie_effect or 0)
end
for _, slot in ipairs(equip_slots) do
local item = windower.ffxi.get_items(equipment[slot .. '_bag'], equipment[slot])
local modifiers = enfeebling_modifiers[item.id]
if modifiers then
for index, value in pairs(modifiers) do
if index == 1 then
duration_modifier = duration_modifier + value
elseif index == 'augment' then
augment_duration_modifier = augment_duration_modifier + value
elseif index == 'saboteur' and buffs.saboteur then
saboteur_modifier = saboteur_modifier + value
end
end
end
if enfeebling_relic_bonus[item.id] then
duration_bonus = duration_bonus + (player.merits.enfeebling_magic_duration and (player.merits.enfeebling_magic_duration * 6) or 0)
end
if composure_gear:contains(item.id) then
composure_count = composure_count + 1
end
end
composure_modifier = composure_modifier + (composure_modifiers[composure_count] or 0)
local duration = (base_duration * saboteur_modifier) + duration_bonus
for _, modifier in ipairs({duration_modifier, augment_duration_modifier, composure_modifier}) do
duration = duration * modifier
end
duration = math.floor(duration)
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end
)
local modifiers = {
["Saboteur"] = saboteur_modifier,
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier,
["Composure"] = composure_modifier
}
return duration_map, modifiers
end
-- Song Calculations
-- Reference page: https://www.bg-wiki.com/ffxi/Category:Song#Song_Effect_Duration
function calculate_song_duration(player, spell, target, equipment, buffs)
if not (player or spell or target or equipment or buffs) then return end
local current_time = socket.gettime()
-- Troubadour is applied after all other modifiers
local duration_bonus = 0
local duration_modifier = 1
local augment_duration_modifier = 1
local troubadour_modifier = 1
local soul_voice_modifier = 1
local base_duration = (spell.duration or 0)
local equipped_items = {}
local equipped_items = fetch_equipped_items(equipment)
-- Standard modifiers
for _, item in ipairs(equipped_items) do
local modifiers = song_modifiers[item.id]
if modifiers then
for song, index in pairs(modifiers) do
if (not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if spell.english:contains(song) then
duration_modifier = duration_modifier + index.value
elseif index == 'All Songs' or 'Increases song effect duration' then
duration_modifier = duration_modifier + index.value
end
end
end
end
end
--Augments
-- All Songs
duration_modifier = duration_modifier + search_augments(equipped_items, 'All Songs'):reduce(function(total, aug) return total + ((not aug.sign or aug.sign=='+') and aug.value or (aug.value * -1)) end, 0) * 0.1
if buffs.Nightingale and next(search_augments(equipped_items, 'Enhances "Nightingale" effect')) then
duration_bonus = duration_bonus + (player.merits.nightingale or 0) * 4
end
if buffs.Troubadour then
troubadour_modifier = 2
duration_bonus = duration_bonus + (player.job_points.brd.troubadour_effect or 0) * 2
if next(search_augments(equipped_items, 'Enhances "Troubadour" effect')) then
duration_bonus = duration_bonus + (player.merits.troubadour or 0) * 4
end
end
-- Job point bonus conditions:
-- clarion_call_effect (2s/per); tenuto_effect (2s/per); lullaby_duration; marcato_effect
if buffs["Clarion Call"] then
duration_bonus = duration_bonus + (player.job_points.brd.clarion_call_effect or 0) * 2
end
-- TODO: Verify this applies only to self
if buffs.Tenuto and target.id == player.id then
duration_bonus = duration_bonus + (player.job_points.brd.tenuto_effect or 0) * 2
end
if spell.english:contains("Lullaby") then
duration_bonus = duration_bonus + (player.job_points.brd.lullaby_duration or 0)
end
-- Soul Voice doubles the duration of Hymnus, Mazurka, and Scherzo, but is not compatible with Marcato.
if spell.english:endswith("Hymnus") or spell.english:endswith("Mazurka") or spell.english:endswith("Scherzo") then
if buffs["Soul Voice"] then
soul_voice_modifier = 2
elseif buffs.Marcato then
soul_voice_modifier = 1.5
end
end
-- TODO: Test to confirm if both SV and Marcato are in use that the JP duration bonus for Marcato would still apply
if buffs.Marcato then
duration_bonus = duration_bonus + (player.job_points.brd.marcato_effect or 0)
end
-- Flat bonuses and percentage based bonuses are both applied independently, then multiplied by Troubadour's doubling bonus. Soul voice, where applicable is multiplicative with this term.
local duration = (base_duration * duration_modifier + duration_bonus) * troubadour_modifier * soul_voice_modifier
duration = math.floor(duration)
-- Applies to debuff songs, e.g. Elegy
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
local modifiers = {
["Troubadour"] = troubadour_modifier,
["Soul Voice"] = soul_voice_modifier,
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier
}
if spell.targets == 32 then
return duration_map, modifiers
else
-- if spell.targets == 1 then
return duration, modifiers
end
end
function calculate_blue_magic_duration(player, spell, target, equipment, buffs)
local equipped_items = fetch_equipped_items(equipment)
local base_duration = spell.duration or 0
local duration_modifier = 1
local duration_bonus = 0
-- Unbridled Learning Effect II (JP, Carcharian Verve is unique here)
if not spell.english == 'Carcharian Verve' then
duration_modifier = duration_modifier + (player.job_points.blu['Unbridled Learning Effect II '] or 0) * 0.01
end
-- Diffusion merits, 20 for raw (5 for each past the first) and mirage+ charuqs [aug] 5/merit
if player.merits['Diffusion'] then
duration_modifier = 1 + (player.merits['Diffusion'] - 1) * 0.05
duration_modifier = duration_modifier +
((player.merits['Diffusion'] - 1)) *
search_augments(equipped_items, 'Enhances "Diffusion" effect'):reduce(function(total, aug) return total + ((not aug.sign or aug.sign=='+') and aug.value or (aug.value * -1)) end, 0) * 0.05
end
local duration = (base_duration * duration_modifier + duration_bonus)
duration = math.floor(duration)
local modifiers = {
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier
}
if spell.targets == 32 then
return duration_map, modifiers
else
-- if spell.targets == 1 then
return duration, modifiers
end
end
-- Summoner Blood Pacts. This needs to be fired on aftercast of the pact going off!
function calculate_bp_duration(player, pact, target, equipment, buffs)
if not (player or spell or target or equipment or buffs) then return end
local current_time = socket.gettime()
local duration_bonus = 0
local duration_modifier = 1
local base_duration = (pact.duration or 0)
-- Perfect Defense is the only Rage pact with variable duration
if pact.type == 'BloodPactRage' and pact.english ~= 'Perfect Defense' then return base_duration end
-- We don't actually care about equipment for this one since skill is pulled directly from memory
--[[ For most abilities the duration is given by:
base_duration + skill_over_300/100
Known exceptions: 15 minutes: Aerial Armor, Earthen Ward,
Perfect Defense, Reraise II, whatever Atomos does
Filter on targets == 32 for enfeebling pacts ]]
-- TODO: Account for Atomos buff stealing
if (player.skills['summoning_magic'] >= 300) and (pact.duration >= 60) and (pact.duration <= 180)
and not pact.targets.Enemy then
duration_bonus = duration_bonus + player.skills['summoning_magic'] - 300
elseif pact.english == 'Perfect Defense' then
duration_bonus = player.skills['summoning_magic'] / 20
if duration_bonus > 30 then duration_bonus = 30 end
end
-- Astral Conduit Job Points
if player.main_job == "SMN" and buffs['Astral Conduit'] then
duration_modifier = duration_modifier + ((player.job_points.smn['Astral Conduit'] or 0) * 0.01)
end
duration = (base_duration + duration_bonus) * duration_modifier
local modifiers = {
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier
}
return duration, modifiers
end
-- Job Ability Calculations
function calculate_ja_duration(player, ability, target, equipment, buffs)
if not (player or ability or target or equipment or buffs) then return end
local current_time = socket.gettime()
local equipped_items = fetch_equipped_items(equipment)
local base_duration = (ability.duration or 0)
local duration_bonus = 0
local duration_modifier = 1
-- Merit or Job Points
job_ability_table = {
['Tomahawk'] = {
trigger='Tomahawk',
value=15,
initial=true}, -- This is an indication to use # of points in the category -1 as a multiplier
['Fealty'] = {
trigger='Fealty',
value=5,
initial=true},
['Killer Instinct'] = {
trigger='Killer Instinct',
value=10,
initial=true},
['Angon'] = {
trigger='Angon',
value=15,
initial=true
}
}
--[[ Special cases that cannot currently be addressed
['Invigorate'] = { -- Maybe special case
trigger='Chakra',
value=24
buff='Regen'},
['Penance'] = {
trigger='Chi Blast',
value=20,
buff='Store TP' -- Buff ID 227
multiplier=-1},
]]
-- General Purpose
for merit_title, index in pairs(job_ability_table) do
if index.trigger == ability.english and player.merits[merit_title:gsub(' ', '_'):lower()] then
local adjustment = index.initial and 1 or 0
duration_bonus = duration_bonus + (player.merits[merit_title:gsub(' ', '_'):lower()] - adjustment) * index.value
end
end
-- White Mage
-- Black Mage
-- Red Mage
-- Thief
-- Paladin
-- Dark Knight
-- Beastmaster
-- Bard
-- Ranger
-- Samurai
-- Ninja
-- Dragoon
if ability.english == "Dragon Breaker" then
-- +1 second per job point
duration_bonus = duration_bonus + player.job_points.drg.dragon_breaker_effect or 0
end
-- Summoner
-- Blue Mage
-- Puppetmaster
-- Scholar
-- Geomancer
-- Equipment
for _, item in ipairs(equipped_items) do
local modifiers = ja_modifiers[item.id]
if modifiers then
for key, index in pairs(modifiers) do
if key:contains(ability.english) and key:contains('duration') and
(not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if index.percent == true then
duration_modifier = duration_modifier + index.value
else
duration_bonus = duration_bonus + index.value
end
end
end
end
end
local duration = (base_duration * duration_modifier) + duration_bonus
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
if ability.targets == 32 then
return duration_map, modifiers
else
-- if ability.targets == 1 then
return duration, modifiers
end
end
-- Corsair Roll Calculations
function calculate_roll_duration(player, ability, target, equipment, buffs)
if not (player or ability or target or equipment or buffs) then return end
local current_time = socket.gettime()
local equipped_items = fetch_equipped_items(equipment)
local base_duration = (ability.duration or 0)
local duration_bonus = 0
local duration_modifier = 1
-- Merits and Job Points
-- Corsair
corsair_merit_modifiers = {
['Winning Streak'] = { -- Special case
trigger='Phantom Roll',
value=20,
initial=true}
}
for merit_title, index in pairs(corsair_merit_modifiers) do
local adjustment = index.initial and 1 or 0
duration_bonus = duration_bonus * (player.merits[merit_title:gsub(' ', '_'):lower()] - adjustment) * index.value
end
duration_bonus = (player.job_points.cor.phantom_roll_effect * 2) or 0
-- Equipment
for _, item in ipairs(equipped_items) do
local modifiers = ja_modifiers[item.id]
if modifiers then -- Everything else
for key, index in pairs(modifiers) do
if key:contains('Phantom Roll') and key:contains('duration') and
(not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if index.percent == true then
duration_modifier = duration_modifier + index.value
else
duration_bonus = duration_bonus + index.value
end
end
end
end
end
local duration = (base_duration + duration_bonus) * duration_modifier
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
if ability.targets == 32 then
return duration_map, modifiers
else
-- if ability.targets == 1 then
return duration, modifiers
end
end
-- Dancer
function calculate_dnc_duration(player, ability, target, equipment, buffs)
if not (player or ability or target or equipment or buffs) then return end
local current_time = socket.gettime()
local equipped_items = fetch_equipped_items(equipment)
local base_duration = (ability.duration or 0)
local duration_bonus = 0
local duration_modifier = 1
-- Merits and Job Points
if player.main_job == "DNC" then
if ability.type == 'Jig' then
duration_bonus = duration_bonus + (player.job_points.dnc['Jig Duration'] or 0) * 1
elseif ability.type == 'Samba' then
duration_bonus = duration_bonus + (player.job_points.dnc['Samba Duration'] or 0) * 2
-- Saber Dance
if buffs['Saber Dance'] then
duration_modifier = duration_modifier + (player.merits.saber_dance or 0) * 0.05
end
elseif ability.type == 'Step' then
duration_bonus = duration_bonus + (player.job_points.dnc['Step Duration'] or 0) * 1
end
end
-- Equipment
for _, item in ipairs(equipped_items) do
local modifiers = ja_modifiers[item.id]
if modifiers then
for key, index in pairs(modifiers) do
if key:contains('"' .. ability.type .. '" duration') and
(not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if index.percent == true then
duration_modifier = duration_modifier + index.value
else
duration_bonus = duration_bonus + index.value
end
end
end
end
end
-- Jig modifier cap
if ability.type == 'Jig' then
if (duration_modifier > 1.5) then duration_modifier = 1.5 end
end
local duration = (base_duration + duration_bonus) * duration_modifier
-- Step duration cap
local step_pairs = {
['Quickstep'] = 'Lethargic Daze',
['Box Step'] = 'Sluggish Daze',
['Stutter Step'] = 'Weakened Daze',
['Feather Step'] = 'Bewildered Daze'
}
if ability.type == 'Step' then
local mob = tracked_mobs[target.id]
if mob and mob:has_buffs() then
for _, buff in pairs(mob.buffs) do
if buff:get_buff_name():contains(step_pairs[ability.english]) then
duration = duration - 30 -- Only initial strike lasts for 60 base seconds
if (buff:get_remaining_duration_in_seconds() + duration) > (120 + duration_bonus) then
duration = 120 + duration_bonus
else
duration = buff:get_remaining_duration_in_seconds() + duration
end
end
end
end
end
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
if ability.targets == 32 then
return duration_map, modifiers
else
-- if ability.targets == 1 then
return duration, modifiers
end
end
-- Rune Fencer
function calculate_run_duration(player, ability, target, equipment, buffs)
if not (player or ability or target or equipment or buffs) then return end
local current_time = socket.gettime()
local equipped_items = fetch_equipped_items(equipment)
local base_duration = (ability.duration or 0)
local duration_bonus = 0
local duration_modifier = 1
local player_buffs = nil
local rune_buff_ids = S{523, 524, 525, 526, 527, 528, 529, 530}
local current_runes = T(tracked_mobs[player.id].buffs:filter(function(buff) return rune_buff_ids:contains(buff:get_buff_id()) end))
if player.main_job == 'RUN' then
-- Merit points
if ability.english == 'Rayke' then
duration_bonus = duration_bonus + ((player.merits.rayke -1) * 3)
-- Job Points
elseif ability.english == 'Vallation' or ability.english == 'Valiance' then
duration_bonus = duration_bonus + (player.job_points.run['Vallation Duration'] or 0)
elseif player.job_points.run[ability.english .. ' Effect Duration'] then
duration_bonus = (player.job_points.run[ability.english .. ' Effect Duration'] or 0)
end
end
-- Consume all runes with Gambit and Rayke
if ability.english == 'Gambit' or ability.english == 'Rayke' then
for _, buff in pairs(current_runes) do
if(rune_buff_ids:contains(buff:get_buff_id())) then
tracked_mobs[player.id]:remove_buff(buff:get_buff_id(), buff:get_spell_id())
end
end
end
-- Equipment
for _, item in ipairs(equipped_items) do
local modifiers = run_modifiers[item.id]
if modifiers then
for key, index in pairs(modifiers) do
if key:contains('"' .. ability.english .. '" duration') and
(not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if index.percent == true then
duration_modifier = duration_modifier + index.value
else
duration_bonus = duration_bonus + index.value
end
end
end
end
end
local duration = (base_duration + duration_bonus) * duration_modifier
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
if ability.targets == 32 then
return duration_map, modifiers
else
-- if ability.targets == 1 then
return duration, modifiers
end
end
-- Note: This covers Swipe and Lunge specifically
function effusion(player, ability)
local rune_buff_ids = S{523, 524, 525, 526, 527, 528, 529, 530}
local current_runes = T(tracked_mobs[player.id].buffs:filter(function(buff) return rune_buff_ids:contains(buff:get_buff_id()) end))
if ability.english == 'Swipe' then
-- TODO: Replace with the 'remove newest' function once implemented
tracked_mobs[player.id]:subtract_rune_buff()
else -- Lunge
for _, buff in pairs(current_runes) do
if(rune_buff_ids:contains(buff:get_buff_id())) then
tracked_mobs[player.id]:remove_buff(buff:get_buff_id(), buff:get_spell_id())
end
end
end
end
--[[ Generic stub for future calculators
function calculate_category_duration(player, ability, target, equipment, buffs)
if not (player or ability or target or equipment or buffs) then return end
local current_time = socket.gettime()
local equipped_items = fetch_equipped_items(equipment)
local base_duration = (ability.duration or 0)
local duration_bonus = 0
local duration_modifier = 1
-- Merits and Job Points
if player.main_job == "FOO" then
player.job_points.charlie['bar']
player.merits.alice_bob
end
-- Equipment
for _, item in ipairs(equipped_items) do
local modifiers = ja_modifiers[item.id]
if modifiers then
for key, index in pairs(modifiers) do
if key:contains('"' .. ability.type .. '" duration') and
(not index.condition) or (index.condition and conditions[index.condition](get_world_info(), buffs)) then
if index.percent == true then
duration_modifier = duration_modifier + index.value
else
duration_bonus = duration_bonus + index.value
end
end
end
end
end
local duration = (base_duration + duration_bonus) * duration_modifier
local duration_map = table.map(resist_state_modifiers,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end)
if ability.targets == 32 then
return duration_map, modifiers
else
-- if ability.targets == 1 then
return duration, modifiers
end
end
]]
function get_base_saboteur_modifier(spell, target, buffs, nm_table)
local saboteur_modifier = 1
if buffs.Saboteur then
if nm_table:contains(target:get_name()) then
saboteur_modifier = 1.25
else
saboteur_modifier = 2
end
end
return saboteur_modifier
end
function get_base_enhancing_composure_modifier(player, spell, target, buffs)
local composure_modifier = 1
if buffs.Composure and target.id == player.id then
composure_modifier = 3
end
return composure_modifier
end
function get_enhancing_duration_bonus(spell, player, buffs)
local duration_bonus = 0
if player.main_job == "RDM" then
if player.merits.enhancing_magic_duration then
duration_bonus = duration_bonus + (player.merits.enhancing_magic_duration * 6)
end
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].enhancing_magic_duration or 0)
elseif player.main_job == "SCH" then
if spell.english:startswith("Regen") and (buffs["Light Arts"] or buffs["Addendum: White"]) then
local light_arts_bonus = math.floor((player.main_job_level - 1) / 4) * 2
if buffs["Tabula Rasa"] then
light_arts_bonus = math.floor(light_arts_bonus * 1.5)
end
duration_bonus = duration_bonus + light_arts_bonus
if player.job_points[player.main_job:lower()].light_arts_effect then
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].light_arts_effect * 3)
end
end
elseif player.main_job == "WHM" then
if spell.english:startswith("Regen") then
if player.job_points[player.main_job:lower()].regen_duration then
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].regen_duration * 3)
end
end
else
end
return duration_bonus
end
function update_gear_map()
-- TODO: Look at inventory and update augmented gear maps
end
function get_player_buffs(player)
player = player or windower.ffxi.get_player()
if not player or not player.buffs then return {} end
local buffs = T{}
for _, buff_id in pairs(player.buffs) do
buffs[buff_id] = (buffs[buff_id] or 0) + 1
local buff_info = res.buffs[buff_id]
if buff_info then
local name = buff_info.english:lower()
buffs[name] = (buffs[name] or 0) + 1
end
end
setmetatable(buffs, {
__index = function(t, key)
if key and type(key) == 'string' then
key = key:lower()
end
return rawget(t, key)
end
})
return buffs
end
function convert_seconds_to_timer(duration)
local hours, minutes, seconds
hours = math.floor(duration / 3600)
minutes = math.floor(duration % 3600 / 60)
seconds = math.floor(duration % 60)
return string.format("%02d:%02d:%02d", hours, minutes, seconds)
end
function get_time_utc(time)
if not time then
return os.date("'!%Y-%m-%dT%H:%M:%SZ'")
else
return os.date("'!%Y-%m-%dT%H:%M:%SZ'", time)
end
end
function get_time_stamp(time)
if not time then
return os.date("%X")
else
return os.date("%X", time)
end
end
function fetch_equipped_items(equipment)
local equipped_items = {}
for _, slot in ipairs(equip_slots) do
local item = item_with_metadata(windower.ffxi.get_items(equipment[slot .. '_bag'], equipment[slot]))
table.insert(equipped_items, item)
end
return equipped_items
end
metadata_definition = {
__index = function(t, index)
if index ~= 'augments' then
return rawget(t, index)
else
local augments = augment_cache[t]
if augments == nil then
local extdata_parse = extdata.decode(t)
if extdata_parse and extdata_parse.type == 'Augmented Equipment' then
augments = T(extdata_parse.augments):filter(function(a) return a ~= 'none' end)
end
augment_cache[t] = augments
rawset(t, 'augments', augments)
end
return augment_cache[t]
end
end
}
function item_with_metadata(item)
return setmetatable(item, metadata_definition)
end
function search_augments(equipped_items, query)
local found_augments = {}
for _, item in ipairs(equipped_items) do
if item.augments then
for _, line in ipairs(item.augments) do
local match, sign, value, percent = line:match('"?('..query..')"?%s*([+%-]?)([%dVI]*)(%%?)')
if match then
local aug = T{match=match, sign=sign, value=value, percent=percent} --this could probably get cached somewhere too
table.insert(found_augments, aug)
end
end
end
end
return(T(found_augments))
end
function unpack_equipment_inf0(equipment)
if not equipment then return end
local equip_info = T{}
for _, slot in ipairs(equip_slots) do
local item = windower.ffxi.get_items(equipment[slot .. "_bag"], equipment[slot])
if item and item.extdata then
local extdata_unpacked = extdata.decode(item)
item.extdata_unpacked = extdata_unpacked.type == "Augmented Equipment" and extdata_unpacked
end
if item then
equip_info:append({
i = item.id,
a = item.extdata_unpacked and table.filter(item.extdata_unpacked.augments, (function(augment) return augment ~= "none" end)) or nil
})
end
end
equipment.unpacked = equip_info
return equipment
end
-- This table will calculate at the time it is called, for the keys it is called
conditions = {
['In Dynamis:'] = function(info, buffs)
local dynamis_zones = S{39,40,41,42,134,135,185,186,187,188,294,295,296,297}
local ffxi_info = windower.ffxi.get_info()
return dynamis_zones:contains(ffxi_info.zone)
end,
['Assault:'] = function(info, buffs)
local assault_zones = S{69,66,63,56,55,77}
local ffxi_info = windower.ffxi.get_info()
return assault_zones:contains(ffxi_info.zone)
end,
-- Conditions which expect an argument will need to be handled separately
['Reives:'] = function(info, buffs)
return buffs['Reive Mark']
end,
['Nighttime:'] = function(info, buffs)
local ffxi_info = windower.ffxi.get_info()
return (ffxi_info['time'] < 360) or (ffxi_info['time'] >= 1080)
end,
['Dusk to Dawn:'] = function(info, buffs)
local ffxi_info = windower.ffxi.get_info()
return (ffxi_info['time'] < 420) or (ffxi_info['time'] >= 1020)
end,
['Daytime:'] = function(info, buffs)
local ffxi_info = windower.ffxi.get_info()
return (ffxi_info['time'] >= 360) and (ffxi_info['time'] < 1080)
end
-- To be implemented
-- Set:
-- Days of the week; firesday = 0
-- Weather:
-- Moon phase
-- vs enemy types
-- Citizenship
-- Nation control
-- Latent Effect:
-- Poison:
-- Paralysis:
-- Besieged:
-- Salvage:
-- Unity Ranking:
}
function get_world_info()
local info = cache.get_info
if not info then
info = windower.ffxi.get_info()
cache.get_info = info
end
end