Module:Disassemble/sandbox

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

function get_mat_cats(parts) local pre = '[[Category:Items that disassemble into '	local post = ']]' local cats = '' for _,v in ipairs(parts) do		if materials[v.n] then cats = cats .. pre .. materials[v.n] .. post end end return cats end

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 }) 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 }) 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 }) 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 }) end end

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

if onmain then table.insert(cats, get_mat_cats(common)) table.insert(cats, get_mat_cats(uncommon)) table.insert(cats, get_mat_cats(rare)) table.insert(cats, get_mat_cats(special)) cats = table.concat(cats) else 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', 'Experience received for disassembling') :wikitext('Disassembly XP ?') :done :tag('td') :wikitext(xp) :done :done :tag('tr') :tag('th') :attr('title', 'Amount disassembled per action') :wikitext('Item quantity required ?') :done :tag('td') :wikitext(iqty) :done :done :tag('tr') :tag('th') :attr('title', '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