Module:Sandbox/TheTrueShaman

local p = {} local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno = loader.require('String', 'Table', 'Yesno')

local armorData = loader.require('Module:Armor/Data') local reforges = loader.require('Module:Reforge/Data') local getArgs = require('Module:Arguments').getArgs local statName = require('Module:Statname').getStatName local statData = mw.loadData('Module:Statname/Data')

function p.statListHelper(item, x, y, percent) local sources = {'hpb', 'reforge'} local colors = {'#FFFF55', '#5555FF'} local text = string.format(x, y, item['total']..percent) for a = 1,#sources,1 do		if item[sources[a]] then local sign if item[sources[a]] >= 0 then sign = '+' else sign = '-' end local source = '('..sign..item[sources[a]]..percent..')' source = string.wrapHtml{source, ' ', {style={color=colors[a]}}} text = text..' '..source end end return text..'' end

function p.makeHtmlStatsList(item, noStatsValue) local t = {} local statFormat1 = '%s: %s' local statFormat2 = '%s: %s&#32;(%s)' local function parseStat(val, stat, percent, item) if not val or val == '' then return end percent = percent and '%' or '' if type(val) == 'number' and val > 0 then t[#t+1] = p.statListHelper(item, '%s: +%s', statName{stat}, percent) elseif type(val) ~= 'table' and string.match(val, '^([^%D]+)$') and not val[2] then t[#t+1] = p.statListHelper(item, '%s: %s', statName{stat}, percent) elseif type(val) == 'table' and string.match(val[1] or '', '^([^%D]+)$') then t[#t+1] = string.format('%s: +%s&#32;(%s)', statName{stat}, val[1]..percent, val[2]) elseif type(val) == 'table' and val.lower then t[#t+1] = string.format('%s: %s-%s', statName{stat}, (val.lower > 0 and '+' or '')..val.lower..percent, val.upper..percent) elseif type(val) == "table" and type(val[2]) ~= 'string' then t[#t+1] = string.format('%s: %s&#32;(%s)', statName{stat}, val[1]..percent, val[2]) elseif tostring(val):match('([%+%-]?)(%d+)%-(%d+)') then t[#t+1] = string.format('%s: %s%s', statName{stat}, not val:match('^[%-%+]') and '+' or , val:gsub('%%$', )..percent) else t[#t+1] = string.format('%s: %s</li>', statName{stat}, val..percent) end end for k,v in pairs(statData) do		if item[v.shortcode] then parseStat(item[v.shortcode]['total'], v.shortcode, v.percent, item[v.shortcode]) end end if #t == 0 then return noStatsValue end return string.wrapHtml{ t, '<ul>', { style="list-style-type:square;"; }	} end

function p.getArmorDataSimple(frame) local args = getArgs(frame) if not args then return 'Invalid Inputs' end

local armor = (args[1] or args['armor']):lower local growth if args['growth'] then growth = {args['growth'],args['growth'],args['growth'],args['growth']} else growth = {0,0,0,0} end local protection if args['protection'] then protection = {args['protection'],args['protection'],args['protection'],args['protection']} else protection = {0,0,0,0} end local hpb if args[2] or args['hpb'] then hpb = {args[2],args[2],args[2],args[2]} else hpb = {0,0,0,0} end local fpb if args[3] or args['fpb'] then fpb = {args[3],args[3],args[3],args[3]} else fpb = {0,0,0,0} end local pbsum = {hpb[1]+fpb[1],hpb[2]+fpb[2],hpb[3]+fpb[3],hpb[4]+fpb[4]} local reforge = args[4] or args['reforge'] or nil return p._getArmorData(armor, growth, protection, pbsum, reforge) end

function p._getArmorData(armorname, growth, protection, hpb, reforge) local armor if type(armorname) == 'string' then armor = {armorData[armorname], armorData[armorname], armorData[armorname], armorData[armorname]} else armor = {armorData[armorname[1]], armorData[armorname[2]], armorData[armorname[3]], armorData[armorname[4]]} end -- O for Ordered, because this is the order in which the stats show up in-game (too many stats variables I know) local statsO = {'str', 'cc', 'cd', 'bas', 'hp', 'def', 'spd', 'int', 'fer', 'mf', 'tdef', 'mns', 'mnf', 'scc'} -- D for Data because these abbreviations come from the Armor/Data module local piecesD = {'head', 'chest', 'legs', 'boots', 'total'} -- Source of stats local source = {'base', 'enchants', 'hpb', 'reforge'} local armorstats = {} for i = 1,4,1 do 		local piece = piecesD[i] local piecestats = {hp={}, def={}, cc={}, cd={}, str={}, int={}, spd={}, scc={}, td={}} for a = 1,#statsO,1 do			if armor[i]['stats'][piece][statsO[a]] then piecestats[statsO[a]]['base'] = armor[i]['stats'][piece][statsO[a]] end end if growth[i] ~= 0 then piecestats['hp']['enchants'] = 15*growth[i] end if protection[i] ~= 0 then piecestats['def']['enchants'] = 3*protection[i] end if hpb[i] ~= 0 then piecestats['hp']['hpb'] = 4*hpb[i] piecestats['def']['hpb'] = 2*hpb[i] end if reforge and reforges['Armor'][reforge] then for a = 1,#statsO,1 do 				if reforges['Armor'][reforge]['stats'][armor[i]['rarity']][statsO[a]] then piecestats[statsO[a]]['reforge'] = reforges['Armor'][reforge]['stats'][armor[i]['rarity']][statsO[a]] end end end for a = 1,#statsO,1 do			if piecestats[statsO[a]] then for b = 1,#source,1 do					if piecestats[statsO[a]][source[b]] then if not piecestats[statsO[a]]['total'] then piecestats[statsO[a]]['total'] = piecestats[statsO[a]][source[b]] else piecestats[statsO[a]]['total'] = piecestats[statsO[a]]['total'] + piecestats[statsO[a]][source[b]] end end end end end piecestats['kind'] = string.gsub(armorname, ' armor', '') armorstats[i] = piecestats end local helmetData = armorstats[1] local chestData = armorstats[2] local legsData = armorstats[3] local bootsData = armorstats[4] local totalData = {} table.insert(source, 'total') -- I shouldn't do this over and over, but I do... Eyo later me, fix this. for i,tData in ipairs({ helmetData, chestData, legsData, bootsData}) do		for i = 1,#statsO,1 do			if tData[statsO[i]] then if not totalData[statsO[i]] then totalData[statsO[i]] = {} end for a = 1,#source,1 do					if tData[statsO[i]][source[a]] then if totalData[statsO[i]][source[a]] then totalData[statsO[i]][source[a]] = totalData[statsO[i]][source[a]] + tData[statsO[i]][source[a]] else totalData[statsO[i]][source[a]] = tData[statsO[i]][source[a]] end end end end end local statslist = {} for i = 1,#statsO,1 do			if tData[statsO[i]] then statslist[statsO[i]] = tData[statsO[i]] end end tData['statslist'] = p.makeHtmlStatsList(statslist) end local statslist = {} for i = 1,#statsO,1 do		if totalData[statsO[i]] then statslist[statsO[i]] = totalData[statsO[i]] end end totalData['statslist'] = p.makeHtmlStatsList(statslist) local function getDefaultImage(pType, pIsLink) local link = table.concat{"File:", title:gsub("Armor", pType), ".png"} if pIsLink then link = table.concat{"40px|center"} end return link end local function makeImageCell(pRow, pData, pType) local td = pRow:tag("td"):attr("id", pType) if next(pData) then if pData["kind"] then td:addClass("as2x2-icon"):wikitext(table.concat{""}) elseif pData["color"] then td:addClass("as2x2-icon"):wikitext(table.concat{""}) elseif defaultImages then td:wikitext(getDefaultImage(pType, true)) else td:wikitext(" ") end else td:attr("colspan", 2):css{ ["border-right-width"]="2px" }:wikitext("") end return td	end local function makeCellCollapsible(pCell, pCollapsed) pCell :addClass("mw-collapsible") :attr("id", "mw-customcollapsible-pcb-toggle-button") if pCollapsed then pCell:addClass("mw-collapsed") end end local function makeDataCell(pRow, pData) if next(pData) then local td = row:tag("td"):wikitext(pData["statslist"]) :css({ ["border-right-width"]="2px" }) makeCellCollapsible(td) -- add a second collapsed cell to allow user to toggle between both cells local td2 = row:tag("td"):css({ ["border-right-width"]="2px" }) makeCellCollapsible(td2, true) if pData["pcb"] or pData["pcb_desc"] then if pData["pcb"] then td2:tag("div"):wikitext(pieceBonus{ pData["pcb"] }) end td2:wikitext(pData["pcb_desc"]) end end end local t = {} t[#t+1] = " Armor Stats \n" t[#t+1] = " Note: You Can Click on the Orange Button below to Show/Hide the Piece Bonuses \n" local wikitable = mw.html.create("table"):addClass("wikitable armorstats2x2"):css{ ["border-width"]="2px", ["border-color"]="#aaa" }; wikitable:tag("tr"):tag("th"):attr("colspan", 4) :tag("div") :addClass("mw-customtoggle-pcb-toggle-button wikia-menu-button hidden"):css{ padding="3px" } :wikitext(pcbToggleButtonName or "Click Here to Show Piece Bonuses") wikitable:tag("tr") :tag("th"):attr("colspan", 2):css{ ["border-right-width"]="2px" } :wikitext(helmetData["special_name"] or "Helmet"):done :tag("th"):attr("colspan", 2) :wikitext(chestData["special_name"] or "Chestplate"):done row = wikitable:tag("tr") makeImageCell(row, helmetData, "Helmet") makeDataCell(row, helmetData) makeImageCell(row, chestData, "Chestplate") makeDataCell(row, chestData) wikitable:tag("tr") :tag("th"):attr("colspan", 2):css{ ["border-right-width"]="2px", ["border-top-width"]="2px" } :wikitext(legsData["special_name"] or "Leggings"):done :tag("th"):attr("colspan", 2):css{ ["border-top-width"]="2px" } :wikitext(bootsData["special_name"] or "Boots"):done -- Legs / Boots image and data row row = wikitable:tag("tr") makeImageCell(row, legsData, "Leggings") makeDataCell(row, legsData) makeImageCell(row, bootsData, "Boots") makeDataCell(row, bootsData) row = wikitable:tag("tr") td = row:tag("th"):attr("colspan", 4):wikitext("Total"):css{ ["border-right-width"]="2px", ["border-top-width"]="2px" } makeCellCollapsible(td) row = wikitable:tag("tr") td = row:tag("td"):attr("colspan", 4):wikitext(totalData["statslist"]):css{ ["border-right-width"]="2px" } makeCellCollapsible(td) t[#t+1] = tostring(wikitable) if additionalEffects then t[#t+1] = additionalEffects.."

"	end	return table.concat(t); end

return p