Module:Dungeon

--Get Required Modules local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') local lu = require('Module:LibraryUtil') local addColor = require('Module:Color')._color local wrapHtml = string.wrapHtml local wrapLink = string.wrapLink local yesno = require('Module:Yesno') local itemDisplay = require('Module:Item')._itemDisplay local checkType, checkType, setRequiredArgs, customArgError = unpack{ lu.checkType, lu.checkType, lu.setRequiredArgs, lu.customArgError, } --Begin Exports local p = {}

--- -- Template: Star -- -- Produces the star icon --- function p.stars(frame) local args = getArgs(frame) local amount = tonumber(args[1]) or 1 return string.pcall(p._stars, amount) end function p._stars(amount) checkType('stars', 1, amount, 'number') return string._repeat('', amount, ' ') 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') 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 color = data[val:upper].color or error('Invalid value "'..val..'"', 2) local score = data[val:upper].score val = val:upper val = addColor(color, val) val = wrapHtml(val, "b") val = wrapHtml(val, "abbr", {title = "Score "..score.." points. Click to go to Dungeon Score page."}) val = nolink and val or 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 string.pcall(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') if type == 'weapon' or type == 'w' then local costs = { tonumber(args[1]) or nil, tonumber(args[2]) or nil, tonumber(args[3]) or nil, tonumber(args[4]) or nil, tonumber(args[5]) or nil, convert = tonumber(args[6]) or tonumber(args['convert']) or tonumber(args['c']) or nil }       wikitable:tag('tr') :tag('th'):wikitext('Essence Required'):done :tag('td'):attr('colspan', 2):css({ ['text-align']='left' }):wikitext(itemDisplay(essence..' Essence', true)):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(p._stars(i)):done :tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs[i]))):done :tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative))):done :done end elseif type == 'armor' or type == 'a' then local costs = {} if allPiecesSameStats then local costs_temp = { tonumber(args[1]) or nil, tonumber(args[2]) or nil, tonumber(args[3]) or nil, tonumber(args[4]) or nil, tonumber(args[5]) or nil, convert = tonumber(args[6]) or tonumber(args['convert']) or tonumber(args['c']) or nil }           costs = { helmet = costs_temp, chestplate = costs_temp, leggings = costs_temp, boots = costs_temp }       else costs = { helmet = { tonumber(args['h1']) or nil, tonumber(args['h2']) or nil, tonumber(args['h3']) or nil, tonumber(args['h4']) or nil, tonumber(args['h5']) or nil, convert = tonumber(args['h_convert']) or tonumber(args['h_c']) or 0 },               chestplate = { tonumber(args['c1']) or nil, tonumber(args['c2']) or nil, tonumber(args['c3']) or nil, tonumber(args['c4']) or nil, tonumber(args['c5']) or nil, convert = tonumber(args['c_convert']) or tonumber(args['c_c']) or nil },               leggings = { tonumber(args['l1']) or nil, tonumber(args['l2']) or nil, tonumber(args['l3']) or nil, tonumber(args['l4']) or nil, tonumber(args['l5']) or nil, convert = tonumber(args['l_convert']) or tonumber(args['l_c']) or nil },               boots = { tonumber(args['b1']) or nil, tonumber(args['b2']) or nil, tonumber(args['b3']) or nil, tonumber(args['b4']) or nil, tonumber(args['b5']) or nil, convert = tonumber(args['b_convert']) or tonumber(args['b_c']) or nil }           }        end wikitable:tag('tr') :tag('th'):wikitext('Essence Required'):done :tag('td'):attr('colspan', 10):css({ ['text-align']='left' }):wikitext(itemDisplay(essence..' Essence', true)):done :done local row = wikitable:tag('tr'):tag('th'):attr('rowspan', 2):wikitext('Action'):done if costs.helmet then row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Helmet'):done end if costs.chestplate then row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Chestplate'):done end if costs.leggings then row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Leggings'):done end if costs.boots then row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Boots'):done end row:tag('th'):attr('colspan', 2):css({ ['width']='120px' }):wikitext('Whole Set'):done row:done row = wikitable:tag('tr') if costs.helmet[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 if costs.chestplate[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 if costs.leggings[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 if costs.boots[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 row:tag('th'):css({ ['width']='60px' }):wikitext('Cost'):done row:tag('th'):css({ ['width']='60px' }):wikitext(string.makeTitle('Cumul.', 'Cumulative')):done row: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 }       if costs.helmet[1] and costs.helmet.convert then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs.helmet.convert))):done wholeSet.convert = wholeSet.convert + costs.helmet.convert end if costs.chestplate[1] and costs.chestplate.convert then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs.chestplate.convert))):done wholeSet.convert = wholeSet.convert + costs.chestplate.convert end if costs.leggings[1] and costs.leggings.convert then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs.leggings.convert))):done wholeSet.convert = wholeSet.convert + costs.leggings.convert end if costs.boots[1] and costs.boots.convert then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(costs.boots.convert))):done wholeSet.convert = wholeSet.convert + costs.helmet.convert end if wholeSet.convert > 0 then row:tag('td'):attr('colspan', 2):wikitext(addColor('#ff55ff', string._formatNum(wholeSet.convert))):done row: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') :tag('td'):wikitext(p._stars(i)):done if costs.helmet[i] then cumulative.helmet = cumulative.helmet + costs.helmet[i] row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs.helmet[i]))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative.helmet))):done wholeSet.stars = wholeSet.stars + costs.helmet[i] end if costs.chestplate[i] then cumulative.chestplate = cumulative.chestplate + costs.chestplate[i] row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs.chestplate[i]))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative.chestplate))):done wholeSet.stars = wholeSet.stars + costs.chestplate[i] end if costs.leggings[i] then cumulative.leggings = cumulative.leggings + costs.leggings[i] row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs.leggings[i]))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative.leggings))):done wholeSet.stars = wholeSet.stars + costs.leggings[i] end if costs.boots[i] then cumulative.boots = cumulative.boots + costs.boots[i] row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(costs.boots[i]))):done row:tag('td'):wikitext(addColor('#ff55ff', string._formatNum(cumulative.boots))):done wholeSet.stars = wholeSet.stars + costs.boots[i] 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 row:done end else error(string.format('Invalid item type "%s"', type), 2) end return tostring(wikitable) end --Finish Module/Exports return p