forked from PeachBlossomWine/HealBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealBot_utils.lua
1357 lines (1273 loc) · 53.1 KB
/
HealBot_utils.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
--==============================================================================
--[[
Author: Ragnarok.Lorand
HealBot utility functions that don't belong anywhere else
--]]
--==============================================================================
-- Input Handling Functions
--==============================================================================
utils = {normalize={}}
local lor_res = _libs.lor.resources
local lc_res = lor_res.lc_res
local ffxi = _libs.lor.ffxi
local debuffs_lists = L()
function utils.normalize_str(str)
return str:lower():gsub(' ', '_'):gsub('%.', '')
end
function utils.normalize_action(action, action_type)
if istable(action) then return action end
if action_type == nil then return nil end
if isstr(action) then
if tonumber(action) == nil then
local naction = res[action_type]:with('en', action)
if naction ~= nil then
return naction
end
return res[action_type]:with('enn', utils.normalize_str(action))
end
action = tonumber(action)
end
if isnum(action) then
return res[action_type][action]
end
--atcf("Unable to normalize: '%s'[%s] (%s)", tostring(action), type(action), tostring(action_type))
return nil
end
function utils.strip_roman_numerals(str)
--return str:sub(1, str:find('I*V?X?I*V?I*$')):trim()
return str:match('^%s*(.-)%s*I*V?X?I*V?I*$')
end
--[[
Add an 'enn' (english, normalized) entry to each relevant resource
--]]
local function normalize_action_names()
local categories = {'spells', 'job_abilities', 'weapon_skills', 'buffs'}
for _,cat in pairs(categories) do
for id,entry in pairs(res[cat]) do
res[cat][id].enn = utils.normalize_str(entry.en)
res[cat][id].ja = nil
res[cat][id].jal = nil
end
end
end
normalize_action_names()
local txtbox_cmd_map = {
moveinfo = 'moveInfo', actioninfo = 'actionInfo',
showq = 'actionQueue', showqueue = 'actionQueue',
queue = 'actionQueue', monitored = 'montoredBox',
showmonitored = 'montoredBox',
}
function processCommand(command,...)
command = command and command:lower() or 'help'
local args = map(windower.convert_auto_trans, {...})
if S{'reload','unload'}:contains(command) then
windower.send_command(('lua %s %s'):format(command, 'healbot'))
elseif command == 'refresh' then
utils.load_configs()
elseif S{'show','sh'}:contains(command) then
if (args[1] and args[1]:lower() == 'party') or not args[1] then
atc('Party Debuff Table:')
table.vprint(buffs.debuffList)
end
if (args[1] and args[1]:lower() == 'aura') or not args[1] then
atc('Aura Table:')
table.vprint(buffs.auras)
end
if (args[1] and args[1]:lower() == 'ignore') or not args[1] then
atc('Ignored Debuff Table:')
table.vprint(buffs.ignored_debuffs)
end
if (args[1] and args[1]:lower() == 'offense') or not args[1] then
atc('Offense Table:')
table.vprint(offense.mobs)
end
if (args[1] and args[1]:lower() == 'debuff') or not args[1] then
atc('Offense debuffs table:')
table.vprint(offense.debuffs)
end
if (args[1] and args[1]:lower() == 'dispel') or not args[1] then
atc('Dispel table:')
table.vprint(offense.dispel.mobs)
end
if (args[1] and args[1]:lower() == 'follow') or not args[1] then
local targ_value = settings.follow.target or 'NIL'
atc('Follow target: '..targ_value)
end
if (args[1] and args[1]:lower() == 'buffs') or not args[1] then
atc('Buffs table: ')
table.vprint(buffs.buffList)
end
elseif S{'start','on'}:contains(command) then
hb.activate()
elseif S{'stop','end','off'}:contains(command) then
hb.active = false
printStatus()
elseif S{'aoe'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (settings.aoe_na and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd) then
settings.aoe_na = false
atc('AOE is now off.')
else
settings.aoe_na = true
atc('AOE is active.')
end
elseif S{'dispel'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (offense.dispel.active and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd) then
offense.dispel.active = false
atc('Auto Dispel is now off.')
elseif S{'resume','on'}:contains(cmd) then
offense.dispel.active = true
atc('Auto Dispel is now active.')
elseif cmd == 'ignore' then
local mob_string = args[2]:lower():capitalize()
offense.dispel.ignored:add(mob_string)
atc('Added mob to dispel ignore list: '..mob_string)
elseif cmd == 'unignore' then
local mob_string = args[2]:lower():capitalize()
if offense.dispel.ignored:contains(mob_string) then
offense.dispel.ignored:remove(mob_string)
atc('Removed mob from dispel ignore list: '..mob_string)
local show_dispel_ignore_names = ''
for k,v in pairs(offense.dispel.ignored) do
show_dispel_ignore_names = show_dispel_ignore_names..'['..k..']'
end
atc('Dispel Ignore List: '..show_dispel_ignore_names)
else
atc('Error: Mob not in current list')
end
end
elseif S{'disable'}:contains(command) then
if not validate(args, 1, 'Error: No argument specified for Disable') then return end
disableCommand(args[1]:lower(), true)
elseif S{'enable'}:contains(command) then
if not validate(args, 1, 'Error: No argument specified for Enable') then return end
disableCommand(args[1]:lower(), false)
elseif S{'moblist'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (offense.moblist.active and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd) then
offense.moblist.active = false
atc('Moblist debuffing is now off.')
elseif S{'resume','on'}:contains(cmd) then
offense.moblist.active = true
atc('Moblist debuffing is now active.')
elseif cmd == 'add' and args[2] then
local mob_string = args[2]:lower():capitalize()
offense.moblist.mobs:add(mob_string)
atc('Added mob to debuff list: '..mob_string)
elseif cmd == 'remove' and args[2] then
local mob_string = args[2]:lower():capitalize()
if offense.moblist.mobs:contains(mob_string) then
offense.moblist.mobs:remove(mob_string)
atc('Removed mob from debuff list: '..mob_string)
local show_moblist_names = ''
for k,v in pairs(offense.moblist.mobs) do
show_moblist_names = show_moblist_names..'['..k..']'
end
atc('Debuff Mob List: '..show_moblist_names)
else
atc('Error: Mob not in current list')
end
elseif (cmd == 'show' or cmd == 'list') and offense.moblist.mobs then
local show_moblist_names = ''
for k,v in pairs(offense.moblist.mobs) do
show_moblist_names = show_moblist_names..'['..k..']'
end
atc('Debuff Mob List: '..show_moblist_names)
elseif cmd == 'clear' or cmd == 'reset' then
offense.moblist.mobs:clear()
atc('Debuff Mob List cleared')
else
atc(123,'Error: No parameter - [add / remove / on / off / clear] specified.')
end
elseif S{'assist','as'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (offense.assist.active and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd) then
offense.assist.active = false
atc('Assist is now off.')
elseif S{'resume'}:contains(cmd) then
if (offense.assist.name ~= nil) then
offense.assist.active = true
atc('Now assisting '..offense.assist.name..'.')
else
atc(123,'Error: Unable to resume assist - no target set')
end
elseif S{'attack','engage'}:contains(cmd) then
local cmd2 = args[2] and args[2]:lower() or (offense.assist.engage and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd2) then
offense.assist.engage = false
atc('Will no longer enagage when assisting.')
else
if not (offense.assist.nolock) then
offense.assist.engage = true
atc('Will now enagage when assisting.')
else
offense.assist.engage = false
atc('ERROR: Cannot engage/attack to assist if using nolock.')
end
end
elseif S{'nolock'}:contains(cmd) then
local cmd2 = args[2] and args[2]:lower() or (offense.assist.nolock and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd2) then
offense.assist.nolock = false
atc('Will now use target/lock on when assisting.')
else
if not (offense.assist.engage) then
offense.assist.nolock = true
atc('Will now use mob id to cast spells when assisting.')
else
offense.assist.nolock = false
atc('ERROR: Cannot use nolock/mob id to assist if engaging to attack.')
end
end
elseif S{'sametarget'}:contains(cmd) then
local cmd2 = args[2] and args[2]:lower() or (offense.assist.sametarget and 'off' or 'resume')
if S{'off','end','false','pause'}:contains(cmd2) then
offense.assist.sametarget = false
atc('Will now NOT switch to the SAME mob when engaged.')
else
if not (offense.assist.nolock) and offense.assist.engage then
offense.assist.sametarget = true
atc('Will now switch to the same mob when attack/engage to assist.')
else
offense.assist.sametarget = false
atc('ERROR: Cannot use sametarget to attack/engage if using [nolock] or not [attack/engage].')
end
end
elseif S{'job','j'}:contains(cmd) then
if args[2] then
offense.register_assistee(args[2],true)
else
atc('ERROR: No JOB specified.')
end
else --args[1] is guaranteed to have a value if this is reached
offense.register_assistee(args[1])
end
elseif S{'ws','weaponskill'}:contains(command) then
local lte,gte = string.char(0x81, 0x85),string.char(0x81, 0x86)
local cmd = args[1] and args[1] or ''
settings.ws = settings.ws or {}
if (cmd == 'waitfor') then --another player's TP
local partner = utils.getPlayerName(args[2])
if (partner ~= nil) then
local partnertp = tonumber(args[3]) or 1000
settings.ws.partner = {name=partner,tp=partnertp}
atc("Will weaponskill when "..partner.."'s TP is "..gte.." "..partnertp)
else
atc(123,'Error: Invalid argument for ws waitfor: '..tostring(args[2]))
end
elseif (cmd == 'nopartner') then
settings.ws.partner = nil
atc('Weaponskill partner removed.')
elseif (cmd == 'hp') then --Target's HP
local sign = S{'<','>'}:contains(args[2]) and args[2] or nil
local hp = tonumber(args[3])
if (sign ~= nil) and (hp ~= nil) then
settings.ws.sign = sign
settings.ws.hp = hp
atc("Will weaponskill when the target's HP is "..sign.." "..hp.."%")
else
atc(123,'Error: Invalid arguments for ws hp: '..tostring(args[2])..', '..tostring(args[3]))
end
else
if S{'use','set'}:contains(cmd) then -- ws name
table.remove(args, 1)
end
utils.register_ws(args)
end
elseif S{'spam','nuke'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (settings.spam.active and 'off' or 'on')
if S{'on','true'}:contains(cmd) then
settings.spam.active = true
if (settings.spam.name ~= nil) then
atc('Action spamming is now on. Action: '..settings.spam.name)
else
atc('Action spamming is now on. To set a spell to use: //hb spam use <action>')
end
elseif S{'off','false'}:contains(cmd) then
settings.spam.active = false
atc('Action spamming is now off.')
else
if S{'use','set'}:contains(cmd) then
table.remove(args, 1)
end
utils.register_spam_action(args)
end
elseif S{'debuff', 'db'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (offense.debuffing_active and 'off' or 'on')
if S{'on','true'}:contains(cmd) then
offense.debuffing_active = true
atc('Debuffing is now on.')
elseif S{'off','false'}:contains(cmd) then
offense.debuffing_active = false
atc('Debuffing is now off.')
elseif S{'bt'}:contains(cmd) then
local battle_cmd = args[2] and args[2]:lower() or (offense.debuffing_battle_target and 'off' or 'on')
if S{'on','true'}:contains(battle_cmd) then
offense.debuffing_active = true
offense.debuffing_battle_target = true
atc('WARNING! Debuffing is now set to battle targets.')
elseif S{'off','false'}:contains(battle_cmd) then
offense.debuffing_battle_target = false
atc('DISABLED debuffing on battle targets.')
end
elseif S{'rm','remove'}:contains(cmd) then
utils.register_offensive_debuff(table.slice(args, 2), true)
elseif S{'ls','list'}:contains(cmd) then
local debuff_print = ''
for k,v in pairs(offense.debuffs) do
debuff_print = debuff_print..offense.debuffs[k].spell.en..','
end
atc('Debuffs: '..debuff_print)
else
if S{'use','set'}:contains(cmd) then
table.remove(args, 1)
end
utils.register_offensive_debuff(args, false)
end
elseif S{'mldebuff', 'mldb'}:contains(command) then
local cmd = args[1] and args[1]:lower()
if S{'rm','remove'}:contains(cmd) then
utils.register_offensive_debuff(table.slice(args, 2), true, true)
elseif S{'ls','list'}:contains(cmd) then
local debuff_print = ''
for k,v in pairs(offense.moblist.debuffs) do
debuff_print = debuff_print..offense.moblist.debuffs[k].spell.en..','
end
atc('Debuffs for Moblist: '..debuff_print)
else
if S{'use','set'}:contains(cmd) then
table.remove(args, 1)
end
utils.register_offensive_debuff(args, false, true)
end
elseif command == 'mincure' then
if not validate(args, 1, 'Error: No argument specified for minCure') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 6) then
settings.healing.min.cure = val
atc('Minimum cure tier set to '..val)
else
atc('Error: Invalid argument specified for minCure')
end
elseif command == 'mincuraga' then
if not validate(args, 1, 'Error: No argument specified for minCuraga') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 6) then
settings.healing.min.curaga = val
atc('Minimum curaga tier set to '..val)
else
atc('Error: Invalid argument specified for minCuraga')
end
elseif command == 'minwaltz' then
if not validate(args, 1, 'Error: No argument specified for minWaltz') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 5) then
settings.healing.min.waltz = val
atc('Minimum waltz tier set to '..val)
else
atc('Error: Invalid argument specified for minWaltz')
end
elseif command == 'minwaltzga' then
if not validate(args, 1, 'Error: No argument specified for minWaltzga') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 2) then
settings.healing.min.waltzga = val
atc('Minimum waltzga tier set to '..val)
else
atc('Error: Invalid argument specified for minWaltzga')
end
elseif command == 'minblue' then
if not validate(args, 1, 'Error: No argument specified for minBlue') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 4) then
settings.healing.min.blue = val
atc('Minimum blue tier set to '..val)
else
atc('Error: Invalid argument specified for minBlue')
end
elseif command == 'minbluega' then
if not validate(args, 1, 'Error: No argument specified for minBluega') then return end
local val = tonumber(args[1])
if (val ~= nil) and (1 <= val) and (val <= 2) then
settings.healing.min.bluega = val
atc('Minimum bluega tier set to '..val)
else
atc('Error: Invalid argument specified for minBluega')
end
elseif command == 'reset' then
if not validate(args, 1, 'Error: No argument specified for reset') then return end
local rcmd = args[1]:lower()
local b,d = false,false
if S{'all','both'}:contains(rcmd) then
b,d = true,true
elseif (rcmd == 'buffs') then
b = true
elseif (rcmd == 'debuffs') then
d = true
else
atc('Error: Invalid argument specified for reset: '..arg[1])
return
end
local resetTarget
if (args[2] ~= nil) and (args[3] ~= nil) and (args[2]:lower() == 'on') then
local pname = utils.getPlayerName(args[3])
if (pname ~= nil) then
resetTarget = pname
else
atc(123,'Error: Invalid name provided as a reset target: '..tostring(args[3]))
return
end
end
resetTarget = resetTarget or 'ALL'
local rtmsg = resetTarget or 'all monitored players'
if b then
buffs.resetBuffTimers(resetTarget)
atc(('Buff timers for %s were reset.'):format(rtmsg))
end
if d then
buffs.resetDebuffTimers(resetTarget)
atc(('Debuffs detected for %s were reset.'):format(rtmsg))
end
elseif command == 'buff' then
buffs.registerNewBuff(args, true)
elseif command == 'buffjob' then
buffs.registerNewBuff(args, true, true)
elseif S{'cancelbuff','nobuff'}:contains(command) then
buffs.registerNewBuff(args, false)
elseif S{'cancelbuffjob','nobuffjob'}:contains(command) then
buffs.registerNewBuff(args, false, true)
elseif S{'bufflist','bl'}:contains(command) then
if not validate(args, 1, 'Error: No argument specified for BuffList') then return end
utils.apply_bufflist(args)
elseif command == 'bufflists' then
pprint(hb.config.buff_lists)
elseif command == 'ignore_debuff' then
buffs.registerIgnoreDebuff(args, true)
elseif command == 'unignore_debuff' then
buffs.registerIgnoreDebuff(args, false)
elseif S{'follow','f'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (settings.follow.active and 'off' or 'resume')
if S{'off','end','false','pause','stop','exit'}:contains(cmd) then
atc('Follow is now off.')
settings.follow.active = false
settings.follow.target = nil
elseif S{'distance', 'dist', 'd'}:contains(cmd) then
local dist = tonumber(args[2])
if (dist ~= nil) and (0 < dist) and (dist < 45) then
settings.follow.distance = dist
atc('Follow distance set to '..settings.follow.distance)
else
atc('Error: Invalid argument specified for follow distance')
end
elseif S{'resume'}:contains(cmd) then
if (settings.follow.target ~= nil) then
settings.follow.active = true
atc('Now following '..settings.follow.target..'.')
else
atc(123,'Error: Unable to resume follow - no target set')
end
elseif S{'job', 'j'}:contains(cmd) then
local pname = utils.getPlayerNameFromJob(args[2])
if (pname ~= nil) then
settings.follow.target = pname
settings.follow.active = true
atc('Now following '..settings.follow.target..'.')
else
atc(123,'Error: Invalid JOB provided as a follow target: '..tostring(args[2]))
end
else --args[1] is guaranteed to have a value if this is reached
local pname = utils.getPlayerName(args[1])
if (pname ~= nil) then
settings.follow.target = pname
settings.follow.active = true
atc('Now following '..settings.follow.target..'.')
else
atc(123,'Error: Invalid name provided as a follow target: '..tostring(args[1]))
end
end
elseif S{'ignore', 'unignore', 'watch', 'unwatch'}:contains(command) then
monitorCommand(command, args[1])
elseif command == 'watchall' then
if watchall == false then
watchall = true
atc(123,'Watch all parties set to true.')
elseif watchall == true then
watchall = false
atc(123,'Watch all parties set to false.')
end
elseif S{'showdebuff'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (hb.showdebuff and 'off' or 'on')
if S{'on','true'}:contains(cmd) then
hb.showdebuff = true
atc('Debuff List is displayed.')
hb.txts.debuffList:visible(true)
elseif S{'off','false'}:contains(cmd) then
hb.showdebuff = false
hb.txts.debuffList:visible(false)
atc('Debuff List is hidden.')
end
elseif S{'automp'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (hb.autoRecoverMPMode and 'off' or 'on')
if S{'on','true'}:contains(cmd) then
hb.autoRecoverMPMode = true
atc('Auto Recover MP [Coalition Ether] is ON.')
elseif S{'off','false'}:contains(cmd) then
hb.autoRecoverMPMode = false
atc('Auto Recover MP [Coalition Ether] is OFF.')
end
elseif S{'autohp'}:contains(command) then
local cmd = args[1] and args[1]:lower() or (hb.autoRecoverHPMode and 'off' or 'on')
if S{'on','true'}:contains(cmd) then
hb.autoRecoverHPMode = true
atc('Auto Recover HP [Vile Elixir] is ON.')
elseif S{'off','false'}:contains(cmd) then
hb.autoRecoverHPMode = false
atc('Auto Recover HP [Vile Elixir] is OFF.')
end
elseif command == 'ignoretrusts' then
utils.toggleX(settings, 'ignoreTrusts', args[1], 'Ignoring of Trust NPCs', 'IgnoreTrusts')
elseif command == 'packetinfo' then
toggleMode('showPacketInfo', args[1], 'Packet info display', 'PacketInfo')
elseif command == 'debug' then
toggleMode('debug', args[1], 'Debug mode', 'debug mode')
elseif S{'ind', 'independent'}:contains(command) then
toggleMode('independent', args[1], 'Independent mode', 'independent mode')
elseif S{'deactivateindoors','deactivate_indoors'}:contains(command) then
utils.toggleX(settings, 'deactivateIndoors', args[1], 'Deactivation in indoor zones', 'DeactivateIndoors')
elseif S{'activateoutdoors','activate_outdoors'}:contains(command) then
utils.toggleX(settings, 'activateOutdoors', args[1], 'Activation in outdoor zones', 'ActivateOutdoors')
elseif txtbox_cmd_map[command] ~= nil then
local boxName = txtbox_cmd_map[command]
if utils.posCommand(boxName, args) then
utils.refresh_textBoxes()
else
utils.toggleVisible(boxName, args[1])
end
elseif S{'help','--help'}:contains(command) then
help_text()
elseif command == 'settings' then
for k,v in pairs(settings) do
local kstr = tostring(k)
local vstr = (type(v) == 'table') and tostring(T(v)) or tostring(v)
atc(kstr:rpad(' ',15)..': '..vstr)
end
elseif command == 'status' then
printStatus()
elseif command == 'info' then
if not _libs.lor.exec then
atc(3,'Unable to parse info. Windower/addons/libs/lor/lor_exec.lua was unable to be loaded.')
atc(3,'If you would like to use this function, please visit https://github.com/lorand-ffxi/lor_libs to download it.')
return
end
local cmd = args[1] --Take the first element as the command
table.remove(args, 1) --Remove the first from the list of args
_libs.lor.exec.process_input(cmd, args)
else
atc('Error: Unknown command')
end
end
local function _get_player_id(player_name)
local player_mob = windower.ffxi.get_mob_by_name(player_name)
if player_mob then
return player_mob.id
end
return nil
end
utils.get_player_id = _libs.lor.advutils.scached(_get_player_id)
function utils.register_offensive_debuff(args, cancel, mob_debuff_list_flag)
local argstr = table.concat(args,' ')
local snames = argstr:split(',')
for index,sname in pairs(snames) do
if (tostring(index) ~= 'n') then
if sname:lower() == 'all' and cancel then
if mob_debuff_list_flag then
atcf(123,'Removing all debuffs from moblist debuff list.')
for k,v in pairs(offense.moblist.debuffs) do
atcf('Removing debuff: ' ..offense.moblist.debuffs[k].spell.enn)
offense.moblist.debuffs[k] = nil
end
else
atcf(123,'Removing all debuffs on mobs.')
for k,v in pairs(offense.debuffs) do
atcf('Removing debuff: ' ..offense.debuffs[k].spell.enn)
offense.debuffs[k] = nil
end
end
else
local spell_name = utils.formatActionName(sname:trim())
local spell = lor_res.action_for(spell_name)
if (spell ~= nil) then
if healer:can_use(spell) then
if mob_debuff_list_flag then
offense.maintain_debuff(spell, cancel, true)
else
offense.maintain_debuff(spell, cancel)
end
else
atcfs(123,'Error: Unable to cast %s', spell.en)
end
else
atcfs(123,'Error: Invalid spell name: %s', spell_name)
end
end
end
end
end
function utils.register_spam_action(args)
local argstr = table.concat(args,' ')
local action_name = utils.formatActionName(argstr)
local action = lor_res.action_for(action_name)
if (action ~= nil) then
if healer:can_use(action) then
settings.spam.name = action.en
atcfs('Will now spam %s', settings.spam.name)
else
atcfs(123,'Error: Unable to cast %s', action.en)
end
else
atcfs(123,'Error: Invalid action name: %s', action_name)
end
end
function utils.register_ws(args)
local argstr = table.concat(args,' ')
local wsname = utils.formatActionName(argstr)
local ws = lor_res.action_for(wsname)
if (ws ~= nil) then
settings.ws.name = ws.en
atcfs('Will now use %s', ws.en)
else
atcfs(123,'Error: Invalid weaponskill name: %s', wsname)
end
end
function utils.apply_bufflist(args)
local mj = windower.ffxi.get_player().main_job
local sj = windower.ffxi.get_player().sub_job
local job = ('%s/%s'):format(mj, sj)
local bl_name = args[1]
local bl_target = args[2]
if bl_target == nil and bl_name == 'self' then
bl_target = 'me'
end
local buff_list = table.get_nested_value(hb.config.buff_lists, {job, job:lower(), mj, mj:lower()}, bl_name)
buff_list = buff_list or hb.config.buff_lists[bl_name]
if buff_list ~= nil then
for _,buff in pairs(buff_list) do
buffs.registerNewBuff({bl_target, buff}, true)
end
else
atc('Error: Invalid argument specified for BuffList: '..bl_name)
end
end
function utils.posCommand(boxName, args)
if (args[1] == nil) or (args[2] == nil) then return false end
local cmd = args[1]:lower()
if not S{'pos','posx','posy'}:contains(cmd) then
return false
end
local x,y = tonumber(args[2]),tonumber(args[3])
if (cmd == 'pos') then
if (x == nil) or (y == nil) then return false end
settings.textBoxes[boxName].x = x
settings.textBoxes[boxName].y = y
elseif (cmd == 'posx') then
if (x == nil) then return false end
settings.textBoxes[boxName].x = x
elseif (cmd == 'posy') then
if (y == nil) then return false end
settings.textBoxes[boxName].y = y
end
return true
end
function utils.toggleVisible(boxName, cmd)
cmd = cmd and cmd:lower() or (settings.textBoxes[boxName].visible and 'off' or 'on')
if (cmd == 'on') then
settings.textBoxes[boxName].visible = true
elseif (cmd == 'off') then
settings.textBoxes[boxName].visible = false
else
atc(123,'Invalid argument for changing text box settings: '..cmd)
end
end
function utils.toggleX(tbl, field, cmd, msg, msgErr)
if (tbl[field] == nil) then
atcf(123, 'Error: Invalid mode to toggle: %s', field)
return
end
cmd = cmd and cmd:lower() or (tbl[field] and 'off' or 'on')
if (cmd == 'on') then
tbl[field] = true
atc(msg..' is now on.')
elseif (cmd == 'off') then
tbl[field] = false
atc(msg..' is now off.')
else
atc(123,'Invalid argument for '..msgErr..': '..cmd)
end
end
function toggleMode(mode, cmd, msg, msgErr)
utils.toggleX(hb.modes, mode, cmd, msg, msgErr)
_libs.lor.debug = hb.modes.debug
end
function disableCommand(cmd, disable)
local msg = ' is now '..(disable and 'disabled.' or 're-enabled.')
if S{'cure','cures','curing'}:contains(cmd) then
if (not disable) then
if (settings.maxCureTier == 0) then
settings.disable.cure = true
atc(123,'Error: Unable to enable curing because you have no Cure spells available.')
return
end
end
settings.disable.cure = disable
atc('Curing'..msg)
elseif S{'curaga'}:contains(cmd) then
settings.disable.curaga = disable
atc('Curaga use'..msg)
elseif S{'na','heal_debuff','cure_debuff'}:contains(cmd) then
settings.disable.na = disable
atc('Removal of status effects'..msg)
elseif S{'erase'}:contains(cmd) then
settings.disable.erase = disable
atc('Erase status effects'..msg)
elseif S{'buff','buffs','buffing'}:contains(cmd) then
settings.disable.buff = disable
atc('Buffing'..msg)
elseif S{'debuff','debuffs','debuffing'}:contains(cmd) then
settings.disable.debuff = disable
atc('Debuffing'..msg)
elseif S{'spam','nuke','nukes','nuking'}:contains(cmd) then
settings.disable.spam = disable
atc('Spamming'..msg)
elseif S{'ws','weaponskill','weaponskills','weaponskilling'}:contains(cmd) then
settings.disable.ws = disable
atc('Weaponskilling'..msg)
else
atc(123,'Error: Invalid argument for disable/enable: '..cmd)
end
end
function monitorCommand(cmd, pname)
if (pname == nil) then
atc('Error: No argument specified for '..cmd)
return
end
local name = utils.getPlayerName(pname)
if cmd == 'ignore' then
if (not hb.ignoreList:contains(name)) then
hb.ignoreList:add(name)
atc('Will now ignore '..name)
if hb.extraWatchList:contains(name) then
hb.extraWatchList:remove(name)
end
else
atc('Error: Already ignoring '..name)
end
elseif cmd == 'unignore' then
if (hb.ignoreList:contains(name)) then
hb.ignoreList:remove(name)
atc('Will no longer ignore '..name)
else
atc('Error: Was not ignoring '..name)
end
elseif cmd == 'watch' then
if (not hb.extraWatchList:contains(name)) then
hb.extraWatchList:add(name)
atc('Will now watch '..name)
if hb.ignoreList:contains(name) then
hb.ignoreList:remove(name)
end
else
atc('Error: Already watching '..name)
end
elseif cmd == 'unwatch' then
if (hb.extraWatchList:contains(name)) then
hb.extraWatchList:remove(name)
atc('Will no longer watch '..name)
else
atc('Error: Was not watching '..name)
end
end
end
function validate(args, numArgs, message)
for i = 1, numArgs do
if (args[i] == nil) then
atc(message..' ('..i..')')
return false
end
end
return true
end
function utils.getPlayerName(name)
local target = ffxi.get_target(name)
if target ~= nil then
return target.name
end
return nil
end
function utils.getPlayerNameFromJob(job)
local target
for k, v in pairs(windower.ffxi.get_party()) do
if type(v) == 'table' and v.mob ~= nil and v.mob.in_party then
if ((job:lower() == 'tank' and S{'PLD','RUN'}:contains(get_registry(v.mob.id))) or (job:lower() ~= 'tank' and get_registry(v.mob.id):lower() == job:lower())) then
target = v.name
end
end
end
if target ~= nil then
return target
end
return nil
end
function num_strats()
local p = windower.ffxi.get_player()
local sch_level = 0
if p.main_job == "SCH" then
sch_level = p.main_job_level
elseif healer.sub_job == "SCH" then
sch_level = p.sub_job_level
end
if sch_level == 0 then return 0 end
if sch_level < 30 then return 1
elseif sch_level < 50 then return 2
elseif sch_level < 70 then return 3
elseif sch_level < 90 then return 4
elseif p.job_points.sch.jp_spent < 550 then return 5
else return 6 end
end
function healer_has_buffs(buffs)
local buff_list = windower.ffxi.get_player().buffs
for _,bid in pairs(buff_list) do
if buffs:contains(bid) then
return true
end
end
return false
end
function utils.isMonster(mob_index)
local mob_in_question = windower.ffxi.get_mob_by_index(mob_index)
if mob_in_question and mob_in_question.is_npc and mob_in_question.spawn_type == 16 and mob_in_question.valid_target then
return true
end
end
function utils.check_claim_id(id)
for k, v in pairs(windower.ffxi.get_party()) do
if type(v) == 'table' then
if id and v.mob and v.mob.id == id then
return true
end
end
end
return false
end
function utils.ready_to_use(action)
if light_strategems:contains(action.en) then
if not healer_has_buffs(light_arts) then return false end
local strats = num_strats()
if strats < 1 then return false end
local rc = windower.ffxi.get_ability_recasts()[action.recast_id]
return rc <= (4 * 60) / strats * (strats - 1)
elseif dark_strategems:contains(action.en) then
if not healer_has_buffs(dark_arts) then return false end
local strats = num_strats()
if strats < 1 then return false end
local rc = windower.ffxi.get_ability_recasts()[action.recast_id]
return rc <= (4 * 60) / strats * (strats - 1)
else
return healer:ready_to_use(action)
end
end
function utils.debuffs_disp()
debuffs_lists = L()
if next(offense.mobs) ~= nil or next(offense.dispel.mobs) ~= nil then
if next(offense.mobs) ~= nil then
local t_target = windower.ffxi.get_mob_by_target('t') or nil
local tindex = 0
for mob_id,debuff_table in pairs(offense.mobs) do
tindex = utils.get_mob_index(debuff_table)
local claim_target = tindex and windower.ffxi.get_mob_by_index(tindex) and windower.ffxi.get_mob_by_index(tindex).claim_id or nil
if (utils.check_claim_id(claim_target)) or (t_target and t_target.valid_target and t_target.is_npc and t_target.spawn_type == 16 and t_target.id == mob_id) then
utils.debuff_display_builder(debuff_table,true,false,mob_id,tindex)
if next(offense.dispel.mobs) ~= nil then
if offense.dispel.mobs[mob_id] then
utils.debuff_display_builder(offense.dispel.mobs[mob_id],false,true,mob_id)
end
end
end
end
end
-- If just dispel buffs
if next(offense.dispel.mobs) ~= nil then
local t_target = windower.ffxi.get_mob_by_target('t') or nil
local tindex = 0
for mob_id,dispel_table in pairs(offense.dispel.mobs) do
tindex = utils.get_mob_index(dispel_table)
local claim_target = tindex and windower.ffxi.get_mob_by_index(tindex) and windower.ffxi.get_mob_by_index(tindex).claim_id or nil
if not offense.mobs[mob_id] and ((utils.check_claim_id(claim_target)) or (t_target and t_target.valid_target and t_target.is_npc and t_target.spawn_type == 16 and t_target.id == mob_id)) then
utils.debuff_display_builder(dispel_table,true,true,mob_id,tindex)
end
end
end
end
hb.txts.debuffList:text(getPrintable(debuffs_lists))
hb.txts.debuffList:visible(settings.textBoxes.debuffList.visible)
end
function utils.debuff_display_builder(d_table, name, dispel, mob_id, mob_index)
local count = 0
local colorOrange = "\\cs(255,165,0)"
local colorRed = "\\cs(255,50,0)"
local formattedMessage = ""
local mob_claim_name = ""
for _,v in pairs(d_table) do
if count == 0 and name then
local claim_target = windower.ffxi.get_mob_by_index(mob_index) and windower.ffxi.get_mob_by_index(mob_index).claim_id or nil
if utils.check_claim_id(claim_target) then
mob_claim_name = string.format("%s%s\\cr", colorRed, v.mob_name)
debuffs_lists:append('['..mob_claim_name..'] - '..mob_id)
else
debuffs_lists:append('['..v.mob_name..'] - '..mob_id)
end
end
if dispel then
formattedMessage = string.format("%s%s\\cr", colorOrange, v.debuff_name)
debuffs_lists:append(formattedMessage.." : "..string.format(os.date('%M:%S',os.time()-v.landed)))
else
debuffs_lists:append(v.spell_name.." : "..string.format(os.date('%M:%S',os.time()-v.landed)))
end
count = count +1
end
end
function utils.get_mob_index(s_table)
for _,v in pairs(s_table) do
if v.mob_index then
return v.mob_index
end
end
return nil
end
function utils.check_debuffs_timer()
if next(offense.mobs) == nil then return end
for mob_id,debuff_table in pairs(offense.mobs) do
for k,v in pairs(debuff_table) do
if maximum_debuff_timers[v.spell_id] then