FANDOM


-- <nowiki>
 
local p = {}
 
local get_price = require('Module:Exchange')._price
local get_value = require('Module:Exchange')._value
local skillpic = require('Module:Skill clickpic')._main
local coins = require('Module:Coins')._amount
 
function p.main(frame)
	local args = frame:getParent().args
	local item = args.item
	local itemqty = tonumber(args.itemn) or 1
	local hasexchange, value = pcall(get_value,item)
	local price
	if hasexchange then
		price = get_price(item,itemqty)
	else
		value = args.value or nil
	end
	value = value * itemqty
	local materials = {}
	local i = 1
 
	local function mat_price(matx)
		local hasexg, mat_p = pcall(get_price, matx)
		if hasexg then
			return mat_p
		else
			return 0
		end
	end
 
	while args['mat'..i] do
		table.insert(materials, {
				name = args['mat'..i],
				qty = tonumber(args['mat'..i..'n']) or 1,
				price = mat_price(args['mat'..i])
		} )
		i = i+1
	end
	if args.core then
		table.insert(materials,100, {
				name = args.core,
				qty = tonumber(args.coren) or 1,
				price = mat_price(args.core)
		} )
	end
	local bxp = tonumber(args.bxp) or 0
	local bxpskill = args.bxpskill
	return p._main(item,itemqty,price,value,bxp,bxpskill,materials)
end
 
function p._main(item,itemqty,price,value,bxp,bxpskill,materials)
	local spring_p = get_price('Spring')
	local nat_p = get_price('Nature rune',itemqty)
	local core = materials[100]
	table.remove(materials,100)
	local highalch = math.floor(value*.6)
	local other_mats
	if (#materials > 0) then
		other_mats = true
	end
	local total_cost = 0
	local core_item
	if core then
		total_cost = total_cost + core.price * core.qty
		if core.qty > 1 then
			core_item = core.qty .. '&nbsp;[['..core.name..']]'
		else
			core_item = '[['..core.name..']]'
		end
		if other_mats then
			core_item = core_item .. '<br>'
		end
	end
	local mat_list
	if other_mats then
		mat_list = ''
		for i, v in ipairs(materials) do
			total_cost = total_cost + v.price * v.qty
			if v.qty > 1 then
				mat_list = mat_list .. v.qty .. '&nbsp;[['..v.name..']]'
			else
				mat_list = mat_list .. '[['..v.name..']]'
			end
			if i < #materials then
				mat_list = mat_list .. '<br>'
			end
		end
	end
	local itemlink = '[['..item..']]'
	if itemqty > 1 then
		itemlink = itemqty..'&nbsp;'..itemlink
	end
	local ret = mw.html.create('tr')
			:tag('td')
				:wikitext('[[File:'..item..'.png|link='..item..']]')
			:done()
			:tag('td')
				:wikitext(itemlink)
			:done()
			:tag('td')
				:wikitext(bxp..' '..skillpic(bxpskill))
			:done()
			:tag('td')
				:wikitext(coins(-(price/bxp)))
			:done()
			:tag('td')
				:wikitext(coins(-(total_cost/bxp)))
			:done()
	if core then
		ret:tag('td')
			:wikitext(core_item)
		:done()
	end
	if other_mats then
		ret:tag('td')
			:wikitext(mat_list)
		:done()
	end
	-- Full success/No core success
	ret	:tag('td')
			:wikitext(coins(total_cost - spring_p))
		:done()
		:tag('td')
			:wikitext(coins(total_cost - price - spring_p))
		:done()
		:tag('td')
			:wikitext(coins(total_cost - spring_p - highalch + nat_p))
		:done()
	-- Partial success
	if core and other_mats then
		local part_cost = core.price * core.qty
		ret	:tag('td')
				:wikitext(coins(part_cost - spring_p))
			:done()
			:tag('td')
				:wikitext(coins(part_cost - price - spring_p))
			:done()
			:tag('td')
				:wikitext(coins(part_cost - spring_p - highalch + nat_p))
			:done()
	end
	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.