Skip to content

Commit

Permalink
Safety check and non elemental magic bypass
Browse files Browse the repository at this point in the history
Co-authored-by: ampitere <ampitere@users.noreply.github.com>
  • Loading branch information
Xaver-DaRed and ampitere committed May 10, 2024
1 parent 1cbf850 commit 7168081
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions scripts/globals/combat/magic_hit_rate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,34 @@ end
-----------------------------------

xi.combat.magicHitRate.calculateResistRate = function(actor, target, skillType, spellElement, magicHitRate, rankModifier)
local targetResistRate = 0 -- The variable we return.
local targetResistRank = target:getMod(xi.combat.element.resistRankMod[spellElement])
local targetResistRate = 1 -- The variable we return.

----------------------------------------
-- Handle 'Magic Shield' status effect.
----------------------------------------
if target:hasStatusEffect(xi.effect.MAGIC_SHIELD, 0) then
return 0
end

----------------------------------------
-- Handle non elemental magic or user error.
----------------------------------------
if
spellElement == xi.element.NONE or -- Non elemental magic (ex. Player Meteor) cannot be resisted.
spellElement > xi.element.DARK or -- That's not even an element.
spellElement == nil -- You shouldnt be using this function.
then
return targetResistRate
end

----------------------------------------
-- Handle target resistance rank.
----------------------------------------
local targetResistRank = target:getMod(xi.combat.element.resistRankMod[spellElement]) or 0

-- Elemental resistance rank.
if spellElement ~= xi.element.NONE then
if targetResistRank > 4 then
targetResistRank = utils.clamp(targetResistRank - rankModifier, 4, 11)
end
if targetResistRank > 4 then
targetResistRank = utils.clamp(targetResistRank - rankModifier, 4, 11)
end

-- Skillchains lowers target resistance rank by 1.
Expand Down

0 comments on commit 7168081

Please sign in to comment.