FANDOM


-- <nowiki>
 
local p = {}
 
-- mw.loadData would be better but it can't handle it (#data.items[1] == 0 with mw.loadData)
local data = require('Module:Porter_items/data')
local gep = require('Module:Exchange')._price
local coins = require('Module:Coins')._amount
 
function p.main(frame)
	local info = {
		{'I',   30, 'Pale',         'Sapphire', 5},
		{'II',  35, 'Bright',       'Sapphire', 10},
		{'III', 40, 'Sparkling',    'Emerald',  15},
		{'IV',  45, 'Vibrant',      'Emerald',  20},
		{'V',   60, 'Radiant',      'Ruby',     25},
		{'VI',  80, 'Incandescent', 'Diamond',  30}
	}
 
	local function get_price(name)
		local _, n = pcall(gep,name)
 
		return n
	end
 
	local cost = {}
 
	for i, v in ipairs(info) do
		local c = (v[2] * get_price(v[3] .. ' energy') + get_price(v[4] .. ' necklace')) / v[5]
 
		table.insert(cost, c)
	end
 
	local function sign_name(n)
		return 'Sign of the porter ' .. info[n][1]
	end
 
	local function link(title, text)
		local s = '[[' .. title
 
		if text then
			s = s .. '|' .. text
		end
 
		return s .. ']]'
	end
 
	local function get_profit(item, i)
		local p = get_price(item)
 
		if type(p) ~= 'number' then
			return 'Untradeable'
		else
			local profit = p - cost[i]
 
			return coins(profit)
		end
	end
 
	local container = mw.html.create('div')
 
	local cols = #info + 1
 
	for i, category in ipairs(data.categories) do
		local t = container:tag('table'):addClass('wikitable mw-collapsible mw-collapsed')
 
		t:tag('tr'):tag('th'):attr('colspan', cols):wikitext(category == 'Other' and category or link(category))
 
		local header = t:tag('tr')
		for j=0, #info do
			local text
			if j == 0 then
				text = 'Item'
			else
				text = link(sign_name(j), info[j][1])
			end
 
			header:tag('th'):wikitext(text)
		end
 
		for _, item in ipairs(data.items[i]) do
			local row = t:tag('tr')
					:tag('td')
					:wikitext('[[File:'..item..'.png|link='..item..
							']][['..item..']]')
					:done()
 
			for j, v in ipairs(info) do
				row:tag('td'):wikitext(get_profit(item, j))
			end
		end
	end
 
	return container
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.