Module:Pylon battery

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Pylon battery/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Pylon battery/doc. [edit]
Module:Pylon battery's function main is invoked by Template:Pylon battery.
Module:Pylon battery's function rex is invoked by Template:Rex skeleton.
Module:Pylon battery loads data from Module:Lamp/data.
Function list
L 7 — dispNum
L 11 — p.main
L 15 — p.rex
L 21 — p._main

local p = {}

-- from [[Module:Lamp]]
local xps = mw.loadData('Module:Lamp/data').lamp_xps

local lang = mw.getContentLanguage()
function dispNum(x)
	return lang:formatNum( math.floor( (tonumber(x) or 0)*10 )/10 )
end

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

function p.rex(frame)
	local args = frame:getParent().args
	args.rex = true
	return p._main(args)
end

function p._main(args)
	local lvl = tonumber(args.level) or 1
	local number = tonumber(args.number) or 1
	local rex = args.rex or false
	
	local xp_per = 0.1 * math.floor(0.5 * xps[math.max(math.min(math.floor(lvl), 120), 1)])
	local mult = 1
	if number >= 100 then
		mult = 1.2
	elseif number >= 10 then
		mult = 1.1
	end
	
	local xp_gained_base = xp_per * number
	local xp_gained = xp_gained_base * mult
	
	xp_gained = math.floor(xp_gained*10)/10
	
	local str = { 'Contributing ', number }
	--local str = { 'Contributing ', number, (number==1 and ' battery' or ' batteries'), ' to the pylon at level ', lvl, ' Archaeology grants a base of ', dispNum(xp_gained_base), ' experience.' }
	if rex then
		table.insert(str, string.format('%s to the skeleton at level %s Archaeology grants a base of %s experience.', (number==1 and ' rex skeleton fragment' or ' rex skeleton fragments'), lvl, dispNum(xp_gained_base)))
		if mult > 1 then
			table.insert(str, string.format(' Because you contributed so many, you gain %s%% additional experience, granting %s total experience.', (mult-1)*100, dispNum(xp_gained)))
		else
			table.insert(str, " You didn't contribute enough to gain any additional experience.")
		end
		table.insert(str, string.format(' You also contribute %s%% power to the skeleton.', 0.001*number*mult))
	else
		table.insert(str, string.format('%s to the pylon at level %s Archaeology grants a base of %s experience.', (number==1 and ' battery' or ' batteries'), lvl, dispNum(xp_gained_base)))
		if mult > 1 then
			table.insert(str, string.format(' Because you contributed so many, you gain %s%% additional experience, granting %s total experience.', (mult-1)*100, dispNum(xp_gained)))
		else
			table.insert(str, " You didn't contribute enough to gain any additional experience.")
		end
		table.insert(str, string.format(' You also contribute %s%% power to the pylon.', 0.001*number*mult))
	end
	
	return table.concat(str, '')
end

return p