Module:DungTable

-- local p = {}

local yesno = require('Module:Yesno')

local tiers = { -- tier = {level,{metal,leather,cloth,wood}} -- spaces put here to avoid an extra catch for ecto items {'1',{'Novite ','Protoleather ','Salve ','Tangle gum '}}, {'10',{'Bathus ','Subleather ','Wildercress ','Seeping elm '}}, {'20',{'Marmaros ','Paraleather ','Blightleaf ','Blood spindle '}}, {'30',{'Kratonite ','Archleather ','Roseblood ','Utuku '}}, {'40',{'Fractite ','Dromoleather ','Bryll ','Spinebeam '}}, {'50',{'Zephyrium ','Spinoleather ','Duskweed ','Bovistrangler '}}, {'60',{'Argonite ','Gallileather ','Soulbell ','Thigat '}}, {'70',{'Katagon ','Stegoleather ','Ecto','Corpsethorn '}}, {'80',{'Gorgonite ','Megaleather ','Runic ','Entgallow '}}, {'90',{'Promethium ','Tyrannoleather ','Spiritbloom ','Gravecreeper '}}, {'99',{'Primal ','Sagittarian ','Celestial ','Sagittarian '}} }

local reqs = { -- type = {{skills},Y for tier[X][Y]} ['dagger'] = {{'Attack'},1}, ['rapier'] = {{'Attack'},1}, ['longsword'] = {{'Attack'},1}, ['battleaxe'] = {{'Attack'},1}, ['warhammer'] = {{'Attack'},1}, ['spear'] = {{'Attack'},1}, ['2h sword'] = {{'Attack'},1}, ['maul'] = {{'strength'},1}, ['pickaxe'] = {{'Attack','Mining'},1}, ['hatchet'] = {{'Attack','Woodcutting'},1}, ['full helm'] = {{'Defence'},1}, ['chainbody'] = {{'Defence'},1}, ['platebody'] = {{'Defence'},1}, ['plateskirt'] = {{'Defence'},1}, ['platelegs'] = {{'Defence'},1}, ['kiteshield'] = {{'Defence'},1}, ['melee boots'] = {{'Defence'},1}, ['gauntlets'] = {{'Defence'},1}, ['shortbow'] = {{'Ranged'},4}, ['longbow'] = {{'Ranged'},4}, ['arrows'] = {{'Ranged'},1}, ['knife'] = {{'Ranged'},1}, ['coif'] = {{'Ranged','Defence'},2}, ['body'] = {{'Ranged','Defence'},2}, ['chaps'] = {{'Ranged','Defence'},2}, ['vambraces'] = {{'Ranged','Defence'},2}, ['ranged shield'] = {{'Ranged','Defence'},2}, ['ranged boots'] = {{'Ranged','Defence'},2}, ['staff'] = {{'Magic'},4}, ['wand'] = {{'Magic'},4}, ['orb'] = {{'Magic'},3}, ['hood'] = {{'Magic','Defence'},3}, ['robe top'] = {{'Magic','Defence'},3}, ['robe bottom'] = {{'Magic','Defence'},3}, ['gloves'] = {{'Magic','Defence'},3}, ['shoes'] = {{'Magic','Defence'},3}, ['magic shield'] = {{'Magic','Defence'},3} }

-- types that can have offhands local off_hands = { ['dagger'] = true, ['rapier'] = true, ['longsword'] = true, ['battleaxe'] = true, ['warhammer'] = true, ['knife'] = true }

local plurals = { -- default is +s ['knife'] = 'knives', ['chainbody'] = 'chainbodies', ['platebody'] = 'platebodies', ['body'] = 'bodies', ['melee boots'] = 'boots', ['ranged boots'] = 'boots', ['gauntlets'] = 'gauntlets', ['chaps'] = 'chaps', ['vambraces'] = 'vambraces', ['gloves'] = 'gloves', ['shoes'] = 'shoes', ['platelegs'] = 'platelegs' }

function p._main(frame) local args = frame:getParent.args local item = string.lower(args[1] or 'dagger') local type = args.type if type and reqs[type:lower] then item = type:lower .. ' ' .. item end local offhand = yesno(args.offhand) if offhand and off_hands[item] then offhand = true else offhand = false end return main(item,offhand) end

function main(item,offhand) local caption = plurals[item] or (item .. 's') if offhand then caption = 'off-hand ' .. item end local ret = mw.html.create('table') :addClass('wikitable') :tag('caption') :wikitext('Table of ' .. caption) :done :tag('tr') :tag('th') :wikitext('Tier') :done :tag('th') :wikitext('Item') :done :tag('th') :wikitext('Levels to use') :done :done

for i, v in ipairs(tiers) do		local level = v[1] local mats = v[2] local requirements = reqs[item] local skill_req = requirements[1] local mat_req = mats[requirements[2]] local item_name = mat_req .. item:gsub('(magic|melee|ranged) ','') -- catch for oddballs if i == 8 then if item == 'wand' then item_name = 'Ecto wand' elseif item == 'orb' then item_name = 'Ectosphere' end elseif i == 11 then if item == 'staff' then item_name = 'Celestial catalytic staff' elseif item == 'wand' then item_name = 'Celestial catalytic wand' elseif item == 'orb' then item_name = 'Celestial catalytic orb' elseif item == 'arrows' then item_name = 'Sagittarian arrows' end end ret:tag('tr') :tag('td') :css('text-align','center') :wikitext(i) :done :tag('td') :wikitext(' '..item_name..'') :done :tag('td') :wikitext(skill_reqs(item,level)) :done :done end return ret end

function skill_reqs(item,level) local req = reqs[item] local ret = '' for i, v in ipairs(req) do ret = ret .. level .. ' ; '	end -- remove last 2 characters ret = ret:sub(1,-3) return ret end

return p