Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!


From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

Builds a table for a certain skill type, showing which heroes can learn it by at most 4★. Used to automate List of inheritable skills.

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

local main = function (args)
	local RARITY_TXTS = Util.getRarityTexts()

	local cat = args[1] or ''
	local skills = List.group_by(cargo.query(
		[[S._pageName=page,S.Name=name,S.Description=desc,S.SP=sp,S.WikiName=wikiname,U._pageName=unitpage,IFNULL(CONCAT(U.Name,': ',U.Title),U.Name)=unitname,
		  IFNULL(defaultRarity,6)=defaultR,IFNULL(unlockRarity,6)=unlockR]], {
			join = 'US.skill=S.WikiName,US.WikiName=U.WikiName',
			where = ("Exclusive=0 AND RefinePath IS NULL AND S.Next IS NULL AND IFNULL(U.Properties__full,'') NOT LIKE '%%enemy%%' AND IFNULL(U.Properties__full,'') NOT LIKE '%%story%%' AND Scategory='%s'"):format(escq(cat)),
			groupBy = 'S.WikiName,U.WikiName',
			orderBy = 'unitpage',
			limit = 5000,
		}), function (v) return v.wikiname end)
	local avail = Util.getHeroAvailability {current = true}

	local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('sortable')
		:css('text-align', 'center')
	local tr = tbl:tag('tr')
	tr:tag('th'):css('width', '150px'):wikitext('Skill')
	tr:tag('th'):addClass('unsortable'):wikitext(RARITY_TXTS[4] .. ' Heroes')
	tr:tag('th'):addClass('unsortable'):wikitext(RARITY_TXTS[5] .. ' Heroes')

	local sortFn = function (v1, v2, k1, k2)
		return v1[1].name < v2[1].name or (v1[1].name == v2[1].name and k1 < k2)
	for _, heroes in Hash.sorted_pairs(skills, sortFn) do
		tr = tbl:tag('tr')
		tr:tag('td'):wikitext(('[[%s%s]]'):format(heroes[1].page, heroes[1].name ~= heroes[1].page and ('|' .. heroes[1].name) or ''))
		local r4 = tr:tag('td')
		local r5 = tr:tag('td')
		for _, v in ipairs(heroes) do
			local minRarity = math.max(math.min(tonumber(v.defaultR), tonumber(v.unlockR)), avail[v.unitpage] and avail[v.unitpage]:bounds() or 6)
			if minRarity <= 4 then
				r4:wikitext(Util.getHeroIcon(v.unitpage, '40px'))
			elseif minRarity <= 5 then
				r5:wikitext(Util.getHeroIcon(v.unitpage, '40px'))

	return tbl

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