Skip to content

Instantly share code, notes, and snippets.

@Elmuti
Created May 15, 2021 22:25
Show Gist options
  • Save Elmuti/a5ff9ac40267b5f0f3d9abaf4635a6e8 to your computer and use it in GitHub Desktop.
Save Elmuti/a5ff9ac40267b5f0f3d9abaf4635a6e8 to your computer and use it in GitHub Desktop.
local mathLib = {}
function mathLib.Lerp(start, goal, alpha)
return start * (1 - alpha) + goal * alpha
end
function mathLib.Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function newStack ()
return {""} -- starts with an empty string
end
function addString (stack, s)
table.insert(stack, s) -- push 's' into the the stack
for i=#stack-1, 1, -1 do
if string.len(stack[i]) > string.len(stack[i+1]) then
break
end
stack[i] = stack[i] .. table.remove(stack)
end
end
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 = SPELL_RESISTANCE[350]
for res = 0, 350, 50 do
if resistance >= res then
min = res
end
end
if resistance < 350 then
print("smaller than 350")
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 PrintResTable(n, t)
local s = newStack()
addString(s, tostring(n).." : ")
for i = 1, 6 do
addString(s, tostring(t[i]))
addString(s, ", ")
end
print(table.concat(s))
end
PrintResTable(25, GetResistanceTable(25))
PrintResTable(49, GetResistanceTable(50))
PrintResTable(50, GetResistanceTable(50))
PrintResTable(51, GetResistanceTable(51))
PrintResTable(350, GetResistanceTable(350))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment