Module:Disassembly category calculator

-- -- code for Template:Disassembly category calculator/t -- -> Calculator:Disassembly by category local p = {}

local cats = mw.loadData('Module:Disassemble/data') local exg = require('Module:ExchangeLite') local coin = require('Module:Coins')._amount local x = '×'

local function gep(item) local err, val = pcall(exg.load, {args={item, 'price'}}) if err then return val else return 0 end end

local function junk(lv) local junkpast75 = { [75] = 4.2, [76] = 3.8, [77] = 3.4, [78] = 3.0, [79] = 2.7,		[80] = 2.3, [81] = 2.0, [82] = 1.7, [83] = 1.4, [84] = 1.2,		[85] = 1.0, [86] = 0.8, [87] = 0.6, [88] = 0.4, [89] = 0.3 }	lv = tonumber(lv) or 1 if lv >= 90 then return 0 elseif lv >= 75 then return junkpast75[lv] else return 100 - 1.1 * lv	end end

local function plink(item) return string.format(' %s', item, item, item) end

local function coins(td, am) if am == 0 then td	:wikitext("N/A") :css('text-align', 'center') :addClass('table-na') else td	:wikitext(coin(am, false)) end td	:attr('data-sort-value', am) end

local function make_row(data) local tr = mw.html.create('tr') local str local valbase = data.price * data.iqty / (data.cqty * (1 - data.junk/100)) local valjcr5 = data.price * data.iqty / (data.cqty * (1 - math.ceil(10*0.91*data.junk)/1000)) local valjcr9 = data.price * data.iqty / (data.cqty * (1 - math.ceil(10*0.8*data.junk)/1000)) if data.iqty > 1 then str = string.format('%s %s %s', data.iqty, x, plink(data.page)) else str = plink(data.page) end tr	:tag('td') :wikitext(str) :done :tag('td') :wikitext(data.cqty) :done :tag('td') :wikitext(string.format('%.1f%%', data.junk)) :done coins(tr:tag('td'), valbase) coins(tr:tag('td'), valjcr5) coins(tr:tag('td'), valjcr9) return tr end

p.main = function(frame) local args = frame:getParent.args local data = {} local cat = cats[string.lower(args.category)] data.page = args['%PAGE%'] data.junk = junk(args.level) data.iqty = tonumber(cat.itemqty) or 1 data.cqty = tonumber(cat.compqty) or 1 data.price = gep(data.page) return make_row(data) end

return p