forked from Celther-FFXI/GearSwap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSel-Utility.lua
2618 lines (2313 loc) · 97.8 KB
/
Sel-Utility.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
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- __________.__ ________ __ .__.__ __ __ .__ .__ _____.__.__
-- \______ | | ____ _____ ______ ____ \______ \ ____ ____ _____/ |_ ____ __| _|___/ |_ _/ |_| |__ |__| ______ _/ ____|__| | ____
-- | ___| | _/ __ \\__ \ / ____/ __ \ | | \ / _ \ / \ / _ \ __\ _/ __ \ / __ || \ __\ \ __| | \| |/ ___/ \ __\| | | _/ __ \
-- | | | |_\ ___/ / __ \_\___ \\ ___/ | ` ( <_> ) | | ( <_> | | \ ___// /_/ || || | | | | Y | |\___ \ | | | | |_\ ___/
-- |____| |____/\___ (____ /____ >\___ > /_______ /\____/ |___| /\____/|__| \___ \____ ||__||__| |__| |___| |__/____ > |__| |__|____/\___ > /\
-- \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
--
-- Please do not edit this file! Please do not edit this file! Please do not edit this file!
--
-- Editing this file will cause you to be unable to use Github Desktop to update!
--
-- Any changes you wish to make in this file you should be able to make by overloading. That is Re-Defining the same variables or functions in another file, by copying and
-- pasting them to a file that is loaded after the original file, all of my library files, and then job files are loaded first.
-- The last files to load are the ones unique to you. User-Globals, Charactername-Globals, Charactername_Job_Gear, in that order, so these changes will take precedence.
--
-- You may wish to "hook" into existing functions, to add functionality without losing access to updates or fixes I make, for example, instead of copying and editing
-- status_change(), you can instead use the function user_status_change() in the same manner, which is called by status_change() if it exists, most of the important
-- gearswap functions work like this in my files, and if it's unique to a specific job, user_job_status_change() would be appropriate instead.
--
-- Variables and tables can be easily redefined just by defining them in one of the later loaded files: autofood = 'Miso Ramen' for example.
-- States can be redefined as well: state.HybridMode:options('Normal','PDT') though most of these are already redefined in the gear files for editing there.
-- Commands can be added easily with: user_self_command(commandArgs, eventArgs) or user_job_self_command(commandArgs, eventArgs)
--
-- If you're not sure where is appropriate to copy and paste variables, tables and functions to make changes or add them:
-- User-Globals.lua - This file loads with all characters, all jobs, so it's ideal for settings and rules you want to be the same no matter what.
-- Charactername-Globals.lua - This file loads with one character, all jobs, so it's ideal for gear settings that are usable on all jobs, but unique to this character.
-- Charactername_Job_Gear.lua- This file loads only on one character, one job, so it's ideal for things that are specific only to that job and character.
--
--
-- If you still need help, feel free to contact me on discord or ask in my chat for help: https://discord.gg/ug6xtvQ
-- !Please do NOT message me in game about anything third party related, though you're welcome to message me there and ask me to talk on another medium.
--
-- Please do not edit this file! Please do not edit this file! Please do not edit this file!
-- __________.__ ________ __ .__.__ __ __ .__ .__ _____.__.__
-- \______ | | ____ _____ ______ ____ \______ \ ____ ____ _____/ |_ ____ __| _|___/ |_ _/ |_| |__ |__| ______ _/ ____|__| | ____
-- | ___| | _/ __ \\__ \ / ____/ __ \ | | \ / _ \ / \ / _ \ __\ _/ __ \ / __ || \ __\ \ __| | \| |/ ___/ \ __\| | | _/ __ \
-- | | | |_\ ___/ / __ \_\___ \\ ___/ | ` ( <_> ) | | ( <_> | | \ ___// /_/ || || | | | | Y | |\___ \ | | | | |_\ ___/
-- |____| |____/\___ (____ /____ >\___ > /_______ /\____/ |___| /\____/|__| \___ \____ ||__||__| |__| |___| |__/____ > |__| |__|____/\___ > /\
-- \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- General utility functions that can be used by any job files.
-- Outside the scope of what the main include file deals with.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- Buff utility functions.
-------------------------------------------------------------------------------------------------------------------
local cancel_spells_to_check = S{'Sneak','Stoneskin','Spectral Jig','Trance','Monomi: Ichi','Utsusemi: Ichi','Utsusemi: Ni','Diamondhide','Magic Barrier','Valiance'}
local cancel_types_to_check = S{'Waltz', 'Samba'}
-- Function to cancel buffs if they'd conflict with using the spell you're attempting.
-- Requirement: Must have Cancel addon installed and loaded for this to work.
function cancel_conflicting_buffs(spell, spellMap, eventArgs)
if cancel_spells_to_check:contains(spell.english) or cancel_types_to_check:contains(spell.type) then
if spell.english == 'Spectral Jig' and buffactive['Sneak'] then
cast_delay(0.2)
send_command('cancel sneak')
tickdelay = os.clock() + 1.5
elseif spell.english == 'Valiance' and buffactive['Vallation'] then
cast_delay(0.2)
send_command('cancel vallation')
tickdelay = os.clock() + 1.5
elseif (spell.english:startswith('Monomi') or (spell.english == 'Sneak' and spell.target.type == 'SELF')) and buffactive['Sneak'] then
send_command('cancel sneak')
elseif spell.english == ('Stoneskin') or spell.english == ('Diamondhide') or spell.english == ('Magic Barrier') then
send_command('@wait 1;cancel stoneskin')
elseif spell.english == 'Utsusemi: Ni' and player.main_job == 'NIN' and lastshadow == 'Utsusemi: San' then
if buffactive['Copy Image (4+)'] and conserveshadows then
add_to_chat(123,'Abort: You have four or more shadows.')
eventArgs.cancel = true
else
send_command('@wait '..utsusemi_ni_cancel_delay..';cancel copy image*')
end
elseif spell.english == 'Utsusemi: Ichi' and lastshadow ~= 'Utsusemi: Ichi' then
if (buffactive['Copy Image (3)'] or buffactive['Copy Image (4+)']) and conserveshadows then
add_to_chat(123,'Abort: You have three or more shadows.')
eventArgs.cancel = true
else
send_command('@wait '..utsusemi_cancel_delay..';cancel copy image*')
end
elseif (spell.english == 'Trance' or spell.type=='Waltz') and buffactive['Saber Dance'] then
cast_delay(0.2)
send_command('cancel saber dance')
tickdelay = os.clock() + 1.7
elseif spell.type=='Samba' and buffactive['Fan Dance'] then
cast_delay(0.2)
send_command('cancel fan dance')
tickdelay = os.clock() + 1.7
end
end
end
function notify_buffs(buff, gain)
if state.NotifyBuffs.value and NotifyBuffs:contains(buff) then
if gain then
windower.chat.input('/p '..buff:ucfirst()..' on me!')
else
windower.chat.input('/p '..buff:ucfirst()..' is off now.')
end
end
end
-- Function to make auto-translate work in windower.
-- Usage: windower.add_to_chat(207, 'Test ' .. auto_translate(command))
do
local cache = {}
auto_translate = function(term)
if not cache[term] then
local entry = res.auto_translates:with('english', term)
cache[term] = entry and 'CH>HC':pack(0xFD, 0x0202, entry.id, 0xFD) or term
end
return cache[term]
end
end
-- Some mythics have special durations for level 1 and 2 aftermaths
local special_aftermath_mythics = S{'Tizona', 'Kenkonken', 'Murgleis', 'Yagrush', 'Carnwenhan', 'Nirvana', 'Tupsimati', 'Idris'}
-- Call from job_precast() to setup aftermath information for custom timers.
function custom_aftermath_timers_precast(spell)
if spell.type == 'WeaponSkill' then
info.aftermath = {}
local relic_ws = data.weaponskills.relic[player.equipment.main] or data.weaponskills.relic[player.equipment.range]
local mythic_ws = data.weaponskills.mythic[player.equipment.main] or data.weaponskills.mythic[player.equipment.range]
local empy_ws = data.weaponskills.empyrean[player.equipment.main] or data.weaponskills.empyrean[player.equipment.range]
if not relic_ws and not mythic_ws and not empy_ws then
return
end
info.aftermath.weaponskill = spell.english
info.aftermath.duration = 0
info.aftermath.level = math.floor(player.tp / 1000)
if info.aftermath.level == 0 then
info.aftermath.level = 1
end
if spell.english == relic_ws then
info.aftermath.duration = math.floor(0.2 * player.tp)
if info.aftermath.duration < 20 then
info.aftermath.duration = 20
end
elseif spell.english == empy_ws then
-- nothing can overwrite lvl 3
if buffactive['Aftermath: Lv.3'] then
return
end
-- only lvl 3 can overwrite lvl 2
if info.aftermath.level ~= 3 and buffactive['Aftermath: Lv.2'] then
return
end
-- duration is based on aftermath level
info.aftermath.duration = 30 * info.aftermath.level
elseif spell.english == mythic_ws then
-- nothing can overwrite lvl 3
if buffactive['Aftermath: Lv.3'] then
return
end
-- only lvl 3 can overwrite lvl 2
if info.aftermath.level ~= 3 and buffactive['Aftermath: Lv.2'] then
return
end
-- Assume mythic is lvl 80 or higher, for duration
if info.aftermath.level == 1 then
info.aftermath.duration = (special_aftermath_mythics:contains(player.equipment.main) and 270) or 90
elseif info.aftermath.level == 2 then
info.aftermath.duration = (special_aftermath_mythics:contains(player.equipment.main) and 270) or 120
else
info.aftermath.duration = 180
end
end
end
end
-- Call from job_aftercast() to create the custom aftermath timer.
function custom_aftermath_timers_aftercast(spell)
if not spell.interrupted and spell.type == 'WeaponSkill' and
info.aftermath and info.aftermath.weaponskill == spell.english and info.aftermath.duration > 0 then
local aftermath_name = 'Aftermath: Lv.'..tostring(info.aftermath.level)
send_command('timers d "Aftermath: Lv.1"')
send_command('timers d "Aftermath: Lv.2"')
send_command('timers d "Aftermath: Lv.3"')
send_command('timers c "'..aftermath_name..'" '..tostring(info.aftermath.duration)..' down abilities/00027.png')
info.aftermath = {}
end
end
-------------------------------------------------------------------------------------------------------------------
-- Utility functions for changing spells and target types in an automatic manner.
-------------------------------------------------------------------------------------------------------------------
waltz_tp_cost = {['Curing Waltz'] = 200, ['Curing Waltz II'] = 350, ['Curing Waltz III'] = 500, ['Curing Waltz IV'] = 650, ['Curing Waltz V'] = 800}
-- Utility function for automatically adjusting the waltz spell being used to match HP needs and TP limits.
-- Handle spell changes before attempting any precast stuff.
function refine_waltz(spell, spellMap, eventArgs)
if not state.RefineWaltz.value or spell.type ~= 'Waltz' then return false end
local effective_tp = player.tp
if state.DefenseMode.value == 'None' and uses_waltz_legs then
effective_tp = player.tp + 50
end
if effective_tp < 200 then
add_to_chat(123, 'Abort: Insufficient TP ['..tostring(player.tp)..'] to waltz.')
eventArgs.cancel = true
return true
end
-- Don't modify anything for Healing Waltz or Divine Waltzes
if spell.english == "Healing Waltz" or spell.english == "Divine Waltz" or spell.english == "Divine Waltz II" then
return false
end
local newWaltz = spell.english
local waltzID
local missingHP
-- If curing ourself, get our exact missing HP
if spell.target.type == "SELF" then
missingHP = player.max_hp - player.hp
-- If curing someone in our alliance, we can estimate their missing HP
elseif spell.target.isallymember then
local target = find_player_in_alliance(spell.target.name)
local est_max_hp = target.hp / (target.hpp/100)
missingHP = math.floor(est_max_hp - target.hp)
if player.main_job == 'DNC' and state.Buff['Contradance'] then
missingHP = missingHP / 2
end
end
-- If we have an estimated missing HP value, we can adjust the preferred tier used.
if missingHP == nil then return end
local abil_recasts = windower.ffxi.get_ability_recasts()
if player.main_job == 'DNC' then
if missingHP < 40 and spell.target.name == player.name then
-- Not worth curing yourself for so little.
-- Don't block when curing others to allow for waking them up.
add_to_chat(123,'Abort: You have full HP!')
eventArgs.cancel = true
return true
elseif missingHP < 200 then
if abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
waltzID = 190
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
end
elseif missingHP < 600 then
if abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
elseif abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
elseif abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
waltzID = 190
end
elseif missingHP < 1100 then
if abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
elseif abil_recasts[188] < latency then
newWaltz = 'Curing Waltz IV'
waltzID = 193
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
end
elseif state.AutoContradanceMode.value and abil_recasts[229] < latency then
eventArgs.cancel = true
windower.chat.input('/ja "Contradance" <me>')
windower.chat.input:schedule(.5,'/ja "Curing Waltz III" '..spell.target.raw..'')
return true
elseif missingHP < 1500 then
if abil_recasts[188] < latency then
newWaltz = 'Curing Waltz IV'
waltzID = 193
elseif abil_recasts[189] < latency then
newWaltz = 'Curing Waltz V'
waltzID = 311
elseif abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
end
else
if abil_recasts[189] < latency then
newWaltz = 'Curing Waltz V'
waltzID = 311
elseif abil_recasts[188] < latency then
newWaltz = 'Curing Waltz IV'
waltzID = 193
elseif abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
end
end
elseif player.sub_job == 'DNC' then
if missingHP < 40 and spell.target.name == player.name then
-- Not worth curing yourself for so little.
-- Don't block when curing others to allow for waking them up.
add_to_chat(123,'Abort: You have full HP!')
eventArgs.cancel = true
return true
elseif missingHP < 150 then
if abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
waltzID = 190
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
end
elseif missingHP < 300 then
if abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
elseif abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
end
else
if abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
waltzID = 192
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
waltzID = 191
end
end
else
-- Not dnc main or sub; bail out
return false
end
local tpCost = waltz_tp_cost[newWaltz]
local downgrade
-- Downgrade the spell to what we can afford
if effective_tp < tpCost and not buffactive.trance then
--[[ Costs:
Curing Waltz: 200 TP
Curing Waltz II: 350 TP
Curing Waltz III: 500 TP
Curing Waltz IV: 650 TP
Curing Waltz V: 800 TP
Divine Waltz: 400 TP
Divine Waltz II: 800 TP
--]]
if effective_tp < 350 and abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
elseif effective_tp < 500 then
if abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
elseif abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
end
elseif effective_tp < 650 then
if abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
elseif abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
end
elseif effective_tp < 800 then
if abil_recasts[188] < latency then
newWaltz = 'Curing Waltz IV'
elseif abil_recasts[187] < latency then
newWaltz = 'Curing Waltz III'
elseif abil_recasts[186] < latency then
newWaltz = 'Curing Waltz II'
elseif abil_recasts[217] < latency then
newWaltz = 'Curing Waltz'
end
end
downgrade = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..newWaltz..'.'
end
if newWaltz ~= spell.english then
windower.chat.input('/ja "'..newWaltz..'" '..tostring(spell.target.raw))
if downgrade then
add_to_chat(122, downgrade)
end
eventArgs.cancel = true
add_to_chat(122,'Trying to cure '..tostring(missingHP)..' HP using '..newWaltz..'.')
return true
end
end
-------------------------------------------------------------------------------------------------------------------
-- Environment utility functions.
-------------------------------------------------------------------------------------------------------------------
-- Returns true if you're in a party solely comprised of Trust NPCs.
-- TODO: Do we need a check to see if we're in a party partly comprised of Trust NPCs?
function is_trust_party()
-- Check if we're solo
if party.count == 1 then
return false
end
-- If we're in an alliance, can't be a Trust party.
if alliance[2].count > 0 or alliance[3].count > 0 then
return false
end
-- Check that, for each party position aside from our own, the party
-- member has one of the Trust NPC names, and that those party members
-- are flagged is_npc.
for i = 2,6 do
if party[i] then
if not data.npcs.trusts:contains(party[i].name) then
return false
end
if party[i].mob and party[i].mob.is_npc == false then
return false
end
end
end
-- If it didn't fail any of the above checks, return true.
return true
end
-- Call these function with a list of equipment slots to check ('head', 'neck', 'body', etc)
-- Returns true if any of the specified slots are currently encumbered.
-- Returns false if all specified slots are unencumbered.
function is_encumbered(...)
local check_list = {...}
-- Compensate for people passing a table instead of a series of strings.
if type(check_list[1]) == 'table' then
check_list = check_list[1]
end
local check_set = S(check_list)
for slot_id,slot_name in pairs(gearswap.default_slot_map) do
if check_set:contains(slot_name) then
if gearswap.encumbrance_table[slot_id] then
return true
end
end
end
return false
end
-------------------------------------------------------------------------------------------------------------------
-- Elemental gear utility functions.
-------------------------------------------------------------------------------------------------------------------
-- Function to get an appropriate obi/cape/ring for the current action.
function set_elemental_obi_cape_ring(spell, spellMap)
if spell.element == 'None' then
return
end
gear.ElementalObi.name = gear.default.obi_waist
if spell.element == world.weather_element or spell.element == world.day_element and item_available("Twilight Cape") then
gear.ElementalCape.name = "Twilight Cape"
else
gear.ElementalCape.name = gear.default.obi_back
end
if spell.english:endswith('helix') then
if item_available("Orpheus's Sash") then
local distance = spell.target.distance - spell.target.model_size
local orpheus_intensity = (16 - (distance <= 1 and 1 or distance >= 15 and 15 or distance)) or 0
if orpheus_intensity > 5 then
equip({waist="Orpheus's Sash"})
end
end
elseif is_nuke(spell, spellMap) then
local distance = spell.target.distance - spell.target.model_size
local single_obi_intensity = 0
local orpheus_intensity = 0
local hachirin_intensity = 0
if item_available("Orpheus's Sash") then
orpheus_intensity = (16 - (distance <= 1 and 1 or distance >= 15 and 15 or distance)) or 0
end
if item_available(data.elements.obi_of[spell.element]) then
if spell.element == world.weather_element then
single_obi_intensity = single_obi_intensity + data.weather_bonus_potency[world.weather_intensity]
end
if spell.element == world.day_element then
single_obi_intensity = single_obi_intensity + 10
end
end
if item_available('Hachirin-no-Obi') then
if spell.element == world.weather_element then
hachirin_intensity = hachirin_intensity + data.weather_bonus_potency[world.weather_intensity]
elseif spell.element == data.elements.weak_to[world.weather_element] then
hachirin_intensity = hachirin_intensity - data.weather_bonus_potency[world.weather_intensity]
end
if spell.element == world.day_element then
hachirin_intensity = hachirin_intensity + 10
elseif spell.element == data.elements.weak_to[world.day_element] then
hachirin_intensity = hachirin_intensity - 10
end
end
if orpheus_intensity > hachirin_intensity and orpheus_intensity > single_obi_intensity and orpheus_intensity > 5 then
gear.ElementalObi.name = "Orpheus's Sash"
elseif hachirin_intensity >= single_obi_intensity and hachirin_intensity > 5 then
gear.ElementalObi.name = "Hachirin-no-Obi"
elseif single_obi_intensity > 5 then
gear.ElementalObi.name = data.elements.obi_of[spell.element]
end
if spell.element == world.day_element and spell.english ~= 'Impact' and not spell.skill == 'Divine Magic' and item_available("Zodiac Ring") then
gear.ElementalRing.name = "Zodiac Ring"
else
gear.ElementalRing.name = gear.default.obi_ring
end
end
end
-- Function to get the appropriate fast cast and/or recast staves for the current spell.
--[[
function set_elemental_staff(spell)
if spell.action_type ~= 'Magic' then
return
end
gear.FastcastStaff.name = get_elemental_item_name("fastcast_staff", S{spell.element}) or gear.default.fastcast_staff or ""
gear.RecastStaff.name = get_elemental_item_name("recast_staff", S{spell.element}) or gear.default.recast_staff or ""
end
]]
-- Gets the name of an elementally-aligned piece of gear within the player's
-- inventory that matches the conditions set in the parameters.
--
-- item_type: Type of item as specified in the elemental_map mappings.
-- EG: gorget, belt, obi, fastcast_staff, recast_staff
--
-- valid_elements: Elements that are valid for the action being taken.
-- IE: Weaponskill skillchain properties, or spell element.
--
-- restricted_to_elements: Secondary elemental restriction that limits
-- whether the item check can be considered valid.
-- EG: Day or weather elements that have to match the spell element being queried.
--
-- Returns: Nil if no match was found (either due to elemental restrictions,
-- or the gear isn't in the player inventory), or the name of the piece of
-- gear that matches the query.
-- function get_elemental_item_name(item_type, valid_elements, restricted_to_elements)
-- local potential_elements = restricted_to_elements or data.elements.list
-- local item_map = elements[item_type:lower()..'_of']
-- for element in (potential_elements.it or it)(potential_elements) do
-- if valid_elements:contains(element) and (player.inventory[item_map[element]] or player.wardrobe[item_map[element]] or player.wardrobe2[item_map[element]]) or player.wardrobe3[item_map[element]] or player.wardrobe4[item_map[element]] then
-- return item_map[element]
-- end
-- end
-- end
-------------------------------------------------------------------------------------------------------------------
-- Function to easily change to a given macro set or book. Book value is optional.
-------------------------------------------------------------------------------------------------------------------
function set_macro_page(set,book)
if not tonumber(set) then
add_to_chat(123,'Error setting macro page: Set is not a valid number ('..tostring(set)..').')
return
end
if set < 1 or set > 10 then
add_to_chat(123,'Error setting macro page: Macro set ('..tostring(set)..') must be between 1 and 10.')
return
end
if book then
if not tonumber(book) then
add_to_chat(123,'Error setting macro page: book is not a valid number ('..tostring(book)..').')
return
end
if book < 1 or book > 20 then
add_to_chat(123,'Error setting macro page: Macro book ('..tostring(book)..') must be between 1 and 20.')
return
end
send_command('@input /macro book '..tostring(book)..';wait .1;input /macro set '..tostring(set))
else
send_command('@input /macro set '..tostring(set))
end
end
-- Function for optionally including files if they exist.
function optional_include(filename)
local path = gearswap.pathsearch({filename})
if path then
include(filename)
else
print('Missing optional file: '..filename..', this is not an error, only diagnostic information.')
return false
end
end
-------------------------------------------------------------------------------------------------------------------
-- Utility functions for vars or other data manipulation.
-------------------------------------------------------------------------------------------------------------------
-- Attempt to locate a specified name within the current alliance.
function find_player_in_alliance(name)
for party_index,ally_party in ipairs(alliance) do
for player_index,_player in ipairs(ally_party) do
if _player.name == name then
return _player
end
end
end
end
function number_of_jps(jp_tab)
local count = 0
for _,v in pairs(jp_tab) do
count = count + v*(v+1)
end
return count/2
end
function add_table_to_chat(table)
for k, v in pairs( table ) do
add_to_chat(123,''..k..', '..v)
end
end
function get_spell_table_by_name(spell_name)
for k in pairs(res.spells) do
if res.spells[k][language] == spell_name then
return res.spells[k]
end
end
return false
end
function silent_can_use(spellid)
local available_spells = windower.ffxi.get_spells()
local spell_jobs = copy_entry(res.spells[spellid].levels)
-- Filter for spells that you do not know. Exclude Impact, Honor March and Dispelga.
if not available_spells[spellid] and not (spellid == 503 or spellid == 417 or spellid == 360) then
return false
-- Filter for spells that you know, but do not currently have access to
elseif (not spell_jobs[player.main_job_id] or not (spell_jobs[player.main_job_id] <= player.main_job_level or
(spell_jobs[player.main_job_id] >= 100 and number_of_jps(player.job_points[(res.jobs[player.main_job_id].ens):lower()]) >= spell_jobs[player.main_job_id]) ) ) and
(not spell_jobs[player.sub_job_id] or not (spell_jobs[player.sub_job_id] <= player.sub_job_level)) then
return false
elseif res.spells[spellid].type == 'BlueMagic' and not ((player.main_job_id == 16 and (data.spells.unbridled:contains(res.spells[spellid].en) or table.contains(windower.ffxi.get_mjob_data().spells,spellid))) or (player.sub_job_id == 16 and table.contains(windower.ffxi.get_sjob_data().spells,spellid))) then
return false
else
return true
end
end
function can_use(spell)
local category = data.command.outgoing_action_category_table[data.command.unify_prefix[spell.prefix]]
if world.in_mog_house then
add_to_chat(123,"Abort: You are currently in a Mog House zone.")
return false
elseif category == 3 then
local available_spells = windower.ffxi.get_spells()
local spell_jobs = copy_entry(res.spells[spell.id].levels)
-- Filter for spells that you do not know. Exclude Impact.
if not available_spells[spell.id] and not (spell.id == 503 or spell.id == 417 or spellid == 360) then
add_to_chat(123,"Abort: You haven't learned ["..(res.spells[spell.id][language] or spell.id).."].")
return false
elseif spell.type == 'Ninjutsu' then
if player.main_job_id ~= 13 and player.sub_job_id ~= 13 then
add_to_chat(123,"Abort: You don't have access to ["..(spell[language] or spell.id).."].")
return false
elseif not player.inventory[data.tools.tool_map[spell.english][language]] and not (player.main_job_id == 13 and player.inventory[data.tools.universal_tool_map[spell.english][language]]) then
if player.main_job == 'NIN' and player.satchel[data.tools.universal_tool_map[spell.english][language]] then
windower.send_command('get "'..data.tools.universal_tool_map[spell.english][language]..'" satchel 99')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
elseif player.satchel[data.tools.tool_map[spell.english][language]] then
windower.send_command('get "'..data.tools.tool_map[spell.english][language]..'" satchel 99')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
elseif player.main_job == 'NIN' and player.inventory[data.tools.universal_toolbag_map[spell.english][language]] then
windower.chat.input('/item "'..data.tools.universal_toolbag_map[spell.english][language]..'" <me>')
windower.chat.input:schedule(4,'/ma "'..spell.english..'" '..spell.target.raw..'')
elseif player.main_job == 'NIN' and player.satchel[data.tools.universal_toolbag_map[spell.english][language]] then
windower.send_command('get "'..data.tools.universal_toolbag_map[spell.english][language]..'" satchel 1')
windower.chat.input:schedule(2,'/item "'..data.tools.universal_toolbag_map[spell.english][language]..'" <me>')
windower.chat.input:schedule(6,'/ma "'..spell.english..'" '..spell.target.raw..'')
elseif player.inventory[data.tools.toolbag_map[spell.english][language]] then
windower.chat.input('/item "'..data.tools.toolbag_map[spell.english][language]..'" <me>')
windower.chat.input:schedule(4,'/ma "'..spell.english..'" '..spell.target.raw..'')
elseif player.satchel[data.tools.toolbag_map[spell.english][language]] then
windower.send_command('get "'..data.tools.toolbag_map[spell.english][language]..'" satchel 1')
windower.chat.input:schedule(2,'/item "'..data.tools.universal_toolbag_map[spell.english][language]..'" <me>')
windower.chat.input:schedule(6,'/ma "'..spell.english..'" '..spell.target.raw..'')
else
add_to_chat(123,"Abort: You don't have the proper ninja tool available.")
end
return false
end
-- Filter for spells that you know, but do not currently have access to
elseif (not spell_jobs[player.main_job_id] or not (spell_jobs[player.main_job_id] <= player.main_job_level or
(spell_jobs[player.main_job_id] >= 100 and number_of_jps(player.job_points[__raw.lower(res.jobs[player.main_job_id].ens)]) >= spell_jobs[player.main_job_id]) ) ) and
(not spell_jobs[player.sub_job_id] or not (spell_jobs[player.sub_job_id] <= player.sub_job_level)) then
add_to_chat(123,"Abort: You don't have access to ["..(res.spells[spell.id][language] or spell.id).."].")
return false
-- At this point, we know that it is technically castable by this job combination if the right conditions are met.
elseif player.main_job == 'SCH'then
if (spell_jobs[player.sub_job_id] and spell_jobs[player.sub_job_id] <= player.sub_job_level) or state.Buff['Enlightenment'] then
return true
elseif data.spells.addendum_white:contains(spell.english) and not state.Buff['Addendum: White'] then
if state.AutoArts.value and not state.Buff['Addendum: White'] and not silent_check_amnesia() and get_current_stratagem_count() > 0 then
if state.Buff['Light Arts'] then
windower.chat.input('/ja "Addendum: White" <me>')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
tickdelay = os.clock() + 4.5
else
local abil_recasts = windower.ffxi.get_ability_recasts()
if abil_recasts[228] < latency then
windower.chat.input('/ja "Light Arts" <me>')
windower.chat.input:schedule(1.5,'/ja "Addendum: White" <me>')
windower.chat.input:schedule(3,'/ma "'..spell.english..'" '..spell.target.raw..'')
tickdelay = os.clock() + 6
else
add_to_chat(123,"Abort: Addendum: White required for ["..spell.name.."].")
end
end
else
add_to_chat(123,"Abort: Addendum: White required for ["..spell.name.."].")
end
return false
elseif data.spells.addendum_black:contains(spell.english) and not state.Buff['Addendum: Black'] then
if state.AutoArts.value and not state.Buff['Addendum: Black'] and not silent_check_amnesia() and get_current_stratagem_count() > 0 then
if state.Buff['Dark Arts'] then
windower.chat.input('/ja "Addendum: Black" <me>')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
tickdelay = os.clock() + 4.5
else
local abil_recasts = windower.ffxi.get_ability_recasts()
if abil_recasts[232] < latency then
windower.chat.input('/ja "Dark Arts" <me>')
windower.chat.input:schedule(1.5,'/ja "Addendum: Black" <me>')
windower.chat.input:schedule(3,'/ma "'..spell.english..'" '..spell.target.raw..'')
tickdelay = os.clock() + 6
else
add_to_chat(123,"Abort: Addendum: Black required for ["..spell.name.."].")
end
end
else
add_to_chat(123,"Abort: Addendum: Black required for ["..spell.name.."].")
end
return false
end
elseif player.sub_job_id == 20 and ((data.spells.addendum_white:contains(spell.english) and not buffactive[401] and not buffactive[416]) or
(data.spells.addendum_black:contains(spell.english) and not buffactive[402] and not buffactive[416])) and
not (spell_jobs[player.main_job_id] and (spell_jobs[player.main_job_id] <= player.main_job_level or
(spell_jobs[player.main_job_id] >= 100 and number_of_jps(player.job_points[__raw.lower(res.jobs[player.main_job_id].ens)]) >= spell_jobs[player.main_job_id]) ) ) then
if data.spells.addendum_white:contains(spell.english) then
if state.AutoArts.value and not buffactive["Addendum: White"] and not silent_check_amnesia() and get_current_stratagem_count() > 0 then
if state.Buff['Light Arts'] then
windower.chat.input('/ja "Addendum: White" <me>')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
else
local abil_recasts = windower.ffxi.get_ability_recasts()
if abil_recasts[228] < latency then
windower.chat.input('/ja "Light Arts" <me>')
windower.chat.input:schedule(1.5,'/ja "Addendum: White" <me>')
windower.chat.input:schedule(3.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
end
end
else
add_to_chat(123,"Abort: Addendum: White required for ["..(res.spells[spell.id][language] or spell.id).."].")
end
end
if data.spells.addendum_black:contains(spell.english) then
if state.AutoArts.value and not buffactive["Addendum: Black"] and not silent_check_amnesia() and get_current_stratagem_count() > 0 then
if buffactive["Dark Arts"] then
windower.chat.input('/ja "Addendum: Black" <me>')
windower.chat.input:schedule(1.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
else
local abil_recasts = windower.ffxi.get_ability_recasts()
if abil_recasts[232] < latency then
windower.chat.input('/ja "Dark Arts" <me>')
windower.chat.input:schedule(1.5,'/ja "Addendum: Black" <me>')
windower.chat.input:schedule(3.5,'/ma "'..spell.english..'" '..spell.target.raw..'')
end
end
else
add_to_chat(123,"Abort: Addendum: Black required for ["..(res.spells[spell.id][language] or spell.id).."].")
end
end
return false
elseif spell.type == 'BlueMagic' and not ((player.main_job_id == 16 and table.contains(windower.ffxi.get_mjob_data().spells,spell.id))
or data.spells.unbridled:contains(spell.english)) and
not (player.sub_job_id == 16 and table.contains(windower.ffxi.get_sjob_data().spells,spell.id)) then
-- This code isn't hurting anything, but it doesn't need to be here either.
add_to_chat(123,"Abort: You haven't set ["..(res.spells[spell.id][language] or spell.id).."].")
return false
end
elseif category == 7 or category == 9 then
local available = windower.ffxi.get_abilities()
if category == 7 and not S(available.weapon_skills)[spell.id] then
add_to_chat(123,"Abort: You don't have access to ["..(res.weapon_skills[spell.id][language] or spell.id).."].")
return false
elseif category == 9 then
if not S(available.job_abilities)[spell.id] then
add_to_chat(123,"Abort: You don't have access to ["..(res.job_abilities[spell.id][language] or spell.id).."].")
return false
elseif spell.type == 'CorsairShot' and not player.inventory['Trump Card'] then
if player.inventory['Trump Card Case'] then
windower.chat.input('/item "Trump Card Case" <me>')
elseif player.satchel['Trump Card Case'] then
windower.send_command('get "Trump Card Case" satchel')
windower.chat.input:schedule(1.5,'/item "Trump Card Case" <me>')
end
return false
end
end
elseif category == 25 and (not player.main_job_id == 23 or not windower.ffxi.get_mjob_data().species or
not res.monstrosity[windower.ffxi.get_mjob_data().species] or not res.monstrosity[windower.ffxi.get_mjob_data().species].tp_moves[spell.id] or
not (res.monstrosity[windower.ffxi.get_mjob_data().species].tp_moves[spell.id] <= player.main_job_level)) then
-- Monstrosity filtering
add_to_chat(123,"Abort: You don't have access to ["..(res.monster_abilities[spell.id][language] or spell.id).."].")
return false
end
return true
end
-- buff_set is a set of buffs in a library table (any of S{}, T{} or L{}).
-- This function checks if any of those buffs are present on the player.
function has_any_buff_of(buff_set)
return buff_set:any(
-- Returns true if any buff from buff set that is sent to this function returns true:
function (b) return buffactive[b] end
)
end
-- Invert a table such that the keys are values and the values are keys.
-- Use this to look up the index value of a given entry.
function invert_table(t)
if t == nil then error('Attempting to invert table, received nil.', 2) end
local i={}
for k,v in pairs(t) do
i[v] = k
end
return i
end
-- Gets sub-tables based on baseSet from the string str that may be in dot form
-- (eg: baseSet=sets, str='precast.FC', this returns the table sets.precast.FC).
function get_expanded_set(baseSet, str)
local cur = baseSet
for i in str:gmatch("[^.]+") do
if cur then
cur = cur[i]
end
end
return cur
end
function copy_entry(tab)
if not tab then return nil end
local ret = setmetatable(table.reassign({},tab),getmetatable(tab))
return ret
end
-------------------------------------------------------------------------------------------------------------------
-- Utility functions data and event tracking.
-------------------------------------------------------------------------------------------------------------------
-- This is a function that can be attached to a registered event for 'time change'.
-- It will send a call to the update() function if the time period changes.
-- It will also call job_time_change when any of the specific time class values have changed.
-- To activate this in your job lua, add this line to your user_setup function:
-- windower.register_event('time change', time_change)
--
-- Variables it sets: classes.Daytime, and classes.DuskToDawn. They are set to true
function item_available(item)
if player.inventory[item] or player.wardrobe[item] or player.wardrobe2[item] or player.wardrobe3[item] or player.wardrobe4[item] or player.satchel[item] then
return true
else
return false
end
end
function item_owned(item)
if player.inventory[item] or player.wardrobe[item] or player.wardrobe2[item] or player.wardrobe3[item] or player.wardrobe4[item] or player.safe[item] or player.safe2[item] or player.storage[item] or player.locker[item] or player.satchel[item] or player.sack[item] or player.case[item] then
return true
else
return false
end
end
function check_disable(spell, spellMap, eventArgs)
if player.hp == 0 then
add_to_chat(123,'Abort: You are dead.')
eventArgs.cancel = true
return true
elseif buffactive.terror then
add_to_chat(123,'Abort: You are terrorized.')
eventArgs.cancel = true
return true
elseif buffactive.petrification then
add_to_chat(123,'Abort: You are petrified.')
eventArgs.cancel = true
return true
elseif buffactive.sleep or buffactive.Lullaby then
add_to_chat(123,'Abort: You are asleep.')
eventArgs.cancel = true
return true
elseif buffactive.stun then
add_to_chat(123,'Abort: You are stunned.')
eventArgs.cancel = true
return true
else
return false
end
end
function silent_check_disable()
if buffactive.terror or buffactive.petrification or buffactive.sleep or buffactive.Lullaby or buffactive.stun then
return true
else
return false
end
end
-- Checks doom, returns true if we're going to cancel and use an or cursna.
function check_doom(spell, spellMap, eventArgs)
if buffactive.doom and state.AutoRemoveDoomMode.value and not cursna_exceptions:contains(spell.english) then
if (buffactive.mute or buffactive.Omerta or buffactive.silence) or not (silent_can_use(20) and windower.ffxi.get_spell_recasts()[20] < spell_latency) then
if state.AutoHolyWaterMode.value and not buffactive.muddle then
if player.inventory['Hallowed Water'] then
windower.chat.input('/item "Hallowed Water" <me>')
add_to_chat(123,'Abort: You are doomed, using Hallowed Water instead.')
eventArgs.cancel = true
return true
elseif player.inventory['Holy Water'] or player.satchel['Holy Water'] then
windower.chat.input('/item "Holy Water" <me>')
add_to_chat(123,'Abort: You are doomed, using Holy Water instead.')
eventArgs.cancel = true
return true
elseif buffactive.silence then
if player.inventory['Echo Drops'] or player.satchel['Echo Drops'] then
windower.chat.input('/item "Echo Drops" <me>')
eventArgs.cancel = true
return true
elseif player.inventory["Remedy"] then
windower.chat.input('/item "Remedy" <me>')
eventArgs.cancel = true
return true
end
return false
end
end
elseif silent_can_use(20) then
windower.chat.input('/ma "Cursna" <me>')
add_to_chat(123,'Abort: You are doomed, using Cursna instead.')
eventArgs.cancel = true