Untitled

 avatar
unknown
plain_text
2 months ago
1.5 kB
5
Indexable
local s = Strength

local function smoothstep(t)
    return t * t * (3 - 2 * t)
end

local function lerp(a, b, t)
    return a + (b - a) * t
end

-- segment functions
local function f1(x) return x * 2 end
local function f2(x) return (x - 250) + 500 end
local function f3(x) return (x - 500)/2 + 750 end
local function f4(x) return (x - 1000)/3 + 1000 end
local function f5(x) return (x - 5000)/6 + 2333 end
local function f6(x) return (x - 8000)/8 + 3000 end
local function f7(x) return (x - 10000)/12 + 3500 end

local blend = 100  -- smoothing width

local function blendSegment(x, edge, fA, fB)
    local t = (x - (edge - blend)) / (2 * blend)
    return lerp(fA(x), fB(x), smoothstep(t))
end

local Damage

if s < 250 - blend then
    Damage = f1(s)
elseif s < 250 + blend then
    Damage = blendSegment(s, 250, f1, f2)

elseif s < 500 - blend then
    Damage = f2(s)
elseif s < 500 + blend then
    Damage = blendSegment(s, 500, f2, f3)

elseif s < 1000 - blend then
    Damage = f3(s)
elseif s < 1000 + blend then
    Damage = blendSegment(s, 1000, f3, f4)

elseif s < 5000 - blend then
    Damage = f4(s)
elseif s < 5000 + blend then
    Damage = blendSegment(s, 5000, f4, f5)

elseif s < 8000 - blend then
    Damage = f5(s)
elseif s < 8000 + blend then
    Damage = blendSegment(s, 8000, f5, f6)

elseif s < 10000 - blend then
    Damage = f6(s)
elseif s < 10000 + blend then
    Damage = blendSegment(s, 10000, f6, f7)

else
    Damage = f7(s)
end
Editor is loading...
Leave a Comment