Module:BTD6 hero xp: Difference between revisions

mNo edit summary
mNo edit summary
Line 8: Line 8:
local p = {}
local p = {}
local lang = mw.language.new("en")
local lang = mw.language.new("en")
local mFloor = math.floor
local function roundHalfToEven(num)
local floored = mFloor(num)
return (num - floored == 0.5) and floor + (floor % 2 == 0 and 0 or 1) or mFloor(num + 0.5)
end


function _main(curve)
function _main(curve)
Line 45: Line 52:
    -- Check if it is a perfect half tie-breaker
    -- Check if it is a perfect half tie-breaker
    total_xp = total_xp + ((((xp * mult) - floor) == 0.5) and ((floor % 2 == 0) and floor or (floor + 1)) or mfloor((xp * mult) + 0.5))
    total_xp = total_xp + roundHalfToEven(xp * mult)
end
end
Line 57: Line 64:
for i, v in ipairs(level_reqs) do
for i, v in ipairs(level_reqs) do
local req = mfloor(v * curve)
local req = roundHalfToEven(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)))