Advertisement
shadowmeld

mage-function.lua

Jan 17th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.10 KB | None | 0 0
  1. local magefunction = {}
  2.  
  3. function file_unload()
  4.  
  5.     unalias_element_match()
  6.  
  7. end
  8.  
  9. function magefunction.precast(spell, action)
  10.  
  11.     local eventArgs = { handled = false, cancel = false }
  12.     local spellMap = spell_map[spell.english]
  13.    
  14.     if job_precast then
  15.         job_precast(spell, action, spellMap, eventArgs)
  16.     end
  17.    
  18.     if eventArgs.cancel then
  19.         cancel_spell()
  20.         return
  21.     end
  22.    
  23.     if eventArgs.handled then
  24.         return
  25.     end
  26.    
  27.     if handled_magic[spell.skill] then
  28.         build_precast_magic_set(spell, action, spellMap, eventArgs)
  29.         build_midcast_magic_set(spell, action, spellMap, eventArgs)
  30.        
  31.         equip(sets.Casting.Precast)
  32.     elseif sets.JA[spell.english] then
  33.         equip(sets.JA[spell.english])
  34.     end
  35.  
  36. end
  37.  
  38. function magefunction.build_precast_magic_set(spell, action, spellMap, eventArgs)
  39.  
  40.     sets.Casting.Precast = sets.FC
  41.    
  42.     if sets.FC[spell.skill] then
  43.         sets.Casting.Precast = set_combine(sets.Casting.Precast, sets.FC[spell.skill])
  44.        
  45.         if sets.FC[spell.skill][spell.english] then
  46.             sets.Casting.Precast = set_combine(sets.Casting.Precast, sets.FC[spell.skill][spell.english])
  47.         elseif sets.FC[spell.skill][spellMap] then
  48.             sets.Casting.Precast = set_combine(sets.Casting.Precast, sets.FC[spell.skill][spellMap])
  49.         end
  50.        
  51.         if sets.Staves.CastTime[spell.element] then
  52.             sets.Casting.Precast = set_combine(sets.Casting.Precast, sets.Staves.CastTime[spell.element])
  53.         end
  54.        
  55.     end
  56.  
  57. end
  58.  
  59. function magefunction.build_midcast_magic_set(spell, action, spellMap, eventArgs)
  60.  
  61.     sets.Casting.Midcast = sets[spell.skill] or {}
  62.    
  63.     if spell.skill == 'ElementalMagic' then
  64.         build_elemental_magic_set(spell, action, spellMap)
  65.     elseif spell.skill == 'HealingMagic' then
  66.         build_healing_magic_set(spell, action, spellMap)
  67.     elseif spell.skill == 'DarkMagic' then
  68.         build_dark_magic_set(spell, action, spellMap)
  69.     elseif spell.skill == 'EnhancingMagic' then
  70.         build_enhancing_magic_set(spell, aciton, spellMap)
  71.     elseif spell.skill == 'EnfeeblingMagic' then
  72.         build_enfeebling_magic_set(spell, action, spellMap)
  73.     elseif spell.skill == 'DivineMagic' then
  74.         build_divine_magic_set(spell, action, spellMap)
  75.     elseif spell.skill == 'Ninjutsu' then
  76.         build_ninjutsu_set(spell, action, spellMap)
  77.     end
  78.    
  79.     if (spell.skill == 'ElementalMagic' and spellMap ~= 'Debuff') or spellMap == 'Cure' or spell.english:find('Drain') or spell.english:find('Aspir') or (spell.skill == 'DivineMagic' and not spell.english == 'Flash') then
  80.         weather_check(spell, spellMap)
  81.     end
  82.  
  83.     if build_post_midcast_set then
  84.         build_post_midcast_set(spell, action, spellMap)
  85.     end
  86.    
  87. end
  88.  
  89. function magefunction.build_elemental_magic_set(spell, action, spellMap)
  90.    
  91.     if sets.ElementalMagic[spell.english] then
  92.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.ElementalMagic[spell.english])
  93.     elseif sets.ElementalMagic[spellMap] then
  94.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.ElementalMagic[spellMap])
  95.     else
  96.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.ElementalMagic.Damage)
  97.     end
  98.    
  99.     if spellMap ~= 'Debuff' and spell.element == 'Earth' then
  100.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.ElementalMagic.Earth)
  101.     end
  102.  
  103. end
  104.  
  105. function magefunction.build_healing_magic_set(spell, action, spellMap)
  106.  
  107.     if sets.HealingMagic[spell.english] then
  108.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.HealingMagic[spell.english])
  109.     elseif sets.HealingMagic[spellMap] then
  110.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.HealingMagic[spellMap])
  111.     end
  112.  
  113. end
  114.  
  115. function magefunction.build_dark_magic_set(spell, action, spellMap)
  116.    
  117.     if sets.DarkMagic[spell.english] then
  118.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DarkMagic[spell.english])
  119.     elseif sets.DarkMagic[spellMap] then
  120.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DarkMagic[spellMap])
  121.     else
  122.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DarkMagic.Damage)
  123.     end
  124.    
  125. end
  126.  
  127. function magefunction.build_enhancing_magic_set(spell, action, spellMap)
  128.  
  129.     if sets.EnhancingMagic[spell.name] then
  130.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.EnhancingMagic[spell.name])
  131.     elseif sets.EnhancingMagic[spellMap] then
  132.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.EnhancingMagic[spellMap])
  133.     end
  134.  
  135. end
  136.  
  137. function magefunction.build_enfeebling_magic_set(spell, action, spellMap)
  138.  
  139.     if spellMap == 'Potency' then
  140.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.EnfeeblingMagic[spell.type])
  141.     end
  142.  
  143. end
  144.  
  145. function magefunction.build_divine_magic_set(spell, action, spellMap)
  146.  
  147.     if sets.DivineMagic[spell.name] then
  148.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DivineMagic[spell.name])
  149.     elseif sets.DivineMagic[spellMap] then
  150.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DivineMagic[spellMap])
  151.     else
  152.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.DivineMagic.Damage)
  153.     end
  154.  
  155. end
  156.  
  157. function magefunction.build_ninjutsu_set(spell, action, spellMap)
  158.  
  159.     -- TODO: Build Ninjutsu Sets for midcast
  160.  
  161. end
  162.  
  163. function magefunction.weather_check(spell, spellMap)
  164.  
  165.     if spell.element == world.day_element or spell.element == world.weather_element then
  166.         sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.Obis.Default)
  167.        
  168.         if spellMap ~= 'Helix' then
  169.             sets.Casting.Midcast = set_combine(sets.Casting.Midcast, sets.Obis[spell.element])
  170.         end
  171.     end
  172.  
  173. end
  174.  
  175. function magefunction.midcast(spell, action)
  176.  
  177.     if handled_magic[spell.skill] then
  178.         equip(sets.Casting.Midcast)
  179.     end
  180.  
  181. end
  182.  
  183. function magefunction.aftercast(spell, action)
  184.  
  185.     if T{'Idle', 'Resting', 'Engaged'}:contains(player.status) then
  186.         equip(sets[player.status])
  187.     end
  188.  
  189. end
  190.  
  191. function magefunction.buff_change(buff, gain)
  192.    
  193.     if job_buff_change then
  194.         job_buff_change(buff, gain)
  195.     end
  196.    
  197.     if buff == 'Sandstorm' then
  198.         update_idle_set()
  199.     end
  200.    
  201. end
  202.  
  203. function magefunction.status_change(new, old)
  204.  
  205.     if T{'Zoning', 'Fishing', 'Event', 'Dead'}:contains(old) then
  206.         return
  207.     end
  208.  
  209.     if T{'Idle', 'Resting', 'Engaged'}:contains(new) then
  210.         equip(sets[new])
  211.     end
  212.  
  213. end
  214.  
  215. function magefunction.self_command(command)
  216.    
  217.     local commandParams = command:split(' ')
  218.     local eventArgs = { handled = false }
  219.    
  220.     if job_self_command then
  221.         job_self_command(commandParams, eventArgs)
  222.     end
  223.    
  224.     if eventArgs.handled then return end
  225.    
  226.     -- Handles matching spell element to day element
  227.     if spell_type[commandParams[1]] then
  228.         cast_element_match(commandParams)
  229.     elseif commandParams[1] == 'update' then
  230.         if commandParams[2] == 'idle' then
  231.             update_idle_set()
  232.         end
  233.     end
  234.    
  235. end
  236.  
  237. --[[ cast_element_match info
  238.     spell_type: mapped table containing stype, description, default_tier, max_tier, default_target
  239.     cmdParams: parameters passed from the self_command function,
  240.         expected values are <tier> <target> in that order, both values are optional
  241. --]]
  242. function magefunction.cast_element_match(cmdParams)
  243.  
  244.     local sType = spell_type[cmdParams[1]].stype
  245.     local tier = spell_type[cmdParams[1]].default_tier
  246.     local max_tier = spell_type[cmdParams[1]].max_tier
  247.     local target = spell_type[cmdParams[1]].default_target
  248.     local spell = element_match[world.day_element][sType]
  249.    
  250.     if not cmdParams[2] then
  251.         if tier ~= 1 then
  252.             windower.add_to_chat(123, 'Placeholder')
  253.             spell = spell .. ' ' .. tier_map[tier]
  254.         end
  255.     elseif tonumber(cmdParams[2]) then
  256.         temp_tier = tonumber(cmdParams[2])
  257.         if temp_tier > 1 and temp_tier < max_tier then
  258.             spell = spell .. ' ' .. tier_map[temp_tier]
  259.         elseif temp_tier ~= 1 then
  260.             windower.add_to_chat(123, 'Invalid tier passed to function for [' .. sType .. '], defaulting to tier [' .. tier .. '].')
  261.            
  262.             if tier ~= 1 then
  263.                 spell = spell .. ' ' .. tier_map[tier]
  264.             end
  265.         end
  266.        
  267.         target = cmdParams[3] or target
  268.     else
  269.         target = cmdParams[2]
  270.     end
  271.    
  272.     windower.send_command('input /ma "' .. spell .. '" ' .. target)
  273. end
  274.  
  275. --[[ update_idle_set()
  276.     updates Idle set with Desert Boots if used and keeps Sublimation set if sublimation active
  277.     --]]
  278. function update_idle_set()
  279.  
  280.     if world.weather_element == 'Earth' or buffactive.Sandstorm then
  281.         sets.Idle = set_combine(sets.Idle, sets.Kite)
  282.     else
  283.         sets.Idle = sets.Idle.Default
  284.     end
  285.    
  286.     if buffactive['Sublimation: Activated'] then
  287.         sets.Idle = set_combine(sets.Idle, sets.Sublimation)
  288.     end
  289.  
  290. end
  291.  
  292. --[[ alias_element_match()
  293.     adds alias commands for casting spells matching the element of the day
  294. --]]
  295. function magefunction.alias_element_match()
  296.  
  297.     for i,v in pairs(spell_type) do
  298.         windower.send_command('alias ' .. i .. ' gs c ' .. i)
  299.     end
  300.    
  301. end
  302.  
  303. --[[ unalias_element_match()
  304.     removes alias commands for casting spells matching the element of the day
  305. --]]
  306. function magefunction.unalias_element_match()
  307.  
  308.     for i,v in pairs(spell_type) do
  309.         windower.send_command('unalias ' .. i)
  310.     end
  311.    
  312. end
  313.  
  314. --[[ This function can be removed if you don't use desert boots
  315.     calls Idle set update on any weather change to accomodate Desert Boots usage
  316.     --]]
  317. windower.register_event('weather change', function(id, name)
  318.    
  319.     if player.status == 'Zoning' then return end
  320.    
  321.     windower.send_command('gs c update idle')
  322.        
  323. end)
  324.  
  325. return magefunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement