Module:Dungeon

--Get Required Modules local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs

local string, table, yesno, lu, color, item = loader.require('String', 'Table', 'Yesno', 'LibraryUtil', 'Color', 'Item')

local addColor = color._color local checkType = lu.checkType

local p = {}

local pieces = { 'Helmet', 'Chestplate', 'Leggings', 'Boots', } local prefixes = { ['Helmet'] = 'h', ['Chestplate'] = 'c', ['Leggings'] = 'l', ['Boots'] = 'b', }

--- -- Template:Star -- -- Produces the star icon --- function p.stars(frame) local args = getArgs(frame) local amount = tonumber(args[1]) or 1 local unfilled = args.unfilled return string.pcall(unfilled and p._stars or p._unfilledstars, amount) end

function p._stars(amount) return string._repeat('', amount, ' ') end

function p._unfilledstars(amount) return string.wrapHtml(p._stars(amount),		'span', { style = 'opacity: .2;' }	) end

--- -- Template:Dungeon Ranking -- -- Produces colored dungeon score with link to the Dungeons Score page and a hover info with the dungeon score needed to get that ranking. --- function p.dungeonRanking(frame) local args = getArgs(frame) local val = args[1] local nolink = yesno(args['nolink'] or args['no_link'] or args['nl'], false) return string.pcall(p._dungeonRanking, val, nolink) end

--Module Access Point function p._dungeonRanking(val, nolink) checkType('dungeonsRanking', 1, val, 'string') checkType('dungeonsRanking', 2, nolink, 'boolean', true) local data = { ['D'] = { color = '#fc2803', score = 'between 0 and 99' },		['C'] = { color = '#0373fc', score = 'between 100 and 159' },		['B'] = { color = '#40a40c', score = 'between 160 and 229' },		['A'] = { color = '#b700ff', score = 'between 230 and 269' },		['S'] = { color = '#ffc800', score = 'between 270 and 299' },		['S+'] = { color = '#ffc800', score = 'above 300' }	}	local col = data[val:upper].color or error('Invalid value "'..val..'"', 2) local score = data[val:upper].score val = val:upper val = addColor(col, val) val = string.wrapHtml(val, 'b') val = string.wrapHtml(val, 'abbr', {title = 'Score '..score..' points. Click to go to Dungeon Score page.'}) val = nolink and val or string.wrapLink('Dungeon Score', val) return val end

--- --Template:Essence Crafting -- --Produces a table with all tiers of essence crafting (star upgrading) --- function p.essenceCrafting(frame) local args = getArgs(frame) local type = args['type'] or args['t'] local essence = args['essence'] or args['e'] local allPiecesSameStats = yesno(args['all_pieces_same_stats'], false) return p._essenceCrafting(type, essence, args, allPiecesSameStats) end

function p._essenceCrafting(type, essence, args, allPiecesSameStats) checkType('essenceCrafting', 1, type, 'string') checkType('essenceCrafting', 2, essence, 'string') checkType('essenceCrafting', 3, args, 'table') essence = mw.text.trim(essence:gsub('[Ee][Ss][Ss][Ee]?[Nn]?[Cc]?[Ee]?', '')) type = type:lower --start the table and make the essence row local wikitable = mw.html.create('table'):addClass('wikitable'):addClass('centertext'):css('border', '3px solid gray') local function forWeapon local costs = { convert = tonumber(args[6]) or tonumber(args['convert']) or tonumber(args['c']) or nil }		for i = 1, 5 do			costs[i] = tonumber(args[i]) end wikitable:tag('tr') :tag('th'):attr('colspan', 3):wikitext(('Essence Required \'\'\'%s Essence\'\'\''):format( essence, essence, essence )):css('white-space: nowrap; padding: 1em 2em !important;'):done :done wikitable:tag('tr') :tag('th'):wikitext('Action'):done :tag('th'):css({ ['width']='80px' }):wikitext('Cost'):done :tag('th'):css({ ['width']='80px' }):wikitext('Cumulative'):done :done if costs.convert then wikitable:tag('tr') :tag('td'):wikitext(string.makeTitle('Conversion', 'The cost of the conversion to a dungeon item.')):done :tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs.convert))):done :done end local cumulative = 0 for i = 1, 5, 1 do			cumulative = cumulative + costs[i] wikitable:tag('tr') :tag('td'):wikitext(('%s %s'):format(p._stars(i), p._unfilledstars(5 - i))):css('white-space', 'nowrap'):done :tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs[i]))):done :tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative))):done :done end end local function forArmor local costs = {} if allPiecesSameStats then local costs_temp = { convert = tonumber(args[6]) or tonumber(args['convert']) or tonumber(args['c']) or nil }			for i = 1, 5 do				costs_temp[i] = tonumber(args[i]) end costs = {} for _, piece in ipairs(pieces) do				costs[piece] = costs_temp end else for _, piece in ipairs(pieces) do				costs[piece] = {} for i = 1, 5 do costs[piece][i] = tonumber(args[prefixes[piece] .. i]) end costs[piece].convert = tonumber(args[prefixes[piece] .. '_convert']) or tonumber(args[prefixes[piece] .. '_c']) or 0 end end wikitable:tag('tr') :tag('th'):attr('colspan', 11):wikitext(('Essence Required \'\'\'%s Essence\'\'\''):format( essence, essence, essence )):css('white-space: nowrap; padding: 1em 2em !important;'):done :done local row = wikitable:tag('tr') :tag('th'):attr('rowspan', 2):wikitext('Action') :done for _, piece in ipairs(pieces) do			if costs[piece] then row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext((piece)):done end end row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Whole Set'):done row = wikitable:tag('tr') for _, piece in ipairs(pieces) do			if costs[piece][1] then row:tag('th'):css({ ['width']='60px' }):wikitext('Cost'):done row:tag('th'):css({ ['width']='60px' }):wikitext(string.makeTitle('Cumul.', 'Cumulative')):done else row:tag('td'):attr({ ['colspan']=2, ['rowspan']=7 }):css({ ['width']='120px', ['border-right-width']='2px' }) :wikitext(string.blankCell):done end end row:tag('th'):css({ ['width']='60px' }):wikitext('Cost'):done row:tag('th'):css({ ['width']='60px' }):wikitext(string.makeTitle('Cumul.', 'Cumulative')):done -- Conversion if costs.Helmet.convert or costs.Chestplate.convert or costs.Leggings.convert or costs.Boots.convert then row = wikitable:tag('tr') :tag('td') :wikitext(string.makeTitle('Conversion', 'The cost of the conversion to a dungeon item.')) :done end local wholeSet = { convert = 0, stars = 0 }		for _, piece in ipairs(pieces) do			if costs[piece][1] and costs[piece].convert then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs[piece].convert))):done wholeSet.convert = wholeSet.convert + costs[piece].convert end end if wholeSet.convert > 0 then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(wholeSet.convert))):done end local cumulative = { Helmet = 0, Chestplate = 0, Leggings = 0, Boots = 0, wholeSet = 0 }		for i = 1, 5, 1 do			wholeSet.stars = 0 row = wikitable:tag('tr') row:tag('td'):wikitext(('%s %s'):format(p._stars(i), p._unfilledstars(5 - i))):css('white-space', 'nowrap'):done for _, piece in ipairs(pieces) do				if costs[piece][i] then cumulative[piece] = cumulative[piece] + costs[piece][i] row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs[piece][i]))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative[piece]))):done wholeSet.stars = wholeSet.stars + costs[piece][i] end end cumulative.wholeSet = cumulative.wholeSet + wholeSet.stars row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(wholeSet.stars))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative.wholeSet))):done end end if type == 'weapon' or type == 'w' then forWeapon elseif type == 'armor' or type == 'a' then forArmor else error(string.format('Invalid item type "%s"', type), 2) end return tostring(wikitable) end

return p