Module:Disassemble

-- local p = {}

function p.main(frame) local args = frame:getParent.args

local common = {} local rare = {} local uncommon = {} local special = {}

local xp = tonumber(args.xp) or "Unknown" local junk = tonumber(args.junk) or "Unknown" junk = string.gsub(junk, '%%', '') -- remove % if present local iqty = tonumber(args.itemqty) or 1 local cqty = tonumber(args.compqty) or "Unknown"

local _common = mw.text.split(args.often or args.common or '','%s*,%s')

for _, v in ipairs(_common) do		local _,_,n,l = string.find(v,'(.-) ?%[(%d+)%]') if not n then n,l = v,level end if not tonumber(l) then l = 1 end if v:find('%S') then table.insert(common,{ n = n, l = l }) end end

local _uncommon = mw.text.split(args.sometimes or args.uncommon or '','%s*,%s')

for _, v in ipairs(_uncommon) do		local _,_,n,l = string.find(v,'(.-) ?%[(%d+)%]') if not n then n,l = v,level end if not tonumber(l) then l = 1 end if v:find('%S') then table.insert(uncommon,{ n = n, l = l }) end end local _rare = mw.text.split(args.rarely or args.rare or '','%s*,%s')

for _, v in ipairs(_rare) do		local _,_,n,l = string.find(v,'(.-) ?%[(%d+)%]') if not n then n,l = v,level end if not tonumber(l) then l = 1 end if v:find('%S') then table.insert(rare,{ n = n, l = l }) end end local _special = mw.text.split(args.special or '','%s*,%s')

for _, v in ipairs(_special) do		local _,_,n,l = string.find(v,'(.-) ?%[(%d+)%]') if not n then n,l = v,level end if not tonumber(l) then l = 1 end if v:find('%S') then table.insert(special,{ n = n, l = l }) end end

return p._main(special,common,uncommon,rare,xp,junk,iqty,cqty) end

function p._main(special,common,uncommon,rare,xp,junk,iqty,cqty) local ret = mw.html.create('div') :wikitext('This item can be disassembled with the Invention skill.')

local _t = ret:tag('table') :addClass('wikitable') :css('width','300px') :tag('tr') :tag('th') :wikitext('Disassembly XP') :done :tag('td') :wikitext(xp) :done :done :tag('tr') :tag('th') :wikitext('Item quantity required') :done :tag('td') :wikitext(iqty) :done :done :tag('tr') :tag('th') :wikitext('Junk chance') :done :tag('td') :wikitext(junk..'%') :done :done :tag('tr') :tag('th') :attr('colspan','2') :wikitext('Possible components') :done :done :tag('tr') :tag('th') :wikitext('Component quantity') :done :tag('td') :wikitext(cqty) :done :done if #special > 0 then _t:tag('tr') :tag('th') :attr('colspan', '2') :wikitext('Special') :done :done for _, v in ipairs(special) do			_t:tag('tr') :tag('td') :attr('colspan', '2') :wikitext(v.l .. ' × ' .. v.n)				:done :done end end -- common

if #common > 0 then _t:tag('tr') :tag('th') :attr('colspan', '2') :wikitext('Often') :done :done for _, v in ipairs(common) do			_t:tag('tr') :tag('td') :attr('colspan', '2') :wikitext(v.n)				:done :done end end

-- uncommon if #uncommon > 0 then _t:tag('tr') :tag('th') :attr('colspan', '2') :wikitext('Sometimes') :done :done for _, v in ipairs(uncommon) do			_t:tag('tr') :tag('td') :attr('colspan', '2') :wikitext(v.n)				:done :done end end

-- rare if #rare > 0 then _t:tag('tr') :tag('th') :attr('colspan', '2') :wikitext('Rarely') :done :done for _, v in ipairs(rare) do			_t:tag('tr') :tag('td') :attr('colspan', '2') :wikitext(v.n)				:done :done end end

return ret end

return p