Trumpy

AllJobs.lua

Sep 30th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.03 KB | None | 0 0
  1. -------- Cure Tier Changing Function --------
  2.  
  3. local cure_mp_cost = {['Cure'] = 8, ['Cure II'] = 24, ['Cure III'] = 46, ['Cure IV'] = 88, ['Cure V'] = 135, ['Cure VI'] = 227}
  4.     -- Utility function for automatically adjusting the Cure spell being used to match HP needs and MP limits.
  5.     -- Handle spell changes before attempting any precast stuff.
  6. function refine_cure(spell, action, spellMap, eventArgs)
  7.     -- Only handles single-target cures.
  8.     -- Get the estimated amount of HP the target of the spell is below max.
  9.     -- Returns nil for targets outside of alliance (no info available).
  10.     local missingHP = get_targets_missing_hp(spell)
  11.     local preferredCure = spell.name
  12.     -- If we have an estimated missing HP value, we can adjust the preferred spell used.
  13.     if missingHP then
  14.         -- Whm has high skill and up to Cure VI
  15.         if player.main_job == 'WHM' then
  16.             if missingHP < 150 then
  17.                 preferredCure = 'Cure'
  18.             elseif missingHP < 350 then
  19.                 preferredCure = 'Cure II'
  20.             elseif missingHP < 650 then
  21.                 preferredCure = 'Cure III'
  22.             elseif missingHP < 1000 then
  23.                 preferredCure = 'Cure IV'
  24.             elseif missingHP < 1600 then
  25.                 preferredCure = 'Cure V'
  26.             else
  27.                 preferredCure = 'Cure VI'
  28.             end
  29.         -- Rdm, Sch and Pld have high skill and up to Cure IV
  30.         elseif player.main_job == 'RDM' or player.main_job == 'SCH' or player.main_job == 'PLD' then
  31.             if missingHP < 150 then
  32.                 preferredCure = 'Cure'
  33.             elseif missingHP < 350 then
  34.                 preferredCure = 'Cure II'
  35.             elseif missingHP < 650 then
  36.                 preferredCure = 'Cure III'
  37.             else
  38.                 preferredCure = 'Cure IV'
  39.             end
  40.         -- Subbing /whm or /rdm gets you up to Cure IV
  41.         elseif player.sub_job == 'WHM' or player.sub_job == 'RDM' then
  42.             if missingHP < 150 then
  43.                 preferredCure = 'Cure'
  44.             elseif missingHP < 300 then
  45.                 preferredCure = 'Cure II'
  46.             elseif missingHP < 550 then
  47.                 preferredCure = 'Cure III'
  48.             else
  49.                 preferredCure = 'Cure IV'
  50.             end
  51.         -- Subbing /sch or /pld gets you up to Cure III
  52.         elseif player.sub_job == 'SCH' or player.sub_job == 'PLD' then
  53.             if missingHP < 150 then
  54.                 preferredCure = 'Cure'
  55.             elseif missingHP < 300 then
  56.                 preferredCure = 'Cure II'
  57.             else
  58.                 preferredCure = 'Cure III'
  59.             end
  60.         else
  61.             -- Not job main or sub that can cast Cure; bail out
  62.             return
  63.         end
  64.     end
  65.     local mpCost = cure_mp_cost[preferredCure]
  66.     if buffactive['Light Arts'] or buffactive['Addendum: White'] then
  67.         mpCost = math.floor(mpCost * 0.9)
  68.     elseif buffactive['Dark Arts'] or buffactive['Addendum: Black'] then
  69.         mpCost = math.floor(mpCost * 1.1)
  70.     end
  71.     local downgrade_msg
  72.     -- Downgrade the spell to what we can actually afford
  73.     if player.mp < mpCost and not (buffactive['Manafont'] or buffactive['Mana Well']) then
  74.         if player.mp < 8 then
  75.             add_to_chat(122, 'Insufficient MP ['..tostring(player.mp)..']. Cancelling.')
  76.             if player.status == 'Engaged' then
  77.                 equip(sets.TP)
  78.             elseif player.status == 'Resting' then
  79.                 equip(sets.Rest)
  80.             else
  81.                 equip(sets.Idle)
  82.             end
  83.             cancel_spell()
  84.             return
  85.         elseif player.mp < 24 then
  86.             preferredCure = 'Cure'
  87.         elseif player.mp < 46 then
  88.             preferredCure = 'Cure II'
  89.         elseif player.mp < 88 then
  90.             preferredCure = 'Cure III'
  91.         elseif player.mp < 135 then
  92.             preferredCure = 'Cure IV'
  93.         elseif player.mp < 227 then
  94.             preferredCure = 'Cure V'
  95.         end
  96.         downgrade_msg = 'Insufficient MP ['..tostring(player.mp)..']. Downgrading to '..preferredCure..'.'
  97.     end
  98.     if preferredCure ~= spell.name then
  99.         cancel_spell()
  100.         send_command('@input /ma "'..preferredCure..'" '..tostring(spell.target.raw))
  101.         if downgrade_msg then
  102.             add_to_chat(122, downgrade_msg)
  103.         end
  104.         return
  105.     end
  106.     if missingHP and missingHP > 0 then
  107.         add_to_chat(122,'Trying to cure '..tostring(missingHP)..' HP using '..preferredCure..'.')
  108.     end
  109. end
  110.  
  111. -------- Cure Tier Changing MP DEPENDANT (NOT HP DEPENDANT) Function --------
  112.  
  113.     -- Utility function for automatically adjusting the Cure spell being used to match MP limits.
  114.     -- Handle spell changes before attempting any precast stuff.
  115. function reduce_cure(spell, action, spellMap, eventArgs)
  116.     -- Only handles single-target cures.
  117.     local preferredCure = spell.name
  118.     local mpCost = cure_mp_cost[preferredCure]
  119.     if buffactive['Light Arts'] or buffactive['Addendum: White'] then
  120.         mpCost = math.floor(mpCost * 0.9)
  121.     elseif buffactive['Dark Arts'] or buffactive['Addendum: Black'] then
  122.         mpCost = math.floor(mpCost * 1.1)
  123.     end
  124.     local downgrade_msg
  125.     -- Downgrade the spell to what we can actually afford
  126.     if player.mp < mpCost and not (buffactive['Manafont'] or buffactive['Mana Well']) then
  127.         if player.mp < 8 then
  128.             add_to_chat(122, 'Insufficient MP ['..tostring(player.mp)..']. Cancelling.')
  129.             if player.status == 'Engaged' then
  130.                 equip(sets.TP)
  131.             elseif player.status == 'Resting' then
  132.                 equip(sets.Rest)
  133.             else
  134.                 equip(sets.Idle)
  135.             end
  136.             cancel_spell()
  137.             return
  138.         elseif player.mp < 24 then
  139.             preferredCure = 'Cure'
  140.         elseif player.mp < 46 then
  141.             preferredCure = 'Cure II'
  142.         elseif player.mp < 88 then
  143.             preferredCure = 'Cure III'
  144.         elseif player.mp < 135 then
  145.             preferredCure = 'Cure IV'
  146.         elseif player.mp < 227 then
  147.             preferredCure = 'Cure V'
  148.         end
  149.         downgrade_msg = 'Insufficient MP ['..tostring(player.mp)..']. Downgrading to '..preferredCure..'.'
  150.     end
  151.     if preferredCure ~= spell.name then
  152.         cancel_spell()
  153.         send_command('@input /ma "'..preferredCure..'" '..tostring(spell.target.raw))
  154.         if downgrade_msg then
  155.             add_to_chat(122, downgrade_msg)
  156.         end
  157.         return
  158.     end
  159. end
  160.  
  161.  
  162. -------- Waltz Tier Changing Function --------
  163.  
  164. local waltz_tp_cost = {['Curing Waltz'] = 200, ['Curing Waltz II'] = 350, ['Curing Waltz III'] = 500, ['Curing Waltz IV'] = 650, ['Curing Waltz V'] = 800}
  165.     -- Utility function for automatically adjusting the waltz spell being used to match HP needs and TP limits.
  166.     -- Handle spell changes before attempting any precast stuff.
  167. function refine_waltz(spell, action, spellMap, eventArgs)
  168.     -- Only handles single-target waltzes.
  169.     -- Get the estimated amount of HP the target of the spell is below max.
  170.     -- Returns nil for targets outside of alliance (no info available).
  171.     local missingHP = get_targets_missing_hp(spell)
  172.     local preferredWaltz = spell.name
  173.     -- If we have an estimated missing HP value, we can adjust the preferred spell used.
  174.     if missingHP then
  175.         -- DNC has up to Curing Waltz V
  176.         if player.main_job == 'DNC' then
  177.             if missingHP < 230 then
  178.                 preferredWaltz = 'Curing Waltz'
  179.             elseif missingHP < 420 then
  180.                 preferredWaltz = 'Curing Waltz II'
  181.             elseif missingHP < 650 then
  182.                 preferredWaltz = 'Curing Waltz III'
  183.             elseif missingHP < 850 then
  184.                 preferredWaltz = 'Curing Waltz IV'
  185.             else
  186.                 preferredWaltz = 'Curing Waltz V'
  187.             end
  188.         -- Subbing /dnc gets you up to Curing Waltz III
  189.         elseif player.sub_job == 'DNC' then
  190.             if missingHP < 180 then
  191.                 preferredWaltz = 'Curing Waltz'
  192.             elseif missingHP < 345 then
  193.                 preferredWaltz = 'Curing Waltz II'
  194.             else
  195.                 preferredWaltz = 'Curing Waltz III'
  196.             end
  197.         else
  198.             -- Not dnc main or sub; bail out
  199.             return
  200.         end
  201.     end
  202.     local tpCost = waltz_tp_cost[preferredWaltz]
  203.     local downgrade_msg
  204.     -- Downgrade the spell to what we can actually afford
  205.     if player.tp < tpCost and not buffactive['Trance'] then
  206.         if player.tp < 200 then
  207.             add_to_chat(122, 'Insufficient TP ['..tostring(player.tp)..']. Cancelling.')
  208.             if player.status == 'Engaged' then
  209.                 equip(sets.TP[TP_Set_Names[TP_Index]])
  210.             elseif player.status == 'Resting' then
  211.                 equip(sets.Rest)
  212.             else
  213.                 equip(sets.Idle[Idle_Set_Names[Idle_Index]])
  214.             end
  215.             cancel_spell()
  216.             return
  217.         elseif player.tp < 350 then
  218.             preferredWaltz = 'Curing Waltz'
  219.         elseif player.tp < 500 then
  220.             preferredWaltz = 'Curing Waltz II'
  221.         elseif player.tp < 650 then
  222.             preferredWaltz = 'Curing Waltz III'
  223.         elseif player.tp < 800 then
  224.             preferredWaltz = 'Curing Waltz IV'
  225.         end
  226.         downgrade_msg = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..preferredWaltz..'.'
  227.     end
  228.     if preferredWaltz ~= spell.name then
  229.         cancel_spell()
  230.         send_command('@input /ja "'..preferredWaltz..'" '..tostring(spell.target.raw))
  231.         if downgrade then
  232.             add_to_chat(122, downgrade_msg)
  233.         end
  234.         return
  235.     end
  236.     if missingHP and missingHP > 0 then
  237.         add_to_chat(122,'Trying to waltz '..tostring(missingHP)..' HP using '..preferredWaltz..'.')
  238.     end
  239. end
  240.  
  241. -------- Waltz Tier Changing TP DEPENDANT (NOT HP DEPENDANT) Function --------
  242.  
  243.     -- Utility function for automatically adjusting the Waltz spell being used to match TP limits.
  244.     -- Handle spell changes before attempting any precast stuff.
  245. function reduce_Waltz(spell, action, spellMap, eventArgs)
  246.     -- Only handles single-target Waltzes.
  247.     local preferredWaltz = spell.name
  248.     local tpCost = waltz_tp_cost[preferredWaltz]
  249.     local downgrade_msg
  250.     -- Downgrade the spell to what we can actually afford
  251.     if player.tp < tpCost and not buffactive['Trance'] then
  252.         if player.tp < 200 then
  253.             add_to_chat(122, 'Insufficient TP ['..tostring(player.tp)..']. Cancelling.')
  254.             if player.status == 'Engaged' then
  255.                 equip(sets.TP[TP_Set_Names[TP_Index]])
  256.             elseif player.status == 'Resting' then
  257.                 equip(sets.Rest)
  258.             else
  259.                 equip(sets.Idle[Idle_Set_Names[Idle_Index]])
  260.             end
  261.             cancel_spell()
  262.             return
  263.         elseif player.tp < 350 then
  264.             preferredWaltz = 'Curing Waltz'
  265.         elseif player.tp < 500 then
  266.             preferredWaltz = 'Curing Waltz II'
  267.         elseif player.tp < 650 then
  268.             preferredWaltz = 'Curing Waltz III'
  269.         elseif player.tp < 800 then
  270.             preferredWaltz = 'Curing Waltz IV'
  271.         end
  272.         downgrade_msg = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..preferredWaltz..'.'
  273.     end
  274.     if preferredWaltz ~= spell.name then
  275.         cancel_spell()
  276.         send_command('@input /ja "'..preferredWaltz..'" '..tostring(spell.target.raw))
  277.         if downgrade then
  278.             add_to_chat(122, downgrade_msg)
  279.         end
  280.         return
  281.     end
  282. end
  283.  
  284. -------- Miscellaneous Functions --------
  285.  
  286. function get_targets_missing_hp(spell)
  287.     local missingHP
  288.     -- If curing yourself, get our exact missing HP
  289.     if spell.target.type == "SELF" then
  290.         missingHP = player.max_hp - player.hp
  291.     -- If curing someone in our alliance, we can estimate their missing HP
  292.     elseif spell.target.isallymember then
  293.         local target = find_player_in_alliance(spell.target.name)
  294.         local est_max_hp = target.hp / (target.hpp/100)
  295.         missingHP = math.floor(est_max_hp - target.hp)
  296.     end
  297.     return missingHP
  298. end
  299.  
  300. function find_player_in_alliance(name)
  301.     -- Attempt to locate a specified name within the current alliance.
  302.     for party_index,ally_party in ipairs(alliance) do
  303.         for player_index,_player in ipairs(ally_party) do
  304.             if _player.name == name then
  305.                 return _player
  306.             end
  307.         end
  308.     end
  309. end
Add Comment
Please, Sign In to add comment