From bc7a8929709ce8bf03a16a1f7dc26ba4c25d685b Mon Sep 17 00:00:00 2001 From: Skold <113406182+Skold177@users.noreply.github.com> Date: Sat, 6 Jun 2026 23:35:04 -0400 Subject: [PATCH] [lua] Refactor Economizer Refactors Economizer --- .../abilities/pets/attachments/economizer.lua | 47 +++++++++++++++---- .../abilities/pets/automaton/economizer.lua | 15 +++--- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/scripts/actions/abilities/pets/attachments/economizer.lua b/scripts/actions/abilities/pets/attachments/economizer.lua index 57141022976..450454739dd 100644 --- a/scripts/actions/abilities/pets/attachments/economizer.lua +++ b/scripts/actions/abilities/pets/attachments/economizer.lua @@ -1,21 +1,50 @@ ----------------------------------- --- Attachment: Economizer +-- Economizer +-- Recovers a percentage of missing MP based on dark maneuvers. +-- Activation threshold is 30% MP, increasing by 10% per dark maneuver. +-- https://wiki.ffo.jp/html/10435.html ----------------------------------- ---@type TAttachment local attachmentObject = {} +local activationThresholds = +{ + [0] = 30, + [1] = 40, + [2] = 50, + [3] = 60, +} + attachmentObject.onEquip = function(pet) pet:addListener('AUTOMATON_ATTACHMENT_CHECK', 'ATTACHMENT_ECONOMIZER', function(automaton, target) + -- If Economizer is still on cooldown, do nothing. + if automaton:hasRecast(xi.recast.ABILITY, xi.automaton.abilities.ECONOMIZER) then + return + end + local master = automaton:getMaster() - local maneuvers = (master and master:countEffect(xi.effect.DARK_MANEUVER) > 0) and master:countEffect(xi.effect.DARK_MANEUVER) or 7 - local mpthreshold = 60 - maneuvers * 10 - local mpp = automaton:getMaxMP() > 0 and math.ceil(automaton:getMP() / automaton:getMaxMP() * 100) or 100 - if - mpp < mpthreshold and - not automaton:hasRecast(xi.recast.ABILITY, xi.automaton.abilities.ECONOMIZER) - then - automaton:useMobAbility(xi.automaton.abilities.ECONOMIZER, automaton) + + if not master then + return end + + local darkManeuvers = master:countEffect(xi.effect.DARK_MANEUVER) + local maxMP = automaton:getMaxMP() + + -- If this automaton has no MP, do nothing. + if maxMP == 0 then + return + end + + local mpPercent = automaton:getMPP() + local mpThreshold = activationThresholds[darkManeuvers] or 30 + + -- If the automaton's MP is above the threshold, do nothing. + if mpPercent > mpThreshold then + return + end + + automaton:useMobAbility(xi.automaton.abilities.ECONOMIZER, automaton) end) end diff --git a/scripts/actions/abilities/pets/automaton/economizer.lua b/scripts/actions/abilities/pets/automaton/economizer.lua index b8d0f6b0e51..624786c168f 100644 --- a/scripts/actions/abilities/pets/automaton/economizer.lua +++ b/scripts/actions/abilities/pets/automaton/economizer.lua @@ -1,5 +1,8 @@ ----------------------------------- -- Economizer +-- Recovers a percentage of missing MP based on dark maneuvers. +-- Activation threshold is 30% MP, increasing by 10% per dark maneuver. +-- https://wiki.ffo.jp/html/10435.html ----------------------------------- ---@type TAbilityAutomaton local abilityObject = {} @@ -10,15 +13,13 @@ end abilityObject.onAutomatonAbility = function(target, automaton, skill, master, action) automaton:addRecast(xi.recast.ABILITY, skill:getID(), 180) - local maneuvers = master:countEffect(xi.effect.DARK_MANEUVER) - local amount = math.floor(automaton:getMaxMP() * 0.2 * maneuvers) - skill:setMsg(xi.msg.basic.SKILL_RECOVERS_MP) - for i = 1, maneuvers do - master:delStatusEffectSilent(xi.effect.DARK_MANEUVER) - end + local darkManeuvers = master:countEffect(xi.effect.DARK_MANEUVER) + local mpRecovered = math.floor(automaton:getMaxMP() * 0.2 * darkManeuvers) + + skill:setMsg(xi.msg.basic.SKILL_RECOVERS_MP) - return automaton:addMP(amount) + return automaton:addMP(mpRecovered) end return abilityObject