Module:BTD6 hero xp: Difference between revisions

mNo edit summary
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
local mFloor = math.floor
local mFloor = math.floor


local function roundHalfToEven(num)
local function RoundHalfUp(num)
local floored = mFloor(num)
local floored = mFloor(num)
return (num - floored == 0.5) and floor + (floor % 2 == 0 and 0 or 1) or mFloor(num + 0.5)
return floored + ((num - floored >= 0.5) and 1 or 0)
end
end


Line 25: Line 25:
-- local functions to improve performance
-- local functions to improve performance
local mfloor = math.floor
local tinsert = table.insert
local tinsert = table.insert
local sformat = string.format
local sformat = string.format
local xp_lv3 = mfloor(640 * curve)
local xp_lv3 = RoundHalfUp(640 * curve)
local total_required = 0
local total_required = 0
Line 48: Line 47:
elseif total_rounds > 20 and total_rounds <= 50 then xp = (total_rounds * 40 - 380)
elseif total_rounds > 20 and total_rounds <= 50 then xp = (total_rounds * 40 - 380)
else xp = (total_rounds * 90 - 2880) end
else xp = (total_rounds * 90 - 2880) end
local floor = mfloor(xp * mult)
    -- Check if it is a perfect half tie-breaker
    -- Check if it is a perfect half tie-breaker
    total_xp = total_xp + roundHalfToEven(xp * mult)
    total_xp = total_xp + RoundHalfUp(xp * mult)
end
end
Line 64: Line 61:
for i, v in ipairs(level_reqs) do
for i, v in ipairs(level_reqs) do
local req = roundHalfToEven(v * curve)
local req = RoundHalfUp(v * curve)
total_required = total_required + req
total_required = total_required + req
tinsert(wikitable, sformat('|-\n!%i\n|%s (%s)', i + 1, lang:formatNum(req), lang:formatNum(total_required)))
tinsert(wikitable, sformat('|-\n!%i\n|%s (%s)', i + 1, lang:formatNum(req), lang:formatNum(total_required)))