-
Notifications
You must be signed in to change notification settings - Fork 32
/
Mote-Include.lua
1125 lines (898 loc) · 38.3 KB
/
Mote-Include.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
-------------------------------------------------------------------------------------------------------------------
-- Common variables and functions to be included in job scripts, for general default handling.
--
-- Include this file in the get_sets() function with the command:
-- include('Mote-Include.lua')
--
-- It will then automatically run its own init_include() function.
--
-- IMPORTANT: This include requires supporting include files:
-- Mote-Utility
-- Mote-Mappings
-- Mote-SelfCommands
-- Mote-Globals
--
-- Place the include() directive at the start of a job's get_sets() function.
--
-- Included variables and functions are considered to be at the same scope level as
-- the job script itself, and can be used as such.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- Initialization function that defines variables to be used.
-- These are accessible at the including job lua script's scope.
--
-- Auto-initialize after defining this function.
-------------------------------------------------------------------------------------------------------------------
current_mote_include_version = 2
function init_include()
-- Used to define various types of data mappings. These may be used in the initialization, so load it up front.
include('Mote-Mappings')
-- Modes is the include for a mode-tracking variable class. Used for state vars, below.
include('Modes')
-- Var for tracking state values
state = {}
-- General melee offense/defense modes, allowing for hybrid set builds, as well as idle/resting/weaponskill.
-- This just defines the vars and sets the descriptions. List modes with no values automatically
-- get assigned a 'Normal' default value.
state.OffenseMode = M{['description'] = 'Offense Mode'}
state.HybridMode = M{['description'] = 'Hybrid Mode'}
state.RangedMode = M{['description'] = 'Ranged Mode'}
state.WeaponskillMode = M{['description'] = 'Weaponskill Mode'}
state.CastingMode = M{['description'] = 'Casting Mode'}
state.IdleMode = M{['description'] = 'Idle Mode'}
state.RestingMode = M{['description'] = 'Resting Mode'}
state.DefenseMode = M{['description'] = 'Defense Mode', 'None', 'Physical', 'Magical'}
state.PhysicalDefenseMode = M{['description'] = 'Physical Defense Mode', 'PDT'}
state.MagicalDefenseMode = M{['description'] = 'Magical Defense Mode', 'MDT'}
state.Kiting = M(false, 'Kiting')
state.SelectNPCTargets = M(false, 'Select NPC Targets')
state.PCTargetMode = M{['description'] = 'PC Target Mode', 'default', 'stpt', 'stal', 'stpc'}
state.EquipStop = M{['description'] = 'Stop Equipping Gear', 'off', 'precast', 'midcast', 'pet_midcast'}
state.CombatWeapon = M{['description']='Combat Weapon', ['string']=''}
state.CombatForm = M{['description']='Combat Form', ['string']=''}
-- Non-mode vars that are used for state tracking.
state.MaxWeaponskillDistance = 0
state.Buff = {}
-- Classes describe a 'type' of action. They are similar to state, but
-- may have any free-form value, or describe an entire table of mapped values.
classes = {}
-- Basic spell mappings are based on common spell series.
-- EG: 'Cure' for Cure, Cure II, Cure III, Cure IV, Cure V, or Cure VI.
classes.SpellMaps = spell_maps
-- List of spells and spell maps that don't benefit from greater skill (though
-- they may benefit from spell-specific augments, such as improved regen or refresh).
-- Spells that fall under this category will be skipped when searching for
-- spell.skill sets.
classes.NoSkillSpells = no_skill_spells_list
classes.SkipSkillCheck = false
-- Custom, job-defined class, like the generic spell mappings.
-- Takes precedence over default spell maps.
-- Is reset at the end of each spell casting cycle (ie: at the end of aftercast).
classes.JAMode = nil
classes.CustomClass = nil
-- Custom groups used for defining melee and idle sets. Persists long-term.
classes.CustomMeleeGroups = L{}
classes.CustomRangedGroups = L{}
classes.CustomIdleGroups = L{}
classes.CustomDefenseGroups = L{}
-- Class variables for time-based flags
classes.Daytime = false
classes.DuskToDawn = false
-- Var for tracking misc info
info = {}
options = {}
-- Special control flags.
mote_vars = {}
mote_vars.set_breadcrumbs = L{}
mote_vars.res_buffs = S{}
for index,struct in pairs(gearswap.res.buffs) do
mote_vars.res_buffs:add(struct.en)
end
-- Sub-tables within the sets table that we expect to exist, and are annoying to have to
-- define within each individual job file. We can define them here to make sure we don't
-- have to check for existence. The job file should be including this before defining
-- any sets, so any changes it makes will override these anyway.
sets.precast = {}
sets.precast.FC = {}
sets.precast.JA = {}
sets.precast.WS = {}
sets.precast.RA = {}
sets.midcast = {}
sets.midcast.RA = {}
sets.midcast.Pet = {}
sets.idle = {}
sets.resting = {}
sets.engaged = {}
sets.defense = {}
sets.buff = {}
gear = {}
gear.default = {}
gear.ElementalGorget = {name=""}
gear.ElementalBelt = {name=""}
gear.ElementalObi = {name=""}
gear.ElementalCape = {name=""}
gear.ElementalRing = {name=""}
gear.FastcastStaff = {name=""}
gear.RecastStaff = {name=""}
-- Load externally-defined information (info that we don't want to change every time this file is updated).
-- Used to define misc utility functions that may be useful for this include or any job files.
include('Mote-Utility')
-- Used for all self-command handling.
include('Mote-SelfCommands')
-- Include general user globals, such as custom binds or gear tables.
-- Load Mote-Globals first, followed by User-Globals, followed by <character>-Globals.
-- Any functions re-defined in the later includes will overwrite the earlier versions.
include('Mote-Globals')
optional_include({'user-globals.lua'})
optional_include({player.name..'-globals.lua'})
-- *-globals.lua may define additional sets to be added to the local ones.
if define_global_sets then
define_global_sets()
end
-- Global default binds (either from Mote-Globals or user-globals)
(binds_on_load or global_on_load)()
-- Load a sidecar file for the job (if it exists) that may re-define init_gear_sets and file_unload.
load_sidecar(player.main_job)
-- General var initialization and setup.
if job_setup then
job_setup()
end
-- User-specific var initialization and setup.
if user_setup then
user_setup()
end
-- Load up all the gear sets.
init_gear_sets()
end
if not mote_include_version or mote_include_version < current_mote_include_version then
add_to_chat(123,'Warning: Your job file is out of date. Please update to the latest repository baseline.')
add_to_chat(123,'For details, visit https://github.com/Kinematics/GearSwap-Jobs/wiki/Upgrading')
rev = mote_include_version or 1
include_path('rev' .. tostring(rev))
include('Mote-Include')
return
end
-- Auto-initialize the include
init_include()
-- Called when this job file is unloaded (eg: job change)
-- Conditional definition so that it doesn't overwrite explicit user
-- versions of this function.
if not file_unload then
file_unload = function()
if user_unload then
user_unload()
elseif job_file_unload then
job_file_unload()
end
_G[(binds_on_unload and 'binds_on_unload') or 'global_on_unload']()
end
end
-------------------------------------------------------------------------------------------------------------------
-- Generalized functions for handling precast/midcast/aftercast for player-initiated actions.
-- This depends on proper set naming.
-- Global hooks can be written as user_xxx() to override functions at a global level.
-- Each job can override any of these general functions using job_xxx() hooks.
-------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------
-- Generic function to map a set processing order to all action events.
------------------------------------------------------------------------
-- Process actions in a specific order of events:
-- Filter - filter_xxx() functions determine whether to run any of the code for this action.
-- Global - user_xxx() functions get called first. Define in Mote-Globals or User-Globals.
-- Local - job_xxx() functions get called next. Define in JOB.lua file.
-- Default - default_xxx() functions get called next. Defined in this file.
-- Cleanup - cleanup_xxx() functions always get called before exiting.
--
-- Parameters:
-- spell - standard spell table passed in by GearSwap
-- action - string defining the function mapping to use (precast, midcast, etc)
function handle_actions(spell, action)
-- Init an eventArgs that allows cancelling.
local eventArgs = {handled = false, cancel = false}
mote_vars.set_breadcrumbs:clear()
-- Get the spell mapping, since we'll be passing it to various functions and checks.
local spellMap = get_spell_map(spell)
-- General filter checks to see whether this function should be run.
-- If eventArgs.cancel is set, cancels this function, not the spell.
if _G['filter_'..action] then
_G['filter_'..action](spell, spellMap, eventArgs)
end
-- If filter didn't cancel it, process user and default actions.
if not eventArgs.cancel then
-- Global user handling of this action
if _G['user_'..action] then
_G['user_'..action](spell, action, spellMap, eventArgs)
if eventArgs.cancel then
cancel_spell()
end
end
-- Job-specific handling of this action
if not eventArgs.cancel and not eventArgs.handled and _G['job_'..action] then
_G['job_'..action](spell, action, spellMap, eventArgs)
if eventArgs.cancel then
cancel_spell()
end
end
-- Default handling of this action
if not eventArgs.cancel and not eventArgs.handled and _G['default_'..action] then
_G['default_'..action](spell, spellMap)
display_breadcrumbs(spell, spellMap, action)
end
-- Global post-handling of this action
if not eventArgs.cancel and _G['user_post_'..action] then
_G['user_post_'..action](spell, action, spellMap, eventArgs)
end
-- Job-specific post-handling of this action
if not eventArgs.cancel and _G['job_post_'..action] then
_G['job_post_'..action](spell, action, spellMap, eventArgs)
end
end
-- Cleanup once this action is done
if _G['cleanup_'..action] then
_G['cleanup_'..action](spell, spellMap, eventArgs)
end
end
--------------------------------------
-- Action hooks called by GearSwap.
--------------------------------------
function pretarget(spell)
handle_actions(spell, 'pretarget')
end
function precast(spell)
if state.Buff[spell.english] ~= nil then
state.Buff[spell.english] = true
end
handle_actions(spell, 'precast')
end
function midcast(spell)
handle_actions(spell, 'midcast')
end
function aftercast(spell)
if state.Buff[spell.english] ~= nil then
state.Buff[spell.english] = not spell.interrupted or buffactive[spell.english] or false
end
handle_actions(spell, 'aftercast')
end
function pet_midcast(spell)
handle_actions(spell, 'pet_midcast')
end
function pet_aftercast(spell)
handle_actions(spell, 'pet_aftercast')
end
--------------------------------------
-- Default code for each action.
--------------------------------------
function default_pretarget(spell, spellMap)
auto_change_target(spell, spellMap)
end
function default_precast(spell, spellMap)
equip(get_precast_set(spell, spellMap))
end
function default_midcast(spell, spellMap)
equip(get_midcast_set(spell, spellMap))
end
function default_aftercast(spell, spellMap)
if not pet_midaction() then
handle_equipping_gear(player.status)
end
end
function default_pet_midcast(spell, spellMap)
equip(get_pet_midcast_set(spell, spellMap))
end
function default_pet_aftercast(spell, spellMap)
handle_equipping_gear(player.status)
end
--------------------------------------
-- Filters for each action.
-- Set eventArgs.cancel to true to stop further processing.
-- May show notification messages, but should not do any processing here.
--------------------------------------
function filter_midcast(spell, spellMap, eventArgs)
if state.EquipStop.value == 'precast' then
eventArgs.cancel = true
end
end
function filter_aftercast(spell, spellMap, eventArgs)
if state.EquipStop.value == 'precast' or state.EquipStop.value == 'midcast' or state.EquipStop.value == 'pet_midcast' then
eventArgs.cancel = true
elseif spell.name == 'Unknown Interrupt' then
eventArgs.cancel = true
end
end
function filter_pet_midcast(spell, spellMap, eventArgs)
-- If we have show_set active for precast or midcast, don't try to equip pet midcast gear.
if state.EquipStop.value == 'precast' or state.EquipStop.value == 'midcast' then
add_to_chat(104, 'Show Sets: Pet midcast not equipped.')
eventArgs.cancel = true
end
end
function filter_pet_aftercast(spell, spellMap, eventArgs)
-- If show_set is flagged for precast or midcast, don't try to equip aftercast gear.
if state.EquipStop.value == 'precast' or state.EquipStop.value == 'midcast' or state.EquipStop.value == 'pet_midcast' then
eventArgs.cancel = true
end
end
--------------------------------------
-- Cleanup code for each action.
--------------------------------------
function cleanup_precast(spell, spellMap, eventArgs)
-- If show_set is flagged for precast, notify that we won't try to equip later gear.
if state.EquipStop.value == 'precast' then
add_to_chat(104, 'Show Sets: Stopping at precast.')
end
end
function cleanup_midcast(spell, spellMap, eventArgs)
-- If show_set is flagged for midcast, notify that we won't try to equip later gear.
if state.EquipStop.value == 'midcast' then
add_to_chat(104, 'Show Sets: Stopping at midcast.')
end
end
function cleanup_aftercast(spell, spellMap, eventArgs)
-- Reset custom classes after all possible precast/midcast/aftercast/job-specific usage of the value.
-- If we're in the middle of a pet action, pet_aftercast will handle clearing it.
if not pet_midaction() then
reset_transitory_classes()
end
end
function cleanup_pet_midcast(spell, spellMap, eventArgs)
-- If show_set is flagged for pet midcast, notify that we won't try to equip later gear.
if state.EquipStop.value == 'pet_midcast' then
add_to_chat(104, 'Show Sets: Stopping at pet midcast.')
end
end
function cleanup_pet_aftercast(spell, spellMap, eventArgs)
-- Reset custom classes after all possible precast/midcast/aftercast/job-specific usage of the value.
reset_transitory_classes()
end
-- Clears the values from classes that only exist til the action is complete.
function reset_transitory_classes()
classes.CustomClass = nil
classes.JAMode = nil
end
-------------------------------------------------------------------------------------------------------------------
-- High-level functions for selecting and equipping gear sets.
-------------------------------------------------------------------------------------------------------------------
-- Central point to call to equip gear based on status.
-- Status - Player status that we're using to define what gear to equip.
function handle_equipping_gear(playerStatus, petStatus)
-- init a new eventArgs
local eventArgs = {handled = false}
-- Allow jobs to override this code
if job_handle_equipping_gear then
job_handle_equipping_gear(playerStatus, eventArgs)
end
-- Equip default gear if job didn't handle it.
if not eventArgs.handled then
equip_gear_by_status(playerStatus, petStatus)
end
end
-- Function to wrap logic for equipping gear on aftercast, status change, or user update.
-- @param status : The current or new player status that determines what sort of gear to equip.
function equip_gear_by_status(playerStatus, petStatus)
if _global.debug_mode then add_to_chat(123,'Debug: Equip gear for status ['..tostring(status)..'], HP='..tostring(player.hp)) end
playerStatus = playerStatus or player.status or 'Idle'
-- If status not defined, treat as idle.
-- Be sure to check for positive HP to make sure they're not dead.
if (playerStatus == 'Idle' or playerStatus == '') and player.hp > 0 then
equip(get_idle_set(petStatus))
elseif playerStatus == 'Engaged' then
equip(get_melee_set(petStatus))
elseif playerStatus == 'Resting' then
equip(get_resting_set(petStatus))
end
end
-------------------------------------------------------------------------------------------------------------------
-- Functions for constructing default gear sets based on status.
-------------------------------------------------------------------------------------------------------------------
-- Returns the appropriate idle set based on current state values and location.
-- Set construction order (all of which are optional):
-- sets.idle[idleScope][state.IdleMode][Pet[Engaged]][CustomIdleGroups]
--
-- Params:
-- petStatus - Optional explicit definition of pet status.
function get_idle_set(petStatus)
local idleSet = sets.idle
if not idleSet then
return {}
end
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('idle')
local idleScope
if buffactive.weakness then
idleScope = 'Weak'
elseif areas.Cities:contains(world.area) then
idleScope = 'Town'
else
idleScope = 'Field'
end
if idleSet[idleScope] then
idleSet = idleSet[idleScope]
mote_vars.set_breadcrumbs:append(idleScope)
end
if idleSet[state.IdleMode.current] then
idleSet = idleSet[state.IdleMode.current]
mote_vars.set_breadcrumbs:append(state.IdleMode.current)
end
if (pet.isvalid or state.Buff.Pet) and idleSet.Pet then
idleSet = idleSet.Pet
petStatus = petStatus or pet.status
mote_vars.set_breadcrumbs:append('Pet')
if petStatus == 'Engaged' and idleSet.Engaged then
idleSet = idleSet.Engaged
mote_vars.set_breadcrumbs:append('Engaged')
end
end
for _,group in ipairs(classes.CustomIdleGroups) do
if idleSet[group] then
idleSet = idleSet[group]
mote_vars.set_breadcrumbs:append(group)
end
end
idleSet = apply_defense(idleSet)
idleSet = apply_kiting(idleSet)
if user_customize_idle_set then
idleSet = user_customize_idle_set(idleSet)
end
if customize_idle_set then
idleSet = customize_idle_set(idleSet)
end
return idleSet
end
-- Returns the appropriate melee set based on current state values.
-- Set construction order (all sets after sets.engaged are optional):
-- sets.engaged[state.CombatForm][state.CombatWeapon][state.OffenseMode][state.DefenseMode][classes.CustomMeleeGroups (any number)]
function get_melee_set()
local meleeSet = sets.engaged
if not meleeSet then
return {}
end
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('engaged')
if state.CombatForm.has_value and meleeSet[state.CombatForm.value] then
meleeSet = meleeSet[state.CombatForm.value]
mote_vars.set_breadcrumbs:append(state.CombatForm.value)
end
if state.CombatWeapon.has_value and meleeSet[state.CombatWeapon.value] then
meleeSet = meleeSet[state.CombatWeapon.value]
mote_vars.set_breadcrumbs:append(state.CombatWeapon.value)
end
if meleeSet[state.OffenseMode.current] then
meleeSet = meleeSet[state.OffenseMode.current]
mote_vars.set_breadcrumbs:append(state.OffenseMode.current)
end
if meleeSet[state.HybridMode.current] then
meleeSet = meleeSet[state.HybridMode.current]
mote_vars.set_breadcrumbs:append(state.HybridMode.current)
end
for _,group in ipairs(classes.CustomMeleeGroups) do
if meleeSet[group] then
meleeSet = meleeSet[group]
mote_vars.set_breadcrumbs:append(group)
end
end
meleeSet = apply_defense(meleeSet)
meleeSet = apply_kiting(meleeSet)
if customize_melee_set then
meleeSet = customize_melee_set(meleeSet)
end
if user_customize_melee_set then
meleeSet = user_customize_melee_set(meleeSet)
end
return meleeSet
end
-- Returns the appropriate resting set based on current state values.
-- Set construction order:
-- sets.resting[state.RestingMode]
function get_resting_set()
local restingSet = sets.resting
if not restingSet then
return {}
end
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('resting')
if restingSet[state.RestingMode.current] then
restingSet = restingSet[state.RestingMode.current]
mote_vars.set_breadcrumbs:append(state.RestingMode.current)
end
return restingSet
end
-------------------------------------------------------------------------------------------------------------------
-- Functions for constructing default gear sets based on action.
-------------------------------------------------------------------------------------------------------------------
-- Get the default precast gear set.
function get_precast_set(spell, spellMap)
-- If there are no precast sets defined, bail out.
if not sets.precast then
return {}
end
local equipSet = sets.precast
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('precast')
-- Determine base sub-table from type of action being performed.
local cat
if spell.action_type == 'Magic' then
cat = 'FC'
elseif spell.action_type == 'Ranged Attack' then
cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
elseif spell.action_type == 'Ability' then
if spell.type == 'WeaponSkill' then
cat = 'WS'
elseif spell.type == 'JobAbility' then
cat = 'JA'
else
-- Allow fallback to .JA table if spell.type isn't found, for all non-weaponskill abilities.
cat = (sets.precast[spell.type] and spell.type) or 'JA'
end
elseif spell.action_type == 'Item' then
cat = 'Item'
end
-- If no proper sub-category is defined in the job file, bail out.
if cat then
if equipSet[cat] then
equipSet = equipSet[cat]
mote_vars.set_breadcrumbs:append(cat)
else
mote_vars.set_breadcrumbs:clear()
return {}
end
end
classes.SkipSkillCheck = false
-- Handle automatic selection of set based on spell class/name/map/skill/type.
equipSet = select_specific_set(equipSet, spell, spellMap)
-- Once we have a named base set, do checks for specialized modes (casting mode, weaponskill mode, etc).
if spell.action_type == 'Magic' then
if equipSet[state.CastingMode.current] then
equipSet = equipSet[state.CastingMode.current]
mote_vars.set_breadcrumbs:append(state.CastingMode.current)
end
elseif spell.type == 'WeaponSkill' then
equipSet = get_weaponskill_set(equipSet, spell, spellMap)
elseif spell.action_type == 'Ability' then
if classes.JAMode and equipSet[classes.JAMode] then
equipSet = equipSet[classes.JAMode]
mote_vars.set_breadcrumbs:append(classes.JAMode)
end
elseif spell.action_type == 'Ranged Attack' then
equipSet = get_ranged_set(equipSet, spell, spellMap)
end
-- Update defintions for element-specific gear that may be used.
set_elemental_gear(spell)
-- Return whatever we've constructed.
return equipSet
end
-- Get the default midcast gear set.
-- This builds on sets.midcast.
function get_midcast_set(spell, spellMap)
-- If there are no midcast sets defined, bail out.
if not sets.midcast then
return {}
end
local equipSet = sets.midcast
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('midcast')
-- Determine base sub-table from type of action being performed.
-- Only ranged attacks and items get specific sub-categories here.
local cat
if spell.action_type == 'Ranged Attack' then
cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
elseif spell.action_type == 'Item' then
cat = 'Item'
end
-- If no proper sub-category is defined in the job file, bail out.
if cat then
if equipSet[cat] then
equipSet = equipSet[cat]
mote_vars.set_breadcrumbs:append(cat)
else
mote_vars.set_breadcrumbs:clear()
return {}
end
end
classes.SkipSkillCheck = classes.NoSkillSpells:contains(spell.english)
-- Handle automatic selection of set based on spell class/name/map/skill/type.
equipSet = select_specific_set(equipSet, spell, spellMap)
-- After the default checks, do checks for specialized modes (casting mode, etc).
if spell.action_type == 'Magic' then
if equipSet[state.CastingMode.current] then
equipSet = equipSet[state.CastingMode.current]
mote_vars.set_breadcrumbs:append(state.CastingMode.current)
end
elseif spell.action_type == 'Ranged Attack' then
equipSet = get_ranged_set(equipSet, spell, spellMap)
end
-- Return whatever we've constructed.
return equipSet
end
-- Get the default pet midcast gear set.
-- This is built in sets.midcast.Pet.
function get_pet_midcast_set(spell, spellMap)
-- If there are no midcast sets defined, bail out.
if not sets.midcast or not sets.midcast.Pet then
return {}
end
local equipSet = sets.midcast.Pet
mote_vars.set_breadcrumbs:append('sets')
mote_vars.set_breadcrumbs:append('midcast')
mote_vars.set_breadcrumbs:append('Pet')
if sets.midcast and sets.midcast.Pet then
classes.SkipSkillCheck = false
equipSet = select_specific_set(equipSet, spell, spellMap)
-- We can only generally be certain about whether the pet's action is
-- Magic (ie: it cast a spell of its own volition) or Ability (it performed
-- an action at the request of the player). Allow CastinMode and
-- OffenseMode to refine whatever set was selected above.
if spell.action_type == 'Magic' then
if equipSet[state.CastingMode.current] then
equipSet = equipSet[state.CastingMode.current]
mote_vars.set_breadcrumbs:append(state.CastingMode.current)
end
elseif spell.action_type == 'Ability' then
if equipSet[state.OffenseMode.current] then
equipSet = equipSet[state.OffenseMode.current]
mote_vars.set_breadcrumbs:append(state.OffenseMode.current)
end
end
end
return equipSet
end
-- Function to handle the logic of selecting the proper weaponskill set.
function get_weaponskill_set(equipSet, spell, spellMap)
-- Custom handling for weaponskills
local ws_mode = state.WeaponskillMode.current
if ws_mode == 'Normal' then
-- If a particular weaponskill mode isn't specified, see if we have a weaponskill mode
-- corresponding to the current offense mode. If so, use that.
if spell.skill == 'Archery' or spell.skill == 'Marksmanship' then
if state.RangedMode.current ~= 'Normal' and state.WeaponskillMode:contains(state.RangedMode.current) then
ws_mode = state.RangedMode.current
end
else
if state.OffenseMode.current ~= 'Normal' and state.WeaponskillMode:contains(state.OffenseMode.current) then
ws_mode = state.OffenseMode.current
end
end
end
local custom_wsmode
-- Allow the job file to specify a preferred weaponskill mode
if get_custom_wsmode then
custom_wsmode = get_custom_wsmode(spell, spellMap, ws_mode)
end
-- If the job file returned a weaponskill mode, use that.
if custom_wsmode then
ws_mode = custom_wsmode
end
if equipSet[ws_mode] then
equipSet = equipSet[ws_mode]
mote_vars.set_breadcrumbs:append(ws_mode)
end
return equipSet
end
-- Function to handle the logic of selecting the proper ranged set.
function get_ranged_set(equipSet, spell, spellMap)
-- Attach Combat Form and Combat Weapon to set checks
if state.CombatForm.has_value and equipSet[state.CombatForm.value] then
equipSet = equipSet[state.CombatForm.value]
mote_vars.set_breadcrumbs:append(state.CombatForm.value)
end
if state.CombatWeapon.has_value and equipSet[state.CombatWeapon.value] then
equipSet = equipSet[state.CombatWeapon.value]
mote_vars.set_breadcrumbs:append(state.CombatWeapon.value)
end
-- Check for specific mode for ranged attacks (eg: Acc, Att, etc)
if equipSet[state.RangedMode.current] then
equipSet = equipSet[state.RangedMode.current]
mote_vars.set_breadcrumbs:append(state.RangedMode.current)
end
-- Tack on any additionally specified custom groups, if the sets are defined.
for _,group in ipairs(classes.CustomRangedGroups) do
if equipSet[group] then
equipSet = equipSet[group]
mote_vars.set_breadcrumbs:append(group)
end
end
return equipSet
end
-------------------------------------------------------------------------------------------------------------------
-- Functions for optional supplemental gear overriding the default sets defined above.
-------------------------------------------------------------------------------------------------------------------
-- Function to apply any active defense set on top of the supplied set
-- @param baseSet : The set that any currently active defense set will be applied on top of. (gear set table)
function apply_defense(baseSet)
if state.DefenseMode.current ~= 'None' then
local defenseSet = sets.defense
defenseSet = sets.defense[state[state.DefenseMode.current .. 'DefenseMode'].current] or defenseSet
for _,group in ipairs(classes.CustomDefenseGroups) do
defenseSet = defenseSet[group] or defenseSet
end
if customize_defense_set then
defenseSet = customize_defense_set(defenseSet)
end
baseSet = set_combine(baseSet, defenseSet)
end
return baseSet
end
-- Function to add kiting gear on top of the base set if kiting state is true.
-- @param baseSet : The gear set that the kiting gear will be applied on top of.
function apply_kiting(baseSet)
if state.Kiting.value then
if sets.Kiting then
baseSet = set_combine(baseSet, sets.Kiting)
end
end
return baseSet
end
-------------------------------------------------------------------------------------------------------------------
-- Utility functions for constructing default gear sets.
-------------------------------------------------------------------------------------------------------------------
-- Get a spell mapping for the spell.
function get_spell_map(spell)
local defaultSpellMap = classes.SpellMaps[spell.english]
local jobSpellMap
if job_get_spell_map then
jobSpellMap = job_get_spell_map(spell, defaultSpellMap)
end
return jobSpellMap or defaultSpellMap
end
-- Select the equipment set to equip from a given starting table, based on standard
-- selection order: custom class, spell name, spell map, spell skill, and spell type.
-- Spell skill and spell type may further refine their selections based on
-- custom class, spell name and spell map.
function select_specific_set(equipSet, spell, spellMap)
-- Take the determined base equipment set and try to get the simple naming extensions that
-- may apply to it (class, spell name, spell map).
local namedSet = get_named_set(equipSet, spell, spellMap)
-- If no simple naming sub-tables were found, and we simply got back the original equip set,
-- check for spell.skill and spell.type, then check the simple naming extensions again.
if namedSet == equipSet then
if spell.skill and equipSet[spell.skill] and not classes.SkipSkillCheck then
namedSet = equipSet[spell.skill]
mote_vars.set_breadcrumbs:append(spell.skill)
elseif spell.type and equipSet[spell.type] then
namedSet = equipSet[spell.type]
mote_vars.set_breadcrumbs:append(spell.type)
else
return equipSet
end
namedSet = get_named_set(namedSet, spell, spellMap)
end
return namedSet or equipSet
end
-- Simple utility function to handle a portion of the equipment set determination.
-- It attempts to select a sub-table of the provided equipment set based on the
-- standard search order of custom class, spell name, and spell map.
-- If no such set is found, it returns the original base set (equipSet) provided.
function get_named_set(equipSet, spell, spellMap)
if equipSet then
if classes.CustomClass and equipSet[classes.CustomClass] then
mote_vars.set_breadcrumbs:append(classes.CustomClass)
return equipSet[classes.CustomClass]
elseif equipSet[spell.english] then
mote_vars.set_breadcrumbs:append(spell.english)
return equipSet[spell.english]
elseif spellMap and equipSet[spellMap] then
mote_vars.set_breadcrumbs:append(spellMap)
return equipSet[spellMap]
else
return equipSet
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Hooks for other events.
-------------------------------------------------------------------------------------------------------------------
-- Called when the player's subjob changes.
function sub_job_change(newSubjob, oldSubjob)
if user_setup then
user_setup()
end
if job_sub_job_change then
job_sub_job_change(newSubjob, oldSubjob)
end
send_command('gs c update')
end
-- Called when the player's status changes.
function status_change(newStatus, oldStatus)
-- init a new eventArgs
local eventArgs = {handled = false}
mote_vars.set_breadcrumbs:clear()
-- Allow a global function to be called on status change.