Skip to content

Commit

Permalink
Add Rune Fencer job helper
Browse files Browse the repository at this point in the history
* Move Rune Enchantment effects into RUN job helper
  • Loading branch information
WinterSolstice8 authored and zach2good committed Mar 2, 2022
1 parent c64e928 commit 74bc7d4
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 75 deletions.
8 changes: 3 additions & 5 deletions scripts/globals/abilities/flabra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.FLABRA
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.FLABRA)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/gelus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.GELUS
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.GELUS)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/ignis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.IGNIS
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.IGNIS)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/lux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.LUX
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.LUX)
end

return ability_object
36 changes: 1 addition & 35 deletions scripts/globals/abilities/rune_enchantment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,9 @@ ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

--this is a dummied ability that is not actually usable by a player due to Rune Enchantment only being the main category in a menu, as well as the name of the ability for recast.
ability_object.onUseAbility = function(user, target, ability)
-- Leave blank.
end

-- helpers for runes
function getRUNLevel(player)
return player:getMainJob() == xi.job.RUN and player:getMainLvl() or player:getSubLvl()
end

function applyRuneEnhancement(effectType, player)
local RUNLevel = getRUNLevel(player)
local meritBonus = (player:getMerit(xi.merit.MERIT_RUNE_ENHANCE) * 2) -- 2 more elemental resistance per merit for a maximum total of (2*5) = 10
local jobPointBonus = player:getJobPointLevel(xi.jp.RUNE_ENCHANTMENT_EFFECT) -- 1 more elemental resistance per level for a maximum total of 20

-- see https://www.bg-wiki.com/ffxi/Category:Rune
local power = math.floor((49 * RUNLevel / 99) + 5.5) + meritBonus + jobPointBonus
player:addStatusEffect(effectType, power, 0, 300)
end

function enforceRuneCounts(target)
local RUNLevel = getRUNLevel(target)
local maxRunes = RUNLevel >= 65 and 3 or RUNLevel >= 35 and 2 or 1
local effects = target:getStatusEffects()
local runes = { }
local i = 0

for _, effect in ipairs(effects) do
type = effect:getType()
if type >= xi.effect.IGNIS and type <= xi.effect.TENEBRAE then
runes[i+1] = effect
i = i + 1
end
end

if i >= maxRunes then -- delete the first rune in the list with the least duration
target:delStatusEffect(runes[1]:getType())
end
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/sulpor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.SULPOR
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.SULPOR)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/tellus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.TELLUS
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.TELLUS)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/tenebrae.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.TENEBRAE
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.TENEBRAE)
end

return ability_object
8 changes: 3 additions & 5 deletions scripts/globals/abilities/unda.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/status")
require("scripts/globals/abilities/rune_enchantment")
require("scripts/globals/job_utils/rune_fencer")
-----------------------------------
local ability_object = {}

ability_object.onAbilityCheck = function(player, target, ability)
return 0, 0
end

ability_object.onUseAbility = function(caster, target, ability, action)
local effect = xi.effect.UNDA
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
ability_object.onUseAbility = function(player, target, ability, action)
xi.job_utils.rune_fencer.useRuneEnchantment(player, target, ability, xi.effect.UNDA)
end

return ability_object
54 changes: 54 additions & 0 deletions scripts/globals/job_utils/rune_fencer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-----------------------------------
-- Rune Fencer Job Utilities
-----------------------------------
require("scripts/settings/main")
require("scripts/globals/ability")
require("scripts/globals/status")
require("scripts/globals/msg")
require("scripts/globals/weaponskills")
require("scripts/globals/jobpoints")
-----------------------------------
xi = xi or {}
xi.job_utils = xi.job_utils or {}
xi.job_utils.rune_fencer = xi.job_utils.rune_fencer or {}
-----------------------------------

local function getRUNLevel(player)
return player:getMainJob() == xi.job.RUN and player:getMainLvl() or player:getSubLvl()
end

local function applyRuneEnhancement(effectType, player)
local RUNLevel = getRUNLevel(player)
local meritBonus = (player:getMerit(xi.merit.MERIT_RUNE_ENHANCE) * 2) -- 2 more elemental resistance per merit for a maximum total of (2*5) = 10
local jobPointBonus = player:getJobPointLevel(xi.jp.RUNE_ENCHANTMENT_EFFECT) -- 1 more elemental resistance per level for a maximum total of 20

-- see https://www.bg-wiki.com/ffxi/Category:Rune
local power = math.floor((49 * RUNLevel / 99) + 5.5) + meritBonus + jobPointBonus
player:addStatusEffect(effectType, power, 0, 300)
end

local function enforceRuneCounts(target)
local RUNLevel = getRUNLevel(target)
local maxRunes = RUNLevel >= 65 and 3 or RUNLevel >= 35 and 2 or 1
local effects = target:getStatusEffects()
local runes = {}
local i = 0

for _, effect in ipairs(effects) do
local type = effect:getType()
if type >= xi.effect.IGNIS and type <= xi.effect.TENEBRAE then
runes[i+1] = effect
i = i + 1
end
end

if i >= maxRunes then -- delete the first rune in the list with the least duration
target:delStatusEffect(runes[1]:getType())
end
end


xi.job_utils.rune_fencer.useRuneEnchantment = function(player, target, ability, effect)
enforceRuneCounts(target)
applyRuneEnhancement(effect, target)
end

0 comments on commit 74bc7d4

Please sign in to comment.