Fire Emblem Heroes Wiki
Advertisement
Template-info Documentation

Creates a table of all summonable heroes, with each row representing a rarity, and each column containing a weapon type. Does not handle limited time heroes, or unsummonable heroes.

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

local heroList = function (args, frame)
	local WEAPON_SORT = Util.getWeaponSortOrder()

	-- Cargo Query
	local heroQueryResult = cargo.query('SummoningAvailability,Units,WeaponTypes', 'Units._pageName=page,WeaponType,Rarity,SummoningAvailability.Property=SAProp,Color,ColorSort', {
		join = 'SummoningAvailability._pageName=Units._pageName,Units.WeaponType=WeaponTypes.WikiName',
		where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%' AND Rarity IS NOT NULL AND (NOW() BETWEEN StartTime AND EndTime)",
		groupBy = 'Units._pageName,Rarity,SAProp',
		limit = 1000,
	})
	for _, v in ipairs(heroQueryResult) do
		v.Rarity = v.SAProp=='specialRate' and '4 SR' or v.SAProp=='SHSpecialRate' and '4 SHSR' or v.Rarity
		v.ColorSort = tonumber(v.ColorSort)
	end
	local heroesByWeapon = List.group_by(heroQueryResult, function (v) return v.WeaponType end)
	local rarities = List.reverse(List.sort_by(List.uniq(List.map(heroQueryResult, function (v) return v.Rarity end)), function (r) return r=='4 SHSR' and '0' or r end))

	-- unit table
	local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default')
		:css('text-align', 'center'):css('width', '100%')
	local row = tbl:tag('tr')
	row:tag('th'):css('width', '4%'):attr('scope', 'row'):wikitext('Rarity')
	for _,r in ipairs(rarities) do
		row:tag('th'):wikitext(mw.getCurrentFrame():expandTemplate {title = 'Rarity', args = {r}})
	end

	for wep, vs in Hash.sorted_pairs(heroesByWeapon, function (_, _, k1, k2) return WEAPON_SORT[k1] < WEAPON_SORT[k2] end) do
		row = tbl:tag('tr')
		row:tag('th'):wikitext('[[File:Icon Class ' .. wep .. '.png|x26px|link=]]')
		for _,r in ipairs(rarities) do
			local heroes = List.select(vs, function (v) return v.Rarity == r end)
			row:tag('td'):wikitext(table.concat(List.map_self(heroes, function (v) return Util.getHeroIcon(v.page, '40px') end)))
		end
	end

	-- summary table
	local heroesByColor = List.group_by(heroQueryResult, function (v) return v.Color end)
	local summary = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center')
	row = summary:tag('tr')
	row:tag('th'):attr('scope', 'row'):wikitext('Rarity')
	for _,r in ipairs(rarities) do
		row:tag('th'):wikitext(mw.getCurrentFrame():expandTemplate {title = 'Rarity', args = {r}})
	end

	for col, vs in Hash.sorted_pairs(heroesByColor, function (vs1, vs2) return vs1[1].ColorSort < vs2[1].ColorSort end) do
		row = summary:tag('tr')
		row:tag('th'):wikitext('[[File:Icon Class ' .. col .. '.png|x26px|link=]] ' .. col)
		for _,r in ipairs(rarities) do
			row:tag('td'):wikitext(List.count_if(vs, function (v) return v.Rarity == r end))
		end
	end

	return tostring(tbl) .. '<p>The above table, in numbers by color only.</p>' .. tostring(summary)
end

return require 'Module:MakeMWModule'.makeMWModule {heroList = heroList}
Advertisement