Guest User

Inclues

a guest
Aug 12th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 34.75 KB | None | 0 0
  1. -------------------------------------------------------------------------------------------------------------------
  2. -- Common variables and functions to be included in job scripts, for general default handling.
  3. --
  4. -- Include this file in the get_sets() function with the command:
  5. -- include('Mote-Include.lua')
  6. --
  7. -- It will then automatically run its own init_include() function.
  8. --
  9. -- IMPORTANT: This include requires supporting include files:
  10. -- Mote-Utility
  11. -- Mote-Mappings
  12. -- Mote-SelfCommands
  13. -- Mote-Globals
  14. --
  15. -- Place the include() directive at the start of a job's get_sets() function.
  16. --
  17. -- Included variables and functions are considered to be at the same scope level as
  18. -- the job script itself, and can be used as such.
  19. -------------------------------------------------------------------------------------------------------------------
  20.  
  21. -------------------------------------------------------------------------------------------------------------------
  22. -- Initialization function that defines variables to be used.
  23. -- These are accessible at the including job lua script's scope.
  24. --
  25. -- Auto-initialize after defining this function.
  26. -------------------------------------------------------------------------------------------------------------------
  27.  
  28.  
  29. function init_include()
  30.     -- Used to define various types of data mappings.  These may be used in the initialization,
  31.     -- so load it up front.
  32.     include('Mote-Mappings')
  33.  
  34.     -- Var for tracking misc info
  35.     info = {}
  36.  
  37.     -- Var for tracking state values
  38.     state = {}
  39.  
  40.     -- General melee offense/defense modes, allowing for hybrid set builds, as well as idle/resting/weaponskill.
  41.     state.OffenseMode     = 'Normal'
  42.     state.DefenseMode     = 'Normal'
  43.     state.RangedMode      = 'Normal'
  44.     state.WeaponskillMode = 'Normal'
  45.     state.CastingMode     = 'Normal'
  46.     state.IdleMode        = 'Normal'
  47.     state.RestingMode     = 'Normal'
  48.  
  49.     -- All-out defense state, either physical or magical
  50.     state.Defense = {}
  51.     state.Defense.Active       = false
  52.     state.Defense.Type         = 'Physical'
  53.     state.Defense.PhysicalMode = 'PDT'
  54.     state.Defense.MagicalMode  = 'MDT'
  55.  
  56.     state.Kiting               = false
  57.     state.MaxWeaponskillDistance = 0
  58.  
  59.     state.SelectNPCTargets     = false
  60.     state.PCTargetMode         = 'default'
  61.  
  62.     state.CombatWeapon = nil
  63.     state.CombatForm = nil
  64.  
  65.     state.Buff = {}
  66.  
  67.  
  68.     -- Vars for specifying valid mode values.
  69.     -- Defaults here are just for example. Set them properly in each job file.
  70.     options = {}
  71.     options.OffenseModes = {'Normal'}
  72.     options.DefenseModes = {'Normal'}
  73.     options.RangedModes = {'Normal'}
  74.     options.WeaponskillModes = {'Normal'}
  75.     options.CastingModes = {'Normal'}
  76.     options.IdleModes = {'Normal'}
  77.     options.RestingModes = {'Normal'}
  78.     options.PhysicalDefenseModes = {'PDT'}
  79.     options.MagicalDefenseModes = {'MDT'}
  80.  
  81.     options.TargetModes = {'default', 'stpc', 'stpt', 'stal'}
  82.  
  83.  
  84.     -- Spell mappings to describe a 'type' of spell.  Used when searching for valid sets.
  85.     classes = {}
  86.     -- Basic spell mappings are based on common spell series.
  87.     -- EG: 'Cure' for Cure, Cure II, Cure III, Cure IV, Cure V, or Cure VI.
  88.     classes.SpellMaps = spell_maps
  89.     -- List of spells and spell maps that don't benefit from greater skill (though
  90.     -- they may benefit from spell-specific augments, such as improved regen or refresh).
  91.     -- Spells that fall under this category will be skipped when searching for
  92.     -- spell.skill sets.
  93.     classes.NoSkillSpells = no_skill_spells_list
  94.     classes.SkipSkillCheck = false
  95.     -- Custom, job-defined class, like the generic spell mappings.
  96.     -- Takes precedence over default spell maps.
  97.     -- Is reset at the end of each spell casting cycle (ie: at the end of aftercast).
  98.     classes.CustomClass = nil
  99.     classes.JAMode = nil
  100.     -- Custom groups used for defining melee and idle sets.  Persists long-term.
  101.     classes.CustomMeleeGroups = L{}
  102.     classes.CustomRangedGroups = L{}
  103.     classes.CustomIdleGroups = L{}
  104.     classes.CustomDefenseGroups = L{}
  105.  
  106.     -- Class variables for time-based flags
  107.     classes.Daytime = false
  108.     classes.DuskToDawn = false
  109.  
  110.  
  111.     -- Special control flags.
  112.     mote_vars = {}
  113.     mote_vars.show_set = nil
  114.     mote_vars.set_breadcrumbs = L{}
  115.  
  116.     -- Display text mapping.
  117.     on_off_names = {[true] = 'on', [false] = 'off'}
  118.     on_off_values = T{'on', 'off', 'true', 'false'}
  119.     true_values = T{'on', 'true'}
  120.  
  121.  
  122.     -- Subtables within the sets table that we expect to exist, and are annoying to have to
  123.     -- define within each individual job file.  We can define them here to make sure we don't
  124.     -- have to check for existence.  The job file should be including this before defining
  125.     -- any sets, so any changes it makes will override these anyway.
  126.     sets.precast = {}
  127.     sets.precast.FC = {}
  128.     sets.precast.JA = {}
  129.     sets.precast.WS = {}
  130.     sets.precast.RA = {}
  131.     sets.midcast = {}
  132.     sets.midcast.RA = {}
  133.     sets.midcast.Pet = {}
  134.     sets.idle = {}
  135.     sets.resting = {}
  136.     sets.engaged = {}
  137.     sets.defense = {}
  138.     sets.buff = {}
  139.  
  140.     gear = {}
  141.     gear.default = {}
  142.  
  143.     gear.ElementalGorget = {name=""}
  144.     gear.ElementalBelt = {name=""}
  145.     gear.ElementalObi = {name=""}
  146.     gear.ElementalCape = {name=""}
  147.     gear.ElementalRing = {name=""}
  148.     gear.FastcastStaff = {name=""}
  149.     gear.RecastStaff = {name=""}
  150.  
  151.  
  152.     -- Load externally-defined information (info that we don't want to change every time this file is updated).
  153.  
  154.     -- Used to define misc utility functions that may be useful for this include or any job files.
  155.     include('Mote-Utility')
  156.  
  157.     -- Used for all self-command handling.
  158.     include('Mote-SelfCommands')
  159.  
  160.     -- Include general user globals, such as custom binds or gear tables.
  161.     -- Load Mote-Globals first, followed by User-Globals, followed by <character>-Globals.
  162.     -- Any functions re-defined in the later includes will overwrite the earlier versions.
  163.     include('Mote-Globals')
  164.     optional_include({'user-globals.lua'})
  165.     optional_include({player.name..'-globals.lua'})
  166.  
  167.     -- *-globals.lua may define additional sets to be added to the local ones.
  168.     if define_global_sets then
  169.         define_global_sets()
  170.     end
  171.  
  172.     -- Global default binds (either from Mote-Globals or user-globals)
  173.     (binds_on_load or global_on_load)()
  174.  
  175.     -- Load a sidecar file for the job (if it exists) that may re-define init_gear_sets and file_unload.
  176.     load_sidecar(player.main_job)
  177.  
  178.     -- General var initialization and setup.
  179.     if job_setup then
  180.         job_setup()
  181.     end
  182.  
  183.     -- User-specific var initialization and setup.
  184.     if user_setup then
  185.         user_setup()
  186.     end
  187.  
  188.     -- Load up all the gear sets.
  189.     init_gear_sets()
  190. end
  191.  
  192. -- Auto-initialize the include
  193. init_include()
  194.  
  195. -- Called when this job file is unloaded (eg: job change)
  196. -- Conditional definition so that it doesn't overwrite explicit user
  197. -- versions of this function.
  198. if not file_unload then
  199.     file_unload = function()
  200.         if user_unload then
  201.             user_unload()
  202.         elseif job_file_unload then
  203.             job_file_unload()
  204.         end
  205.         _G[(binds_on_unload and 'binds_on_unload') or 'global_on_unload']()
  206.     end
  207. end
  208.  
  209.  
  210. -------------------------------------------------------------------------------------------------------------------
  211. -- Generalized functions for handling precast/midcast/aftercast for player-initiated actions.
  212. -- This depends on proper set naming.
  213. -- Global hooks can be written as user_xxx() to override functions at a global level.
  214. -- Each job can override any of these general functions using job_xxx() hooks.
  215. -------------------------------------------------------------------------------------------------------------------
  216.  
  217. ------------------------------------------------------------------------
  218. -- Generic function to map a set processing order to all action events.
  219. ------------------------------------------------------------------------
  220.  
  221.  
  222. -- Process actions in a specific order of events:
  223. -- Filter  - filter_xxx() functions determine whether to run any of the code for this action.
  224. -- Global  - user_xxx() functions get called first.  Define in Mote-Globals or User-Globals.
  225. -- Local   - job_xxx() functions get called next. Define in JOB.lua file.
  226. -- Default - default_xxx() functions get called next. Defined in this file.
  227. -- Cleanup - cleanup_xxx() functions always get called before exiting.
  228. --
  229. -- Parameters:
  230. -- spell - standard spell table passed in by GearSwap
  231. -- action - string defining the function mapping to use (precast, midcast, etc)
  232. function handle_actions(spell, action)
  233.     -- Init an eventArgs that allows cancelling.
  234.     local eventArgs = {handled = false, cancel = false}
  235.    
  236.     mote_vars.set_breadcrumbs:clear()
  237.  
  238.     -- Get the spell mapping, since we'll be passing it to various functions and checks.
  239.     local spellMap = get_spell_map(spell)
  240.  
  241.     -- General filter checks to see whether this function should be run.
  242.     -- If eventArgs.cancel is set, cancels this function, not the spell.
  243.     if _G['filter_'..action] then
  244.         _G['filter_'..action](spell, spellMap, eventArgs)
  245.     end
  246.  
  247.     -- If filter didn't cancel it, process user and default actions.
  248.     if not eventArgs.cancel then
  249.         -- Global user handling of this action
  250.         if _G['user_'..action] then
  251.             _G['user_'..action](spell, action, spellMap, eventArgs)
  252.            
  253.             if eventArgs.cancel then
  254.                 cancel_spell()
  255.             end
  256.         end
  257.        
  258.         -- Job-specific handling of this action
  259.         if not eventArgs.cancel and not eventArgs.handled and _G['job_'..action] then
  260.             _G['job_'..action](spell, action, spellMap, eventArgs)
  261.            
  262.             if eventArgs.cancel then
  263.                 cancel_spell()
  264.             end
  265.         end
  266.    
  267.         -- Default handling of this action
  268.         if not eventArgs.cancel and not eventArgs.handled and _G['default_'..action] then
  269.             _G['default_'..action](spell, spellMap)
  270.             display_breadcrumbs(spell, spellMap, action)
  271.         end
  272.        
  273.         -- Job-specific post-handling of this action
  274.         if not eventArgs.cancel and _G['job_post_'..action] then
  275.             _G['job_post_'..action](spell, action, spellMap, eventArgs)
  276.         end
  277.     end
  278.  
  279.     -- Cleanup once this action is done
  280.     if _G['cleanup_'..action] then
  281.         _G['cleanup_'..action](spell, spellMap, eventArgs)
  282.     end
  283. end
  284.  
  285.  
  286. --------------------------------------
  287. -- Action hooks called by GearSwap.
  288. --------------------------------------
  289.  
  290. function pretarget(spell)
  291.     handle_actions(spell, 'pretarget')
  292. end
  293.  
  294. function precast(spell)
  295.     if state.Buff[spell.english] ~= nil then
  296.         state.Buff[spell.english] = true
  297.     end
  298.     handle_actions(spell, 'precast')
  299. end
  300.  
  301. function midcast(spell)
  302.     handle_actions(spell, 'midcast')
  303. end
  304.  
  305. function aftercast(spell)
  306.     if state.Buff[spell.english] ~= nil then
  307.         state.Buff[spell.english] = not spell.interrupted or buffactive[spell.english] or false
  308.     end
  309.     handle_actions(spell, 'aftercast')
  310. end
  311.  
  312. function pet_midcast(spell)
  313.     handle_actions(spell, 'pet_midcast')
  314. end
  315.  
  316. function pet_aftercast(spell)
  317.     handle_actions(spell, 'pet_aftercast')
  318. end
  319.  
  320. --------------------------------------
  321. -- Default code for each action.
  322. --------------------------------------
  323.  
  324. function default_pretarget(spell, spellMap)
  325.     auto_change_target(spell, spellMap)
  326. end
  327.  
  328. function default_precast(spell, spellMap)
  329.     equip(get_precast_set(spell, spellMap))
  330. end
  331.  
  332. function default_midcast(spell, spellMap)
  333.     equip(get_midcast_set(spell, spellMap))
  334. end
  335.  
  336. function default_aftercast(spell, spellMap)
  337.     if not pet_midaction() then
  338.         handle_equipping_gear(player.status)
  339.     end
  340. end
  341.  
  342. function default_pet_midcast(spell, spellMap)
  343.     equip(get_pet_midcast_set(spell, spellMap))
  344. end
  345.  
  346. function default_pet_aftercast(spell, spellMap)
  347.     handle_equipping_gear(player.status)
  348. end
  349.  
  350. --------------------------------------
  351. -- Filters for each action.
  352. -- Set eventArgs.cancel to true to stop further processing.
  353. -- May show notification messages, but should not do any processing here.
  354. --------------------------------------
  355.  
  356. function filter_midcast(spell, spellMap, eventArgs)
  357.     if mote_vars.show_set == 'precast' then
  358.         eventArgs.cancel = true
  359.     end
  360. end
  361.  
  362. function filter_aftercast(spell, spellMap, eventArgs)
  363.     if mote_vars.show_set == 'precast' or mote_vars.show_set == 'midcast' or mote_vars.show_set == 'pet_midcast' then
  364.         eventArgs.cancel = true
  365.     elseif spell.name == 'Unknown Interrupt' then
  366.         eventArgs.cancel = true
  367.     end
  368. end
  369.  
  370. function filter_pet_midcast(spell, spellMap, eventArgs)
  371.     -- If we have show_set active for precast or midcast, don't try to equip pet midcast gear.
  372.     if mote_vars.show_set == 'precast' or mote_vars.show_set == 'midcast' then
  373.         add_to_chat(104, 'Show Sets: Pet midcast not equipped.')
  374.         eventArgs.cancel = true
  375.     end
  376. end
  377.  
  378. function filter_pet_aftercast(spell, spellMap, eventArgs)
  379.     -- If show_set is flagged for precast or midcast, don't try to equip aftercast gear.
  380.     if mote_vars.show_set == 'precast' or mote_vars.show_set == 'midcast' or mote_vars.show_set == 'pet_midcast' then
  381.         eventArgs.cancel = true
  382.     end
  383. end
  384.  
  385. --------------------------------------
  386. -- Cleanup code for each action.
  387. --------------------------------------
  388.  
  389. function cleanup_precast(spell, spellMap, eventArgs)
  390.     -- If show_set is flagged for precast, notify that we won't try to equip later gear.
  391.     if mote_vars.show_set == 'precast' then
  392.         add_to_chat(104, 'Show Sets: Stopping at precast.')
  393.     end
  394. end
  395.  
  396. function cleanup_midcast(spell, spellMap, eventArgs)
  397.     -- If show_set is flagged for midcast, notify that we won't try to equip later gear.
  398.     if mote_vars.show_set == 'midcast' then
  399.         add_to_chat(104, 'Show Sets: Stopping at midcast.')
  400.     end
  401. end
  402.  
  403. function cleanup_aftercast(spell, spellMap, eventArgs)
  404.     -- Reset custom classes after all possible precast/midcast/aftercast/job-specific usage of the value.
  405.     -- If we're in the middle of a pet action, pet_aftercast will handle clearing it.
  406.     if not pet_midaction() then
  407.         reset_transitory_classes()
  408.     end
  409. end
  410.  
  411. function cleanup_pet_midcast(spell, spellMap, eventArgs)
  412.     -- If show_set is flagged for pet midcast, notify that we won't try to equip later gear.
  413.     if mote_vars.show_set == 'pet_midcast' then
  414.         add_to_chat(104, 'Show Sets: Stopping at pet midcast.')
  415.     end
  416. end
  417.  
  418. function cleanup_pet_aftercast(spell, spellMap, eventArgs)
  419.     -- Reset custom classes after all possible precast/midcast/aftercast/job-specific usage of the value.
  420.     reset_transitory_classes()
  421. end
  422.  
  423.  
  424. -- Clears the values from classes that only exist til the action is complete.
  425. function reset_transitory_classes()
  426.     classes.CustomClass = nil
  427.     classes.JAMode = nil
  428. end
  429.  
  430.  
  431.  
  432. -------------------------------------------------------------------------------------------------------------------
  433. -- High-level functions for selecting and equipping gear sets.
  434. -------------------------------------------------------------------------------------------------------------------
  435.  
  436. -- Central point to call to equip gear based on status.
  437. -- Status - Player status that we're using to define what gear to equip.
  438. function handle_equipping_gear(playerStatus, petStatus)
  439.     -- init a new eventArgs
  440.     local eventArgs = {handled = false}
  441.  
  442.     -- Allow jobs to override this code
  443.     if job_handle_equipping_gear then
  444.         job_handle_equipping_gear(playerStatus, eventArgs)
  445.     end
  446.  
  447.     -- Equip default gear if job didn't handle it.
  448.     if not eventArgs.handled then
  449.         equip_gear_by_status(playerStatus, petStatus)
  450.     end
  451. end
  452.  
  453.  
  454. -- Function to wrap logic for equipping gear on aftercast, status change, or user update.
  455. -- @param status : The current or new player status that determines what sort of gear to equip.
  456. function equip_gear_by_status(playerStatus, petStatus)
  457.     if _global.debug_mode then add_to_chat(123,'Debug: Equip gear for status ['..tostring(status)..'], HP='..tostring(player.hp)) end
  458.  
  459.     playerStatus = playerStatus or player.status or 'Idle'
  460.    
  461.     -- If status not defined, treat as idle.
  462.     -- Be sure to check for positive HP to make sure they're not dead.
  463.     if (playerStatus == 'Idle' or playerStatus == '') and player.hp > 0 then
  464.         equip(get_idle_set(petStatus))
  465.     elseif playerStatus == 'Engaged' then
  466.         equip(get_melee_set(petStatus))
  467.     elseif playerStatus == 'Resting' then
  468.         equip(get_resting_set(petStatus))
  469.     end
  470. end
  471.  
  472.  
  473. -------------------------------------------------------------------------------------------------------------------
  474. -- Functions for constructing default gear sets based on status.
  475. -------------------------------------------------------------------------------------------------------------------
  476.  
  477. -- Returns the appropriate idle set based on current state values and location.
  478. -- Set construction order (all of which are optional):
  479. --   sets.idle[idleScope][state.IdleMode][Pet[Engaged]][CustomIdleGroups]
  480. --
  481. -- Params:
  482. -- petStatus - Optional explicit definition of pet status.
  483. function get_idle_set(petStatus)
  484.     local idleSet = sets.idle
  485.    
  486.     if not idleSet then
  487.         return {}
  488.     end
  489.    
  490.     mote_vars.set_breadcrumbs:append('sets')
  491.     mote_vars.set_breadcrumbs:append('idle')
  492.    
  493.     local idleScope
  494.  
  495.     if buffactive.weakness then
  496.         idleScope = 'Weak'
  497.     elseif areas.Cities:contains(world.area) then
  498.         idleScope = 'Town'
  499.     else
  500.         idleScope = 'Field'
  501.     end
  502.  
  503.     if idleSet[idleScope] then
  504.         idleSet = idleSet[idleScope]
  505.         mote_vars.set_breadcrumbs:append(idleScope)
  506.     end
  507.  
  508.     if idleSet[state.IdleMode] then
  509.         idleSet = idleSet[state.IdleMode]
  510.         mote_vars.set_breadcrumbs:append(state.IdleMode)
  511.     end
  512.  
  513.     if (pet.isvalid or state.Buff.Pet) and idleSet.Pet then
  514.         idleSet = idleSet.Pet
  515.         petStatus = petStatus or pet.status
  516.         mote_vars.set_breadcrumbs:append('Pet')
  517.  
  518.         if petStatus == 'Engaged' and idleSet.Engaged then
  519.             idleSet = idleSet.Engaged
  520.             mote_vars.set_breadcrumbs:append('Engaged')
  521.         end
  522.     end
  523.  
  524.     for _,group in ipairs(classes.CustomIdleGroups) do
  525.         if idleSet[group] then
  526.             idleSet = idleSet[group]
  527.             mote_vars.set_breadcrumbs:append(group)
  528.         end
  529.     end
  530.  
  531.     idleSet = apply_defense(idleSet)
  532.     idleSet = apply_kiting(idleSet)
  533.  
  534.     if customize_idle_set then
  535.         idleSet = customize_idle_set(idleSet)
  536.     end
  537.  
  538.     return idleSet
  539. end
  540.  
  541.  
  542. -- Returns the appropriate melee set based on current state values.
  543. -- Set construction order (all sets after sets.engaged are optional):
  544. --   sets.engaged[state.CombatForm][state.CombatWeapon][state.OffenseMode][state.DefenseMode][classes.CustomMeleeGroups (any number)]
  545. function get_melee_set()
  546.     local meleeSet = sets.engaged
  547.    
  548.     if not meleeSet then
  549.         return {}
  550.     end
  551.    
  552.     mote_vars.set_breadcrumbs:append('sets')
  553.     mote_vars.set_breadcrumbs:append('engaged')
  554.  
  555.     if state.CombatForm and meleeSet[state.CombatForm] then
  556.         meleeSet = meleeSet[state.CombatForm]
  557.         mote_vars.set_breadcrumbs:append(state.CombatForm)
  558.     end
  559.  
  560.     if state.CombatWeapon and meleeSet[state.CombatWeapon] then
  561.         meleeSet = meleeSet[state.CombatWeapon]
  562.         mote_vars.set_breadcrumbs:append(state.CombatWeapon)
  563.     end
  564.  
  565.     if meleeSet[state.OffenseMode] then
  566.         meleeSet = meleeSet[state.OffenseMode]
  567.         mote_vars.set_breadcrumbs:append(state.OffenseMode)
  568.     end
  569.  
  570.     if meleeSet[state.DefenseMode] then
  571.         meleeSet = meleeSet[state.DefenseMode]
  572.         mote_vars.set_breadcrumbs:append(state.DefenseMode)
  573.     end
  574.  
  575.     for _,group in ipairs(classes.CustomMeleeGroups) do
  576.         if meleeSet[group] then
  577.             meleeSet = meleeSet[group]
  578.             mote_vars.set_breadcrumbs:append(group)
  579.         end
  580.     end
  581.  
  582.     meleeSet = apply_defense(meleeSet)
  583.     meleeSet = apply_kiting(meleeSet)
  584.  
  585.     if customize_melee_set then
  586.         meleeSet = customize_melee_set(meleeSet)
  587.     end
  588.  
  589.     return meleeSet
  590. end
  591.  
  592.  
  593. -- Returns the appropriate resting set based on current state values.
  594. -- Set construction order:
  595. --   sets.resting[state.RestingMode]
  596. function get_resting_set()
  597.     local restingSet = sets.resting
  598.  
  599.     if not restingSet then
  600.         return {}
  601.     end
  602.  
  603.     mote_vars.set_breadcrumbs:append('sets')
  604.     mote_vars.set_breadcrumbs:append('resting')
  605.  
  606.     if restingSet[state.RestingMode] then
  607.         restingSet = restingSet[state.RestingMode]
  608.         mote_vars.set_breadcrumbs:append(state.RestingMode)
  609.     end
  610.  
  611.     return restingSet
  612. end
  613.  
  614.  
  615. -------------------------------------------------------------------------------------------------------------------
  616. -- Functions for constructing default gear sets based on action.
  617. -------------------------------------------------------------------------------------------------------------------
  618.  
  619. -- Get the default precast gear set.
  620. function get_precast_set(spell, spellMap)
  621.     -- If there are no precast sets defined, bail out.
  622.     if not sets.precast then
  623.         return {}
  624.     end
  625.  
  626.     local equipSet = sets.precast
  627.  
  628.     mote_vars.set_breadcrumbs:append('sets')
  629.     mote_vars.set_breadcrumbs:append('precast')
  630.    
  631.     -- Determine base sub-table from type of action being performed.
  632.    
  633.     local cat
  634.    
  635.     if spell.action_type == 'Magic' then
  636.         cat = 'FC'
  637.     elseif spell.action_type == 'Ranged Attack' then
  638.         cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
  639.     elseif spell.action_type == 'Ability' then
  640.         if spell.type == 'WeaponSkill' then
  641.             cat = 'WS'
  642.         elseif spell.type == 'JobAbility' then
  643.             cat = 'JA'
  644.         else
  645.             -- Allow fallback to .JA table if spell.type isn't found, for all non-weaponskill abilities.
  646.             cat = (sets.precast[spell.type] and spell.type) or 'JA'
  647.         end
  648.     elseif spell.action_type == 'Item' then
  649.         cat = 'Item'
  650.     end
  651.    
  652.     -- If no proper sub-category is defined in the job file, bail out.
  653.     if cat then
  654.         if equipSet[cat] then
  655.             equipSet = equipSet[cat]
  656.             mote_vars.set_breadcrumbs:append(cat)
  657.         else
  658.             mote_vars.set_breadcrumbs:clear()
  659.             return {}
  660.         end
  661.     end
  662.  
  663.     classes.SkipSkillCheck = false
  664.     -- Handle automatic selection of set based on spell class/name/map/skill/type.
  665.     equipSet = select_specific_set(equipSet, spell, spellMap)
  666.  
  667.    
  668.     -- Once we have a named base set, do checks for specialized modes (casting mode, weaponskill mode, etc).
  669.    
  670.     if spell.action_type == 'Magic' then
  671.         if equipSet[state.CastingMode] then
  672.             equipSet = equipSet[state.CastingMode]
  673.             mote_vars.set_breadcrumbs:append(state.CastingMode)
  674.         end
  675.     elseif spell.type == 'WeaponSkill' then
  676.         equipSet = get_weaponskill_set(equipSet, spell, spellMap)
  677.     elseif spell.action_type == 'Ability' then
  678.         if classes.JAMode and equipSet[classes.JAMode] then
  679.             equipSet = equipSet[classes.JAMode]
  680.             mote_vars.set_breadcrumbs:append(classes.JAMode)
  681.         end
  682.     elseif spell.action_type == 'Ranged Attack' then
  683.         equipSet = get_ranged_set(equipSet, spell, spellMap)
  684.     end
  685.  
  686.     -- Update defintions for element-specific gear that may be used.
  687.     set_elemental_gear(spell)
  688.    
  689.     -- Return whatever we've constructed.
  690.     return equipSet
  691. end
  692.  
  693.  
  694.  
  695. -- Get the default midcast gear set.
  696. -- This builds on sets.midcast.
  697. function get_midcast_set(spell, spellMap)
  698.     -- If there are no midcast sets defined, bail out.
  699.     if not sets.midcast then
  700.         return {}
  701.     end
  702.    
  703.     local equipSet = sets.midcast
  704.  
  705.     mote_vars.set_breadcrumbs:append('sets')
  706.     mote_vars.set_breadcrumbs:append('midcast')
  707.    
  708.     -- Determine base sub-table from type of action being performed.
  709.     -- Only ranged attacks and items get specific sub-categories here.
  710.    
  711.     local cat
  712.  
  713.     if spell.action_type == 'Ranged Attack' then
  714.         cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
  715.     elseif spell.action_type == 'Item' then
  716.         cat = 'Item'
  717.     end
  718.    
  719.     -- If no proper sub-category is defined in the job file, bail out.
  720.     if cat then
  721.         if equipSet[cat] then
  722.             equipSet = equipSet[cat]
  723.             mote_vars.set_breadcrumbs:append(cat)
  724.         else
  725.             mote_vars.set_breadcrumbs:clear()
  726.             return {}
  727.         end
  728.     end
  729.    
  730.     classes.SkipSkillCheck = classes.NoSkillSpells:contains(spell.english)
  731.     -- Handle automatic selection of set based on spell class/name/map/skill/type.
  732.     equipSet = select_specific_set(equipSet, spell, spellMap)
  733.    
  734.     -- After the default checks, do checks for specialized modes (casting mode, etc).
  735.    
  736.     if spell.action_type == 'Magic' then
  737.         if equipSet[state.CastingMode] then
  738.             equipSet = equipSet[state.CastingMode]
  739.             mote_vars.set_breadcrumbs:append(state.CastingMode)
  740.         end
  741.     elseif spell.action_type == 'Ranged Attack' then
  742.         equipSet = get_ranged_set(equipSet, spell, spellMap)
  743.     end
  744.    
  745.     -- Return whatever we've constructed.
  746.     return equipSet
  747. end
  748.  
  749.  
  750. -- Get the default pet midcast gear set.
  751. -- This is built in sets.midcast.Pet.
  752. function get_pet_midcast_set(spell, spellMap)
  753.     -- If there are no midcast sets defined, bail out.
  754.     if not sets.midcast or not sets.midcast.Pet then
  755.         return {}
  756.     end
  757.  
  758.     local equipSet = sets.midcast.Pet
  759.  
  760.     mote_vars.set_breadcrumbs:append('sets')
  761.     mote_vars.set_breadcrumbs:append('midcast')
  762.     mote_vars.set_breadcrumbs:append('Pet')
  763.  
  764.     if sets.midcast and sets.midcast.Pet then
  765.         classes.SkipSkillCheck = false
  766.         equipSet = select_specific_set(equipSet, spell, spellMap)
  767.  
  768.         -- We can only generally be certain about whether the pet's action is
  769.         -- Magic (ie: it cast a spell of its own volition) or Ability (it performed
  770.         -- an action at the request of the player).  Allow CastinMode and
  771.         -- OffenseMode to refine whatever set was selected above.
  772.         if spell.action_type == 'Magic' then
  773.             if equipSet[state.CastingMode] then
  774.                 equipSet = equipSet[state.CastingMode]
  775.                 mote_vars.set_breadcrumbs:append(state.CastingMode)
  776.             end
  777.         elseif spell.action_type == 'Ability' then
  778.             if equipSet[state.OffenseMode] then
  779.                 equipSet = equipSet[state.OffenseMode]
  780.                 mote_vars.set_breadcrumbs:append(state.OffenseMode)
  781.             end
  782.         end
  783.     end
  784.  
  785.     return equipSet
  786. end
  787.  
  788.  
  789. -- Function to handle the logic of selecting the proper weaponskill set.
  790. function get_weaponskill_set(equipSet, spell, spellMap)
  791.     -- Custom handling for weaponskills
  792.     local ws_mode = state.WeaponskillMode
  793.    
  794.     if ws_mode == 'Normal' then
  795.         -- If a particular weaponskill mode isn't specified, see if we have a weaponskill mode
  796.         -- corresponding to the current offense mode.  If so, use that.
  797.         if spell.skill == 'Archery' or spell.skill == 'Marksmanship' then
  798.             if state.RangedMode ~= 'Normal' and S(options.WeaponskillModes):contains(state.RangedMode) then
  799.                 ws_mode = state.RangedMode
  800.             end
  801.         else
  802.             if state.OffenseMode ~= 'Normal' and S(options.WeaponskillModes):contains(state.OffenseMode) then
  803.                 ws_mode = state.OffenseMode
  804.             end
  805.         end
  806.     end
  807.  
  808.     local custom_wsmode
  809.  
  810.     -- Allow the job file to specify a preferred weaponskill mode
  811.     if get_custom_wsmode then
  812.         custom_wsmode = get_custom_wsmode(spell, spellMap, ws_mode)
  813.     end
  814.  
  815.     -- If the job file returned a weaponskill mode, use that.
  816.     if custom_wsmode then
  817.         ws_mode = custom_wsmode
  818.     end
  819.  
  820.     if equipSet[ws_mode] then
  821.         equipSet = equipSet[ws_mode]
  822.         mote_vars.set_breadcrumbs:append(ws_mode)
  823.     end
  824.    
  825.     return equipSet
  826. end
  827.  
  828.  
  829. -- Function to handle the logic of selecting the proper ranged set.
  830. function get_ranged_set(equipSet, spell, spellMap)
  831.     -- Attach Combat Form and Combat Weapon to set checks
  832.     if state.CombatForm and equipSet[state.CombatForm] then
  833.         equipSet = equipSet[state.CombatForm]
  834.         mote_vars.set_breadcrumbs:append(state.CombatForm)
  835.     end
  836.  
  837.     if state.CombatWeapon and equipSet[state.CombatWeapon] then
  838.         equipSet = equipSet[state.CombatWeapon]
  839.         mote_vars.set_breadcrumbs:append(state.CombatWeapon)
  840.     end
  841.  
  842.     -- Check for specific mode for ranged attacks (eg: Acc, Att, etc)
  843.     if equipSet[state.RangedMode] then
  844.         equipSet = equipSet[state.RangedMode]
  845.         mote_vars.set_breadcrumbs:append(state.RangedMode)
  846.     end
  847.  
  848.     -- Tack on any additionally specified custom groups, if the sets are defined.
  849.     for _,group in ipairs(classes.CustomRangedGroups) do
  850.         if equipSet[group] then
  851.             equipSet = equipSet[group]
  852.             mote_vars.set_breadcrumbs:append(group)
  853.         end
  854.     end
  855.  
  856.     return equipSet
  857. end
  858.  
  859.  
  860. -------------------------------------------------------------------------------------------------------------------
  861. -- Functions for optional supplemental gear overriding the default sets defined above.
  862. -------------------------------------------------------------------------------------------------------------------
  863.  
  864. -- Function to apply any active defense set on top of the supplied set
  865. -- @param baseSet : The set that any currently active defense set will be applied on top of. (gear set table)
  866. function apply_defense(baseSet)
  867.     if state.Defense.Active then
  868.         local defenseSet = sets.defense
  869.  
  870.         if state.Defense.Type == 'Physical' then
  871.             defenseSet = sets.defense[state.Defense.PhysicalMode] or defenseSet
  872.         else
  873.             defenseSet = sets.defense[state.Defense.MagicalMode] or defenseSet
  874.         end
  875.  
  876.         for _,group in ipairs(classes.CustomDefenseGroups) do
  877.             defenseSet = defenseSet[group] or defenseSet
  878.         end
  879.  
  880.         baseSet = set_combine(baseSet, defenseSet)
  881.     end
  882.  
  883.     return baseSet
  884. end
  885.  
  886.  
  887. -- Function to add kiting gear on top of the base set if kiting state is true.
  888. -- @param baseSet : The gear set that the kiting gear will be applied on top of.
  889. function apply_kiting(baseSet)
  890.     if state.Kiting then
  891.         if sets.Kiting then
  892.             baseSet = set_combine(baseSet, sets.Kiting)
  893.         end
  894.     end
  895.  
  896.     return baseSet
  897. end
  898.  
  899.  
  900. -------------------------------------------------------------------------------------------------------------------
  901. -- Utility functions for constructing default gear sets.
  902. -------------------------------------------------------------------------------------------------------------------
  903.  
  904. -- Get a spell mapping for the spell.
  905. function get_spell_map(spell)
  906.     local defaultSpellMap = classes.SpellMaps[spell.english]
  907.     local jobSpellMap
  908.    
  909.     if job_get_spell_map then
  910.         jobSpellMap = job_get_spell_map(spell, defaultSpellMap)
  911.     end
  912.  
  913.     return jobSpellMap or defaultSpellMap
  914. end
  915.  
  916.  
  917. -- Select the equipment set to equip from a given starting table, based on standard
  918. -- selection order: custom class, spell name, spell map, spell skill, and spell type.
  919. -- Spell skill and spell type may further refine their selections based on
  920. -- custom class, spell name and spell map.
  921. function select_specific_set(equipSet, spell, spellMap)
  922.     -- Take the determined base equipment set and try to get the simple naming extensions that
  923.     -- may apply to it (class, spell name, spell map).
  924.     local namedSet = get_named_set(equipSet, spell, spellMap)
  925.    
  926.     -- If no simple naming sub-tables were found, and we simply got back the original equip set,
  927.     -- check for spell.skill and spell.type, then check the simple naming extensions again.
  928.     if namedSet == equipSet then
  929.         if spell.skill and equipSet[spell.skill] and not classes.SkipSkillCheck then
  930.             namedSet = equipSet[spell.skill]
  931.             mote_vars.set_breadcrumbs:append(spell.skill)
  932.         elseif spell.type and equipSet[spell.type] then
  933.             namedSet = equipSet[spell.type]
  934.             mote_vars.set_breadcrumbs:append(spell.type)
  935.         else
  936.             return equipSet
  937.         end
  938.        
  939.         namedSet = get_named_set(namedSet, spell, spellMap)
  940.     end
  941.  
  942.     return namedSet or equipSet
  943. end
  944.  
  945.  
  946. -- Simple utility function to handle a portion of the equipment set determination.
  947. -- It attempts to select a sub-table of the provided equipment set based on the
  948. -- standard search order of custom class, spell name, and spell map.
  949. -- If no such set is found, it returns the original base set (equipSet) provided.
  950. function get_named_set(equipSet, spell, spellMap)
  951.     if equipSet then
  952.         if classes.CustomClass and equipSet[classes.CustomClass] then
  953.             mote_vars.set_breadcrumbs:append(classes.CustomClass)
  954.             return equipSet[classes.CustomClass]
  955.         elseif equipSet[spell.english] then
  956.             mote_vars.set_breadcrumbs:append(spell.english)
  957.             return equipSet[spell.english]
  958.         elseif spellMap and equipSet[spellMap] then
  959.             mote_vars.set_breadcrumbs:append(spellMap)
  960.             return equipSet[spellMap]
  961.         else
  962.             return equipSet
  963.         end
  964.     end
  965. end
  966.  
  967.  
  968. -------------------------------------------------------------------------------------------------------------------
  969. -- Hooks for other events.
  970. -------------------------------------------------------------------------------------------------------------------
  971.  
  972. -- Called when the player's subjob changes.
  973. function sub_job_change(newSubjob, oldSubjob)
  974.     if user_setup then
  975.         user_setup()
  976.     end
  977.    
  978.     if job_sub_job_change then
  979.         job_sub_job_change(newSubjob, oldSubjob)
  980.     end
  981.    
  982.     send_command('gs c update')
  983. end
  984.  
  985.  
  986. -- Called when the player's status changes.
  987. function status_change(newStatus, oldStatus)
  988.     -- init a new eventArgs
  989.     local eventArgs = {handled = false}
  990.     mote_vars.set_breadcrumbs:clear()
  991.  
  992.     -- Allow a global function to be called on status change.
  993.     if user_status_change then
  994.         user_status_change(newStatus, oldStatus, eventArgs)
  995.     end
  996.  
  997.     -- Then call individual jobs to handle status change events.
  998.     if not eventArgs.handled then
  999.         if job_status_change then
  1000.             job_status_change(newStatus, oldStatus, eventArgs)
  1001.         end
  1002.     end
  1003.  
  1004.     -- Handle equipping default gear if the job didn't mark this as handled.
  1005.     if not eventArgs.handled then
  1006.         handle_equipping_gear(newStatus)
  1007.         display_breadcrumbs()
  1008.     end
  1009. end
  1010.  
  1011.  
  1012. -- Called when a player gains or loses a buff.
  1013. -- buff == buff gained or lost
  1014. -- gain == true if the buff was gained, false if it was lost.
  1015. function buff_change(buff, gain)
  1016.     -- Init a new eventArgs
  1017.     local eventArgs = {handled = false}
  1018.  
  1019.     if state.Buff[buff] ~= nil then
  1020.         state.Buff[buff] = gain
  1021.     end
  1022.  
  1023.     -- Allow a global function to be called on buff change.
  1024.     if user_buff_change then
  1025.         user_buff_change(buff, gain, eventArgs)
  1026.     end
  1027.  
  1028.     -- Allow jobs to handle buff change events.
  1029.     if not eventArgs.handled then
  1030.         if job_buff_change then
  1031.             job_buff_change(buff, gain, eventArgs)
  1032.         end
  1033.     end
  1034. end
  1035.  
  1036.  
  1037. -- Called when a player gains or loses a pet.
  1038. -- pet == pet gained or lost
  1039. -- gain == true if the pet was gained, false if it was lost.
  1040. function pet_change(pet, gain)
  1041.     -- Init a new eventArgs
  1042.     local eventArgs = {handled = false}
  1043.  
  1044.     -- Allow jobs to handle pet change events.
  1045.     if job_pet_change then
  1046.         job_pet_change(pet, gain, eventArgs)
  1047.     end
  1048.  
  1049.     -- Equip default gear if not handled by the job.
  1050.     if not eventArgs.handled then
  1051.         handle_equipping_gear(player.status)
  1052.     end
  1053. end
  1054.  
  1055.  
  1056. -- Called when the player's pet's status changes.
  1057. -- Note that this is also called after pet_change when the pet is released.
  1058. -- As such, don't automatically handle gear equips.  Only do so if directed
  1059. -- to do so by the job.
  1060. function pet_status_change(newStatus, oldStatus)
  1061.     -- Init a new eventArgs
  1062.     local eventArgs = {handled = false}
  1063.  
  1064.     -- Allow jobs to override this code
  1065.     if job_pet_status_change then
  1066.         job_pet_status_change(newStatus, oldStatus, eventArgs)
  1067.     end
  1068. end
  1069.  
  1070.  
  1071. -------------------------------------------------------------------------------------------------------------------
  1072. -- Debugging functions.
  1073. -------------------------------------------------------------------------------------------------------------------
  1074.  
  1075. -- This is a debugging function that will print the accumulated set selection
  1076. -- breadcrumbs for the default selected set for any given action stage.
  1077. function display_breadcrumbs(spell, spellMap, action)
  1078.     if not _settings.debug_mode then
  1079.         return
  1080.     end
  1081.    
  1082.     local msg = 'Default '
  1083.    
  1084.     if action and spell then
  1085.         msg = msg .. action .. ' set selection for ' .. spell.name
  1086.     end
  1087.    
  1088.     if spellMap then
  1089.         msg = msg .. ' (' .. spellMap .. ')'
  1090.     end
  1091.     msg = msg .. ' : '
  1092.    
  1093.     local cons
  1094.    
  1095.     for _,name in ipairs(mote_vars.set_breadcrumbs) do
  1096.         if not cons then
  1097.             cons = name
  1098.         else
  1099.             if name:contains(' ') or name:contains("'") then
  1100.                 cons = cons .. '["' .. name .. '"]'
  1101.             else
  1102.                 cons = cons .. '.' .. name
  1103.             end
  1104.         end
  1105.     end
  1106.  
  1107.     if cons then
  1108.         if action and cons == ('sets.' .. action) then
  1109.             msg = msg .. "None"
  1110.         else
  1111.             msg = msg .. tostring(cons)
  1112.         end
  1113.         add_to_chat(123, msg)
  1114.     end
  1115. end
Advertisement
Add Comment
Please, Sign In to add comment