Module:LegendaryEffectTable

local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local cargo = mw.ext.cargo

local ROWS = {'Water', 'Wind', 'Earth', 'Fire'} local COLUMNS = {'Atk', 'Spd', 'Def', 'Res', 'Duel'}

local main = function (args) local query = Hash.map_self(List.group_by(cargo.query(   'LegendaryHero',    '_pageName=Hero,LegendaryEffect=Effect,AllyBoostHP=HP,AllyBoostAtk=Atk,AllyBoostSpd=Spd,AllyBoostDef=Def,AllyBoostRes=Res,Duel=Duel',    {limit = 100}  ), function (v) return v.Effect end), function (v)    return List.group_by(v, function (x) return select(2, List.find_if(COLUMNS, function (col) return x[col] ~= '0' end)) end) end)

local tbl = mw.html.create('table'):addClass('wikitable default'):css('text-align', 'center') tbl:tag('th'):wikitext('Legendary Effect') tbl:tag('th'):wikitext(' Atk+2') tbl:tag('th'):wikitext(' Spd+3') tbl:tag('th'):wikitext(' Def+4') tbl:tag('th'):wikitext(' Res+4') tbl:tag('th'):css("vertical-align","text-top"):wikitext('')

for _, element in ipairs(ROWS) do   local tr = tbl:tag('tr') tr:tag('td'):wikitext((' %s'):format(element, element))

for _, col in ipairs(COLUMNS) do     local heroes = query[element] and query[element][col] or {} tr:tag('td'):css('padding', '1em'):wikitext(table.concat(List.map(heroes, function (h)       return mw.getCurrentFrame:expandTemplate{title = 'UnitIcon', args = {name = h.Hero, size = '45px'}}      end), ' ')) end end

return tostring(tbl) end

return require 'Module:MakeMWModule'.makeMWModule { main = main, }