RuneScape Wiki
Advertisement

Documentation for this module may be created at Module:Infobox rock/doc

-- <pre>
local p = {}

-- "imports"
local onmain = require('Module:Mainonly').on_main
local paramtest = require('Module:Paramtest')
local exchange = require('Module:Exchange')
local commas = require('Module:Addcommas')._add
local infobox = require('Module:Infobox')

function p.main(frame)
	local args = frame:getParent().args
	local ret = infobox.new(args)
	ret:defineParams{
		{ name = 'name' , func = 'name' },
		{ name = 'image', func = 'has_content' },
		{ name = 'release', func = 'release' },
		{ name = 'members', func = 'has_content' },
		{ name = 'quest', func = 'has_content' },
		{ name = 'level', func = 'has_content' },
		{ name = 'xp', func = 'has_content' },
		{ name = 'toolxp', func = { name = toolxp , params = { 'xp' } } },
		{ name = 'ore', func = { name = ore_param , params = { 'ore', 'price' } } },
		{ name = 'max', func = 'has_content' },
		{ name = 'location', func = 'has_content' },
		{ name = 'examine', func = 'has_content' }
	}

	ret:create()
	ret:cleanParams()
	ret:caption()
	ret:defineName('Infobox rock')
	ret:css{ ['max-width'] = '250px' }
	ret:addRow{
		{ tag = 'argd', content = 'image', colspan = '2', css = { ['text-align'] = 'center' } } }
	:addRow{
		{ tag = 'th', content = 'Release' },
		{ tag = 'argd', content = 'release' } }
	:addRow{
		{ tag = 'th', content = '[[Members]]' },
		{ tag = 'argd', content = 'members' } }
	:addRow{
		{ tag = 'th', content = 'Level' },
		{ tag = 'argd', content = 'level' } }
	:addRow{
		{ tag = 'th', content = 'Quest' },
		{ tag = 'argd', content = 'quest' } }
	:addRow{
		{ tag = 'th', content = 'Location' },
		{ tag = 'argd', content = 'location' } }
	:addRow{
		{ tag = 'th', content = 'Output', colspan = '2' } }
	:addRow{
		{ tag = 'th', content = 'Ore' },
		{ tag = 'argd', content = 'ore' } }
	:addRow{
		{ tag = 'th', content = 'Mining XP' },
		{ tag = 'argd', content = 'xp' } }
	:addRow{
		{ tag = 'th', content = '[[Calculator:Equipment level/Mining|Tool XP]]' },
		{ tag = 'argd', content = 'toolxp' } }
	:addRow{
		{ tag = 'th', content = 'Max yield' },
		{ tag = 'argd', content = 'max' } }
	:addRow{
		{ tag = 'th', content = '[[Examine]]', colspan = '2' } }
	:addRow{
		{ tag = 'argd', content = 'examine', colspan = '2', css = { ['text-align'] = 'center' } } }

	ret:finish()

	if onmain() then
		local a = ret:categoryData()
		ret:wikitext(addcategories(a))
	end

	return ret:tostring()
end

function ore_param(arg,price)
	if paramtest.is_empty(arg) then
		return nil
	end
	price = price or ''

	if price:lower() == 'gemw' then
		price = true
	else
		price = false
	end

	local ret = { string.format('[[%s]]',arg) }
	if price and exchange._exists(arg) then
		price = commas(exchange._price(arg))
		table.insert(ret,string.format('(%s coins)',price))
	end

	return table.concat(ret,' ')
end

function toolxp(xp)
	if not tonumber(xp,10) then
		return '-'
	end
	return math.floor(118 * tonumber(xp or 0,10))/1000
end

function addcategories(arg)
	ret = { 'Rocks', 'Interactive scenery' }
	if not arg.members.all_defined then
		table.insert(ret,'Needs members status')
	end

	if not arg.release.all_defined then
		table.insert(ret,'Needs update added')
	end

	-- combine table and format category wikicode
	for i, v in ipairs(ret) do
		ret[i] = string.format('[[Category:%s]]',v)
	end

	return table.concat(ret,'')
end

return p
Advertisement