Skip to content

Instantly share code, notes, and snippets.

@Elmuti
Created May 15, 2021 22:48
Show Gist options
  • Save Elmuti/3d8169c6075fabe0ae976b607a78d829 to your computer and use it in GitHub Desktop.
Save Elmuti/3d8169c6075fabe0ae976b607a78d829 to your computer and use it in GitHub Desktop.
local SpellResistType = {
SpellResult.Miss,
SpellResult.Resist,
SpellResult.Resist75,
SpellResult.Resist50,
SpellResult.Resist25,
SpellResult.ResistNone,
}
local SPELL_RESISTANCE = {
--resist, 100%, 75%, 50%, 25%, full
[0] = {0, 0, 0, 0, 0, 0}; --none
[50] = {0, 0, 2, 11, 33, 54}; --poor
[100] = {1, 1, 6, 24, 49, 20}; --fair
[150] = {1, 1, 18, 48, 26, 7}; --good
[200] = {11, 11, 34, 40, 14, 1}; --good
[250] = {25, 25, 55, 16, 3, 1}; --very good
[300] = {35, 35, 65, 6, 1, 1}; --very good
[350] = {55, 55, 45, 10, 0, 0}; --super
}
function GetResistanceTable(resistance)
local min = 0
local max = 350
local ret = Array.ShallowCopy(SPELL_RESISTANCE[350])
for res = 0, 350, 50 do
if resistance >= res then
min = res
end
end
if resistance < 350 then
max = min + 50
if resistance == min then
return SPELL_RESISTANCE[min]
end
local alpha = (resistance-min) / (max-min)
print(string.format("res:%s, min:%s, max:%s, alpha:%s", tostring(resistance), tostring(min), tostring(max), tostring(alpha)))
for i = 1, 6 do
ret[i] = mathLib.Lerp(SPELL_RESISTANCE[min][i], SPELL_RESISTANCE[max][i], alpha)
end
end
return ret
end
function Combat.GetResistanceRoll(resistance, school)
--local resistance = target:GetStat(school.."Resistance") + target:GetStat("Resistance")
if resistance <= 0 then
return SpellResult.ResistNone -- NO RESISTS
end
local resTable = GetResistanceTable(resistance)
local sum = 0
for key, value in ipairs(resTable) do
sum += value
end
local rand = math.random(0, sum) -- i think max is exclusive?
local acc = 0
for key, value in ipairs(resTable) do
acc += value
if acc >= rand then
return SpellResistType[key]
end
end
return SpellResult.ResistNone
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment