Module:BTD6 hero xp: Difference between revisions

mNo edit summary
No edit summary
Line 1: Line 1:
-- This code is copyrighted and available under the Creative Commons Attribution-NonCommercial-ShareAlike International license, version 4.0. You may use and adapt this code if:
-- * You give appropriate credit
-- * You are not using this material for commercial purposes
-- * You are releasing it under the same license
-- Further information: https://www.bloonswiki.com/Blooncyclopedia:Copyrights
-- By editing this code, you agree to release your changes under the same terms.
local p = {}
local p = {}
local lang = mw.language.new("en")
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 }
function _main(curve)
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 }
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 = {
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]]'
'{|class="wikitable" style="text-align:center"\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 w/ [[File:BTD6_mk_MonkeyEducationIcon.png|x20px|link=Monkey Education]][[File:BTD6_mk_SelfTaughtHeroesIcon.png|x20px|link=Self Taught Heroes]][[File:BTD6_mk_MonkeysStrongerTogetherIcon.png|x20px|link=Monkeys Together Strong]]</span>\n|-\n![[Beginner]]!![[Intermediate]]!![[Advanced]]!![[Expert]]!![[Beginner]]!![[Intermediate]]!![[Advanced]]!![[Expert]]'
}
}
local curve = tonumber(frame.args[1])
-- local functions to improve performance
local xp_lv3 = math.floor(640 * curve)
local mfloor = math.floor
local tinsert = table.insert
local sformat = string.format
local xp_lv3 = mfloor(640 * curve)
local total_required = 0
local total_required = 0
Line 31: Line 42:
else xp = (total_rounds * 90 - 2880) end
else xp = (total_rounds * 90 - 2880) end
total_xp = total_xp + math.floor((xp * mult) + 0.05)
total_xp = total_xp + mfloor((xp * mult) + 0.05)
end
end
if total_rounds == 0 then table.insert(wikitable, '|—')
if total_rounds == 0 then tinsert(wikitable, '|—')
else table.insert(wikitable, string.format('|%i (%i)', total_rounds - total_rounds_diff[index], total_rounds))
else tinsert(wikitable, sformat('|%i (%i)', total_rounds - total_rounds_diff[index], total_rounds))
end
end
Line 43: Line 54:
for i, v in ipairs(level_reqs) do
for i, v in ipairs(level_reqs) do
local req = math.floor(v * curve)
local req = mfloor(v * curve)
total_required = total_required + req
total_required = total_required + req
table.insert(wikitable, string.format('|-\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)))
insert_rounds(1, total_required)
insert_rounds(1, total_required)
Line 57: Line 68:
end
end
table.insert(wikitable, '|}')
tinsert(wikitable, '|}')
return table.concat(wikitable, '\n')
return table.concat(wikitable, '\n')
end
function p.main(frame)
return _main(tonumber(frame.args[1]))
end
end


return p
return p