Skip to content

Commit

Permalink
[LUA]Move PUP JA to jobUtils file
Browse files Browse the repository at this point in the history
[LUA]Move PUP JA to jobUtils file

[LUA]Move PUP JA to jobUtils file

[LUA]Move PUP JA to jobUtils file
  • Loading branch information
hooksta4 committed Nov 16, 2024
1 parent 77d4aa8 commit d068cbf
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 303 deletions.
20 changes: 2 additions & 18 deletions scripts/actions/abilities/activate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
if player:getPet() ~= nil then
return xi.msg.basic.ALREADY_HAS_A_PET, 0
elseif not player:canUseMisc(xi.zoneMisc.PET) then
return xi.msg.basic.CANT_BE_USED_IN_AREA, 0
elseif player:isExceedingElementalCapacity() then
return xi.msg.basic.AUTO_EXCEEDS_CAPACITY, 0
end

return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckActivate(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
xi.pet.spawnPet(player, xi.petId.AUTOMATON)

local pet = player:getPet()

if pet then
local jpValue = player:getJobPointLevel(xi.jp.AUTOMATON_HP_MP_BONUS)
pet:addMod(xi.mod.HP, jpValue * 10)
pet:addMod(xi.mod.MP, jpValue * 5)
end
return xi.job_utils.puppetmaster.onAbilityUseActivate(player, target, ability)
end

return abilityObject
15 changes: 2 additions & 13 deletions scripts/actions/abilities/cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
if not player:getPet() then
-- TODO: Add check to verify this is an automaton
return xi.msg.basic.REQUIRES_A_PET, 0
end

return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckCooldown(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
local jpValue = player:getJobPointLevel(xi.jp.COOLDOWN_EFFECT)

player:reduceBurden(50, jpValue)

if player:hasStatusEffect(xi.effect.OVERLOAD) then
player:delStatusEffect(xi.effect.OVERLOAD)
end
return xi.job_utils.puppetmaster.onAbilityUseCooldown(player, target, ability)
end

return abilityObject
14 changes: 2 additions & 12 deletions scripts/actions/abilities/deactivate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckDeactivate(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
-- Reset the Activate ability.
local pet = player:getPet()

if
pet and
pet:getHP() == pet:getMaxHP()
then
player:resetRecast(xi.recast.ABILITY, 205) -- activate
end

target:despawnPet()
return xi.job_utils.puppetmaster.onAbilityUseDeactivate(player, target, ability)
end

return abilityObject
4 changes: 2 additions & 2 deletions scripts/actions/abilities/deploy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckDeploy(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
player:petAttack(target)
return xi.job_utils.puppetmaster.onAbilityUseDeploy(player, target, ability)
end

return abilityObject
21 changes: 2 additions & 19 deletions scripts/actions/abilities/deus_ex_automata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
if player:getPet() ~= nil then
return xi.msg.basic.ALREADY_HAS_A_PET, 0
elseif not player:canUseMisc(xi.zoneMisc.PET) then
return xi.msg.basic.CANT_BE_USED_IN_AREA, 0
else
local jpValue = player:getJobPointLevel(xi.jp.DEUS_EX_AUTOMATA_RECAST)

ability:setRecast(ability:getRecast() - jpValue)

return 0, 0
end
return xi.job_utils.puppetmaster.onAbilityCheckDeuxExAutomata(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
xi.pet.spawnPet(player, xi.petId.AUTOMATON)
local pet = player:getPet()

if pet then
local percent = math.floor((player:getMainLvl() / 3)) / 100
pet:setHP(math.max(pet:getHP() * percent, 1))
pet:setMP(pet:getMP() * percent)
end
return xi.job_utils.puppetmaster.onAbilityUseDeuxExAutomata(player, target, ability)
end

return abilityObject
6 changes: 2 additions & 4 deletions scripts/actions/abilities/heady_artifice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
ability:setRecast(math.max(0, ability:getRecast() - player:getMod(xi.mod.ONE_HOUR_RECAST) * 60))

return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckHeadyArtiface(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
-- target:addStatusEffect(xi.effect.HEADY_ARTIFICE, 18, 1, 1) -- TODO: implement xi.effect.HEADY_ARTIFICE
return xi.job_utils.puppetmaster.onAbilityUseHeadyArtiface(player, target, ability)
end

return abilityObject
68 changes: 2 additions & 66 deletions scripts/actions/abilities/maintenance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,12 @@
---@type TAbility
local abilityObject = {}

local idStrengths =
{
[18731] = 1, -- Automaton Oil
[18732] = 2, -- Automaton Oil + 1
[18733] = 3, -- Automaton Oil + 2
[19185] = 4 -- Automaton Oil + 3
}

local removableStatus =
{
xi.effect.PETRIFICATION,
xi.effect.SILENCE,
xi.effect.BANE,
xi.effect.CURSE_II,
xi.effect.CURSE_I,
xi.effect.PARALYSIS,
xi.effect.PLAGUE,
xi.effect.POISON,
xi.effect.DISEASE,
xi.effect.BLINDNESS,
}

local function removeStatus(target)
for _, effectId in ipairs(removableStatus) do
if target:delStatusEffect(effectId) then
return true
end
end

if target:eraseStatusEffect() ~= xi.effect.NONE then
return true
end

return false
end

abilityObject.onAbilityCheck = function(player, target, ability)
local pet = player:getPet()
if not pet then
return xi.msg.basic.REQUIRES_A_PET, 0
elseif not pet:isAutomaton() then
return xi.msg.basic.NO_EFFECT_ON_PET, 0
else
local id = player:getEquipID(xi.slot.AMMO)
if idStrengths[id] then
return 0, 0
else
return xi.msg.basic.UNABLE_TO_USE_JA, 0
end
end
return xi.job_utils.puppetmaster.onAbilityCheckMaintenance(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
local id = player:getEquipID(xi.slot.AMMO)
local pet = player:getPet()
local toRemove = idStrengths[id] or 1
local numRemoved = 0

repeat
if not removeStatus(pet) then
break
end

toRemove = toRemove - 1
numRemoved = numRemoved + 1
until toRemove <= 0

player:removeAmmo()

return numRemoved
return xi.job_utils.puppetmaster.onAbilityUseMaintenance(player, target, ability)
end

return abilityObject
14 changes: 2 additions & 12 deletions scripts/actions/abilities/overdrive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
local pet = player:getPet()
if not pet then
return xi.msg.basic.REQUIRES_A_PET, 0
elseif not pet:isAutomaton() then
return xi.msg.basic.NO_EFFECT_ON_PET, 0
else
ability:setRecast(math.max(0, ability:getRecast() - player:getMod(xi.mod.ONE_HOUR_RECAST) * 60))
return 0, 0
end
return xi.job_utils.puppetmaster.onAbilityCheckOverdrive(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
player:addStatusEffect(xi.effect.OVERDRIVE, 0, 0, 60)

return xi.effect.OVERDRIVE
return xi.job_utils.puppetmaster.onAbilityUseOverdrive(player, target, ability)
end

return abilityObject
89 changes: 2 additions & 87 deletions scripts/actions/abilities/repair.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,12 @@
---@type TAbility
local abilityObject = {}

local removableEffectIds =
{
xi.effect.PETRIFICATION,
xi.effect.SILENCE,
xi.effect.BANE,
xi.effect.CURSE_II,
xi.effect.CURSE_I,
xi.effect.PARALYSIS,
xi.effect.PLAGUE,
xi.effect.POISON,
xi.effect.DISEASE,
xi.effect.BLINDNESS,
}

-- https://www.bg-wiki.com/ffxi/Repair
local oilType =
{
-- ItemId { Base, %HP, Time(s) }
[xi.item.CAN_OF_AUTOMATON_OIL ] = { 20, 0.1, 15 },
[xi.item.CAN_OF_AUTOMATON_OIL_P1] = { 40, 0.2, 30 },
[xi.item.CAN_OF_AUTOMATON_OIL_P2] = { 60, 0.3, 45 },
[xi.item.CAN_OF_AUTOMATON_OIL_P3] = { 80, 0.4, 60 },
}

local function removeStatus(pet)
for _, effectId in ipairs(removableEffectIds) do
if pet:delStatusEffect(effectId) then
return true
end
end

if pet:eraseStatusEffect() ~= xi.effect.NONE then
return true
end

return false
end

abilityObject.onAbilityCheck = function(player, target, ability)
local pet = player:getPet()
if not pet then
return xi.msg.basic.REQUIRES_A_PET, 0
elseif not pet:isAutomaton() then
return xi.msg.basic.NO_EFFECT_ON_PET, 0
else
local id = player:getEquipID(xi.slot.AMMO)

if oilType[id] then
return 0, 0
else
return xi.msg.basic.UNABLE_TO_USE_JA, 0
end
end
return xi.job_utils.puppetmaster.onAbilityCheckRepair(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
local pet = player:getPet()
if not pet then
return
end

local petMaxHP = pet:getMaxHP()
local numRemovableEffects = player:getMod(xi.mod.REPAIR_EFFECT)

-- Need to start to calculate the HP to restore to the pet.
-- Ref: https://www.bg-wiki.com/ffxi/Repair
local oilData = oilType[player:getEquipID(xi.slot.AMMO)]
local regenAmount = oilData[1]
local totalHealing = oilData[2] * petMaxHP
local regenTime = oilData[3]

for _ = 1, numRemovableEffects do
if not removeStatus(pet) then
break
end
end

local bonus = 1 + player:getMerit(xi.merit.REPAIR_EFFECT) / 100
totalHealing = totalHealing * bonus

bonus = bonus + player:getMod(xi.mod.REPAIR_POTENCY) / 100
regenAmount = regenAmount * bonus

totalHealing = pet:addHP(totalHealing)

pet:wakeUp()

pet:delStatusEffect(xi.effect.REGEN)
pet:addStatusEffect(xi.effect.REGEN, regenAmount, 3, regenTime) -- 3 = tick, each 3 seconds.
player:removeAmmo()
return totalHealing
return xi.job_utils.puppetmaster.onAbilityUseRepair(player, target, ability)
end

return abilityObject
4 changes: 2 additions & 2 deletions scripts/actions/abilities/retrieve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
return 0, 0
return xi.job_utils.puppetmaster.onAbilityCheckRetrieve(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
player:petRetreat()
return xi.job_utils.puppetmaster.onAbilityUseRetrieve(player, target, ability)
end

return abilityObject
20 changes: 2 additions & 18 deletions scripts/actions/abilities/role_reversal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
local pet = player:getPet()

if not pet then
return xi.msg.basic.REQUIRES_A_PET, 0
elseif not pet:isAutomaton() then
return xi.msg.basic.NO_EFFECT_ON_PET, 0
else
return 0, 0
end
return xi.job_utils.puppetmaster.onAbilityCheckRoleReversal(player, target, ability)
end

abilityObject.onUseAbility = function(player, target, ability)
local pet = player:getPet()
if pet then
local bonus = 1 + (player:getMerit(xi.merit.ROLE_REVERSAL) - 5) / 100
local playerHP = player:getHP()
local petHP = pet:getHP()

pet:setHP(math.max(playerHP * bonus, 1))
player:setHP(math.max(petHP * bonus, 1))
end
return xi.job_utils.puppetmaster.onAbilityUseRoleReversal(player, target, ability)
end

return abilityObject
Loading

0 comments on commit d068cbf

Please sign in to comment.