Advertisement
Guest User

eliroo-SMN-lib-3.lua

a guest
Oct 3rd, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 53.05 KB | None | 0 0
  1. --1.20.2016
  2. -------------------------------------------------------------------------------------------------------------------
  3. -- Under the hood after this point, modify at your own risk
  4. -------------------------------------------------------------------------------------------------------------------
  5.  
  6. function setup_hud()
  7.     smn_property = {
  8.         avatar="\\cs(255,0,0)None\\cr",
  9.         pacts = {['Rage']="",['Ward']=""},
  10.     }
  11.     smn_info = {}
  12.     smn_info.box={
  13.         pos={x=hud_x_pos,y=hud_y_pos},
  14.         text={font='Segoe UI Symbol', size=hud_font_size, Fonts={'sans-serif'},},
  15.         bg={alpha=hud_transparency,red=0,green=15,blue=0},
  16.         flags={draggable=hud_draggable},
  17.         padding=7
  18.     }
  19.     window = texts.new(smn_info.box)
  20.     initialize(window, smn_info.box)
  21.     icon_settings = {
  22.         name='avatar_icon',
  23.         color={alpha=hud_transparency,red=255,green=255,blue=255},
  24.         size={height=hud_icon_width,width=hud_icon_height},
  25.         pos={x=1300,y=0},
  26.         draggable=false
  27.     }
  28.     --avatar_icon = images.new('',icon_settings,nil)
  29.     --images.path(avatar_icon,base_icon_dir..'base.png')
  30.     --images.show(avatar_icon)
  31.  
  32.     window:show()
  33.     updatedisplay()
  34. end
  35. --images =require('images')
  36. inwkr = 0
  37. --display_hud=true
  38.  
  39. function d_chat(s)
  40.     if debug_gs1 then add_to_chat(122,s) end
  41. end
  42. function get_sets()
  43.     mote_include_version = 2
  44.  
  45.     -- Load and initialize the include file.
  46.     include('Mote-Include.lua')
  47.     include('organizer-lib')
  48. end
  49.  
  50. function initialize(text, settings)
  51.     local properties = L{}
  52.     properties:append('Avatar : ${avatar}')
  53.     properties:append('${ragepacts}')
  54.     properties:append('${wardpacts}')
  55.     properties:append('${pactinfo}')
  56.     properties:append('${modestates}')
  57.     text:clear()
  58.     text:append(properties:concat('\n'))
  59. end
  60. function concat_strings(s)
  61.     local t = { }
  62.     for k,v in ipairs(s) do
  63.         t[#t+1] = tostring(v)
  64.     end
  65.     return table.concat(t,"\n")
  66. end
  67. fenrir_effects = {
  68.     'Lunar Cry\n\\cs(125,125,255) Eva. -31 Acc. -1\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +1 Eva. +25\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +1 \n AGI/INT/MND/CHR +7\\cr',
  69.     'Lunar Cry\n\\cs(125,125,255) Eva. -26 Acc. -6\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +5 Eva. +21\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +2 \n AGI/INT/MND/CHR +6\\cr',
  70.     'Lunar Cry\n\\cs(125,125,255) Eva. -21 Acc. -11\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +9 Eva. +17\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +3 \n AGI/INT/MND/CHR +5\\cr',
  71.     'Lunar Cry\n\\cs(125,125,255) Eva. -16 Acc. -16\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +13 Eva. +13\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +4 \n AGI/INT/MND/CHR +4\\cr',
  72.     'Lunar Cry\n\\cs(125,125,255) Eva. -11 Acc. -21\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +17 Eva. +9\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +5 \n AGI/INT/MND/CHR +3\\cr',
  73.     'Lunar Cry\n\\cs(125,125,255) Eva. -6 Acc. -26\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +21 Eva. +5\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +6 \n AGI/INT/MND/CHR +2\\cr',
  74.     'Lunar Cry\n\\cs(125,125,255) Eva. -1 Acc. -31\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +25 Eva. +1\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +7 \n AGI/INT/MND/CHR +1\\cr',
  75.     'Lunar Cry\n\\cs(125,125,255) Eva. -6 Acc. -26\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +21 Eva. +5\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +6 \n AGI/INT/MND/CHR +2\\cr',
  76.     'Lunar Cry\n\\cs(125,125,255) Eva. -11 Acc. -21\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +17 Eva. +9\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +5 \n AGI/INT/MND/CHR +3\\cr',
  77.     'Lunar Cry\n\\cs(125,125,255) Eva. -16 Acc. -16\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +13 Eva. +13\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +4 \n AGI/INT/MND/CHR +4\\cr',
  78.     'Lunar Cry\n\\cs(125,125,255) Eva. -21 Acc. -6\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +9 Eva. +17\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +3 \n AGI/INT/MND/CHR +5\\cr',
  79.     'Lunar Cry\n\\cs(125,125,255) Eva. -26 Acc. -1\\cr\nEcliptic Howl\n\\cs(125,125,255) Acc. +5 Eva. +21\\cr\nEcliptic Growl\n\\cs(125,125,255) STR/DEX/VIT +2 \n AGI/INT/MND/CHR +6\\cr'
  80. }
  81. diabolos_effects = {
  82.     'Dream Shroud\n\\cs(125,125,255) MAB +13, MDB +1\\cr',
  83.     'Dream Shroud\n\\cs(125,125,255) MAB +12, MDB +2\\cr',
  84.     'Dream Shroud\n\\cs(125,125,255) MAB +11, MDB +3\\cr',
  85.     'Dream Shroud\n\\cs(125,125,255) MAB +10, MDB +4\\cr',
  86.     'Dream Shroud\n\\cs(125,125,255) MAB +9, MDB +5\\cr',
  87.     'Dream Shroud\n\\cs(125,125,255) MAB +8, MDB +6\\cr',
  88.     'Dream Shroud\n\\cs(125,125,255) MAB +7, MDB +7\\cr',
  89.     'Dream Shroud\n\\cs(125,125,255) MAB +6, MDB +8\\cr',
  90.     'Dream Shroud\n\\cs(125,125,255) MAB +5, MDB +9\\cr',
  91.     'Dream Shroud\n\\cs(125,125,255) MAB +4, MDB +10\\cr',
  92.     'Dream Shroud\n\\cs(125,125,255) MAB +3, MDB +11\\cr',
  93.     'Dream Shroud\n\\cs(125,125,255) MAB +2, MDB +12\\cr',
  94.     'Dream Shroud\n\\cs(125,125,255) MAB +1, MDB +13\\cr',
  95. }
  96. function set_hud_info()
  97.     if pet.name then
  98.         smn_property.avatar = "\\cs(125,125,255)"..pet.name.."\\cr"
  99.     else
  100.         smn_property.avatar = "\\cs(125,125,125)None\\cr"
  101.     end
  102.     --print('c:'..pet.name)
  103.     tmp_sort = {['Rage']={},['Ward']={}}
  104.     --print(tostring(tmp_sort['Ward']))
  105.     smn_property.pacts['Rage'] = ''
  106.     smn_property.pacts['Ward'] = ''
  107.     for index,value in pairs(pacts) do
  108.         --print('p:'..smn_property.pacts)
  109.         --print('i:'..index)
  110.         --print('v:'..pacts[index][pet.name])
  111.         if pacts[index][pet.name] then
  112.             keybindtxt = ''
  113.             category = ''
  114.             for k,v in pairs(pact_keys[index]) do
  115.                 category = k
  116.                 keybindtxt = v
  117.                 break
  118.             end
  119.             --print (category..keybindtxt)
  120.             tmp_sort[category][keybindtxt] = smn_property.pacts[category].."\n     ".. keybindtxt.. ": \\cs(125,125,255)".. pacts[index][pet.name]..'\\cr     '
  121.         end
  122.     end
  123.     for index,value in spairs(tmp_sort['Rage']) do
  124.         smn_property.pacts['Rage'] = smn_property.pacts['Rage']..value
  125.     end
  126.     for index,value in spairs(tmp_sort['Ward']) do
  127.         smn_property.pacts['Ward'] = smn_property.pacts['Ward']..value
  128.     end
  129.     if smn_property.pacts['Rage'] ~= '' then smn_property.pacts['Rage'] = "-- Rage --"..smn_property.pacts['Rage'] end
  130.     if smn_property.pacts['Ward'] ~= '' then smn_property.pacts['Ward'] = "\n-- Ward --"..smn_property.pacts['Ward'] end
  131.     if display_states then
  132.         modestates_table = {
  133.             '\n-- Modes --\n     Offense: \\cs(125,125,255)'..tostring(state.OffenseMode.value)..'\\cr',
  134.             '     Casting: \\cs(125,125,255)'..tostring(state.CastingMode.value)..'\\cr',
  135.             '     DT: \\cs(125,125,255)'..tostring(state.damagetaken.value)..'\\cr',
  136.             '     Pet DT: \\cs(125,125,255)'..tostring(state.petdamagetaken.value)..'\\cr',
  137.             '     Capacity Points: \\cs(125,125,255)'..tostring(state.cpmode.value)..'\\cr',
  138.             '     Movement: \\cs(125,125,255)'..tostring(state.movement.value)..'\\cr',
  139.             '     TP/Staff Lock: \\cs(125,125,255)'..tostring(state.tplock.value)..'\\cr',
  140.             '     Impact Debuff: \\cs(125,125,255)'..tostring(state.impactmode.value)..'\\cr',
  141.             '     Favor: \\cs(125,125,255)'..tostring(state.favor.value)..'\\cr',
  142.             '     Magic Burst: \\cs(125,125,255)'..tostring(state.burstmode.value)..'\\cr',
  143.         }
  144.         smn_property.modestates = concat_strings(modestates_table)
  145.     else
  146.         smn_property.modestates = ''
  147.     end
  148.     smn_property.pactinfo = ''
  149.     if pet.name=="Fenrir" then
  150.         moon_phase = windower.ffxi.get_info().moon_phase + 1
  151.         if moon_phase == 1 or moon_phase > 6 then
  152.             howl='\n \\cs(125,125,255)Enaspir\\cr'
  153.         else
  154.             howl='\n \\cs(125,125,255)Endrain\\cr'
  155.         end
  156.         smn_property.pactinfo = {
  157.             fenrir_effects[moon_phase],
  158.             'Heavenward Howl '..howl
  159.         }
  160.         smn_property.pactinfo = '\n'..concat_strings(smn_property.pactinfo)
  161.     elseif pet.name=="Diabolos" then
  162.         local hour = math.floor(windower.ffxi.get_info().time / 60)
  163.         if hour > 12 then
  164.             hour = 24 - hour
  165.         end
  166.         smn_property.pactinfo = {
  167.             diabolos_effects[hour + 1]
  168.         }
  169.         smn_property.pactinfo = '\n'..concat_strings(smn_property.pactinfo)
  170.     end
  171. end
  172. update_delay=0
  173. function updatedisplay() --update hud display
  174.     if update_delay ~=0 then
  175.         coroutine.sleep(update_delay)
  176.         update_delay = 0
  177.     end
  178.     set_hud_info()
  179.     local info = {}
  180.     info.avatar = smn_property.avatar
  181.     info.ragepacts = smn_property.pacts['Rage']
  182.     info.wardpacts = smn_property.pacts['Ward']
  183.     info.pactinfo = smn_property.pactinfo
  184.     info.modestates = smn_property.modestates
  185.     if pet.name then
  186.         icon = pet.name:lower()
  187.     else
  188.         icon = 'base'
  189.     end
  190.     --images.path(avatar_icon,base_icon_dir..icon..'.png')
  191.     --images.pos(avatar_icon,smn_info.box.pos.x,smn_info.box.pos.y-32)
  192.     --images.update(avatar_icon)
  193.     --button:update(info)
  194.     --button:show()
  195.     window:update(info)
  196.     if display_hud then
  197.         window:show()
  198.     end
  199. end
  200.  
  201. -- Setup vars that are user-independent.  state.Buff vars initialized here will automatically be tracked.
  202. function job_setup()
  203.     --send_command('exec verda/verda_smn.txt');
  204.     state.Buff["Avatar's Favor"] = buffactive["Avatar's Favor"] or false
  205.     state.Buff["Astral Conduit"] = buffactive["Astral Conduit"] or false
  206.     buffrotation = {
  207.         [0] = {['Hastega II']='Garuda'},
  208.         [1] = {['Aerial Armor']='Garuda'},
  209.         [2] = {['Crimson Howl']='Ifrit'},
  210.         [3] = {['Earthen Armor']='Titan'},
  211.         [4] = {['Crystal Blessing']='Shiva'},
  212.         [5] = {['Frost Armor']='Shiva'},
  213.         [6] = {['Ecliptic Growl']='Fenrir'},
  214.         [7] = {['Ecliptic Howl']='Fenrir'},
  215.         [8] = {['Heavenward Howl']='Fenrir'},
  216.         [9] = {['Dream Shroud']='Diabolos'},
  217.         [10] = {['Noctoshield']='Diabolos'},
  218.         [11] = {['Soothing Current']='Leviathan'},
  219.     }
  220.     rotationfavor = 'Ifrit'
  221.     buffrot_count = 0
  222.     for index, value in pairs( buffrotation ) do
  223.         buffrot_count = buffrot_count + 1
  224.     end
  225.  
  226.     spirits = S{"LightSpirit", "DarkSpirit", "FireSpirit", "EarthSpirit", "WaterSpirit", "AirSpirit", "IceSpirit", "ThunderSpirit"}
  227.     avatars = S{"Carbuncle", "Fenrir", "Diabolos", "Ifrit", "Titan", "Leviathan", "Garuda", "Shiva", "Ramuh", "Odin", "Alexander", "Cait Sith"}
  228.  
  229.     magicalRagePacts = S{
  230.         'Inferno','Earthen Fury','Tidal Wave','Aerial Blast','Diamond Dust','Judgment Bolt','Searing Light','Howling Moon','Ruinous Omen',
  231.         'Fire II','Stone II','Water II','Aero II','Blizzard II','Thunder II',
  232.         'Fire IV','Stone IV','Water IV','Aero IV','Blizzard IV','Thunder IV','Chaotic strike',
  233.         'Thunderspark','Volt strike','Burning Strike','Meteorite','Nether Blast',
  234.         'Meteor Strike','Conflag Strike','Heavenly Strike','Wind Blade','Geocrush','Crag Throw','Grand Fall','Thunderstorm',
  235.         'Holy Mist','Lunar Bay','Night Terror','Level ? Holy','Impact','Zantetsuken'}
  236.     enticersRagePacts = S{
  237.         'Impact','Conflag Strike', 'Fire II','Stone II','Water II','Aero II','Blizzard II','Thunder II',
  238.         'Fire IV','Stone IV','Water IV','Aero IV','Blizzard IV','Thunder IV'
  239.     }
  240.     meritPacts = S{
  241.         'Heavenly Strike','Wind Blade','Geocrush','Thunderstorm','Meteor Strike','Grand Fall'
  242.     }
  243.     enticersWardPacts = S{
  244.         'HealingRuby II','Healing Ruby'
  245.     }
  246.     healingWardPacts = S{
  247.         'HealingRuby II','Healing Ruby'
  248.     }
  249.     hybridPacts = S{
  250.         'Flaming Crush'
  251.     }
  252.  
  253.     sets.cpmode = {back="Mecisto. Mantle"}
  254. --    sets.dtmode = {
  255. --      main="Earth Staff",
  256. --      left_ring="Gelatinous Ring +1",
  257. --      right_ring="Defending Ring",
  258. --    }
  259.  
  260.     pacts = {}
  261.     pacts.cure = {['Carbuncle']='Healing Ruby'}
  262.     pacts.curaga = {['Carbuncle']='Healing Ruby II', ['Garuda']='Whispering Wind', ['Leviathan']='Spring Water'}
  263.     pacts.buffoffense = {['Carbuncle']='Glittering Ruby', ['Ifrit']='Crimson Howl', ['Garuda']='Hastega', ['Garuda']='Hastega II', ['Ramuh']='Rolling Thunder',
  264.         ['Fenrir']='Ecliptic Growl'}
  265.     pacts.buffdefense = {['Carbuncle']='Shining Ruby', ['Shiva']='Frost Armor', ['Garuda']='Aerial Armor', ['Titan']='Earthen Ward',
  266.         ['Ramuh']='Lightning Armor', ['Fenrir']='Ecliptic Howl', ['Diabolos']='Noctoshield', ['Cait Sith']='Reraise II'}
  267.  
  268.     pacts.buffspecial = {['Ifrit']='Inferno Howl', ['Garuda']='Fleet Wind', ['Titan']='Earthen Armor', ['Diabolos']='Dream Shroud',
  269.         ['Carbuncle']='Soothing Ruby',['Carbuncle']='Pacifying ruby', ['Shiva']='Crystal blessing',['Fenrir']='Heavenward Howl', ['Leviathan']='Soothing current',['Cait Sith']='Raise II',}
  270.  
  271.     pacts.debuff1 = {['Shiva']='Diamond Storm', ['Ramuh']='Shock Squall', ['Leviathan']='Tidal Roar', ['Fenrir']='Lunar Cry',
  272.         ['Diabolos']='Pavor Nocturnus', ['Cait Sith']='Eerie Eye',['Carbuncle']='Soothing Ruby' }
  273.     pacts.debuff2 = {['Leviathan']='Slowga', ['Fenrir']='Lunar Roar', ['Diabolos']='Somnolence'}
  274.     pacts.sleep = {['Shiva']='Sleepga', ['Diabolos']='Nightmare', ['Cait Sith']='Mewing Lullaby'}
  275.     pacts.nuke2 = {['Ifrit']='Fire II', ['Shiva']='Blizzard II', ['Garuda']='Aero II', ['Titan']='Stone II',
  276.         ['Ramuh']='Thunder II', ['Leviathan']='Water II'}
  277.     pacts.nuke4 = {['Ifrit']='Fire IV', ['Shiva']='Blizzard IV', ['Garuda']='Aero IV', ['Titan']='Stone IV',
  278.         ['Ramuh']='Thunder IV', ['Leviathan']='Water IV',['Fenrir']='Crescent Fang'}
  279.     pacts.bp70 = {
  280.         ['Ifrit']='Flaming Crush', ['Shiva']='Rush', ['Garuda']='Predator Claws', ['Titan']='Mountain Buster',
  281.         ['Ramuh']='Chaotic Strike', ['Leviathan']='Spinning Dive', ['Carbuncle']='Meteorite', ['Fenrir']='Eclipse Bite',
  282.         ['Diabolos']='Nether Blast',['Cait Sith']='Regal Scratch'
  283.     }
  284.     pacts.bp75 = {['Ifrit']='Meteor Strike', ['Shiva']='Heavenly Strike', ['Garuda']='Wind Blade', ['Titan']='Geocrush',
  285.         ['Ramuh']='Thunderstorm', ['Leviathan']='Grand Fall', ['Carbuncle']='Holy Mist', ['Fenrir']='Lunar Bay',
  286.         ['Diabolos']='Night Terror', ['Cait Sith']='Level ? Holy'}
  287.     pacts.astralflow = {['Ifrit']='Inferno', ['Shiva']='Diamond Dust', ['Garuda']='Aerial Blast', ['Titan']='Earthen Fury',
  288.         ['Ramuh']='Judgment Bolt', ['Leviathan']='Tidal Wave', ['Carbuncle']='Searing Light', ['Fenrir']='Howling Moon',
  289.         ['Diabolos']='Ruinous Omen', ['Cait Sith']="Altana's Favor"}
  290.     pacts.bprage1 = {['Fenrir']='Impact',['Ramuh']='Volt Strike',['Cait Sith']='Regal Gash',['Carbuncle']='Poison Nails',['Ifrit']='Conflag Strike',['Titan']='Crag Throw',['Diabolos']='Blindside'}
  291.     pacts.misc1 = {['Ramuh']='Thunderspark',['Fenrir']='Moonlit Charge'}
  292.     pacts.misc2 = {['Diabolos']='Ultimate Terror'}
  293.  
  294.     --Note this is only for display on the Summoner HUD, if you want to change the actual keybinds you need to go to the user_setup function, this saves string comparisons but mostly makes it easier on the programmer (me)
  295.     pact_keys = {}
  296.     pact_keys.cure = {['Ward']='Alt 1'}
  297.     pact_keys.curaga = {['Ward']='Alt 2'}
  298.     pact_keys.buffoffense = {['Ward']='Alt 3'}
  299.     pact_keys.buffdefense = {['Ward']='Alt 4'}
  300.     pact_keys.buffspecial = {['Ward']='Alt 5'}
  301.     pact_keys.debuff1 = {['Ward']='Alt 6'}
  302.     pact_keys.debuff2 = {['Ward']='Alt 7'}
  303.     pact_keys.sleep = {['Ward']='Alt 8'}
  304.     pact_keys.nuke2 = {['Rage']='Ctrl 1'}
  305.     pact_keys.nuke4 = {['Rage']='Ctrl 2'}
  306.     pact_keys.bp70 = {['Rage']='Ctrl 3'}
  307.     pact_keys.bp75 = {['Rage']='Ctrl 4'}
  308.     pact_keys.bprage1 = {['Rage']='Ctrl 5'}
  309.     pact_keys.astralflow = {['Rage']='Ctrl 6'}
  310.     pact_keys.misc1 = {['Rage']='Ctrl 7'}
  311.     pact_keys.misc2 = {['Ward']='Alt 9'}
  312.  
  313.     -- Wards table for creating custom timers  
  314.     wards = {}
  315.     -- Base duration for ward pacts.
  316.     -- Icons to use when creating the custom timer.
  317.     -- Base duration for ward pacts.
  318.     wards.durations = {
  319.         ['Crimson Howl'] = 60, ['Earthen Armor'] = 60, ['Inferno Howl'] = 60, ['Heavenward Howl'] = 60,
  320.         ['Rolling Thunder'] = 120, ['Fleet Wind'] = 120,
  321.         ['Shining Ruby'] = 180, ['Frost Armor'] = 180, ['Lightning Armor'] = 180, ['Ecliptic Growl'] = 180,
  322.         ['Glittering Ruby'] = 180, ['Hastega'] = 180, ['Hastega II'] = 180,['Noctoshield'] = 180, ['Ecliptic Howl'] = 180,
  323.         ['Dream Shroud'] = 180,
  324.         ['Reraise II'] = 3600
  325.     }
  326.     -- Icons to use when creating the custom timer.
  327. --    wards.icons = {
  328. --        ['Earthen Armor']   = 'spells/00299.png', -- 00299 for Titan
  329. --        ['Shining Ruby']    = 'spells/00043.png', -- 00043 for Protect
  330. --        ['Dream Shroud']    = 'spells/00304.png', -- 00304 for Diabolos
  331. --        ['Noctoshield']     = 'spells/00106.png', -- 00106 for Phalanx
  332. --        ['Inferno Howl']    = 'spells/00298.png', -- 00298 for Ifrit
  333. --        ['Hastega']         = 'spells/00358.png', -- 00358 for Hastega
  334. --        ['Hastega II']         = 'spells/00358.png', -- 00358 for Hastega
  335. --        ['Rolling Thunder'] = 'spells/00104.png', -- 00358 for Enthunder
  336. --        ['Frost Armor']     = 'spells/00250.png', -- 00250 for Ice Spikes
  337. --        ['Lightning Armor'] = 'spells/00251.png', -- 00251 for Shock Spikes
  338. --        ['Reraise II']      = 'spells/00135.png', -- 00135 for Reraise
  339. --        ['Fleet Wind']      = 'abilities/00074.png', --
  340. --    }
  341.  
  342. end
  343.  
  344. -------------------------------------------------------------------------------------------------------------------
  345. -- User setup functions for this job.  Recommend that these be overridden in a sidecar file.
  346. -------------------------------------------------------------------------------------------------------------------
  347.  
  348. function user_unload()
  349.     send_command('lua u send_commands')
  350.     --send_command('lua u pet_tp')
  351.     send_command('unbind !1')
  352.     send_command('unbind !2')
  353.     send_command('unbind !3')
  354.     send_command('unbind !4')
  355.     send_command('unbind !5')
  356.     send_command('unbind !6')
  357.     send_command('unbind !7')
  358.     send_command('unbind !8')
  359.     send_command('unbind !9')
  360.     send_command('unbind !0')
  361.  
  362.     send_command('unbind ^1')
  363.     send_command('unbind ^2')
  364.     send_command('unbind ^3')
  365.     send_command('unbind ^4')
  366.     send_command('unbind ^5')
  367.     send_command('unbind ^6')
  368.     send_command('unbind ^7')
  369.     send_command('unbind ^8')
  370.     send_command('unbind ^9')
  371.     send_command('unbind ^0')
  372.     send_command('unbind !%numpad1')
  373.     send_command('unbind !%numpad2')
  374.     send_command('unbind !%numpad3')
  375.     send_command('unbind !%numpad4')
  376.     send_command('unbind !%numpad5')
  377.     send_command('unbind !%numpad6')
  378.     send_command('unbind !%numpad7')
  379.     send_command('unbind !%numpad8')
  380.     send_command('unbind !%numpad9')
  381.     send_command('unbind !%numpad0')
  382.     send_command('unbind !%numpadenter')
  383.     send_command('unbind !%numpad.')
  384.  
  385.     send_command('unbind !%delete')
  386.     send_command('unbind !%pagedown')
  387.     send_command('unbind !%end')
  388.  
  389.     send_command('unbind @%numpad0')
  390.     send_command('unbind #0')
  391.     send_command('unbind #9')
  392.  
  393.     send_command('unbind ^o')
  394.     send_command('unbind !q')
  395.     send_command('unbind !o')
  396.     send_command('unbind !%numpad+')
  397.     send_command('unbind !%numpad-')
  398.     send_command('unbind f11')
  399.     send_command('unbind !f11')
  400.     send_command('unbind f10')
  401.     send_command('unbind ^f10')
  402.     send_command('unbind !f10')
  403.     send_command('unbind !f9')
  404.     send_command('unbind ^[')
  405.     send_command('unbind ![')
  406.     send_command('unbind ^]')
  407.     --send_command('unbind %numpad1 setkey f8 down;wait .1;setkey f8 up;input /pet "Heavenly Strike" <t>')
  408.     --send_command('unbind %numpad3 setkey f8 down;wait .1;setkey f8 up;input /pet "Sleepga" <t>')
  409.     send_command('unbind %numpad3')
  410.     send_command('unbind !%numpad.')
  411. end
  412. -------------------------------------------------------------------------------------------------------------------
  413. -- Job-specific hooks for standard casting events.
  414. -------------------------------------------------------------------------------------------------------------------
  415.  
  416. --swapspaused = false
  417. --function pauseswaps(seconds)
  418. --  swapspaused = true
  419. --  coroutine.sleep(seconds)
  420. --  swapspaused = false
  421. --end
  422.  
  423. is_midpact = false
  424. function check_midpact(spell,eventArgs)
  425.     local recast = windower.ffxi.get_ability_recasts()
  426.     d_chat('checking if mid pact prev is '..tostring(is_midpact))
  427.     --174 BP Ward
  428.     --173 BP Rage
  429.  
  430.     if spell.type == "BloodPactWard" and recast[174] ~= 0 then
  431.         d_chat('Blood Pact Ward Cancelled, it is on cooldown')
  432.         eventArgs.handled = true
  433.         return true
  434.     end
  435.     if spell.type == "BloodPactRage" and recast[173] ~= 0 then
  436.     d_chat('Blood Pact Rage Cancelled, it is on cooldown')
  437.         eventArgs.handled = true
  438.         return true
  439.     end
  440. --    if (spell.type == "BloodPactRage" and recast[173] == 0) or (spell.type=="BloodPactWard" and recast[174] == 0) then
  441. --  swapspaused = true
  442. --  coroutine.schedule(function()
  443. --      swapspaused = false
  444. --  end, 3000)
  445. --    end
  446.     if pet_midaction() then
  447.         d_chat('Avatar Midaction, cancelling')
  448.         eventArgs.handled = true
  449.         return true
  450.     end
  451.     return false
  452. end
  453. -- Set eventArgs.handled to true if we don't want any automatic gear equipping to be done.
  454. -- Set eventArgs.useMidcastGear to true if we want midcast gear equipped on precast.
  455. function job_precast(spell, action, spellMap, eventArgs)
  456.     d_chat("Job Precast")
  457. --    if state.damagetaken.value ~= "None" then
  458. --      tempset = {}
  459. --      pr (eventArgs)
  460. --      pr(action)
  461. --    end
  462. --
  463.     --if swapspaused then eventArgs.handled = true end
  464.     beforemp = player.mp
  465.     is_midpact = check_midpact(spell,eventArgs)
  466. --    if is_midpact then
  467. --      d_chat('job_precast return due to midpact')
  468. --      return
  469. --    end
  470.     if buffactive['Astral Conduit'] and conduit_lock then
  471.         eventArgs.handled = true
  472.     end
  473.     if buffactive['Apogee'] and conduit_lock then
  474.         eventArgs.handled = true
  475.     end
  476.     if state.damagetaken.value ~= "None" then
  477.         state.CastingMode:set('PDT')
  478.         --eventArgs.handled = true
  479.     elseif state.CastingMode.value == 'PDT' then
  480.         state.CastingMode:reset()
  481.     end
  482. end
  483.  
  484. function job_midcast(spell, action, spellMap, eventArgs)
  485.     --if swapspaused then eventArgs.handled = true end
  486.     is_midpact = check_midpact(spell,eventArgs)
  487.     if spellMap == nil and spell.skill=="Enhancing Magic" then
  488.         spellMap="Enhancing Magic"
  489.     end
  490.     --print ('check '..check)
  491. --    if is_midpact then
  492. --      d_chat('job_midcast return due to midpact')
  493. --      return
  494. --    end
  495.     --print (spell.english)
  496.     --print(spell.type)
  497.     --if state.Buff['Astral Conduit'] and pet_midaction() then
  498.     --    eventArgs.handled = true
  499.     --end
  500. --    elseif spell.type=='SummonerPact' then
  501. --  equip(sets.midcast.interruption)
  502. --        eventArgs.handled = true
  503. --    end
  504. end
  505. function job_post_midcast(spell, action, spellMap, eventArgs)
  506. end
  507. function job_pet_midcast(spell,action,spellMap,eventArgs)
  508.     d_chat('Pet Midcast')
  509. end
  510. sets.cait = {
  511.     hands="Lamassu Mitts +1"
  512. }
  513. function job_post_pet_midcast(spell,action,spellMap,eventArgs)--override equip sets for bloodpacts without lots of messy sets
  514.     d_chat('Pet Post Midcast')
  515.     if pet.name=='Cait Sith' then
  516.         --equip({ hands="Lamassu Mitts +1", })
  517.     elseif pet.name=='Carbuncle' then
  518.         --equip({ hands="Asteria Mitts +1", })
  519.     end
  520. --  if state.bpmagicacc.current=='on' and (spellMap == 'TPMagicalBloodPactRage' or spellMap == 'MagicalBloodPactRage' or spellMap == 'IfritMagicalBloodPactRage') then
  521. --      spellMap = spellMap .. ".Acc"
  522. --  --if state.bpmagicacc.current=='on' then
  523. --      equip(sets.bp_magic_acc)
  524. --  end
  525. --  if state.bpmagicacc.current=='on' and (spellMap == 'PhysicalBloodPactRage') then
  526. --      equip(sets.bp_phys_acc)
  527. --  end
  528. --  if state.bpmagicacc.current=='on' and (spellMap == 'HybridBloodPactRage') then
  529. --      equip(sets.bp_hybrid_acc)
  530. --  end
  531.     if state.burstmode.value=='Burst' and enticersRagePacts:contains(spell.english) and spell.english~="Impact" then
  532.         equip(sets.burstmode.Burst)
  533.     end
  534. end
  535. function job_aftercast(spell, action, spellMap, eventArgs)
  536.     if spell.type=="BloodPactRage" or spell.type=="BloodPactWard" then
  537.         eventArgs.handled=true
  538.     end
  539. --  if pet_midaction() then
  540. --      eventArgs.handled=true
  541. --  end
  542.     --if swapspaused then eventArgs.handled = true end
  543.     is_midpact = check_midpact(spell,eventArgs,false)
  544.     d_chat('Job Aftercast')
  545.     --if is_midpact then return end
  546.  
  547.     --print('spell '..spell.type..' aftercast')
  548.     --handle_equipping_gear(player.status,pet.status)
  549.     --    if spell.type == 'Summoning' then
  550.     --  return 'idle.Avatar'
  551.     --    end
  552. end
  553.  
  554. -- Runs when pet completes an action.
  555. function job_pet_aftercast(spell, action, spellMap, eventArgs)
  556.     is_midpact = check_midpact(spell,eventArgs)
  557.     d_chat('Job Pet Aftercast')
  558.     d_chat('player status is'..player.status)
  559.     handle_equipping_gear(player.status,pet.status)
  560.     --if is_midpact then return end
  561. --  if is_midpact then
  562. --      d_chat('job_pet_aftercast returned due to midpact')
  563. --      return
  564. --  end
  565.  
  566.     --d_chat('check is '..tostring(is_midpact))
  567.     --add_to_chat(122,'Player Status is '..player.status)
  568.     --    if not spell.interrupted and spell.type == 'BloodPactWard' and spellMap ~= 'DebuffBloodPactWard' then
  569.     --        wards.flag = true
  570.     --        wards.spell = spell.english
  571.     --        send_command('wait 4; gs c reset_ward_flag')
  572.     --    end
  573.     --    if player.status == 'Engaged' then
  574.     --  equip(sets.engaged)
  575.     --    end
  576. --  aftermp = player.mp
  577. --  diffmp = beforemp - aftermp
  578. --  savemp = 100*diffmp/248
  579. --  savemp = tonumber(string.format("%.3f", savemp))
  580.     --if(spell.en == "Hastega II" and diffmp < 248) then add_to_chat (122,'Blood Boon! Cost was about '..savemp..'% ['..diffmp..'] before:'..beforemp..' after:'..aftermp) end
  581.     --handle_equipping_gear(player.status,pet.status)
  582.     --print ('pet aftercast '..pet.status..' action '..action)
  583.     --    if pet.isvalid and pet.status == 'Engaged'  then
  584.     --      print('pet aftercast')
  585.     --      equip(sets.Avatar.Haste)
  586.     --      return 'Avatar.Haste'
  587.     --    end
  588.     --    if pet.isvalid and not midaction() and not pet_midaction() then
  589.     --      if player.status == "Idle" then
  590.     --          --equip(sets.idle.Avatar)
  591.     --          return 'idle.Avatar'
  592.     --      end
  593.     --    end
  594. end
  595.  
  596. -------------------------------------------------------------------------------------------------------------------
  597. -- Job-specific hooks for non-casting events.
  598. -------------------------------------------------------------------------------------------------------------------
  599.  
  600. -- Called when a player gains or loses a buff.
  601. -- buff == buff gained or lost
  602. -- gain == true if the buff was gained, false if it was lost.
  603. function job_buff_change(buff, gain)
  604.     if state.Buff[buff] ~= nil then
  605.         handle_equipping_gear(player.status)
  606.     elseif storms:contains(buff) then
  607.         handle_equipping_gear(player.status)
  608.     end
  609.     if gain and buff=="quickening" then
  610.         handle_equipping_gear(player.status)
  611.     end
  612.     if pet.isvalid and buff == 'sleep' then
  613.         if gain then
  614.             equip(sets.wakeup)
  615.         end
  616.     end
  617. end
  618.  
  619.  
  620. -- Called when the player's pet's status changes.
  621. -- This is also called after pet_change after a pet is released.  Check for pet validity.
  622. function job_pet_status_change(newStatus, oldStatus, eventArgs)
  623. --   local check = check_midpact(spell,eventArgs)
  624.     --d_chat('Pet Status Change new '..newStatus..' old '..oldStatus..' player'..player.status..' midaction '..tostring(pet_midaction())..' is_midpact '..tostring(is_midpact))
  625.     d_chat('Pet Status Change new '..newStatus..' old '..oldStatus..' player'..player.status..' midaction '..tostring(pet_midaction()))
  626.     if pet_midaction() then
  627.         --d_chat('check is '..tostring(is_midpact))
  628.         d_chat('Pet Status Change cancelled')
  629.         eventArgs.handled=true
  630.         return
  631.         --coroutine.sleep(1)
  632.     end
  633.     handle_equipping_gear(player.status,newStatus)
  634.  
  635. end
  636.  
  637. function spairs(t, order)
  638.     -- collect the keys
  639.     local keys = {}
  640.     for k in pairs(t) do keys[#keys+1] = k end
  641.  
  642.     -- if order function given, sort by it by passing the table and keys a, b,
  643.     -- otherwise just sort the keys
  644.     if order then
  645.         table.sort(keys, function(a,b) return order(t, a, b) end)
  646.     else
  647.         table.sort(keys)
  648.     end
  649.  
  650.     -- return the iterator function
  651.     local i = 0
  652.     return function()
  653.         i = i + 1
  654.         if keys[i] then
  655.             return keys[i], t[keys[i]]
  656.         end
  657.     end
  658. end
  659. -- Called when a player gains or loses a pet.
  660. -- pet == pet structure
  661. -- gain == true if the pet was gained, false if it was lost.
  662. function job_pet_change(petparam, gain)
  663.     classes.CustomIdleGroups:clear()
  664.     if gain then
  665.     trackavatar = pet.name
  666.     smn_property.pacts = {['Rage']="",['Ward']=""}
  667.         if avatars:contains(pet.name) then
  668.             classes.CustomIdleGroups:append('Avatar')
  669.         elseif spirits:contains(pet.name) then
  670.             classes.CustomIdleGroups:append('Spirit')
  671.         end
  672.     updatedisplay()
  673.     else
  674.     smn_property.avatar = "\\cs(255,0,0)None\\cr"
  675.     smn_property.pacts = {['Rage']="",['Ward']=""}
  676.     updatedisplay()
  677.     end
  678. end
  679.  
  680. -- Called any time we attempt to handle automatic gear equips (ie: engaged or idle gear).
  681. function job_handle_equipping_gear(playerStatus, eventArgs)
  682.     if pet_midaction() then
  683.         eventArgs.handled = true
  684.         send_command('wait 1;gs c updategear')
  685.     end
  686. end
  687.  
  688.  
  689. -------------------------------------------------------------------------------------------------------------------
  690. -- User code that supplements standard library decisions.
  691. -------------------------------------------------------------------------------------------------------------------
  692. -- Custom spell mapping.
  693. function job_get_spell_map(spell)
  694.     --print(pet.tp)
  695.     --print(pet_tp)
  696.     spellMapMod = ""
  697.     if state.bpmagicacc.current=='on' then
  698.         spellMapMod = "Acc"
  699.     end
  700.     if spell.type == 'BloodPactRage' then
  701.     if spell.english == "Impact" and state.impactmode.value==true then
  702.         return 'DebuffBloodPactWard'
  703.     elseif (meritPacts:contains(spell.english) and pet_tp < 749) or (enticersRagePacts:contains(spell.english) and pet_tp < 2350) then
  704.     --elseif enticersRagePacts:contains(spell.english) and spell.english ~= 'Impact' then
  705.         return 'TPMagicalBloodPactRage'..spellMapMod
  706.         --return 'MagicalBloodPactRage'
  707.     elseif hybridPacts:contains(spell.english) then
  708.         return 'HybridBloodPactRage'..spellMapMod
  709.     elseif magicalRagePacts:contains(spell.english) and pet.name=="Ifrit" then
  710.         return 'IfritMagicalBloodPactRage'..spellMapMod
  711.     elseif magicalRagePacts:contains(spell.english) then
  712.         return 'MagicalBloodPactRage'..spellMapMod
  713.     else
  714.         return 'PhysicalBloodPactRage'..spellMapMod
  715.     end
  716.     elseif spell.type=='BloodPactWard' and healingWardPacts:contains(spell.english) then
  717.         return 'HealingWard'
  718.     elseif spell.type == 'BloodPactWard' and spell.target.type == 'MONSTER' then
  719.         return 'DebuffBloodPactWard'
  720.     elseif spell.type=='BloodPactWard' and enticersWardPacts:contains(spell.english) then
  721.         return 'TPBloodPactWard'
  722.     end
  723.     if spell.skill=="Enhancing Magic" then
  724.         return 'Enhancing Magic'
  725.     end
  726.     if spell.english:contains('Refresh') and spell.target.name == player.name then
  727.         return 'RefreshSelf'
  728.     end
  729.     if spell.english:startswith('Cure') and spell.target.name == player.name then
  730.         return 'CureSelf'
  731.     end
  732.     if spell.english:contains('Cursna') and spell.target.name == player.name then
  733.         return 'CursnaSelf'
  734.     end
  735.     --log_data_structure(buffactive)
  736.     if state.Buff['aurorastorm']==1 then
  737.         return 'CureAurora'
  738.     end
  739. end
  740. -- Modify the default idle set after it was constructed.
  741. function customize_idle_set(idleSet)
  742.     --print('customize idle set')
  743.     if pet.isvalid then
  744.         if pet.element == world.day_element then
  745.             idleSet = set_combine(idleSet, sets.perp.Day)
  746.         end
  747.         if pet.element == world.weather_element then
  748.             idleSet = set_combine(idleSet, sets.perp.Weather)
  749.         end
  750.         if sets.perp[pet.name] then
  751.             idleSet = set_combine(idleSet, sets.perp[pet.name])
  752.         end
  753. --      gear.perp_staff.name = elements.perpetuance_staff_of[pet.element]
  754. --      if gear.perp_staff.name and (player.inventory[gear.perp_staff.name] or player.wardrobe[gear.perp_staff.name]) then
  755. --          idleSet = set_combine(idleSet, sets.perp.staff_and_grip)
  756. --      end
  757.         if state.Buff["Avatar's Favor"] and avatars:contains(pet.name) then
  758.             --idleSet = set_combine(idleSet, sets.idle.Avatar.Favor)
  759.             idleSet = set_combine(idleSet,sets.favor[state.favor.value])
  760.         end
  761.         if pet.status == 'Engaged' then
  762.             idleSet = set_combine(idleSet, sets.Avatar.Haste)
  763.         end
  764.     end
  765.     if player.max_mp - player.mp < 100 and usemephitas then
  766.         if pet.isvalid then idleSet = set_combine(idleSet, {right_ring="Mephitas's Ring +1" })
  767.         else idleSet = set_combine(idleSet, {right_ring="Mephitas's Ring +1"})
  768.         end
  769.     end
  770.     if pet.name=='Cait Sith' then
  771.         --idleSet = set_combine(idleSet, {hands="Lamassu Mitts +1"})
  772.     end
  773.  
  774.     if player.mpp < 51 then -- this won't work because gear isn't considered only base
  775.         idleSet = set_combine(idleSet, sets.latent_refresh)
  776.     end
  777.    
  778.     if state.damagetaken.value ~= "None" then idleSet = set_combine(idleSet,sets.damagetaken[state.damagetaken.value]) end
  779.     if state.petdamagetaken.value ~= "None" then idleSet = set_combine(idleSet,sets.petdamagetaken[state.petdamagetaken.value]) end
  780.  
  781.     if areas.Cities:contains(world.area) and world.area:contains("Adoulin") then
  782.         idleSet = set_combine(idleSet, sets.adoulinmovement)
  783.     elseif  world.area:contains("Mog Garden") then
  784.         idleSet = set_combine(idleSet, sets.farmer)
  785.         --windower.send_command('input /ja Release <me>;wait 2;input /ma '..tosummon..' <me>')
  786.     elseif buffactive["Quickening"] or buffactive["Fleet Wind"] or areas.Cities:contains(world.area) then
  787.         idleSet = set_combine(idleSet, sets.movement)
  788.     elseif state.movement.current == 'on' then
  789.         idleSet = set_combine(idleSet, sets.movement)
  790.     end
  791.  
  792.    
  793.     if state.cpmode.current == 'on' then idleSet = set_combine(idleSet,sets.cpmode) end
  794.     if state.tplock.current == 'on' then
  795.         idleSet = set_combine(idleSet,sets.tplock)
  796.         equip(idleSet)
  797.         disable('main','sub')
  798.     elseif state.kclub.current == 'on' then
  799.         idleSet = set_combine(idleSet,sets.kclub)
  800.         equip(idleSet)
  801.         disable('main','sub')
  802.     elseif state.pullmode.current == 'on' then
  803.         --disable('main','sub')
  804.     else
  805.         enable('main','sub')
  806.     end
  807.     if state.pullmode.current == 'on' then idleSet = set_combine(idleSet,sets.pullmode) end
  808.     if state.idlehealer.current == 'on' then idleSet = set_combine(idleSet,sets.idlehealer) end
  809.     if state.magiceva.current == 'on' then idleSet = set_combine(idleSet,sets.magiceva) end
  810.    
  811.     if inwkr == 1 then
  812.         idleSet = set_combine(idleSet, sets.inwkr)
  813.     end
  814.     equip(idleSet)
  815.  
  816.     return idleSet
  817. end
  818.  
  819. function customize_melee_set(meleeSet)
  820.     if state.damagetaken.value ~= "None" then meleeSet = set_combine(meleeSet,sets.damagetaken[state.damagetaken.value]) end
  821.     if state.petdamagetaken.value ~= "None" then meleeSet = set_combine(meleeSet,sets.petdamagetaken[state.petdamagetaken.value]) end
  822.     if state.cpmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.cpmode) end
  823.     if state.tplock.current == 'on' then
  824.         meleeSet = set_combine(meleeSet,sets.tplock)
  825.         equip(meleeSet)
  826.         disable('main','sub')
  827.     elseif state.kclub.current == 'on' then
  828.         meleeSet = set_combine(meleeSet,sets.kclub)
  829.         equip(meleeSet)
  830.         disable('main','sub')
  831.     elseif state.pullmode.current == 'on' then
  832.         --disable('main','sub')
  833.     else
  834.         enable('main','sub')
  835.     end
  836.     if state.OffenseMode.value == 'Perp' then
  837.         if pet.status == 'Engaged' then
  838.             meleeSet = set_combine(meleeSet, sets.Avatar.Haste)
  839.         end
  840.     end
  841.     if state.pullmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.pullmode) end
  842.     if state.idlehealer.current == 'on' then idleSet = set_combine(idleSet,sets.idlehealer) end
  843.     if state.magiceva.current == 'on' then meleeSet = set_combine(meleeSet,sets.magiceva) end
  844.     if inwkr == 1 then
  845.         meleeSet = set_combine(meleeSet, sets.inwkr)
  846.     end
  847.     return meleeSet
  848.     --if state.dtmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.dtmode) end
  849. end
  850. function customize_resting_set(restingSet)
  851.     if state.damagetaken.value ~= "None" then restingSet = set_combine(meleeSet,sets.damagetaken[state.damagetaken.value]) end
  852.    
  853.     if state.cpmode.current == 'on' then restingSet = set_combine(restingSet,sets.cpmode) end
  854.     return restingSet
  855. end
  856.  
  857.  
  858. -- Called by the 'update' self-command, for common needs.
  859. -- Set eventArgs.handled to true if we don't want automatic equipping of gear.
  860. function job_update(cmdParams, eventArgs)
  861.     classes.CustomIdleGroups:clear()
  862.     if pet.isvalid then
  863.         if avatars:contains(pet.name) then
  864.             classes.CustomIdleGroups:append('Avatar')
  865.         elseif spirits:contains(pet.name) then
  866.             classes.CustomIdleGroups:append('Spirit')
  867.         end
  868.     end
  869. end
  870.  
  871. -- Set eventArgs.handled to true if we don't want the automatic display to be run.
  872. function display_current_job_state(eventArgs)
  873.  
  874. end
  875.  
  876.  
  877. -------------------------------------------------------------------------------------------------------------------
  878. -- User self-commands.
  879. -------------------------------------------------------------------------------------------------------------------
  880.  
  881. modepage = 0
  882. movement=0
  883. buffrotkey=0
  884. pet_tp=0
  885. -- Called for custom player commands.
  886. function job_self_command(cmdParams, eventArgs)
  887.  
  888.     if cmdParams[1] == 'toggle' or cmdParams[1] == 'cycle' then
  889.         send_command('wait .5;gs c force_hud_refresh')-- there is no way to hook into motes modes function when called, if I update now it is before motes does, a .5 second delay is minimal for update to hud and seems to work well.  coroutine.sleep gives a return error because we have function returns going on
  890.     end
  891.     if cmdParams[1] == 'printtp' then
  892.         print(pet_tp)
  893.     end
  894.     if cmdParams[1]:lower() == 'petweather' then
  895.         handle_petweather()
  896.         eventArgs.handled = true
  897.     elseif cmdParams[1]:lower() == 'test' then
  898.     pr(buffactive['Apogee'])
  899.     elseif cmdParams[1]:lower() == 'siphon' then
  900.         handle_siphoning()
  901.         eventArgs.handled = true
  902.     elseif cmdParams[1]:lower() == 'pact' then
  903.         handle_pacts(cmdParams)
  904.         eventArgs.handled = true
  905.     elseif cmdParams[1] == 'reset_ward_flag' then
  906.         wards.flag = false
  907.         wards.spell = ''
  908.         eventArgs.handled = true
  909.     elseif cmdParams[1] == 'smn' then
  910.     tosummon = cmdParams[2]
  911.     smntarget = "<me>"
  912.     if tosummon=='atomos' then smntarget="<t>" end
  913.     if tosummon == 'caitsith' then tosummon='cait sith' end
  914.     if tosummon == 'lightspirit' then tosummon='light spirit' end
  915.         if pet.isvalid and pet.name:lower()==tosummon then
  916.         add_to_chat(122,cmdParams[2].." is already summoned!")
  917.         elseif pet.isvalid then
  918.         windower.send_command('input /ja Release <me>;wait 2;input /ma '..tosummon..' '..smntarget)
  919.         else  
  920.         windower.send_command('input /ma '..tosummon..' '..smntarget)
  921.     end
  922.         eventArgs.handled = true
  923.     elseif cmdParams[1] == 'fleet_wind' then
  924.         if pet.isvalid and pet.name:lower()=='garuda' then
  925.         send_command('input /ma Fleet Wind <me>')
  926.     elseif pet.isvalid then
  927.         send_command('input /ja Release <me>;wait 1;input /ma Garuda <me>;wait 4;input /ma Fleet Wind <me>;wait 2')
  928.     else
  929.         send_command('input /ma Garuda <me>;wait 4;input /ma Fleet Wind <me>')
  930.     end
  931.     elseif cmdParams[1] == 'supportmode' then
  932.         send_command('input /ja "Light Arts";wait 1;input /ja "Sublimation";wait 1;input /ja "Addendum: White";wait 1;input /ma "Aurorastorm" <me>')
  933.     elseif cmdParams[1] == 'nukemode' then
  934.         send_command('input /ja "Dark Arts";wait 1;input /ja "Sublimation";wait 1;input /ja "Addendum: Black";wait 1;input /ma "Firestorm" <me>')
  935.  
  936.     elseif cmdParams[1] == 'release' then
  937.         set_macro_page(1,2)
  938.     send_command('input /pet "Release" <me>')
  939.     elseif cmdParams[1] == 'buffrotation' then
  940.         buffability,buffavatar = next(buffrotation[buffrotkey])
  941.         if pet.isvalid and pet.name ~= buffavatar then
  942.             send_command('input /ja "Release" <me>;wait 1;input /ma "'..buffavatar..'" <me>;wait 5;input /ja "'..buffability..'"')
  943.         elseif not pet.isvalid then
  944.             send_command('input /ma "'..buffavatar..'" <me>;wait 5;input /ja "'..buffability..'"')
  945.         else
  946.             send_command('input /ja "'..buffability..'"')
  947.         end
  948.         buffrotkey = buffrotkey + 1
  949.         if buffrotkey >= buffrot_count then buffrotkey=0 end
  950.     elseif cmdParams[1] == 'warpring' then
  951.         equip({left_ring="Warp Ring"})
  952.         send_command('gs disable left_ring;wait 10;input /item "Warp Ring" <me>;wait 1;input /item "Warp Ring" <me>;wait 1;input /item "Warp Ring" <me>;wait 10;gs enable left_ring')
  953.     elseif cmdParams[1] == 'toggle_hud' then
  954.         if display_hud==true then
  955.             display_hud = false
  956.             window:hide()
  957.             --images.hide(avatar_icon)
  958.         else
  959.             display_hud=true
  960.             window:show()
  961.             --images.show(avatar_icon)
  962.         end
  963.     elseif cmdParams[1] == 'toggle_states' then
  964.         if display_states==true then
  965.             display_states = false
  966.         else
  967.             display_states=true
  968.         end
  969.         updatedisplay()
  970.     elseif cmdParams[1] == 'force_hud_refresh' then
  971.         updatedisplay()
  972.     elseif cmdParams[1] == 'toggle' and cmdParams[2]=='cpmode' then
  973.     --logic is reversed b/c it's true/false and lags behind motes toggle since this is called first
  974.     if state.cpmode.current ~= 'on' then
  975.         equip(sets.cpmode)
  976.         send_command('gs disable back')
  977.     else
  978.         send_command('gs enable back')
  979.     end
  980.     elseif cmdParams[1] == "switch_dualbox_binds" then -- disables stp_m1 to stp_m10 for dual box commands, or enables them
  981.         if use_dualbox then
  982.             if cureIV then
  983.                 send_command('alias stp_m1 input /ma "Cure IV" <p0>')
  984.                 send_command('alias stp_m2 input /ma "Cure IV" <p1>')
  985.                 send_command('alias stp_m3 input /ma "Cure IV" <p2>')
  986.                 send_command('alias stp_m4 input /ma "Cure IV" <p3>')
  987.                 send_command('alias stp_m5 input /ma "Cure IV" <p4>')
  988.                 send_command('alias stp_m6 input /ma "Cure IV" <p5>')
  989.                 send_command('alias stp_m7 input /ma "Cure IV"')
  990.             else
  991.                 send_command('alias stp_m1 input /ma "Cure III" <p0>')
  992.                 send_command('alias stp_m2 input /ma "Cure III" <p1>')
  993.                 send_command('alias stp_m3 input /ma "Cure III" <p2>')
  994.                 send_command('alias stp_m4 input /ma "Cure III" <p3>')
  995.                 send_command('alias stp_m5 input /ma "Cure III" <p4>')
  996.                 send_command('alias stp_m6 input /ma "Cure III" <p5>')
  997.                 send_command('alias stp_m7 input /ma "Cure III"')
  998.             end
  999.             send_command('alias stp_m8 gs c nukemode')
  1000.             send_command('alias stp_m9 gs c supportmode')
  1001.             use_dualbox=false
  1002.         else
  1003.             send_command('alias stp_m1 nil')
  1004.             send_command('alias stp_m2 nil')
  1005.             send_command('alias stp_m3 nil')
  1006.             send_command('alias stp_m4 nil')
  1007.             send_command('alias stp_m5 nil')
  1008.             send_command('alias stp_m6 nil')
  1009.             send_command('alias stp_m7 nil')
  1010.             send_command('alias stp_m8 nil')
  1011.             send_command('alias stp_m9 nil')
  1012.             --send_command('alias stp_m10 nil')
  1013.             use_dualbox=true
  1014.         end
  1015.     elseif cmdParams[1] == 'pet_tp' then
  1016.         --print('pet tp is now '..tostring(pet_tp))
  1017.         pet_tp = tonumber(cmdParams[2])
  1018.     elseif cmdParams[1] == 'conduit_lock' then
  1019.         if conduit_lock then
  1020.             conduit_lock = false
  1021.             add_to_chat(122,"conduit lock off")
  1022.         else
  1023.             conduit_lock = true
  1024.             add_to_chat(122,"conduit lock on")
  1025.         end
  1026.     elseif cmdParams[1] == 'updategear' then
  1027.         handle_equipping_gear(player.status)
  1028.     end
  1029. end
  1030.  
  1031.  
  1032. -------------------------------------------------------------------------------------------------------------------
  1033. -- Utility functions specific to this job.
  1034. -------------------------------------------------------------------------------------------------------------------
  1035.  
  1036. -- Cast the appopriate storm for the currently summoned avatar, if possible.
  1037. function handle_petweather()
  1038.     if player.sub_job ~= 'SCH' then
  1039.         add_to_chat(122, "You can not cast storm spells")
  1040.         return
  1041.     end
  1042.        
  1043.     if not pet.isvalid then
  1044.         add_to_chat(122, "You do not have an active avatar.")
  1045.         return
  1046.     end
  1047.    
  1048.     local element = pet.element
  1049.     if element == 'Thunder' then
  1050.         element = 'Lightning'
  1051.     end
  1052.    
  1053. --    if S{'Light','Dark','Lightning'}:contains(element) then
  1054. --        add_to_chat(122, 'You do not have access to '..elements.storm_of[element]..'.')
  1055. --        return
  1056. --    end
  1057.    
  1058.     local storm = elements.storm_of[element]
  1059.    
  1060.     if storm then
  1061.         send_command('@input /ma "'..elements.storm_of[element]..'" <me>')
  1062.     else
  1063.         add_to_chat(123, 'Error: Unknown element ('..tostring(element)..')')
  1064.     end
  1065. end
  1066.  
  1067.  
  1068. -- Custom uber-handling of Elemental Siphon
  1069. function handle_siphoning()
  1070.     if areas.Cities:contains(world.area) then
  1071.         add_to_chat(122, 'Cannot use Elemental Siphon in a city area.')
  1072.         return
  1073.     end
  1074.  
  1075.     local siphonElement
  1076.     local stormElementToUse
  1077.     local releasedAvatar
  1078.     local dontRelease
  1079.    
  1080.     -- If we already have a spirit out, just use that.
  1081.     if pet.isvalid and spirits:contains(pet.name) then
  1082.         siphonElement = pet.element
  1083.         dontRelease = true
  1084.         -- If current weather doesn't match the spirit, but the spirit matches the day, try to cast the storm.
  1085.         if player.sub_job == 'SCH' and pet.element == world.day_element and pet.element ~= world.weather_element then
  1086. --            if not S{'Light','Dark','Lightning'}:contains(pet.element) then
  1087. --                stormElementToUse = pet.element
  1088. --            end
  1089.         stormElementToUse = pet.element
  1090.         end
  1091.     -- If we're subbing /sch, there are some conditions where we want to make sure specific weather is up.
  1092.     -- If current (single) weather is opposed by the current day, we want to change the weather to match
  1093.     -- the current day, if possible.
  1094.     elseif player.sub_job == 'SCH' and world.weather_element ~= 'None' then
  1095.         -- We can override single-intensity weather; leave double weather alone, since even if
  1096.         -- it's partially countered by the day, it's not worth changing.
  1097.         if get_weather_intensity() == 1 then
  1098.             -- If current weather is weak to the current day, it cancels the benefits for
  1099.             -- siphon.  Change it to the day's weather if possible (+0 to +20%), or any non-weak
  1100.             -- weather if not.
  1101.             -- If the current weather matches the current avatar's element (being used to reduce
  1102.             -- perpetuation), don't change it; just accept the penalty on Siphon.
  1103.             if world.weather_element == elements.weak_to[world.day_element] and
  1104.                 (not pet.isvalid or world.weather_element ~= pet.element) then
  1105.                 -- We can't cast lightning/dark/light weather, so use a neutral element
  1106. --                if S{'Light','Dark','Lightning'}:contains(world.day_element) then
  1107. --                    stormElementToUse = 'Wind'
  1108. --                else
  1109. --                    stormElementToUse = world.day_element
  1110. --                end
  1111.         stormElementToUse = world.day_element
  1112.             end
  1113.         end
  1114.     end
  1115.    
  1116.     -- If we decided to use a storm, set that as the spirit element to cast.
  1117.     if stormElementToUse then
  1118.         siphonElement = stormElementToUse
  1119.     elseif world.weather_element ~= 'None' and (get_weather_intensity() == 2 or world.weather_element ~= elements.weak_to[world.day_element]) then
  1120.         siphonElement = world.weather_element
  1121.     else
  1122.         siphonElement = world.day_element
  1123.     end
  1124.    
  1125.     local command = ''
  1126.     local releaseWait = 0
  1127.     local elementused = ''
  1128.    
  1129.     if pet.isvalid and avatars:contains(pet.name) then
  1130.         command = command..'input /pet "Release" <me>;wait 1.1;'
  1131.         releasedAvatar = pet.name
  1132.         releaseWait = 10
  1133.     end
  1134.    
  1135.     if stormElementToUse then
  1136.         command = command..'input /ma "'..elements.storm_of[stormElementToUse]..'" <me>;wait 5;'
  1137.         releaseWait = releaseWait - 4
  1138.     elementused = stormElementToUse
  1139.     end
  1140.    
  1141.     if not (pet.isvalid and spirits:contains(pet.name)) then
  1142.         command = command..'input /ma "'..elements.spirit_of[siphonElement]..'" <me>;wait 5;'
  1143.         releaseWait = releaseWait - 4
  1144.     elementused = siphonElement
  1145.     end
  1146.    
  1147.     command = command..'input /ja "Elemental Siphon" <me>;'
  1148.     releaseWait = releaseWait - 1
  1149.     releaseWait = releaseWait + 0.1
  1150.    
  1151.     if not dontRelease then
  1152.         if releaseWait > 0 then
  1153.             command = command..'wait '..tostring(releaseWait)..';'
  1154.         else
  1155.             command = command..'wait 1.1;'
  1156.         end
  1157.        
  1158.         command = command..'input /pet "Release" <me>;'
  1159.     end
  1160.    
  1161.     if releasedAvatar then
  1162.         command = command..'wait 1.1;input /ma "'..releasedAvatar..'" <me>'
  1163.     end
  1164.    
  1165.     send_command(command)
  1166. end
  1167.  
  1168.  
  1169. -- Handles executing blood pacts in a generic, avatar-agnostic way.
  1170. -- cmdParams is the split of the self-command.
  1171. -- gs c [pact] [pacttype]
  1172. function handle_pacts(cmdParams)
  1173.     if areas.Cities:contains(world.area) then
  1174.         add_to_chat(122, 'You cannot use pacts in town.')
  1175.         return
  1176.     end
  1177.  
  1178.     if not pet.isvalid then
  1179.         --add_to_chat(122,'No avatar currently available. Returning to default macro set.')
  1180.         return
  1181.     end
  1182.  
  1183.     if spirits:contains(pet.name) then
  1184.         add_to_chat(122,'Cannot use pacts with spirits.')
  1185.         return
  1186.     end
  1187.  
  1188.     if not cmdParams[2] then
  1189.         add_to_chat(123,'No pact type given.')
  1190.         return
  1191.     end
  1192.    
  1193.     local pact = cmdParams[2]:lower()
  1194.    
  1195.     if not pacts[pact] then
  1196.         add_to_chat(123,'Unknown pact type: '..tostring(pact))
  1197.         return
  1198.     end
  1199.    
  1200.     if pacts[pact][pet.name] then
  1201.         if pact == 'astralflow' and not buffactive['astral flow'] then
  1202.             add_to_chat(122,'Cannot use Astral Flow pacts at this time.')
  1203.             return
  1204.         end
  1205.        
  1206.         -- Leave out target; let Shortcuts auto-determine it.
  1207.         send_command('@input /pet "'..pacts[pact][pet.name]..'"')
  1208.     else
  1209.         add_to_chat(122,pet.name..' does not have a pact of type ['..pact..'].')
  1210.     end
  1211. end
  1212.  
  1213. function select_default_macro_book(reset)
  1214.     -- Default macro set/book
  1215.     set_macro_page(1, 2)
  1216. end
  1217. load_debugging=1
  1218. if load_debugging then
  1219.     function log_data_structure(data_object)
  1220.         str = inspect(data_object)
  1221.         local ouf = assert(io.open("D:/Program Files (x86)/Windower4/addons/GearSwap/data/file_log.txt", "a"))
  1222.         if ouf then
  1223.             ouf:write(tostring(str))
  1224.             ouf:write("\n")
  1225.             io.close(ouf)
  1226.             --print('wrote to file')
  1227.         else
  1228.             --print('could not open file to write')
  1229.         end
  1230.     end
  1231.     inspect = require 'inspect'
  1232. end
  1233.  
  1234. --windower.send_command('lua l pet_tp')
  1235. pet_tp = 0
  1236. --Fix missing Pet.TP field by getting the packets from the fields lib
  1237. packets = require('packets')
  1238. function update_pet_tp(id,data)
  1239.     if id == 0x068 then
  1240.         pet_tp = 0
  1241.         local update = packets.parse('incoming', data)
  1242.         pet_tp = update["Pet TP"]
  1243.         windower.send_command('lua c gearswap c pet_tp '..pet_tp)
  1244.         --print(pet_tp)
  1245.         --log_data_structure(update)
  1246.         --log_data_structure(pet_tp)
  1247.         --debuginfo = debug.getinfo(1)
  1248.         --log_data_structure(debuginfo)
  1249.         --print('here')
  1250.         --log_data_structure(data)
  1251.     end
  1252. end
  1253. id = windower.raw_register_event('incoming chunk', update_pet_tp)
  1254.  
  1255. --pet_tp = 350
  1256. ----Fix missing Pet.TP field by getting the packets from the fields lib
  1257. --packets = require('packets')
  1258. --function update_pet_tp(id,data)
  1259. --  if id == 0x068 then
  1260. --      --debuginfo = debug.getinfo(1)
  1261. --      --log_data_structure(debuginfo)
  1262. --      --print('here')
  1263. --      --log_data_structure(data)
  1264. --      local update = packets.parse('incoming', data)
  1265. --      --log_data_structure(update)
  1266. --      pet_tp = update["Pet TP"]
  1267. --      log_data_structure(pet_tp)
  1268. --      event=_global.current_event
  1269. --
  1270. --      log_data_structure(_global)
  1271. --  end
  1272. --end
  1273. --id = windower.register_event('incoming chunk', update_pet_tp)
  1274. --log_data_structure(id)
  1275. --info = debug.getinfo(update_pet_tp)
  1276.    
  1277. --windower.register_event('incoming chunk', function(id, data)
  1278. --    if id == 0x068 then
  1279. --      --log_data_structure(data)
  1280. --      local update = packets.parse('incoming', data)
  1281. --      --log_data_structure(update)
  1282. --      pet_tp = update["Pet TP"]
  1283. --      --log_data_structure(pet_tp)
  1284. --    end
  1285. --end)
  1286.  
  1287.  
  1288. -- Event handler for updates to player skill, since we can't rely on skill being
  1289. -- correct at pet_aftercast for the creation of custom timers.
  1290. --windower.raw_register_event('incoming chunk',
  1291. --    function (id)
  1292. --        if id == 0x62 then
  1293. --            if wards.flag then
  1294. --                create_pact_timer(wards.spell)
  1295. --                wards.flag = false
  1296. --                wards.spell = ''
  1297. --            end
  1298. --        end
  1299. --    end)
  1300.  
  1301. -- Function to create custom timers using the Timers addon.  Calculates ward duration
  1302. -- based on player skill and base pact duration (defined in job_setup).
  1303. --function create_pact_timer(spell_name)
  1304. --    -- Create custom timers for ward pacts.
  1305. --    if wards.durations[spell_name] then
  1306. --        local ward_duration = wards.durations[spell_name]
  1307. --        if ward_duration < 181 then
  1308. --            local skill = player.skills.summoning_magic
  1309. --            if skill > 300 then
  1310. --                skill = skill - 300
  1311. --                --if skill > 200 then skill = 200 end
  1312. --                ward_duration = ward_duration + skill
  1313. --            end
  1314. --        end
  1315. --      
  1316. --        local timer_cmd = 'timers c "'..spell_name..'" '..tostring(ward_duration)..' down'
  1317. --      
  1318. --        if wards.icons[spell_name] then
  1319. --            timer_cmd = timer_cmd..' '..wards.icons[spell_name]
  1320. --        end
  1321. --
  1322. --        send_command(timer_cmd)
  1323. --    end
  1324. --end
  1325.  
  1326. -- Select default macro book on initial load or subjob change.
  1327. --windower.raw_register_event('mouse', function(type, x, y, delta, blocked)
  1328. --    if type == 2 then
  1329. --      updatedisplay()
  1330. --    end
  1331. --end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement