FANDOM


-- <nowiki>
-- implements [[Template:Bank value]]
 
-- dependencies: [[Module:ExchangeLite]], [[Module:Addcommas]]
local exg = require('Module:ExchangeLite')
local commas = require('Module:Addcommas')._add
 
local p = {}
 
local total
local table
 
--check if item exists, per [[Module:Exchange]]
local function exists(item)
    local noErr, data = pcall( mw.loadData, 'Module:Exchange/' .. item )
 
    if noErr then
        return true
    end
 
    return false
end
 
local function gep(item, qty)
    if exists(item) then
        return exg.load({args = {item, 'price'}}) * tonumber(qty)
    else
        return 0
    end
end
 
local function plink(item)
    return '[[File:' .. item .. '.png|link=' .. item .. ']] [[' .. item .. ']]'
end
 
local function row(item, qty)
    local p  = gep(item, qty)
    table   :tag('tr')
                :tag('td')
                    :wikitext(plink(item))
                :done()
                :tag('td')
                    :css('text-align','right')
                    :wikitext(qty)
                :done()
                :tag('td')
                    :css('text-align','right')
                    :wikitext(commas(p))
                :done()
            :done()
    total = total + p
end
 
p.main = function(frame)
    local args = frame:getParent().args
    total = 0
    table = mw.html.create('table')
 
    if args.align then
        table:css('float', args.align)
    end
 
    if args.style then
        table:cssText(args.style)
    end
 
    if args.class then
        table:addClass(args.class)
    else
        table:addClass('sortable mw-collapsible')
    end
 
    table   :addClass('wikitable')
            :tag('caption')
                :wikitext(args.title or 'Bank value')
            :done()
            :tag('tr')
                :tag('th')
                    :wikitext('Item')
                :done()
                :tag('th')
                    :wikitext('Quantity')
                :done()
                :tag('th')
                    :wikitext('Value')
                :done()
            :done()
        :done()
    if args.coins and tonumber(args.coins) then
        table:tag('tr')
                :tag('td')
                    :attr('colspan', '2')
                    :wikitext('[[File:Coins 10000.png]] [[Coins]]')
                :done()
                :tag('td')
                    :css('text-align','right')
                    :wikitext(commas(tonumber(args.coins)))
                :done()
            :done()
        total = total + tonumber(args.coins)
    end
 
    local i = 1
    while args[i] and args[i+1] do
        row(args[i], args[i+1])
        i = i + 2
    end
 
    table   :tag('tr')
                :addClass('sortbottom')
                :tag('th')
                    :attr('colspan', '2')
                    :wikitext('Total')
                :done()
                :tag('th')
                    :css('text-align','right')
                    :wikitext(commas(total))
                :done()
            :done()
 
    return table
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.