Module:Dungeon

--Get Required Modules local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') local table = require('Module:Table') 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', 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 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 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') local pieces = { 'Helmet', 'Chestplate', 'Leggings', 'Boots', }	if type == 'weapon' or type == 'w' then 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') :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 = { 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 local prefixes = { ['Helmet'] = 'h', ['Chestplate'] = 'c', ['Leggings'] = 'l', ['Boots'] = 'b', }			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') :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 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: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 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 }		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 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 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 row:done end else error(string.format('Invalid item type "%s"', type), 2) end return tostring(wikitable) end --Finish Module/Exports return p