Module:BTD6 hero xp
Documentation for this module may be created at Module:BTD6 hero xp/doc
local p = {}
local lang = mw.language.new("en")
local level_reqs = { 180, 460, 1000, 1860, 3280, 5180, 8320, 9380, 13620, 16380, 14400, 16650, 14940, 16380, 17820, 19260, 20700, 16470, 17280 }
local xp_modifiers = { 1, 1.1, 1.2, 1.3, 1 * 1.1 * 1.05 * 1.08, 1.1 * 1.1 * 1.05 * 1.08, 1.2 * 1.1 * 1.05 * 1.08, 1.3 * 1.1 * 1.05 * 1.08 }
function p.main(frame)
local wikitable = {
'{|class="wikitable" style="text-align:center;display:inline-table"\n!rowspan="2"|Level!!rowspan="2"|XP required!!colspan="4"|<span class="explain" title="if placed on round 1 and no other Heroes are placed">Rounds to level up</span>!!colspan="4"|<span class="explain" title="if placed on round 1 and no other Heroes are placed">Rounds to level up with max [[Monkey Knowledge (BTD6)|Monkey Knowledge]]</span>\n|-\n![[Beginner]]!![[Intermediate]]!![[Advanced]]!![[Expert]]!![[Beginner]]!![[Intermediate]]!![[Advanced]]!![[Expert]]'
}
local curve = tonumber(frame.args[1])
local xp_lv3 = math.floor(640 * curve)
local total_required = 0
local total_xp_diff = {0, 0, 0, 0, xp_lv3, xp_lv3, xp_lv3, xp_lv3}
local total_rounds_diff = {0, 0, 0, 0, 0, 0, 0, 0}
local function insert_rounds(index, req)
local xp = 0
local mult = xp_modifiers[index]
local total_xp = total_xp_diff[index]
local total_rounds = total_rounds_diff[index]
while total_xp < req do
total_rounds = total_rounds + 1
if total_rounds <= 20 then xp = (total_rounds * 20 + 20)
elseif total_rounds > 20 and total_rounds <= 50 then xp = (total_rounds * 50 - 380)
else xp = (total_rounds * 90 - 2880) end
total_xp = total_xp + math.floor((xp * mult) + 0.05)
end
if total_rounds == 0 then table.insert(wikitable, '|—')
else table.insert(wikitable, string.format('|%i (%i)', total_rounds - total_rounds_diff[index], total_rounds))
end
total_xp_diff[index] = total_xp
total_rounds_diff[index] = total_rounds
end
for i, v in ipairs(level_reqs) do
local req = math.floor(v * curve)
total_required = total_required + req
table.insert(wikitable, string.format('|-\n!%i\n|%s (%s)', i + 1, lang:formatNum(req), lang:formatNum(total_required)))
insert_rounds(1, total_required)
insert_rounds(2, total_required)
insert_rounds(3, total_required)
insert_rounds(4, total_required)
insert_rounds(5, total_required)
insert_rounds(6, total_required)
insert_rounds(7, total_required)
insert_rounds(8, total_required)
end
table.insert(wikitable, '|}')
return table.concat(wikitable, '\n')
end
return p