Module:DefenseCalc: Difference between revisions

From IdleOn MMO Wiki
imported>Kiokurashi
No edit summary
mNo edit summary
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
local defenseCalc = {}
local defenseCalc = {}


local function f1(x, attack)
local function f1(x, y)
local y = tonumber(attack)
return (x^2.5) + ((500 * y) * (x^0.8)) - (200 * (y^2)) + (100 * y)
return (x^2.5) + ((500 * y) * (x^0.8)) - (200 * (y^2)) + (100 * y)
end
end
local function f2(x, attack)
local function f2(x, y)
local y = tonumber(attack)
return (2.5 * (x^1.5)) + (400 * y * (x^-0.2))
return (2.5 * (x^1.5)) + (400 * y * (x^-0.2))
end
end
function defenseCalc.calc(frame)
function defenseCalc.calc(frame)
local attack = frame.args.Attack
local frameArgs = frame.args
local attack = tonumber(frameArgs.Attack)
if attack == 0 then return 0 end
local z = 1
local z = 1
local eps = 0.1
local eps = 0.1
Line 17: Line 17:
end
end
-- Lua only has floor and ceil standard so this is to bypass that and make a round to 0.00
-- Lua only has floor and ceil standard so this is to bypass that and make a round to 0.00
return tonumber(string.format("%.2f", z))
return tonumber(string.format("%.2f", math.max(z, 1)))
end
end


return defenseCalc
return defenseCalc

Latest revision as of 19:40, 15 March 2024

Documentation for this module may be created at Module:DefenseCalc/doc

local defenseCalc = {}

local function f1(x, y)
	return (x^2.5) + ((500 * y) * (x^0.8)) - (200 * (y^2)) + (100 * y)
end
local function f2(x, y)
	return (2.5 * (x^1.5)) + (400 * y * (x^-0.2))
end
function defenseCalc.calc(frame)
	local frameArgs = frame.args
	local attack = tonumber(frameArgs.Attack)
	if attack == 0 then return 0 end
	local z = 1
	local eps = 0.1
	while (math.abs(f1(z, attack) / f2(z, attack)) > eps) do
		z = z - (f1(z, attack) / f2(z, attack))
	end
	-- Lua only has floor and ceil standard so this is to bypass that and make a round to 0.00
	return tonumber(string.format("%.2f", math.max(z, 1)))
end

return defenseCalc