Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------- Cure Tier Changing Function --------
- local cure_mp_cost = {['Cure'] = 8, ['Cure II'] = 24, ['Cure III'] = 46, ['Cure IV'] = 88, ['Cure V'] = 135, ['Cure VI'] = 227}
- -- Utility function for automatically adjusting the Cure spell being used to match HP needs and MP limits.
- -- Handle spell changes before attempting any precast stuff.
- function refine_cure(spell, action, spellMap, eventArgs)
- -- Only handles single-target cures.
- -- Get the estimated amount of HP the target of the spell is below max.
- -- Returns nil for targets outside of alliance (no info available).
- local missingHP = get_targets_missing_hp(spell)
- local preferredCure = spell.name
- -- If we have an estimated missing HP value, we can adjust the preferred spell used.
- if missingHP then
- -- Whm has high skill and up to Cure VI
- if player.main_job == 'WHM' then
- if missingHP < 150 then
- preferredCure = 'Cure'
- elseif missingHP < 350 then
- preferredCure = 'Cure II'
- elseif missingHP < 650 then
- preferredCure = 'Cure III'
- elseif missingHP < 1000 then
- preferredCure = 'Cure IV'
- elseif missingHP < 1600 then
- preferredCure = 'Cure V'
- else
- preferredCure = 'Cure VI'
- end
- -- Rdm, Sch and Pld have high skill and up to Cure IV
- elseif player.main_job == 'RDM' or player.main_job == 'SCH' or player.main_job == 'PLD' then
- if missingHP < 150 then
- preferredCure = 'Cure'
- elseif missingHP < 350 then
- preferredCure = 'Cure II'
- elseif missingHP < 650 then
- preferredCure = 'Cure III'
- else
- preferredCure = 'Cure IV'
- end
- -- Subbing /whm or /rdm gets you up to Cure IV
- elseif player.sub_job == 'WHM' or player.sub_job == 'RDM' then
- if missingHP < 150 then
- preferredCure = 'Cure'
- elseif missingHP < 300 then
- preferredCure = 'Cure II'
- elseif missingHP < 550 then
- preferredCure = 'Cure III'
- else
- preferredCure = 'Cure IV'
- end
- -- Subbing /sch or /pld gets you up to Cure III
- elseif player.sub_job == 'SCH' or player.sub_job == 'PLD' then
- if missingHP < 150 then
- preferredCure = 'Cure'
- elseif missingHP < 300 then
- preferredCure = 'Cure II'
- else
- preferredCure = 'Cure III'
- end
- else
- -- Not job main or sub that can cast Cure; bail out
- return
- end
- end
- local mpCost = cure_mp_cost[preferredCure]
- if buffactive['Light Arts'] or buffactive['Addendum: White'] then
- mpCost = math.floor(mpCost * 0.9)
- elseif buffactive['Dark Arts'] or buffactive['Addendum: Black'] then
- mpCost = math.floor(mpCost * 1.1)
- end
- local downgrade_msg
- -- Downgrade the spell to what we can actually afford
- if player.mp < mpCost and not (buffactive['Manafont'] or buffactive['Mana Well']) then
- if player.mp < 8 then
- add_to_chat(122, 'Insufficient MP ['..tostring(player.mp)..']. Cancelling.')
- if player.status == 'Engaged' then
- equip(sets.TP)
- elseif player.status == 'Resting' then
- equip(sets.Rest)
- else
- equip(sets.Idle)
- end
- cancel_spell()
- return
- elseif player.mp < 24 then
- preferredCure = 'Cure'
- elseif player.mp < 46 then
- preferredCure = 'Cure II'
- elseif player.mp < 88 then
- preferredCure = 'Cure III'
- elseif player.mp < 135 then
- preferredCure = 'Cure IV'
- elseif player.mp < 227 then
- preferredCure = 'Cure V'
- end
- downgrade_msg = 'Insufficient MP ['..tostring(player.mp)..']. Downgrading to '..preferredCure..'.'
- end
- if preferredCure ~= spell.name then
- cancel_spell()
- send_command('@input /ma "'..preferredCure..'" '..tostring(spell.target.raw))
- if downgrade_msg then
- add_to_chat(122, downgrade_msg)
- end
- return
- end
- if missingHP and missingHP > 0 then
- add_to_chat(122,'Trying to cure '..tostring(missingHP)..' HP using '..preferredCure..'.')
- end
- end
- -------- Cure Tier Changing MP DEPENDANT (NOT HP DEPENDANT) Function --------
- -- Utility function for automatically adjusting the Cure spell being used to match MP limits.
- -- Handle spell changes before attempting any precast stuff.
- function reduce_cure(spell, action, spellMap, eventArgs)
- -- Only handles single-target cures.
- local preferredCure = spell.name
- local mpCost = cure_mp_cost[preferredCure]
- if buffactive['Light Arts'] or buffactive['Addendum: White'] then
- mpCost = math.floor(mpCost * 0.9)
- elseif buffactive['Dark Arts'] or buffactive['Addendum: Black'] then
- mpCost = math.floor(mpCost * 1.1)
- end
- local downgrade_msg
- -- Downgrade the spell to what we can actually afford
- if player.mp < mpCost and not (buffactive['Manafont'] or buffactive['Mana Well']) then
- if player.mp < 8 then
- add_to_chat(122, 'Insufficient MP ['..tostring(player.mp)..']. Cancelling.')
- if player.status == 'Engaged' then
- equip(sets.TP)
- elseif player.status == 'Resting' then
- equip(sets.Rest)
- else
- equip(sets.Idle)
- end
- cancel_spell()
- return
- elseif player.mp < 24 then
- preferredCure = 'Cure'
- elseif player.mp < 46 then
- preferredCure = 'Cure II'
- elseif player.mp < 88 then
- preferredCure = 'Cure III'
- elseif player.mp < 135 then
- preferredCure = 'Cure IV'
- elseif player.mp < 227 then
- preferredCure = 'Cure V'
- end
- downgrade_msg = 'Insufficient MP ['..tostring(player.mp)..']. Downgrading to '..preferredCure..'.'
- end
- if preferredCure ~= spell.name then
- cancel_spell()
- send_command('@input /ma "'..preferredCure..'" '..tostring(spell.target.raw))
- if downgrade_msg then
- add_to_chat(122, downgrade_msg)
- end
- return
- end
- end
- -------- Waltz Tier Changing Function --------
- local waltz_tp_cost = {['Curing Waltz'] = 200, ['Curing Waltz II'] = 350, ['Curing Waltz III'] = 500, ['Curing Waltz IV'] = 650, ['Curing Waltz V'] = 800}
- -- Utility function for automatically adjusting the waltz spell being used to match HP needs and TP limits.
- -- Handle spell changes before attempting any precast stuff.
- function refine_waltz(spell, action, spellMap, eventArgs)
- -- Only handles single-target waltzes.
- -- Get the estimated amount of HP the target of the spell is below max.
- -- Returns nil for targets outside of alliance (no info available).
- local missingHP = get_targets_missing_hp(spell)
- local preferredWaltz = spell.name
- -- If we have an estimated missing HP value, we can adjust the preferred spell used.
- if missingHP then
- -- DNC has up to Curing Waltz V
- if player.main_job == 'DNC' then
- if missingHP < 230 then
- preferredWaltz = 'Curing Waltz'
- elseif missingHP < 420 then
- preferredWaltz = 'Curing Waltz II'
- elseif missingHP < 650 then
- preferredWaltz = 'Curing Waltz III'
- elseif missingHP < 850 then
- preferredWaltz = 'Curing Waltz IV'
- else
- preferredWaltz = 'Curing Waltz V'
- end
- -- Subbing /dnc gets you up to Curing Waltz III
- elseif player.sub_job == 'DNC' then
- if missingHP < 180 then
- preferredWaltz = 'Curing Waltz'
- elseif missingHP < 345 then
- preferredWaltz = 'Curing Waltz II'
- else
- preferredWaltz = 'Curing Waltz III'
- end
- else
- -- Not dnc main or sub; bail out
- return
- end
- end
- local tpCost = waltz_tp_cost[preferredWaltz]
- local downgrade_msg
- -- Downgrade the spell to what we can actually afford
- if player.tp < tpCost and not buffactive['Trance'] then
- if player.tp < 200 then
- add_to_chat(122, 'Insufficient TP ['..tostring(player.tp)..']. Cancelling.')
- if player.status == 'Engaged' then
- equip(sets.TP[TP_Set_Names[TP_Index]])
- elseif player.status == 'Resting' then
- equip(sets.Rest)
- else
- equip(sets.Idle[Idle_Set_Names[Idle_Index]])
- end
- cancel_spell()
- return
- elseif player.tp < 350 then
- preferredWaltz = 'Curing Waltz'
- elseif player.tp < 500 then
- preferredWaltz = 'Curing Waltz II'
- elseif player.tp < 650 then
- preferredWaltz = 'Curing Waltz III'
- elseif player.tp < 800 then
- preferredWaltz = 'Curing Waltz IV'
- end
- downgrade_msg = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..preferredWaltz..'.'
- end
- if preferredWaltz ~= spell.name then
- cancel_spell()
- send_command('@input /ja "'..preferredWaltz..'" '..tostring(spell.target.raw))
- if downgrade then
- add_to_chat(122, downgrade_msg)
- end
- return
- end
- if missingHP and missingHP > 0 then
- add_to_chat(122,'Trying to waltz '..tostring(missingHP)..' HP using '..preferredWaltz..'.')
- end
- end
- -------- Waltz Tier Changing TP DEPENDANT (NOT HP DEPENDANT) Function --------
- -- Utility function for automatically adjusting the Waltz spell being used to match TP limits.
- -- Handle spell changes before attempting any precast stuff.
- function reduce_Waltz(spell, action, spellMap, eventArgs)
- -- Only handles single-target Waltzes.
- local preferredWaltz = spell.name
- local tpCost = waltz_tp_cost[preferredWaltz]
- local downgrade_msg
- -- Downgrade the spell to what we can actually afford
- if player.tp < tpCost and not buffactive['Trance'] then
- if player.tp < 200 then
- add_to_chat(122, 'Insufficient TP ['..tostring(player.tp)..']. Cancelling.')
- if player.status == 'Engaged' then
- equip(sets.TP[TP_Set_Names[TP_Index]])
- elseif player.status == 'Resting' then
- equip(sets.Rest)
- else
- equip(sets.Idle[Idle_Set_Names[Idle_Index]])
- end
- cancel_spell()
- return
- elseif player.tp < 350 then
- preferredWaltz = 'Curing Waltz'
- elseif player.tp < 500 then
- preferredWaltz = 'Curing Waltz II'
- elseif player.tp < 650 then
- preferredWaltz = 'Curing Waltz III'
- elseif player.tp < 800 then
- preferredWaltz = 'Curing Waltz IV'
- end
- downgrade_msg = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..preferredWaltz..'.'
- end
- if preferredWaltz ~= spell.name then
- cancel_spell()
- send_command('@input /ja "'..preferredWaltz..'" '..tostring(spell.target.raw))
- if downgrade then
- add_to_chat(122, downgrade_msg)
- end
- return
- end
- end
- -------- Miscellaneous Functions --------
- function get_targets_missing_hp(spell)
- local missingHP
- -- If curing yourself, get our exact missing HP
- if spell.target.type == "SELF" then
- missingHP = player.max_hp - player.hp
- -- If curing someone in our alliance, we can estimate their missing HP
- elseif spell.target.isallymember then
- local target = find_player_in_alliance(spell.target.name)
- local est_max_hp = target.hp / (target.hpp/100)
- missingHP = math.floor(est_max_hp - target.hp)
- end
- return missingHP
- end
- function find_player_in_alliance(name)
- -- Attempt to locate a specified name within the current alliance.
- for party_index,ally_party in ipairs(alliance) do
- for player_index,_player in ipairs(ally_party) do
- if _player.name == name then
- return _player
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment