Módulo:Lâmpada

De RuneScape Wiki
Ir para: navegação, pesquisa
Documentação do módulo
Esta documentação é transcluída de Módulo:Lâmpada/doc. [editar] [atualizar]
Módulo:Lâmpada's a função main é invocada por Predefinição:LâmpadaEXP.
Módulo:Lâmpada requer Módulo:Addcommas.
Módulo:Lâmpada requer Módulo:Tabelas.

Usado em conjunção com {{LâmpadaEXP}}.


local p = {}

local commas = require('Módulo:Addcommas')._add
local tables = require('Módulo:Tabelas')

local xps = {
	250, 276, 308, 340, 373, 416, 492, 508, 577, 614,						-- 1 to 10
	680, 752, 822, 916, 1008, 1046, 1096, 1140, 1192, 1240,					--11 to 20
	1298, 1348, 1408, 1470, 1536, 1596, 1621, 1656, 1812, 1892,				--21 to 30
	1973, 2056, 2144, 2237, 2332, 2434, 2539, 2648, 2766, 2882,				--31 to 40
	3008, 3138, 3272, 3414, 3558, 3716, 3882, 4050, 4220, 4404, 			--41 to 50
	4593, 4800, 4998, 5218, 5448, 5688, 5940, 6183, 6464.5, 6737, 			--51 to 60
	7028.5, 7342, 7645, 8016.5, 8335.5, 8686, 9076, 9516, 9880, 10371,			--61 to 70
	10771.5, 11237, 11786, 12327.5, 12854.5, 13357.5, 13980, 14587, 15168.5, 15920,	--71 to 80
	16664, 17390, 18087, 19048, 19673.5, 20598, 21501, 22369, 23690, 24486,	--81 to 90
	25806, 26457, 27712, 28943, 30130.5, 32258.5, 33389.5, 34407.5					--91 to 98
}

local multipliers = {
	-- Small Lamp
	SMALL 	= 1,
	PEQUENA	= 1,
	PEQUENO	= 1,
	TINY	= 1,
	MINI	= 1,
	DEFAULT	= 1,
	BASE	= 1,
	BASIC	= 1,
	QUARTER	= 1,
	
	-- Medium Lamp
	MEDIUM	= 2,
	MEDIA	= 2,
	MEDIO	= 2,
	MED		= 2,
	HALF	= 2,
	
	-- Large Lamp
	LARGE 	= 4,
	BIG		= 4,
	WHOLE	= 4,
	GRANDE  = 4,
	
	-- Huge Lamp
	HUGE	= 8,
	DOUBLE	= 8,
	ENORME  = 8
}

local function getMultiplier(multiplo)
	if tonumber(multiplo) then return multiplo end
	if not multiplo then return 1 end
	local synonym = multipliers[tostring(multiplo):upper()]
	if synonym then return synonym end
	
	-- otherwise
	return 1
end

-- Returns the xp gained from a lamp at a given level and multiplier
--	level: Level to query
--	multiplier: Size of the lamp as a case-insensitive string ("Small", "Medium", "Large", "Huge") or a raw numeric value
--
--	returns xp as an unformatted number
function p._level_to_xp(level, multiplo)
	multiplo = getMultiplier(multiplo)
	return math.floor(xps[level] * multiplo / 4)
end

-- Returns the level required to gain the provided amount of xp
--	xp: Amount of xp to query
--	multiplier: Size of the lamp as a case-insensitive string ("Small", "Medium", "Large", "Huge") or a raw numeric value
--	(overflow): Whether to consider lamps that would provide more than the requested xp (default: true)
--
--	returns level as an unformatted number
function p._xp_to_level(xp, multiplo, overflow)
	multiplo = getMultiplier(multiplo)
	if overflow == nil then overflow = true end
	local offset = 1
	if overflow then offset = 0 end
	
	local scan = xp * 4 / multiplo
	local level = 0
	repeat
		level = level + 1
	until level == 98 or scan < xps[level + offset] + 1 - offset
	
	return level
end

-- Print table
function p._main(args)
	cols = tonumber(args.cols)
	local xptable = mw.html.create('table'):addClass('wikitable'):css({['text-align'] = 'center'})
	rows = math.ceil(99 / cols)
	data = {{{text = 'Nível', tag = 'th'}, {text = 'Experiência', tag = 'th'}}}
	for i=2,cols do
		data[1][3*i-3] = {text = '', tag = 'th', attr = {rowspan = rows + 1}}
		data[1][3*i-2] = {text = 'Nível', tag = 'th'}
		data[1][3*i-1] = {text = 'Experiência', tag = 'th'}
	end
	for i=1,rows do
		data[i+1] = {}
		for j=1,cols do
			level = (j-1) * rows + i
			if level < 99 then
				xp = commas(p._level_to_xp(level, args.multiplo))
				if level == 98 then
					level = '98+'
				end
				data[i+1][j*3-2] = {text = level}
				data[i+1][j*3-1] = {text = xp}
				data[i+1][j*3] = false
			end
		end
	end
	tables._table(xptable, data)
	return tostring(xptable)
end

---- Outward-facing functions

function p.main(frame)
    return p._main(frame:getParent().args)
end

function p.xp_to_level(frame)
	local args = frame:getParent().args
	return p._xp_to_level(args.xp, args.multiplo, args.overflow)
end

function p.level_to_xp(frame)
	local args = frame:getParent().args
	return p._level_to_xp(args.level, args.multiplo)
end

return p