FANDOM


-- <pre>
-- TODO: Module:Exchange when it's live
local p = {}
 
local itemdata = mw.loadData('Module:Smithing profit calculator/Data')
local ucf = require('Module:Paramtest').ucfirst
local gep = require('Module:Exchange')._price
local coins = require('Module:Coins')._amount
local scroll = {
	['Bronze bar'] = .5,
	['Iron bar'] = .25,
	['Steel bar'] = .2,
	['Mithril bar'] = .1,
	['Adamant bar'] = .08,
	['Rune bar'] = .05
}
local hammer = {
	['Bronze bar'] = .55,
	['Iron bar'] = .3,
	['Steel bar'] = .25,
	['Mithril bar'] = .15,
	['Adamant bar'] = .13,
	['Rune bar'] = .1
}
 
function p.main(frame)
	local args = frame:getParent().args
	local metal = args[1] or ''
	metal = mw.text.trim(metal:lower())
	local metaldata = itemdata[metal]
	if not metaldata then
		error('Data set not found for: '..metal)
	else
		local bar = ucf(metal)..' bar'
		return p._main(metaldata,bar,frame)
	end
end
 
function p._main(itemtbl,bar,frame)
	local bar_img = '[[File:'..bar..'.png|link='..bar..']]'
	local bar_link = bar_img .. '&nbsp;[['..bar..']]'
	local bar_price = gep(bar)
	local ret = 'The cost of 1 '..bar_link..' is '..coins(bar_price)..'.'
	local ret_tbl = mw.html.create('table')
				:addClass('wikitable')
				:addClass('sortable')
				:tag('tr')
					:tag('th')
						:addClass('unsortable')
					:done()
					:tag('th')
						:wikitext('Item')
					:done()
					:tag('th')
						:wikitext('Level')
					:done()
					:tag('th')
						:wikitext('# Bars')
					:done()
					:tag('th')
						:wikitext('XP')
					:done()
					:tag('th')
						:wikitext('GE Price')
					:done()
					:tag('th')
						:wikitext('Profit/XP')
					:done()
					:tag('th')
						:wikitext('Profit/XP 2')
					:done()
					:tag('th')
						:wikitext('Profit/XP 3')
					:done()
					:tag('th')
						:wikitext('Profit/XP 4')
					:done()
				:done()
	for i, itbl in ipairs(itemtbl) do
		local item = itbl.name
		local item_price_1 = gep(item)
		item_price_1 = coins(item_price_1)
		local item_price = gep(item) * (itbl.amount or 1)
		local bars_scroll
		local bars_hammer = itbl.bars * .9
		local bars_both = itbl.bars * .9
		if itbl.bars >= 3 then
			bars_scroll = itbl.bars - scroll[bar]
			bars_hammer = bars_hammer - hammer[bar]
			bars_both = bars_both - scroll[bar]
		end
		local profit1 = coins( ( item_price - bar_price * itbl.bars) / itbl.xp .. 'round2' )
		local profit2 = coins( ( item_price - bar_price * (bars_scroll or itbl.bars) ) / itbl.xp ..' round2' )
		local profit3 = coins( ( item_price - bar_price * bars_both ) / (itbl.xp * 1.1) .. ' round2' )
		local profit4 = coins( ( item_price - bar_price * bars_hammer ) / (itbl.xp * 1.1) .. ' round2' )
		ret_tbl	:tag('tr')
				:tag('td')
					:wikitext('[[File:'..item..'.png|link='..item..']]')
				:done()
				:tag('td')
					:wikitext('[['..item..']]')
				:done()
				:tag('td')
					:wikitext(itbl.level)
				:done()
				:tag('td')
					:wikitext(itbl.bars)
				:done()
				:tag('td')
					:wikitext(itbl.xp)
				:done()
				:tag('td')
				:css('text-align','right')
					:wikitext(item_price_1)
				:done()
				:tag('td')
					:css('text-align','right')
					:wikitext(profit1)
				:done()
				:tag('td')
					:css('text-align','right')
					:wikitext(profit2)
				:done()
				:tag('td')
					:css('text-align','right')
					:wikitext(profit3)
				:done()
				:tag('td')
					:css('text-align','right')
					:wikitext(profit4)
				:done()
			:done()
	end
	ret = ret..'\n\nIn the table below, the first Profit/XP column is the base, the second column includes calculations for the [[scroll of efficiency]], the third column includes calculations for both the scroll of efficiency and a [[portable forge]], and the fourth column includes calculations for the scroll of efficiency, crystal hammer, and a [[portable forge]]. The GE Price given is that of 1 item; not the entire stack produced. For example, 10 dart tips are made with 1 bar, the price given is that of 1 tip.\n'..tostring(ret_tbl)
 
	return ret 
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.