FANDOM


-- <nowiki>
 
local p = {}
local coins = require('Module:Coins')
 
function table.shallow_copy(t)
  local t2 = {}
  for k,v in pairs(t) do
    t2[k] = v
  end
  return t2
end
 
function table.remove_by_value(t, val)
	for k,v in pairs(t) do
		if v == val then
			table.remove(t, k)
			return
		end
	end
end
 
function b2i(b)
	return b and 1 or 0
end
 
local runes = {
	"Air", "Water", "Earth", "Fire", "Dust", "Lava", "Mist", "Mud", "Smoke", "Steam", "Mind", "Body", "Cosmic", "Chaos", "Nature", "Law", "Death", "Astral", "Blood", "Soul"
}
 
local rune_quantities = {
	1000, 1000, 1000, 1000, 500, 500, 500, 300, 500, 500, 2000, 2000, 400, 500, 350, 300, 400, 300, 350, 300
}
 
function get_prices(frame)
	local prices = {}
 
	for _, r in pairs(runes) do
		table.insert(prices, tonumber(frame:expandTemplate{ title = 'GEP', args = { r .. " rune" } }))
	end
 
	return prices
end
 
function p.quantity(frame)
	local index = tonumber(frame.args[1])
	if index == 0 or index > #rune_quantities then
		return ""
	else
		return rune_quantities[index]
	end
end
 
function p.table(frame)
	local prices = get_prices(frame)
 
	local t = mw.html.create('table')
	          :addClass('wikitable sortable')
	          :tag('tr')
	              :tag('th'):wikitext('Rune'):done()
	              :tag('th'):wikitext('Amount needed'):done()
	              :tag('th'):wikitext('Price per rune'):done()
	              :tag('th'):wikitext('Total price'):done()
	          :done()
 
	for i, r in pairs(runes) do
		t:tag('tr')
			:tag('td'):wikitext('[[File:' .. r .. ' rune.png]] [[' .. r .. ' rune]]'):done()
			:tag('td'):wikitext(rune_quantities[i]):done()
			:tag('td'):wikitext(coins._amount(prices[i])):done()
			:tag('td'):wikitext(coins._amount(rune_quantities[i] * prices[i])):done()
	end
 
	return t
end
 
function p.main(frame)
	local prices = get_prices(frame)
 
	local remaining_runes = table.shallow_copy(runes)
 
	for _, arg in pairs(frame.args) do
		local a = tonumber(arg)
		if a ~= 0 then
			table.remove_by_value(remaining_runes, runes[a])
		end
	end
 
	local r1 = tonumber(frame.args[1])
	local r21 = tonumber(frame.args[2])
	local r22 = tonumber(frame.args[3])
	local r23 = tonumber(frame.args[4])
	local r3 = tonumber(frame.args[5])
 
	local r1unknown = r1 == 0
	local r2unknown = r21 + r22 + r23 == 0
	local r3unknown = r3 == 0
 
	local total_unknowns = b2i(r1unknown) + b2i(r2unknown) + b2i(r3unknown)
 
	local average_price = 0
 
	if not r1unknown then
		average_price = average_price + rune_quantities[r1] * prices[r1]
	end
 
	local best_rune2 = "Unknown"
	if not r2unknown then
		local min_price = -1
		for i=2,4 do
			local n = tonumber(frame.args[i])
			if n ~= 0 then
				local price = rune_quantities[n] * prices[n]
				if price < min_price or min_price == -1 then
					min_price = price
					best_rune2 = runes[n]
				end
			end
		end
 
		average_price = average_price + min_price
	end
 
	if not r3unknown then
		average_price = average_price + rune_quantities[r3] * prices[r3]
	end
 
	local sum = 0
	for k, _ in pairs(remaining_runes) do
		sum = sum + rune_quantities[k] * prices[k]
	end
	local avg = sum / #remaining_runes
 
	average_price = average_price + avg * total_unknowns
 
	local vis_wax_price = tonumber(frame:expandTemplate{ title = 'GEP', args = { "Vis wax" } })
 
	local profit = vis_wax_price * 100 - average_price
 
	local prefix = total_unknowns == 0 and "Price" or "Expected (average) price"
 
	return prefix .. " for 100 vis wax: " .. coins._amount(average_price) .. "<br>Expected profit: " .. coins._amount(profit) .. "<br>Cheapest 2nd rune is: " .. best_rune2 .. " rune"
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.