Module:Essence

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Essence/doc. [edit]
Module:Essence's function essence is invoked by Template:Essence.
Module:Essence requires Module:Coins.
Module:Essence requires Module:ExchangeLite.
Module:Essence requires Module:Paramtest.
Function list
L 48 — plink
L 66 — plinkp
L 70 — p.essence
L 73 — p._essence
L 84 — p._main

local p = {}

local gemw = require('Module:ExchangeLite')
local coins = require('Module:Coins')
local uclc = require('Module:Paramtest').ucflc

local data = {
	malevolent = {	-- Malevolent Essence
		{name = 'Malevolent helm',		bbc = 2},		
		{name = 'Malevolent cuirass',	bbc = 6},
		{name = 'Malevolent greaves',	bbc = 4},
		set = 12
	},
	['praesulic-melee'] = {			-- Praesulic Essence
		{name = 'Torva full helm',	bbc = 2},
		{name = 'Torva platebody',	bbc = 5},
		{name = 'Torva platelegs',	bbc = 3},
		{name = 'Torva gloves',		bbc = 1},
		{name = 'Torva boots',		bbc = 1},
		set = 12
	},
	['praesulic-magic'] = {
		{name = 'Virtus mask',		bbc = 2},
		{name = 'Virtus robe top',	bbc = 5},
		{name = 'Virtus robe legs',	bbc = 3},
		{name = 'Virtus gloves',	bbc = 1},
		{name = 'Virtus boots',		bbc = 1},
		set = 12
	},
	['praesulic-ranged'] = {
		{name = 'Pernix cowl',		bbc = 2},
		{name = 'Pernix body',		bbc = 5},
		{name = 'Pernix chaps',		bbc = 3},
		{name = 'Pernix gloves',	bbc = 1},
		{name = 'Pernix boots',		bbc = 1},
		set = 12
	}
}
for j,k in pairs(data) do
	k['min'] = math.inf
	for i,v in ipairs(k) do
		v.price = gemw.price(v.name)
		k['min'] = math.min(v.price / v.bbc)
	end
end
local ticks = 10	-- Number of ticks per base bar cost it takes to turn items into essence

function plink(name, opts)
    local file = name.. '.png'
    local link = name
    local text = name
    if type(opts) == 'table' then
        if opts.txt then
            text = opts.txt
        end
        if opts.img then
            file = opts.img
        end
    end
    if text ~= '' then
        text = string.format(' [[%s|%s]]', link,text)
    end

    return string.format('[[File:%s|link=%s]]%s', file, link, text)
end
function plinkp(name, img)
    return plink(name, {img = img, txt = ''})
end

function p.essence(frame)
	return p._essence(frame:getParent().args)
end
function p._essence(args)
	local ess_type = string.lower(args[1] or '')
	local d = data[ess_type]
	
	if not d then
		error('Unrecognised essence type. Use: "malevolent", "praesulic-melee", "praesulic-magic", "praesulic-ranged"')
	end
	
	return p._main(d)
end

function p._main(info)
	local t = mw.html.create('table')
	t:addClass('wikitable align-center-2 align-center-3')
		:tag('tr')
		:tag('th')	:wikitext('Item')				:done()
		:tag('th')	:wikitext('Ticks')				:done()
		:tag('th')	:wikitext('Essence')			:done()
		:tag('th')	:wikitext('Price per essence')	:done()
	
	for index,i in ipairs(info) do
		t:tag('tr')
			:tag('td')	:wikitext(plink(i.name))							:done()
			:tag('td')	:wikitext(i.bbc * ticks)							:done()
			:tag('td')	:wikitext(i.bbc)									:done()
			:tag('td')	:wikitext(coins._amount(math.ceil(i.price/i.bbc)))	:done()
	end
	t:tag('tr')
		:tag('th')	:wikitext('Total')	:done()
		:tag('th')	:wikitext(info.set * ticks)										:done()
		:tag('th')	:wikitext(info.set)												:done()
		:tag('th')	:wikitext(coins._amount(math.ceil(info['min'] * info.set)))		:done()

	return t
end
return p