Advertisement
Guest User

SMN-lib.lua

a guest
Sep 5th, 2016
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 52.73 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.     --if state.bpmagicacc.current=='on' then
  522.         equip(sets.bp_magic_acc)
  523.     end
  524.     if state.bpmagicacc.current=='on' and (spellMap == 'PhysicalBloodPactRage') then
  525.         equip(sets.bp_phys_acc)
  526.     end
  527.     if state.bpmagicacc.current=='on' and (spellMap == 'HybridBloodPactRage') then
  528.         equip(sets.bp_hybrid_acc)
  529.     end
  530.     if state.burstmode.value=='Burst' and enticersRagePacts:contains(spell.english) and spell.english~="Impact" then
  531.         equip(sets.burstmode.Burst)
  532.     end
  533. end
  534. function job_aftercast(spell, action, spellMap, eventArgs)
  535.     if spell.type=="BloodPactRage" or spell.type=="BloodPactWard" then
  536.         eventArgs.handled=true
  537.     end
  538. --  if pet_midaction() then
  539. --      eventArgs.handled=true
  540. --  end
  541.     --if swapspaused then eventArgs.handled = true end
  542.     is_midpact = check_midpact(spell,eventArgs,false)
  543.     d_chat('Job Aftercast')
  544.     --if is_midpact then return end
  545.  
  546.     --print('spell '..spell.type..' aftercast')
  547.     --handle_equipping_gear(player.status,pet.status)
  548.     --    if spell.type == 'Summoning' then
  549.     --  return 'idle.Avatar'
  550.     --    end
  551. end
  552.  
  553. -- Runs when pet completes an action.
  554. function job_pet_aftercast(spell, action, spellMap, eventArgs)
  555.     is_midpact = check_midpact(spell,eventArgs)
  556.     d_chat('Job Pet Aftercast')
  557.     d_chat('player status is'..player.status)
  558.     handle_equipping_gear(player.status,pet.status)
  559.     --if is_midpact then return end
  560. --  if is_midpact then
  561. --      d_chat('job_pet_aftercast returned due to midpact')
  562. --      return
  563. --  end
  564.  
  565.     --d_chat('check is '..tostring(is_midpact))
  566.     --add_to_chat(122,'Player Status is '..player.status)
  567.     --    if not spell.interrupted and spell.type == 'BloodPactWard' and spellMap ~= 'DebuffBloodPactWard' then
  568.     --        wards.flag = true
  569.     --        wards.spell = spell.english
  570.     --        send_command('wait 4; gs c reset_ward_flag')
  571.     --    end
  572.     --    if player.status == 'Engaged' then
  573.     --  equip(sets.engaged)
  574.     --    end
  575. --  aftermp = player.mp
  576. --  diffmp = beforemp - aftermp
  577. --  savemp = 100*diffmp/248
  578. --  savemp = tonumber(string.format("%.3f", savemp))
  579.     --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
  580.     --handle_equipping_gear(player.status,pet.status)
  581.     --print ('pet aftercast '..pet.status..' action '..action)
  582.     --    if pet.isvalid and pet.status == 'Engaged'  then
  583.     --      print('pet aftercast')
  584.     --      equip(sets.Avatar.Haste)
  585.     --      return 'Avatar.Haste'
  586.     --    end
  587.     --    if pet.isvalid and not midaction() and not pet_midaction() then
  588.     --      if player.status == "Idle" then
  589.     --          --equip(sets.idle.Avatar)
  590.     --          return 'idle.Avatar'
  591.     --      end
  592.     --    end
  593. end
  594.  
  595. -------------------------------------------------------------------------------------------------------------------
  596. -- Job-specific hooks for non-casting events.
  597. -------------------------------------------------------------------------------------------------------------------
  598.  
  599. -- Called when a player gains or loses a buff.
  600. -- buff == buff gained or lost
  601. -- gain == true if the buff was gained, false if it was lost.
  602. function job_buff_change(buff, gain)
  603.     if state.Buff[buff] ~= nil then
  604.         handle_equipping_gear(player.status)
  605.     elseif storms:contains(buff) then
  606.         handle_equipping_gear(player.status)
  607.     end
  608.     if gain and buff=="quickening" then
  609.         handle_equipping_gear(player.status)
  610.     end
  611.     if pet.isvalid and buff == 'sleep' then
  612.         if gain then
  613.             equip(sets.wakeup)
  614.         end
  615.     end
  616. end
  617.  
  618.  
  619. -- Called when the player's pet's status changes.
  620. -- This is also called after pet_change after a pet is released.  Check for pet validity.
  621. function job_pet_status_change(newStatus, oldStatus, eventArgs)
  622. --   local check = check_midpact(spell,eventArgs)
  623.     --d_chat('Pet Status Change new '..newStatus..' old '..oldStatus..' player'..player.status..' midaction '..tostring(pet_midaction())..' is_midpact '..tostring(is_midpact))
  624.     d_chat('Pet Status Change new '..newStatus..' old '..oldStatus..' player'..player.status..' midaction '..tostring(pet_midaction()))
  625.     if pet_midaction() then
  626.         --d_chat('check is '..tostring(is_midpact))
  627.         d_chat('Pet Status Change cancelled')
  628.         eventArgs.handled=true
  629.         return
  630.         --coroutine.sleep(1)
  631.     end
  632.     handle_equipping_gear(player.status,newStatus)
  633.  
  634. end
  635.  
  636. function spairs(t, order)
  637.     -- collect the keys
  638.     local keys = {}
  639.     for k in pairs(t) do keys[#keys+1] = k end
  640.  
  641.     -- if order function given, sort by it by passing the table and keys a, b,
  642.     -- otherwise just sort the keys
  643.     if order then
  644.         table.sort(keys, function(a,b) return order(t, a, b) end)
  645.     else
  646.         table.sort(keys)
  647.     end
  648.  
  649.     -- return the iterator function
  650.     local i = 0
  651.     return function()
  652.         i = i + 1
  653.         if keys[i] then
  654.             return keys[i], t[keys[i]]
  655.         end
  656.     end
  657. end
  658. -- Called when a player gains or loses a pet.
  659. -- pet == pet structure
  660. -- gain == true if the pet was gained, false if it was lost.
  661. function job_pet_change(petparam, gain)
  662.     classes.CustomIdleGroups:clear()
  663.     if gain then
  664.     trackavatar = pet.name
  665.     smn_property.pacts = {['Rage']="",['Ward']=""}
  666.         if avatars:contains(pet.name) then
  667.             classes.CustomIdleGroups:append('Avatar')
  668.         elseif spirits:contains(pet.name) then
  669.             classes.CustomIdleGroups:append('Spirit')
  670.         end
  671.     updatedisplay()
  672.     else
  673.     smn_property.avatar = "\\cs(255,0,0)None\\cr"
  674.     smn_property.pacts = {['Rage']="",['Ward']=""}
  675.     updatedisplay()
  676.     end
  677. end
  678.  
  679. -- Called any time we attempt to handle automatic gear equips (ie: engaged or idle gear).
  680. function job_handle_equipping_gear(playerStatus, eventArgs)
  681.     if pet_midaction() then
  682.         eventArgs.handled = true
  683.         send_command('wait 1;gs c updategear')
  684.     end
  685. end
  686.  
  687.  
  688. -------------------------------------------------------------------------------------------------------------------
  689. -- User code that supplements standard library decisions.
  690. -------------------------------------------------------------------------------------------------------------------
  691. -- Custom spell mapping.
  692. function job_get_spell_map(spell)
  693.     --print(pet.tp)
  694.     --print(pet_tp)
  695.     if spell.type == 'BloodPactRage' then
  696.     if spell.english == "Impact" and state.impactmode.value==true then
  697.             return 'DebuffBloodPactWard'
  698.     elseif (meritPacts:contains(spell.english) and pet_tp < 749) or (enticersRagePacts:contains(spell.english) and pet_tp < 2350) then
  699.     --elseif enticersRagePacts:contains(spell.english) and spell.english ~= 'Impact' then
  700.             return 'TPMagicalBloodPactRage'
  701.             --return 'MagicalBloodPactRage'
  702.         elseif hybridPacts:contains(spell.english) then
  703.             return 'HybridBloodPactRage'
  704.     elseif magicalRagePacts:contains(spell.english) and pet.name=="Ifrit" then
  705.             return 'IfritMagicalBloodPactRage'
  706.     elseif magicalRagePacts:contains(spell.english) then
  707.             return 'MagicalBloodPactRage'
  708.     else
  709.             return 'PhysicalBloodPactRage'
  710.         end
  711.     elseif spell.type=='BloodPactWard' and healingWardPacts:contains(spell.english) then
  712.         return 'HealingWard'
  713.     elseif spell.type == 'BloodPactWard' and spell.target.type == 'MONSTER' then
  714.         return 'DebuffBloodPactWard'
  715.     elseif spell.type=='BloodPactWard' and enticersWardPacts:contains(spell.english) then
  716.         return 'TPBloodPactWard'
  717.     end
  718.     if spell.skill=="Enhancing Magic" then
  719.         return 'Enhancing Magic'
  720.     end
  721.     if spell.english:contains('Refresh') and spell.target.name == player.name then
  722.         return 'RefreshSelf'
  723.     end
  724.     if spell.english:startswith('Cure') and spell.target.name == player.name then
  725.         return 'CureSelf'
  726.     end
  727.     if spell.english:contains('Cursna') and spell.target.name == player.name then
  728.         return 'CursnaSelf'
  729.     end
  730.     --log_data_structure(buffactive)
  731.     if state.Buff['aurorastorm']==1 then
  732.         return 'CureAurora'
  733.     end
  734. end
  735. -- Modify the default idle set after it was constructed.
  736. function customize_idle_set(idleSet)
  737.     --print('customize idle set')
  738.     if pet.isvalid then
  739.         if pet.element == world.day_element then
  740.             idleSet = set_combine(idleSet, sets.perp.Day)
  741.         end
  742.         if pet.element == world.weather_element then
  743.             idleSet = set_combine(idleSet, sets.perp.Weather)
  744.         end
  745.         if sets.perp[pet.name] then
  746.             idleSet = set_combine(idleSet, sets.perp[pet.name])
  747.         end
  748. --      gear.perp_staff.name = elements.perpetuance_staff_of[pet.element]
  749. --      if gear.perp_staff.name and (player.inventory[gear.perp_staff.name] or player.wardrobe[gear.perp_staff.name]) then
  750. --          idleSet = set_combine(idleSet, sets.perp.staff_and_grip)
  751. --      end
  752.         if state.Buff["Avatar's Favor"] and avatars:contains(pet.name) then
  753.             --idleSet = set_combine(idleSet, sets.idle.Avatar.Favor)
  754.             idleSet = set_combine(idleSet,sets.favor[state.favor.value])
  755.         end
  756.         if pet.status == 'Engaged' then
  757.             idleSet = set_combine(idleSet, sets.Avatar.Haste)
  758.         end
  759.     end
  760.     if player.max_mp - player.mp < 100 and usemephitas then
  761.         if pet.isvalid then idleSet = set_combine(idleSet, {right_ring="Mephitas's Ring +1" })
  762.         else idleSet = set_combine(idleSet, {right_ring="Mephitas's Ring +1"})
  763.         end
  764.     end
  765.     if pet.name=='Cait Sith' then
  766.         --idleSet = set_combine(idleSet, {hands="Lamassu Mitts +1"})
  767.     end
  768.  
  769.     if player.mpp < 51 then -- this won't work because gear isn't considered only base
  770.         idleSet = set_combine(idleSet, sets.latent_refresh)
  771.     end
  772.    
  773.     if state.damagetaken.value ~= "None" then idleSet = set_combine(idleSet,sets.damagetaken[state.damagetaken.value]) end
  774.     if state.petdamagetaken.value ~= "None" then idleSet = set_combine(idleSet,sets.petdamagetaken[state.petdamagetaken.value]) end
  775.  
  776.     if areas.Cities:contains(world.area) and world.area:contains("Adoulin") then
  777.         idleSet = set_combine(idleSet, sets.adoulinmovement)
  778.     elseif  world.area:contains("Mog Garden") then
  779.         idleSet = set_combine(idleSet, sets.farmer)
  780.         --windower.send_command('input /ja Release <me>;wait 2;input /ma '..tosummon..' <me>')
  781.     elseif buffactive["Quickening"] or buffactive["Fleet Wind"] or areas.Cities:contains(world.area) then
  782.         idleSet = set_combine(idleSet, sets.movement)
  783.     elseif state.movement.current == 'on' then
  784.         idleSet = set_combine(idleSet, sets.movement)
  785.     end
  786.  
  787.    
  788.     if state.cpmode.current == 'on' then idleSet = set_combine(idleSet,sets.cpmode) end
  789.     if state.tplock.current == 'on' then
  790.         idleSet = set_combine(idleSet,sets.tplock)
  791.         equip(idleSet)
  792.         disable('main','sub')
  793.     elseif state.kclub.current == 'on' then
  794.         idleSet = set_combine(idleSet,sets.kclub)
  795.         equip(idleSet)
  796.         disable('main','sub')
  797.     elseif state.pullmode.current == 'on' then
  798.         --disable('main','sub')
  799.     else
  800.         enable('main','sub')
  801.     end
  802.     if state.pullmode.current == 'on' then idleSet = set_combine(idleSet,sets.pullmode) end
  803.     if state.idlehealer.current == 'on' then idleSet = set_combine(idleSet,sets.idlehealer) end
  804.    
  805.     if inwkr == 1 then
  806.         idleSet = set_combine(idleSet, sets.inwkr)
  807.     end
  808.     equip(idleSet)
  809.  
  810.     return idleSet
  811. end
  812.  
  813. function customize_melee_set(meleeSet)
  814.     if state.damagetaken.value ~= "None" then meleeSet = set_combine(meleeSet,sets.damagetaken[state.damagetaken.value]) end
  815.     if state.petdamagetaken.value ~= "None" then meleeSet = set_combine(meleeSet,sets.petdamagetaken[state.petdamagetaken.value]) end
  816.     if state.cpmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.cpmode) end
  817.     if state.tplock.current == 'on' then
  818.         meleeSet = set_combine(meleeSet,sets.tplock)
  819.         equip(meleeSet)
  820.         disable('main','sub')
  821.     elseif state.kclub.current == 'on' then
  822.         meleeSet = set_combine(meleeSet,sets.kclub)
  823.         equip(meleeSet)
  824.         disable('main','sub')
  825.     elseif state.pullmode.current == 'on' then
  826.         --disable('main','sub')
  827.     else
  828.         enable('main','sub')
  829.     end
  830.     if state.OffenseMode.value == 'Perp' then
  831.         if pet.status == 'Engaged' then
  832.             meleeSet = set_combine(meleeSet, sets.Avatar.Haste)
  833.         end
  834.     end
  835.     if state.pullmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.pullmode) end
  836.     if state.idlehealer.current == 'on' then idleSet = set_combine(idleSet,sets.idlehealer) end
  837.     if inwkr == 1 then
  838.         meleeSet = set_combine(meleeSet, sets.inwkr)
  839.     end
  840.     return meleeSet
  841.     --if state.dtmode.current == 'on' then meleeSet = set_combine(meleeSet,sets.dtmode) end
  842. end
  843. function customize_resting_set(restingSet)
  844.     if state.damagetaken.value ~= "None" then restingSet = set_combine(meleeSet,sets.damagetaken[state.damagetaken.value]) end
  845.    
  846.     if state.cpmode.current == 'on' then restingSet = set_combine(restingSet,sets.cpmode) end
  847.     return restingSet
  848. end
  849.  
  850.  
  851. -- Called by the 'update' self-command, for common needs.
  852. -- Set eventArgs.handled to true if we don't want automatic equipping of gear.
  853. function job_update(cmdParams, eventArgs)
  854.     classes.CustomIdleGroups:clear()
  855.     if pet.isvalid then
  856.         if avatars:contains(pet.name) then
  857.             classes.CustomIdleGroups:append('Avatar')
  858.         elseif spirits:contains(pet.name) then
  859.             classes.CustomIdleGroups:append('Spirit')
  860.         end
  861.     end
  862. end
  863.  
  864. -- Set eventArgs.handled to true if we don't want the automatic display to be run.
  865. function display_current_job_state(eventArgs)
  866.  
  867. end
  868.  
  869.  
  870. -------------------------------------------------------------------------------------------------------------------
  871. -- User self-commands.
  872. -------------------------------------------------------------------------------------------------------------------
  873.  
  874. modepage = 0
  875. movement=0
  876. buffrotkey=0
  877. pet_tp=0
  878. -- Called for custom player commands.
  879. function job_self_command(cmdParams, eventArgs)
  880.  
  881.     if cmdParams[1] == 'toggle' or cmdParams[1] == 'cycle' then
  882.         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
  883.     end
  884.     if cmdParams[1] == 'printtp' then
  885.         print(pet_tp)
  886.     end
  887.     if cmdParams[1]:lower() == 'petweather' then
  888.         handle_petweather()
  889.         eventArgs.handled = true
  890.     elseif cmdParams[1]:lower() == 'test' then
  891.     pr(buffactive['Apogee'])
  892.     elseif cmdParams[1]:lower() == 'siphon' then
  893.         handle_siphoning()
  894.         eventArgs.handled = true
  895.     elseif cmdParams[1]:lower() == 'pact' then
  896.         handle_pacts(cmdParams)
  897.         eventArgs.handled = true
  898.     elseif cmdParams[1] == 'reset_ward_flag' then
  899.         wards.flag = false
  900.         wards.spell = ''
  901.         eventArgs.handled = true
  902.     elseif cmdParams[1] == 'smn' then
  903.     tosummon = cmdParams[2]
  904.     smntarget = "<me>"
  905.     if tosummon=='atomos' then smntarget="<t>" end
  906.     if tosummon == 'caitsith' then tosummon='cait sith' end
  907.     if tosummon == 'lightspirit' then tosummon='light spirit' end
  908.         if pet.isvalid and pet.name:lower()==tosummon then
  909.         add_to_chat(122,cmdParams[2].." is already summoned!")
  910.         elseif pet.isvalid then
  911.         windower.send_command('input /ja Release <me>;wait 2;input /ma '..tosummon..' '..smntarget)
  912.         else  
  913.         windower.send_command('input /ma '..tosummon..' '..smntarget)
  914.     end
  915.         eventArgs.handled = true
  916.     elseif cmdParams[1] == 'fleet_wind' then
  917.         if pet.isvalid and pet.name:lower()=='garuda' then
  918.         send_command('input /ma Fleet Wind <me>')
  919.     elseif pet.isvalid then
  920.         send_command('input /ja Release <me>;wait 1;input /ma Garuda <me>;wait 4;input /ma Fleet Wind <me>;wait 2')
  921.     else
  922.         send_command('input /ma Garuda <me>;wait 4;input /ma Fleet Wind <me>')
  923.     end
  924.     elseif cmdParams[1] == 'supportmode' then
  925.         send_command('input /ja "Light Arts";wait 1;input /ja "Sublimation";wait 1;input /ja "Addendum: White";wait 1;input /ma "Aurorastorm" <me>')
  926.     elseif cmdParams[1] == 'nukemode' then
  927.         send_command('input /ja "Dark Arts";wait 1;input /ja "Sublimation";wait 1;input /ja "Addendum: Black";wait 1;input /ma "Firestorm" <me>')
  928.  
  929.     elseif cmdParams[1] == 'release' then
  930.         set_macro_page(1,2)
  931.     send_command('input /pet "Release" <me>')
  932.     elseif cmdParams[1] == 'buffrotation' then
  933.         buffability,buffavatar = next(buffrotation[buffrotkey])
  934.         if pet.isvalid and pet.name ~= buffavatar then
  935.             send_command('input /ja "Release" <me>;wait 1;input /ma "'..buffavatar..'" <me>;wait 5;input /ja "'..buffability..'"')
  936.         elseif not pet.isvalid then
  937.             send_command('input /ma "'..buffavatar..'" <me>;wait 5;input /ja "'..buffability..'"')
  938.         else
  939.             send_command('input /ja "'..buffability..'"')
  940.         end
  941.         buffrotkey = buffrotkey + 1
  942.         if buffrotkey >= buffrot_count then buffrotkey=0 end
  943.     elseif cmdParams[1] == 'warpring' then
  944.         equip({left_ring="Warp Ring"})
  945.         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')
  946.     elseif cmdParams[1] == 'toggle_hud' then
  947.         if display_hud==true then
  948.             display_hud = false
  949.             window:hide()
  950.             images.hide(avatar_icon)
  951.         else
  952.             display_hud=true
  953.             window:show()
  954.             images.show(avatar_icon)
  955.         end
  956.     elseif cmdParams[1] == 'toggle_states' then
  957.         if display_states==true then
  958.             display_states = false
  959.         else
  960.             display_states=true
  961.         end
  962.         updatedisplay()
  963.     elseif cmdParams[1] == 'force_hud_refresh' then
  964.         updatedisplay()
  965.     elseif cmdParams[1] == 'toggle' and cmdParams[2]=='cpmode' then
  966.     --logic is reversed b/c it's true/false and lags behind motes toggle since this is called first
  967.     if state.cpmode.current ~= 'on' then
  968.         equip(sets.cpmode)
  969.         send_command('gs disable back')
  970.     else
  971.         send_command('gs enable back')
  972.     end
  973.     elseif cmdParams[1] == "switch_dualbox_binds" then -- disables stp_m1 to stp_m10 for dual box commands, or enables them
  974.         if use_dualbox then
  975.             if cureIV then
  976.                 send_command('alias stp_m1 input /ma "Cure IV" <p0>')
  977.                 send_command('alias stp_m2 input /ma "Cure IV" <p1>')
  978.                 send_command('alias stp_m3 input /ma "Cure IV" <p2>')
  979.                 send_command('alias stp_m4 input /ma "Cure IV" <p3>')
  980.                 send_command('alias stp_m5 input /ma "Cure IV" <p4>')
  981.                 send_command('alias stp_m6 input /ma "Cure IV" <p5>')
  982.                 send_command('alias stp_m7 input /ma "Cure IV"')
  983.             else
  984.                 send_command('alias stp_m1 input /ma "Cure III" <p0>')
  985.                 send_command('alias stp_m2 input /ma "Cure III" <p1>')
  986.                 send_command('alias stp_m3 input /ma "Cure III" <p2>')
  987.                 send_command('alias stp_m4 input /ma "Cure III" <p3>')
  988.                 send_command('alias stp_m5 input /ma "Cure III" <p4>')
  989.                 send_command('alias stp_m6 input /ma "Cure III" <p5>')
  990.                 send_command('alias stp_m7 input /ma "Cure III"')
  991.             end
  992.             send_command('alias stp_m8 gs c nukemode')
  993.             send_command('alias stp_m9 gs c supportmode')
  994.             use_dualbox=false
  995.         else
  996.             send_command('alias stp_m1 nil')
  997.             send_command('alias stp_m2 nil')
  998.             send_command('alias stp_m3 nil')
  999.             send_command('alias stp_m4 nil')
  1000.             send_command('alias stp_m5 nil')
  1001.             send_command('alias stp_m6 nil')
  1002.             send_command('alias stp_m7 nil')
  1003.             send_command('alias stp_m8 nil')
  1004.             send_command('alias stp_m9 nil')
  1005.             --send_command('alias stp_m10 nil')
  1006.             use_dualbox=true
  1007.         end
  1008.     elseif cmdParams[1] == 'pet_tp' then
  1009.         --print('pet tp is now '..tostring(pet_tp))
  1010.         pet_tp = tonumber(cmdParams[2])
  1011.     elseif cmdParams[1] == 'conduit_lock' then
  1012.         if conduit_lock then
  1013.             conduit_lock = false
  1014.             add_to_chat(122,"conduit lock off")
  1015.         else
  1016.             conduit_lock = true
  1017.             add_to_chat(122,"conduit lock on")
  1018.         end
  1019.     elseif cmdParams[1] == 'updategear' then
  1020.         handle_equipping_gear(player.status)
  1021.     end
  1022. end
  1023.  
  1024.  
  1025. -------------------------------------------------------------------------------------------------------------------
  1026. -- Utility functions specific to this job.
  1027. -------------------------------------------------------------------------------------------------------------------
  1028.  
  1029. -- Cast the appopriate storm for the currently summoned avatar, if possible.
  1030. function handle_petweather()
  1031.     if player.sub_job ~= 'SCH' then
  1032.         add_to_chat(122, "You can not cast storm spells")
  1033.         return
  1034.     end
  1035.        
  1036.     if not pet.isvalid then
  1037.         add_to_chat(122, "You do not have an active avatar.")
  1038.         return
  1039.     end
  1040.    
  1041.     local element = pet.element
  1042.     if element == 'Thunder' then
  1043.         element = 'Lightning'
  1044.     end
  1045.    
  1046. --    if S{'Light','Dark','Lightning'}:contains(element) then
  1047. --        add_to_chat(122, 'You do not have access to '..elements.storm_of[element]..'.')
  1048. --        return
  1049. --    end
  1050.    
  1051.     local storm = elements.storm_of[element]
  1052.    
  1053.     if storm then
  1054.         send_command('@input /ma "'..elements.storm_of[element]..'" <me>')
  1055.     else
  1056.         add_to_chat(123, 'Error: Unknown element ('..tostring(element)..')')
  1057.     end
  1058. end
  1059.  
  1060.  
  1061. -- Custom uber-handling of Elemental Siphon
  1062. function handle_siphoning()
  1063.     if areas.Cities:contains(world.area) then
  1064.         add_to_chat(122, 'Cannot use Elemental Siphon in a city area.')
  1065.         return
  1066.     end
  1067.  
  1068.     local siphonElement
  1069.     local stormElementToUse
  1070.     local releasedAvatar
  1071.     local dontRelease
  1072.    
  1073.     -- If we already have a spirit out, just use that.
  1074.     if pet.isvalid and spirits:contains(pet.name) then
  1075.         siphonElement = pet.element
  1076.         dontRelease = true
  1077.         -- If current weather doesn't match the spirit, but the spirit matches the day, try to cast the storm.
  1078.         if player.sub_job == 'SCH' and pet.element == world.day_element and pet.element ~= world.weather_element then
  1079. --            if not S{'Light','Dark','Lightning'}:contains(pet.element) then
  1080. --                stormElementToUse = pet.element
  1081. --            end
  1082.         stormElementToUse = pet.element
  1083.         end
  1084.     -- If we're subbing /sch, there are some conditions where we want to make sure specific weather is up.
  1085.     -- If current (single) weather is opposed by the current day, we want to change the weather to match
  1086.     -- the current day, if possible.
  1087.     elseif player.sub_job == 'SCH' and world.weather_element ~= 'None' then
  1088.         -- We can override single-intensity weather; leave double weather alone, since even if
  1089.         -- it's partially countered by the day, it's not worth changing.
  1090.         if get_weather_intensity() == 1 then
  1091.             -- If current weather is weak to the current day, it cancels the benefits for
  1092.             -- siphon.  Change it to the day's weather if possible (+0 to +20%), or any non-weak
  1093.             -- weather if not.
  1094.             -- If the current weather matches the current avatar's element (being used to reduce
  1095.             -- perpetuation), don't change it; just accept the penalty on Siphon.
  1096.             if world.weather_element == elements.weak_to[world.day_element] and
  1097.                 (not pet.isvalid or world.weather_element ~= pet.element) then
  1098.                 -- We can't cast lightning/dark/light weather, so use a neutral element
  1099. --                if S{'Light','Dark','Lightning'}:contains(world.day_element) then
  1100. --                    stormElementToUse = 'Wind'
  1101. --                else
  1102. --                    stormElementToUse = world.day_element
  1103. --                end
  1104.         stormElementToUse = world.day_element
  1105.             end
  1106.         end
  1107.     end
  1108.    
  1109.     -- If we decided to use a storm, set that as the spirit element to cast.
  1110.     if stormElementToUse then
  1111.         siphonElement = stormElementToUse
  1112.     elseif world.weather_element ~= 'None' and (get_weather_intensity() == 2 or world.weather_element ~= elements.weak_to[world.day_element]) then
  1113.         siphonElement = world.weather_element
  1114.     else
  1115.         siphonElement = world.day_element
  1116.     end
  1117.    
  1118.     local command = ''
  1119.     local releaseWait = 0
  1120.     local elementused = ''
  1121.    
  1122.     if pet.isvalid and avatars:contains(pet.name) then
  1123.         command = command..'input /pet "Release" <me>;wait 1.1;'
  1124.         releasedAvatar = pet.name
  1125.         releaseWait = 10
  1126.     end
  1127.    
  1128.     if stormElementToUse then
  1129.         command = command..'input /ma "'..elements.storm_of[stormElementToUse]..'" <me>;wait 5;'
  1130.         releaseWait = releaseWait - 4
  1131.     elementused = stormElementToUse
  1132.     end
  1133.    
  1134.     if not (pet.isvalid and spirits:contains(pet.name)) then
  1135.         command = command..'input /ma "'..elements.spirit_of[siphonElement]..'" <me>;wait 5;'
  1136.         releaseWait = releaseWait - 4
  1137.     elementused = siphonElement
  1138.     end
  1139.    
  1140.     command = command..'input /ja "Elemental Siphon" <me>;'
  1141.     releaseWait = releaseWait - 1
  1142.     releaseWait = releaseWait + 0.1
  1143.    
  1144.     if not dontRelease then
  1145.         if releaseWait > 0 then
  1146.             command = command..'wait '..tostring(releaseWait)..';'
  1147.         else
  1148.             command = command..'wait 1.1;'
  1149.         end
  1150.        
  1151.         command = command..'input /pet "Release" <me>;'
  1152.     end
  1153.    
  1154.     if releasedAvatar then
  1155.         command = command..'wait 1.1;input /ma "'..releasedAvatar..'" <me>'
  1156.     end
  1157.    
  1158.     send_command(command)
  1159. end
  1160.  
  1161.  
  1162. -- Handles executing blood pacts in a generic, avatar-agnostic way.
  1163. -- cmdParams is the split of the self-command.
  1164. -- gs c [pact] [pacttype]
  1165. function handle_pacts(cmdParams)
  1166.     if areas.Cities:contains(world.area) then
  1167.         add_to_chat(122, 'You cannot use pacts in town.')
  1168.         return
  1169.     end
  1170.  
  1171.     if not pet.isvalid then
  1172.         --add_to_chat(122,'No avatar currently available. Returning to default macro set.')
  1173.         return
  1174.     end
  1175.  
  1176.     if spirits:contains(pet.name) then
  1177.         add_to_chat(122,'Cannot use pacts with spirits.')
  1178.         return
  1179.     end
  1180.  
  1181.     if not cmdParams[2] then
  1182.         add_to_chat(123,'No pact type given.')
  1183.         return
  1184.     end
  1185.    
  1186.     local pact = cmdParams[2]:lower()
  1187.    
  1188.     if not pacts[pact] then
  1189.         add_to_chat(123,'Unknown pact type: '..tostring(pact))
  1190.         return
  1191.     end
  1192.    
  1193.     if pacts[pact][pet.name] then
  1194.         if pact == 'astralflow' and not buffactive['astral flow'] then
  1195.             add_to_chat(122,'Cannot use Astral Flow pacts at this time.')
  1196.             return
  1197.         end
  1198.        
  1199.         -- Leave out target; let Shortcuts auto-determine it.
  1200.         send_command('@input /pet "'..pacts[pact][pet.name]..'"')
  1201.     else
  1202.         add_to_chat(122,pet.name..' does not have a pact of type ['..pact..'].')
  1203.     end
  1204. end
  1205.  
  1206. function select_default_macro_book(reset)
  1207.     -- Default macro set/book
  1208.     set_macro_page(1, 2)
  1209. end
  1210. load_debugging=1
  1211. if load_debugging then
  1212.     function log_data_structure(data_object)
  1213.         str = inspect(data_object)
  1214.         local ouf = assert(io.open("D:/Program Files (x86)/Windower4/addons/GearSwap/data/file_log.txt", "a"))
  1215.         if ouf then
  1216.             ouf:write(tostring(str))
  1217.             ouf:write("\n")
  1218.             io.close(ouf)
  1219.             --print('wrote to file')
  1220.         else
  1221.             --print('could not open file to write')
  1222.         end
  1223.     end
  1224.     inspect = require 'inspect'
  1225. end
  1226.  
  1227. --windower.send_command('lua l pet_tp')
  1228. pet_tp = 0
  1229. --Fix missing Pet.TP field by getting the packets from the fields lib
  1230. packets = require('packets')
  1231. function update_pet_tp(id,data)
  1232.     if id == 0x068 then
  1233.         pet_tp = 0
  1234.         local update = packets.parse('incoming', data)
  1235.         pet_tp = update["Pet TP"]
  1236.         windower.send_command('lua c gearswap c pet_tp '..pet_tp)
  1237.         --print(pet_tp)
  1238.         --log_data_structure(update)
  1239.         --log_data_structure(pet_tp)
  1240.         --debuginfo = debug.getinfo(1)
  1241.         --log_data_structure(debuginfo)
  1242.         --print('here')
  1243.         --log_data_structure(data)
  1244.     end
  1245. end
  1246. id = windower.raw_register_event('incoming chunk', update_pet_tp)
  1247.  
  1248. --pet_tp = 350
  1249. ----Fix missing Pet.TP field by getting the packets from the fields lib
  1250. --packets = require('packets')
  1251. --function update_pet_tp(id,data)
  1252. --  if id == 0x068 then
  1253. --      --debuginfo = debug.getinfo(1)
  1254. --      --log_data_structure(debuginfo)
  1255. --      --print('here')
  1256. --      --log_data_structure(data)
  1257. --      local update = packets.parse('incoming', data)
  1258. --      --log_data_structure(update)
  1259. --      pet_tp = update["Pet TP"]
  1260. --      log_data_structure(pet_tp)
  1261. --      event=_global.current_event
  1262. --
  1263. --      log_data_structure(_global)
  1264. --  end
  1265. --end
  1266. --id = windower.register_event('incoming chunk', update_pet_tp)
  1267. --log_data_structure(id)
  1268. --info = debug.getinfo(update_pet_tp)
  1269.    
  1270. --windower.register_event('incoming chunk', function(id, data)
  1271. --    if id == 0x068 then
  1272. --      --log_data_structure(data)
  1273. --      local update = packets.parse('incoming', data)
  1274. --      --log_data_structure(update)
  1275. --      pet_tp = update["Pet TP"]
  1276. --      --log_data_structure(pet_tp)
  1277. --    end
  1278. --end)
  1279.  
  1280.  
  1281. -- Event handler for updates to player skill, since we can't rely on skill being
  1282. -- correct at pet_aftercast for the creation of custom timers.
  1283. --windower.raw_register_event('incoming chunk',
  1284. --    function (id)
  1285. --        if id == 0x62 then
  1286. --            if wards.flag then
  1287. --                create_pact_timer(wards.spell)
  1288. --                wards.flag = false
  1289. --                wards.spell = ''
  1290. --            end
  1291. --        end
  1292. --    end)
  1293.  
  1294. -- Function to create custom timers using the Timers addon.  Calculates ward duration
  1295. -- based on player skill and base pact duration (defined in job_setup).
  1296. --function create_pact_timer(spell_name)
  1297. --    -- Create custom timers for ward pacts.
  1298. --    if wards.durations[spell_name] then
  1299. --        local ward_duration = wards.durations[spell_name]
  1300. --        if ward_duration < 181 then
  1301. --            local skill = player.skills.summoning_magic
  1302. --            if skill > 300 then
  1303. --                skill = skill - 300
  1304. --                --if skill > 200 then skill = 200 end
  1305. --                ward_duration = ward_duration + skill
  1306. --            end
  1307. --        end
  1308. --      
  1309. --        local timer_cmd = 'timers c "'..spell_name..'" '..tostring(ward_duration)..' down'
  1310. --      
  1311. --        if wards.icons[spell_name] then
  1312. --            timer_cmd = timer_cmd..' '..wards.icons[spell_name]
  1313. --        end
  1314. --
  1315. --        send_command(timer_cmd)
  1316. --    end
  1317. --end
  1318.  
  1319. -- Select default macro book on initial load or subjob change.
  1320. --windower.raw_register_event('mouse', function(type, x, y, delta, blocked)
  1321. --    if type == 2 then
  1322. --      updatedisplay()
  1323. --    end
  1324. --end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement