Module:Disassemble

-- local edit_mod = require('Module:Edit button') local edit = edit_mod('Unknown') local onmain_mod = require('Module:Mainonly').on_main local onmain = onmain_mod

local p = {}

local pre = '[[Category:Items that disassemble into ' local post = ']]'

local materials = { ['Base parts'] = pre .. 'Base parts' .. post, ['Blade parts'] = pre .. 'Blade parts' .. post, ['Clear parts'] = pre .. 'Clear parts' .. post, ['Connector parts'] = pre .. 'Connector parts' .. post, ['Cover parts'] = pre .. 'Cover parts' .. post, ['Crafted parts'] = pre .. 'Crafted parts' .. post, ['Crystal parts'] = pre .. 'Crystal parts' .. post, ['Delicate parts'] = pre .. 'Delicate parts' .. post, ['Deflecting parts'] = pre .. 'Deflecting parts' .. post, ['Flexible parts'] = pre .. 'Flexible parts' .. post, ['Head parts'] = pre .. 'Head parts' .. post, ['Magic parts'] = pre .. 'Magic parts' .. post, ['Metallic parts'] = pre .. 'Metallic parts' .. post, ['Organic parts'] = pre .. 'Organic parts' .. post, ['Padded parts'] = pre .. 'Padded parts' .. post, ['Plated parts'] = pre .. 'Plated parts' .. post, ['Simple parts'] = pre .. 'Simple parts' .. post, ['Smooth parts'] = pre .. 'Smooth parts' .. post, ['Spiked parts'] = pre .. 'Spiked parts' .. post, ['Spiritual parts'] = pre .. 'Spiritual parts' .. post, ['Stave parts'] = pre .. 'Stave parts' .. post, ['Tensile parts'] = pre .. 'Tensile parts' .. post, ['Dextrous components'] = pre .. 'Dextrous components' .. post, ['Direct components'] = pre .. 'Direct components' .. post, ['Enhancing components'] = pre .. 'Enhancing components' .. post, ['Ethereal components'] = pre .. 'Ethereal components' .. post, ['Evasive components'] = pre .. 'Evasive components' .. post, ['Healthy components'] = pre .. 'Healthy components' .. post, ['Heavy components'] = pre .. 'Heavy components' .. post, ['Imbued components'] = pre .. 'Imbued components' .. post, ['Light components'] = pre .. 'Light components' .. post, ['Living components'] = pre .. 'Living components' .. post, ['Pious components'] = pre .. 'Pious components' .. post, ['Powerful components'] = pre .. 'Powerful components' .. post, ['Precious components'] = pre .. 'Precious components' .. post, ['Precise components'] = pre .. 'Precise components' .. post, ['Protective components'] = pre .. 'Protective components' .. post, ['Refined components'] = pre .. 'Refined components' .. post, ['Sharp components'] = pre .. 'Sharp components' .. post, ['Strong components'] = pre .. 'Strong components' .. post, ['Stunning components'] = pre .. 'Stunning components' .. post, ['Subtle components'] = pre .. 'Subtle components' .. post, ['Swift components'] = pre .. 'Swift components' .. post, ['Variable components'] = pre .. 'Variable components' .. post, ['Ancient components'] = pre .. 'Ancient components' .. post, ['Armadyl components'] = pre .. 'Armadyl components' .. post, ['Ascended components'] = pre .. 'Ascended components' .. post, ['Augmented components'] = pre .. 'Augmented components' .. post, ['Bandos components'] = pre .. 'Bandos components' .. post, ['Brassican components'] = pre .. 'Brassican components' .. post, ['Corporeal components'] = pre .. 'Corporeal components' .. post, ['Culinary components'] = pre .. 'Culinary components' .. post, ['Dragonfire components'] = pre .. 'Dragonfire components' .. post, ['Explosive components'] = pre .. 'Explosive components' .. post, ['Fortunate components'] = pre .. 'Fortunate components' .. post, ['Fungal components'] = pre .. 'Fungal components' .. post, ['Harnessed components'] = pre .. 'Harnessed components' .. post, ['Knightly components'] = pre .. 'Knightly components' .. post, ['Noxious components'] = pre .. 'Noxious components' .. post, ['Oceanic components'] = pre .. 'Oceanic components' .. post, ['Pestiferous components'] = pre .. 'Pestiferous components' .. post, ['Refined components'] = pre .. 'Refined components' .. post, ['Resilient components'] = pre .. 'Resilient components' .. post, ['Rumbling components'] = pre .. 'Rumbling components' .. post, ['Saradomin components'] = pre .. 'Saradomin components' .. post, ['Seren components'] = pre .. 'Seren components' .. post, ['Shifting components'] = pre .. 'Shifting components' .. post, ['Silent components'] = pre .. 'Silent components' .. post, ['Zamorak components'] = pre .. 'Zamorak components' .. post, ['Zaros components'] = pre .. 'Zaros components' .. post }

function p.main(frame) local args = frame:getParent.args local common = {} local rare = {} local uncommon = {} local special = {} local cats = {''}

local xp = tonumber(args.xp) if not xp then xp = edit table.insert(cats, '') end

local junk = tonumber(args.junk) if junk then if junk == 0 then table.insert(cats, '') end junk = string.gsub(junk, '%%', '') -- remove % if present junk = junk .. '%'	else junk = edit table.insert(cats, '') end

local cqty = tonumber(args.compqty) if not cqty then cqty = edit table.insert(cats, '') end local iqty = tonumber(args.itemqty) or 1

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

for _, v in ipairs(_common) do		v = string.gsub(v, '%[%[(.+)%]%]', '%1') 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 }) for name, cat in pairs(materials) do			   if n == name then table.insert(cats, cat) end end end end

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

for _, v in ipairs(_uncommon) do		v = string.gsub(v, '%[%[(.+)%]%]', '%1') 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 }) for name, cat in pairs(materials) do			   if n == name then table.insert(cats, cat) end end end end local _rare = mw.text.split(args.rarely or args.rare or '','%s*,%s')

for _, v in ipairs(_rare) do		v = string.gsub(v, '%[%[(.+)%]%]', '%1') 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 }) for name, cat in pairs(materials) do			   if n == name then table.insert(cats, cat) end end end end local _special = mw.text.split(args.special or '','%s*,%s')

for _, v in ipairs(_special) do		v = string.gsub(v, '%[%[(.+)%]%]', '%1') 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 }) for name, cat in pairs(materials) do			   if n == name then table.insert(cats, cat) end end end end

if (#special + #common + #uncommon + #rare) < 1 then table.insert(cats, '') end

if onmain then cats = table.concat(cats) else --cats = table.concat(cats) cats = '' end

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

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

local _t = ret:tag('table') :addClass('wikitable') :css('width','300px') :tag('tr') :tag('th') :attr('title', 'The amount of experience received from disassembling the item') :wikitext('Disassembly XP ?') :done :tag('td') :wikitext(xp) :done :done :tag('tr') :tag('th') :attr('title', 'The amount of the item needed before disassembling') :wikitext('Item quantity required ?') :done :tag('td') :wikitext(iqty) :done :done :tag('tr') :tag('th') :attr('title', 'The base chance of receiving junk') :wikitext('Junk chance ?') :done :tag('td') :wikitext(junk) :done :done :tag('tr') :tag('th') :attr('title', 'The amount of materials received normally (excluding specials), shown in chat window') :wikitext('Total materials received ?') :done :tag('td') :wikitext(cqty) :done :done :tag('tr') :tag('td') :attr('colspan','2') :done :done :tag('tr') :tag('th') :attr('colspan','2') :css('background','#e5e5e5') :wikitext('Possible materials') :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