Advertisement
Guest User

Mote Include

a guest
Jun 16th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.38 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. current_mote_include_version = 2
  29.  
  30. function init_include()
  31. -- Used to define various types of data mappings. These may be used in the initialization, so load it up front.
  32. include('Mote-Mappings')
  33.  
  34. -- Modes is the include for a mode-tracking variable class. Used for state vars, below.
  35. include('Modes')
  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. -- This just defines the vars and sets the descriptions. List modes with no values automatically
  42. -- get assigned a 'Normal' default value.
  43. state.OffenseMode = M{['description'] = 'Offense Mode'}
  44. state.HybridMode = M{['description'] = 'Hybrid Mode'}
  45. state.RangedMode = M{['description'] = 'Ranged Mode'}
  46. state.WeaponskillMode = M{['description'] = 'Weaponskill Mode'}
  47. state.CastingMode = M{['description'] = 'Casting Mode'}
  48. state.IdleMode = M{['description'] = 'Idle Mode'}
  49. state.RestingMode = M{['description'] = 'Resting Mode'}
  50.  
  51. state.DefenseMode = M{['description'] = 'Defense Mode', 'None', 'Physical', 'Magical'}
  52. state.PhysicalDefenseMode = M{['description'] = 'Physical Defense Mode', 'PDT'}
  53. state.MagicalDefenseMode = M{['description'] = 'Magical Defense Mode', 'MDT'}
  54.  
  55. state.Kiting = M(false, 'Kiting')
  56. state.SelectNPCTargets = M(false, 'Select NPC Targets')
  57. state.PCTargetMode = M{['description'] = 'PC Target Mode', 'default', 'stpt', 'stal', 'stpc'}
  58.  
  59. state.EquipStop = M{['description'] = 'Stop Equipping Gear', 'off', 'precast', 'midcast', 'pet_midcast'}
  60.  
  61. state.CombatWeapon = M{['description']='Combat Weapon', ['string']=''}
  62. state.CombatForm = M{['description']='Combat Form', ['string']=''}
  63.  
  64. -- Non-mode vars that are used for state tracking.
  65. state.MaxWeaponskillDistance = 0
  66. state.Buff = {}
  67.  
  68. -- Classes describe a 'type' of action. They are similar to state, but
  69. -- may have any free-form value, or describe an entire table of mapped values.
  70. classes = {}
  71. -- Basic spell mappings are based on common spell series.
  72. -- EG: 'Cure' for Cure, Cure II, Cure III, Cure IV, Cure V, or Cure VI.
  73. classes.SpellMaps = spell_maps
  74. -- List of spells and spell maps that don't benefit from greater skill (though
  75. -- they may benefit from spell-specific augments, such as improved regen or refresh).
  76. -- Spells that fall under this category will be skipped when searching for
  77. -- spell.skill sets.
  78. classes.NoSkillSpells = no_skill_spells_list
  79. classes.SkipSkillCheck = false
  80. -- Custom, job-defined class, like the generic spell mappings.
  81. -- Takes precedence over default spell maps.
  82. -- Is reset at the end of each spell casting cycle (ie: at the end of aftercast).
  83. classes.JAMode = nil
  84. classes.CustomClass = nil
  85. -- Custom groups used for defining melee and idle sets. Persists long-term.
  86. classes.CustomMeleeGroups = L{}
  87. classes.CustomRangedGroups = L{}
  88. classes.CustomIdleGroups = L{}
  89. classes.CustomDefenseGroups = L{}
  90.  
  91. -- Class variables for time-based flags
  92. classes.Daytime = false
  93. classes.DuskToDawn = false
  94.  
  95.  
  96. -- Var for tracking misc info
  97. info = {}
  98. options = {}
  99.  
  100. -- Special control flags.
  101. mote_vars = {}
  102. mote_vars.set_breadcrumbs = L{}
  103. mote_vars.res_buffs = S{}
  104. for index,struct in pairs(gearswap.res.buffs) do
  105. mote_vars.res_buffs:add(struct.en)
  106. end
  107.  
  108. -- Sub-tables within the sets table that we expect to exist, and are annoying to have to
  109. -- define within each individual job file. We can define them here to make sure we don't
  110. -- have to check for existence. The job file should be including this before defining
  111. -- any sets, so any changes it makes will override these anyway.
  112. sets.precast = {}
  113. sets.precast.FC = {}
  114. sets.precast.JA = {}
  115. sets.precast.WS = {}
  116. sets.precast.RA = {}
  117. sets.midcast = {}
  118. sets.midcast.RA = {}
  119. sets.midcast.Pet = {}
  120. sets.idle = {}
  121. sets.resting = {}
  122. sets.engaged = {}
  123. sets.defense = {}
  124. sets.buff = {}
  125.  
  126. gear = {}
  127. gear.default = {}
  128.  
  129. gear.ElementalGorget = {name=""}
  130. gear.ElementalBelt = {name=""}
  131. gear.ElementalObi = {name=""}
  132. gear.ElementalCape = {name=""}
  133. gear.ElementalRing = {name=""}
  134. gear.FastcastStaff = {name=""}
  135. gear.RecastStaff = {name=""}
  136.  
  137.  
  138. -- Load externally-defined information (info that we don't want to change every time this file is updated).
  139.  
  140. -- Used to define misc utility functions that may be useful for this include or any job files.
  141. include('Mote-Utility')
  142.  
  143. -- Used for all self-command handling.
  144. include('Mote-SelfCommands')
  145.  
  146. -- Include general user globals, such as custom binds or gear tables.
  147. -- Load Mote-Globals first, followed by User-Globals, followed by <character>-Globals.
  148. -- Any functions re-defined in the later includes will overwrite the earlier versions.
  149. include('Mote-Globals')
  150. optional_include({'user-globals.lua'})
  151. optional_include({player.name..'-globals.lua'})
  152.  
  153. -- *-globals.lua may define additional sets to be added to the local ones.
  154. if define_global_sets then
  155. define_global_sets()
  156. end
  157.  
  158. -- Global default binds (either from Mote-Globals or user-globals)
  159. (binds_on_load or global_on_load)()
  160.  
  161. -- Load a sidecar file for the job (if it exists) that may re-define init_gear_sets and file_unload.
  162. load_sidecar(player.main_job)
  163.  
  164. -- General var initialization and setup.
  165. if job_setup then
  166. job_setup()
  167. end
  168.  
  169. -- User-specific var initialization and setup.
  170. if user_setup then
  171. user_setup()
  172. end
  173.  
  174. -- Load up all the gear sets.
  175. init_gear_sets()
  176. end
  177.  
  178. if not mote_include_version or mote_include_version < current_mote_include_version then
  179. add_to_chat(123,'Warning: Your job file is out of date. Please update to the latest repository baseline.')
  180. add_to_chat(123,'For details, visit https://github.com/Kinematics/GearSwap-Jobs/wiki/Upgrading')
  181. rev = mote_include_version or 1
  182. include_path('rev' .. tostring(rev))
  183. include('Mote-Include')
  184. return
  185. end
  186.  
  187. -- Auto-initialize the include
  188. init_include()
  189.  
  190. -- Called when this job file is unloaded (eg: job change)
  191. -- Conditional definition so that it doesn't overwrite explicit user
  192. -- versions of this function.
  193. if not file_unload then
  194. file_unload = function()
  195. if user_unload then
  196. user_unload()
  197. elseif job_file_unload then
  198. job_file_unload()
  199. end
  200. _G[(binds_on_unload and 'binds_on_unload') or 'global_on_unload']()
  201. end
  202. end
  203.  
  204.  
  205. -------------------------------------------------------------------------------------------------------------------
  206. -- Generalized functions for handling precast/midcast/aftercast for player-initiated actions.
  207. -- This depends on proper set naming.
  208. -- Global hooks can be written as user_xxx() to override functions at a global level.
  209. -- Each job can override any of these general functions using job_xxx() hooks.
  210. -------------------------------------------------------------------------------------------------------------------
  211.  
  212. ------------------------------------------------------------------------
  213. -- Generic function to map a set processing order to all action events.
  214. ------------------------------------------------------------------------
  215.  
  216.  
  217. -- Process actions in a specific order of events:
  218. -- Filter - filter_xxx() functions determine whether to run any of the code for this action.
  219. -- Global - user_xxx() functions get called first. Define in Mote-Globals or User-Globals.
  220. -- Local - job_xxx() functions get called next. Define in JOB.lua file.
  221. -- Default - default_xxx() functions get called next. Defined in this file.
  222. -- Cleanup - cleanup_xxx() functions always get called before exiting.
  223. --
  224. -- Parameters:
  225. -- spell - standard spell table passed in by GearSwap
  226. -- action - string defining the function mapping to use (precast, midcast, etc)
  227. function handle_actions(spell, action)
  228. -- Init an eventArgs that allows cancelling.
  229. local eventArgs = {handled = false, cancel = false}
  230.  
  231. mote_vars.set_breadcrumbs:clear()
  232.  
  233. -- Get the spell mapping, since we'll be passing it to various functions and checks.
  234. local spellMap = get_spell_map(spell)
  235.  
  236. -- General filter checks to see whether this function should be run.
  237. -- If eventArgs.cancel is set, cancels this function, not the spell.
  238. if _G['filter_'..action] then
  239. _G['filter_'..action](spell, spellMap, eventArgs)
  240. end
  241.  
  242. -- If filter didn't cancel it, process user and default actions.
  243. if not eventArgs.cancel then
  244. -- Global user handling of this action
  245. if _G['user_'..action] then
  246. _G['user_'..action](spell, action, spellMap, eventArgs)
  247.  
  248. if eventArgs.cancel then
  249. cancel_spell()
  250. end
  251. end
  252.  
  253. -- Job-specific handling of this action
  254. if not eventArgs.cancel and not eventArgs.handled and _G['job_'..action] then
  255. _G['job_'..action](spell, action, spellMap, eventArgs)
  256.  
  257. if eventArgs.cancel then
  258. cancel_spell()
  259. end
  260. end
  261.  
  262. -- Default handling of this action
  263. if not eventArgs.cancel and not eventArgs.handled and _G['default_'..action] then
  264. _G['default_'..action](spell, spellMap)
  265. display_breadcrumbs(spell, spellMap, action)
  266. end
  267.  
  268. -- Global post-handling of this action
  269. if not eventArgs.cancel and _G['user_post_'..action] then
  270. _G['user_post_'..action](spell, action, spellMap, eventArgs)
  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 state.EquipStop.value == 'precast' then
  358. eventArgs.cancel = true
  359. end
  360. end
  361.  
  362. function filter_aftercast(spell, spellMap, eventArgs)
  363. if state.EquipStop.value == 'precast' or state.EquipStop.value == 'midcast' or state.EquipStop.value == '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 state.EquipStop.value == 'precast' or state.EquipStop.value == '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 state.EquipStop.value == 'precast' or state.EquipStop.value == 'midcast' or state.EquipStop.value == '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 state.EquipStop.value == '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 state.EquipStop.value == '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 state.EquipStop.value == '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.current] then
  509. idleSet = idleSet[state.IdleMode.current]
  510. mote_vars.set_breadcrumbs:append(state.IdleMode.current)
  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 user_customize_idle_set then
  535. idleSet = user_customize_idle_set(idleSet)
  536. end
  537.  
  538. if customize_idle_set then
  539. idleSet = customize_idle_set(idleSet)
  540. end
  541.  
  542. return idleSet
  543. end
  544.  
  545.  
  546. -- Returns the appropriate melee set based on current state values.
  547. -- Set construction order (all sets after sets.engaged are optional):
  548. -- sets.engaged[state.CombatForm][state.CombatWeapon][state.OffenseMode][state.DefenseMode][classes.CustomMeleeGroups (any number)]
  549. function get_melee_set()
  550. local meleeSet = sets.engaged
  551.  
  552. if not meleeSet then
  553. return {}
  554. end
  555.  
  556. mote_vars.set_breadcrumbs:append('sets')
  557. mote_vars.set_breadcrumbs:append('engaged')
  558.  
  559. if state.CombatForm.has_value and meleeSet[state.CombatForm.value] then
  560. meleeSet = meleeSet[state.CombatForm.value]
  561. mote_vars.set_breadcrumbs:append(state.CombatForm.value)
  562. end
  563.  
  564. if state.CombatWeapon.has_value and meleeSet[state.CombatWeapon.value] then
  565. meleeSet = meleeSet[state.CombatWeapon.value]
  566. mote_vars.set_breadcrumbs:append(state.CombatWeapon.value)
  567. end
  568.  
  569. if meleeSet[state.OffenseMode.current] then
  570. meleeSet = meleeSet[state.OffenseMode.current]
  571. mote_vars.set_breadcrumbs:append(state.OffenseMode.current)
  572. end
  573.  
  574. if meleeSet[state.HybridMode.current] then
  575. meleeSet = meleeSet[state.HybridMode.current]
  576. mote_vars.set_breadcrumbs:append(state.HybridMode.current)
  577. end
  578.  
  579. for _,group in ipairs(classes.CustomMeleeGroups) do
  580. if meleeSet[group] then
  581. meleeSet = meleeSet[group]
  582. mote_vars.set_breadcrumbs:append(group)
  583. end
  584. end
  585.  
  586. meleeSet = apply_defense(meleeSet)
  587. meleeSet = apply_kiting(meleeSet)
  588.  
  589. if customize_melee_set then
  590. meleeSet = customize_melee_set(meleeSet)
  591. end
  592.  
  593. if user_customize_melee_set then
  594. meleeSet = user_customize_melee_set(meleeSet)
  595. end
  596.  
  597. return meleeSet
  598. end
  599.  
  600.  
  601. -- Returns the appropriate resting set based on current state values.
  602. -- Set construction order:
  603. -- sets.resting[state.RestingMode]
  604. function get_resting_set()
  605. local restingSet = sets.resting
  606.  
  607. if not restingSet then
  608. return {}
  609. end
  610.  
  611. mote_vars.set_breadcrumbs:append('sets')
  612. mote_vars.set_breadcrumbs:append('resting')
  613.  
  614. if restingSet[state.RestingMode.current] then
  615. restingSet = restingSet[state.RestingMode.current]
  616. mote_vars.set_breadcrumbs:append(state.RestingMode.current)
  617. end
  618.  
  619. return restingSet
  620. end
  621.  
  622.  
  623. -------------------------------------------------------------------------------------------------------------------
  624. -- Functions for constructing default gear sets based on action.
  625. -------------------------------------------------------------------------------------------------------------------
  626.  
  627. -- Get the default precast gear set.
  628. function get_precast_set(spell, spellMap)
  629. -- If there are no precast sets defined, bail out.
  630. if not sets.precast then
  631. return {}
  632. end
  633.  
  634. local equipSet = sets.precast
  635.  
  636. mote_vars.set_breadcrumbs:append('sets')
  637. mote_vars.set_breadcrumbs:append('precast')
  638.  
  639. -- Determine base sub-table from type of action being performed.
  640.  
  641. local cat
  642.  
  643. if spell.action_type == 'Magic' then
  644. cat = 'FC'
  645. elseif spell.action_type == 'Ranged Attack' then
  646. cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
  647. elseif spell.action_type == 'Ability' then
  648. if spell.type == 'WeaponSkill' then
  649. cat = 'WS'
  650. elseif spell.type == 'JobAbility' then
  651. cat = 'JA'
  652. else
  653. -- Allow fallback to .JA table if spell.type isn't found, for all non-weaponskill abilities.
  654. cat = (sets.precast[spell.type] and spell.type) or 'JA'
  655. end
  656. elseif spell.action_type == 'Item' then
  657. cat = 'Item'
  658. end
  659.  
  660. -- If no proper sub-category is defined in the job file, bail out.
  661. if cat then
  662. if equipSet[cat] then
  663. equipSet = equipSet[cat]
  664. mote_vars.set_breadcrumbs:append(cat)
  665. else
  666. mote_vars.set_breadcrumbs:clear()
  667. return {}
  668. end
  669. end
  670.  
  671. classes.SkipSkillCheck = false
  672. -- Handle automatic selection of set based on spell class/name/map/skill/type.
  673. equipSet = select_specific_set(equipSet, spell, spellMap)
  674.  
  675.  
  676. -- Once we have a named base set, do checks for specialized modes (casting mode, weaponskill mode, etc).
  677.  
  678. if spell.action_type == 'Magic' then
  679. if equipSet[state.CastingMode.current] then
  680. equipSet = equipSet[state.CastingMode.current]
  681. mote_vars.set_breadcrumbs:append(state.CastingMode.current)
  682. end
  683. elseif spell.type == 'WeaponSkill' then
  684. equipSet = get_weaponskill_set(equipSet, spell, spellMap)
  685. elseif spell.action_type == 'Ability' then
  686. if classes.JAMode and equipSet[classes.JAMode] then
  687. equipSet = equipSet[classes.JAMode]
  688. mote_vars.set_breadcrumbs:append(classes.JAMode)
  689. end
  690. elseif spell.action_type == 'Ranged Attack' then
  691. equipSet = get_ranged_set(equipSet, spell, spellMap)
  692. end
  693.  
  694. -- Update defintions for element-specific gear that may be used.
  695. set_elemental_gear(spell)
  696.  
  697. -- Return whatever we've constructed.
  698. return equipSet
  699. end
  700.  
  701.  
  702.  
  703. -- Get the default midcast gear set.
  704. -- This builds on sets.midcast.
  705. function get_midcast_set(spell, spellMap)
  706. -- If there are no midcast sets defined, bail out.
  707. if not sets.midcast then
  708. return {}
  709. end
  710.  
  711. local equipSet = sets.midcast
  712.  
  713. mote_vars.set_breadcrumbs:append('sets')
  714. mote_vars.set_breadcrumbs:append('midcast')
  715.  
  716. -- Determine base sub-table from type of action being performed.
  717. -- Only ranged attacks and items get specific sub-categories here.
  718.  
  719. local cat
  720.  
  721. if spell.action_type == 'Ranged Attack' then
  722. cat = (sets.precast.RangedAttack and 'RangedAttack') or 'RA'
  723. elseif spell.action_type == 'Item' then
  724. cat = 'Item'
  725. end
  726.  
  727. -- If no proper sub-category is defined in the job file, bail out.
  728. if cat then
  729. if equipSet[cat] then
  730. equipSet = equipSet[cat]
  731. mote_vars.set_breadcrumbs:append(cat)
  732. else
  733. mote_vars.set_breadcrumbs:clear()
  734. return {}
  735. end
  736. end
  737.  
  738. classes.SkipSkillCheck = classes.NoSkillSpells:contains(spell.english)
  739. -- Handle automatic selection of set based on spell class/name/map/skill/type.
  740. equipSet = select_specific_set(equipSet, spell, spellMap)
  741.  
  742. -- After the default checks, do checks for specialized modes (casting mode, etc).
  743.  
  744. if spell.action_type == 'Magic' then
  745. if equipSet[state.CastingMode.current] then
  746. equipSet = equipSet[state.CastingMode.current]
  747. mote_vars.set_breadcrumbs:append(state.CastingMode.current)
  748. end
  749. elseif spell.action_type == 'Ranged Attack' then
  750. equipSet = get_ranged_set(equipSet, spell, spellMap)
  751. end
  752.  
  753. -- Return whatever we've constructed.
  754. return equipSet
  755. end
  756.  
  757.  
  758. -- Get the default pet midcast gear set.
  759. -- This is built in sets.midcast.Pet.
  760. function get_pet_midcast_set(spell, spellMap)
  761. -- If there are no midcast sets defined, bail out.
  762. if not sets.midcast or not sets.midcast.Pet then
  763. return {}
  764. end
  765.  
  766. local equipSet = sets.midcast.Pet
  767.  
  768. mote_vars.set_breadcrumbs:append('sets')
  769. mote_vars.set_breadcrumbs:append('midcast')
  770. mote_vars.set_breadcrumbs:append('Pet')
  771.  
  772. if sets.midcast and sets.midcast.Pet then
  773. classes.SkipSkillCheck = false
  774. equipSet = select_specific_set(equipSet, spell, spellMap)
  775.  
  776. -- We can only generally be certain about whether the pet's action is
  777. -- Magic (ie: it cast a spell of its own volition) or Ability (it performed
  778. -- an action at the request of the player). Allow CastinMode and
  779. -- OffenseMode to refine whatever set was selected above.
  780. if spell.action_type == 'Magic' then
  781. if equipSet[state.CastingMode.current] then
  782. equipSet = equipSet[state.CastingMode.current]
  783. mote_vars.set_breadcrumbs:append(state.CastingMode.current)
  784. end
  785. elseif spell.action_type == 'Ability' then
  786. if equipSet[state.OffenseMode.current] then
  787. equipSet = equipSet[state.OffenseMode.current]
  788. mote_vars.set_breadcrumbs:append(state.OffenseMode.current)
  789. end
  790. end
  791. end
  792.  
  793. return equipSet
  794. end
  795.  
  796.  
  797. -- Function to handle the logic of selecting the proper weaponskill set.
  798. function get_weaponskill_set(equipSet, spell, spellMap)
  799. -- Custom handling for weaponskills
  800. local ws_mode = state.WeaponskillMode.current
  801.  
  802. if ws_mode == 'Normal' then
  803. -- If a particular weaponskill mode isn't specified, see if we have a weaponskill mode
  804. -- corresponding to the current offense mode. If so, use that.
  805. if spell.skill == 'Archery' or spell.skill == 'Marksmanship' then
  806. if state.RangedMode.current ~= 'Normal' and state.WeaponskillMode:contains(state.RangedMode.current) then
  807. ws_mode = state.RangedMode.current
  808. end
  809. else
  810. if state.OffenseMode.current ~= 'Normal' and state.WeaponskillMode:contains(state.OffenseMode.current) then
  811. ws_mode = state.OffenseMode.current
  812. end
  813. end
  814. end
  815.  
  816. local custom_wsmode
  817.  
  818. -- Allow the job file to specify a preferred weaponskill mode
  819. if get_custom_wsmode then
  820. custom_wsmode = get_custom_wsmode(spell, spellMap, ws_mode)
  821. end
  822.  
  823. -- If the job file returned a weaponskill mode, use that.
  824. if custom_wsmode then
  825. ws_mode = custom_wsmode
  826. end
  827.  
  828. if equipSet[ws_mode] then
  829. equipSet = equipSet[ws_mode]
  830. mote_vars.set_breadcrumbs:append(ws_mode)
  831. end
  832.  
  833. return equipSet
  834. end
  835.  
  836.  
  837. -- Function to handle the logic of selecting the proper ranged set.
  838. function get_ranged_set(equipSet, spell, spellMap)
  839. -- Attach Combat Form and Combat Weapon to set checks
  840. if state.CombatForm.has_value and equipSet[state.CombatForm.value] then
  841. equipSet = equipSet[state.CombatForm.value]
  842. mote_vars.set_breadcrumbs:append(state.CombatForm.value)
  843. end
  844.  
  845. if state.CombatWeapon.has_value and equipSet[state.CombatWeapon.value] then
  846. equipSet = equipSet[state.CombatWeapon.value]
  847. mote_vars.set_breadcrumbs:append(state.CombatWeapon.value)
  848. end
  849.  
  850. -- Check for specific mode for ranged attacks (eg: Acc, Att, etc)
  851. if equipSet[state.RangedMode.current] then
  852. equipSet = equipSet[state.RangedMode.current]
  853. mote_vars.set_breadcrumbs:append(state.RangedMode.current)
  854. end
  855.  
  856. -- Tack on any additionally specified custom groups, if the sets are defined.
  857. for _,group in ipairs(classes.CustomRangedGroups) do
  858. if equipSet[group] then
  859. equipSet = equipSet[group]
  860. mote_vars.set_breadcrumbs:append(group)
  861. end
  862. end
  863.  
  864. return equipSet
  865. end
  866.  
  867.  
  868. -------------------------------------------------------------------------------------------------------------------
  869. -- Functions for optional supplemental gear overriding the default sets defined above.
  870. -------------------------------------------------------------------------------------------------------------------
  871.  
  872. -- Function to apply any active defense set on top of the supplied set
  873. -- @param baseSet : The set that any currently active defense set will be applied on top of. (gear set table)
  874. function apply_defense(baseSet)
  875. if state.DefenseMode.current ~= 'None' then
  876. local defenseSet = sets.defense
  877.  
  878. defenseSet = sets.defense[state[state.DefenseMode.current .. 'DefenseMode'].current] or defenseSet
  879.  
  880. for _,group in ipairs(classes.CustomDefenseGroups) do
  881. defenseSet = defenseSet[group] or defenseSet
  882. end
  883.  
  884. if customize_defense_set then
  885. defenseSet = customize_defense_set(defenseSet)
  886. end
  887.  
  888. baseSet = set_combine(baseSet, defenseSet)
  889. end
  890.  
  891. return baseSet
  892. end
  893.  
  894.  
  895. -- Function to add kiting gear on top of the base set if kiting state is true.
  896. -- @param baseSet : The gear set that the kiting gear will be applied on top of.
  897. function apply_kiting(baseSet)
  898. if state.Kiting.value then
  899. if sets.Kiting then
  900. baseSet = set_combine(baseSet, sets.Kiting)
  901. end
  902. end
  903.  
  904. return baseSet
  905. end
  906.  
  907.  
  908. -------------------------------------------------------------------------------------------------------------------
  909. -- Utility functions for constructing default gear sets.
  910. -------------------------------------------------------------------------------------------------------------------
  911.  
  912. -- Get a spell mapping for the spell.
  913. function get_spell_map(spell)
  914. local defaultSpellMap = classes.SpellMaps[spell.english]
  915. local jobSpellMap
  916.  
  917. if job_get_spell_map then
  918. jobSpellMap = job_get_spell_map(spell, defaultSpellMap)
  919. end
  920.  
  921. return jobSpellMap or defaultSpellMap
  922. end
  923.  
  924.  
  925. -- Select the equipment set to equip from a given starting table, based on standard
  926. -- selection order: custom class, spell name, spell map, spell skill, and spell type.
  927. -- Spell skill and spell type may further refine their selections based on
  928. -- custom class, spell name and spell map.
  929. function select_specific_set(equipSet, spell, spellMap)
  930. -- Take the determined base equipment set and try to get the simple naming extensions that
  931. -- may apply to it (class, spell name, spell map).
  932. local namedSet = get_named_set(equipSet, spell, spellMap)
  933.  
  934. -- If no simple naming sub-tables were found, and we simply got back the original equip set,
  935. -- check for spell.skill and spell.type, then check the simple naming extensions again.
  936. if namedSet == equipSet then
  937. if spell.skill and equipSet[spell.skill] and not classes.SkipSkillCheck then
  938. namedSet = equipSet[spell.skill]
  939. mote_vars.set_breadcrumbs:append(spell.skill)
  940. elseif spell.type and equipSet[spell.type] then
  941. namedSet = equipSet[spell.type]
  942. mote_vars.set_breadcrumbs:append(spell.type)
  943. else
  944. return equipSet
  945. end
  946.  
  947. namedSet = get_named_set(namedSet, spell, spellMap)
  948. end
  949.  
  950. return namedSet or equipSet
  951. end
  952.  
  953.  
  954. -- Simple utility function to handle a portion of the equipment set determination.
  955. -- It attempts to select a sub-table of the provided equipment set based on the
  956. -- standard search order of custom class, spell name, and spell map.
  957. -- If no such set is found, it returns the original base set (equipSet) provided.
  958. function get_named_set(equipSet, spell, spellMap)
  959. if equipSet then
  960. if classes.CustomClass and equipSet[classes.CustomClass] then
  961. mote_vars.set_breadcrumbs:append(classes.CustomClass)
  962. return equipSet[classes.CustomClass]
  963. elseif equipSet[spell.english] then
  964. mote_vars.set_breadcrumbs:append(spell.english)
  965. return equipSet[spell.english]
  966. elseif spellMap and equipSet[spellMap] then
  967. mote_vars.set_breadcrumbs:append(spellMap)
  968. return equipSet[spellMap]
  969. else
  970. return equipSet
  971. end
  972. end
  973. end
  974.  
  975.  
  976. -------------------------------------------------------------------------------------------------------------------
  977. -- Hooks for other events.
  978. -------------------------------------------------------------------------------------------------------------------
  979.  
  980. -- Called when the player's subjob changes.
  981. function sub_job_change(newSubjob, oldSubjob)
  982. if user_setup then
  983. user_setup()
  984. end
  985.  
  986. if job_sub_job_change then
  987. job_sub_job_change(newSubjob, oldSubjob)
  988. end
  989.  
  990. send_command('gs c update')
  991. end
  992.  
  993.  
  994. -- Called when the player's status changes.
  995. function status_change(newStatus, oldStatus)
  996. -- init a new eventArgs
  997. local eventArgs = {handled = false}
  998. mote_vars.set_breadcrumbs:clear()
  999.  
  1000. -- Allow a global function to be called on status change.
  1001. if user_status_change then
  1002. user_status_change(newStatus, oldStatus, eventArgs)
  1003. end
  1004.  
  1005. -- Then call individual jobs to handle status change events.
  1006. if not eventArgs.handled then
  1007. if job_status_change then
  1008. job_status_change(newStatus, oldStatus, eventArgs)
  1009. end
  1010. end
  1011.  
  1012. -- Handle equipping default gear if the job didn't mark this as handled.
  1013. if not eventArgs.handled then
  1014. handle_equipping_gear(newStatus)
  1015. display_breadcrumbs()
  1016. end
  1017. end
  1018.  
  1019.  
  1020. -- Called when a player gains or loses a buff.
  1021. -- buff == buff gained or lost
  1022. -- gain == true if the buff was gained, false if it was lost.
  1023. function buff_change(buff, gain)
  1024. -- Init a new eventArgs
  1025. local eventArgs = {handled = false}
  1026.  
  1027. if state.Buff[buff] ~= nil then
  1028. state.Buff[buff] = gain
  1029. end
  1030.  
  1031. -- Allow a global function to be called on buff change.
  1032. if user_buff_change then
  1033. user_buff_change(buff, gain, eventArgs)
  1034. end
  1035.  
  1036. -- Allow jobs to handle buff change events.
  1037. if not eventArgs.handled then
  1038. if job_buff_change then
  1039. job_buff_change(buff, gain, eventArgs)
  1040. end
  1041. end
  1042. end
  1043.  
  1044.  
  1045. -- Called when a player gains or loses a pet.
  1046. -- pet == pet gained or lost
  1047. -- gain == true if the pet was gained, false if it was lost.
  1048. function pet_change(pet, gain)
  1049. -- Init a new eventArgs
  1050. local eventArgs = {handled = false}
  1051.  
  1052. -- Allow jobs to handle pet change events.
  1053. if job_pet_change then
  1054. job_pet_change(pet, gain, eventArgs)
  1055. end
  1056.  
  1057. -- Equip default gear if not handled by the job.
  1058. if not eventArgs.handled then
  1059. handle_equipping_gear(player.status)
  1060. end
  1061. end
  1062.  
  1063.  
  1064. -- Called when the player's pet's status changes.
  1065. -- Note that this is also called after pet_change when the pet is released.
  1066. -- As such, don't automatically handle gear equips. Only do so if directed
  1067. -- to do so by the job.
  1068. function pet_status_change(newStatus, oldStatus)
  1069. -- Init a new eventArgs
  1070. local eventArgs = {handled = false}
  1071.  
  1072. -- Allow jobs to override this code
  1073. if job_pet_status_change then
  1074. job_pet_status_change(newStatus, oldStatus, eventArgs)
  1075. end
  1076. end
  1077.  
  1078.  
  1079. -------------------------------------------------------------------------------------------------------------------
  1080. -- Debugging functions.
  1081. -------------------------------------------------------------------------------------------------------------------
  1082.  
  1083. -- This is a debugging function that will print the accumulated set selection
  1084. -- breadcrumbs for the default selected set for any given action stage.
  1085. function display_breadcrumbs(spell, spellMap, action)
  1086. if not _settings.debug_mode then
  1087. return
  1088. end
  1089.  
  1090. local msg = 'Default '
  1091.  
  1092. if action and spell then
  1093. msg = msg .. action .. ' set selection for ' .. spell.name
  1094. end
  1095.  
  1096. if spellMap then
  1097. msg = msg .. ' (' .. spellMap .. ')'
  1098. end
  1099. msg = msg .. ' : '
  1100.  
  1101. local cons
  1102.  
  1103. for _,name in ipairs(mote_vars.set_breadcrumbs) do
  1104. if not cons then
  1105. cons = name
  1106. else
  1107. if name:contains(' ') or name:contains("'") then
  1108. cons = cons .. '["' .. name .. '"]'
  1109. else
  1110. cons = cons .. '.' .. name
  1111. end
  1112. end
  1113. end
  1114.  
  1115. if cons then
  1116. if action and cons == ('sets.' .. action) then
  1117. msg = msg .. "None"
  1118. else
  1119. msg = msg .. tostring(cons)
  1120. end
  1121. add_to_chat(123, msg)
  1122. end
  1123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement