Module:BuildValidityChecker

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation
This module has been deprecated. Reason: "Module:SkillBuildInfobox performs this directly in the main function since it relies on not having to re-query the database for skill definitions."

This module is no longer supported, and exists solely to maintain integrity of previous page revisions that used this module. New content should not use this module anymore, as it might be moved, deleted, or broken without prior notice.

Checks for validity of a build.

{{#invoke:BuildValidityChecker|main|Hero|Skill1|Skill2|...}}

Returns something if invalid, nothing if valid.

local cargo = mw.ext.cargo
local List = require 'Module:ListUtil'
local Hash = require 'Module:HashUtil'
local getArgs = require('Module:Arguments').getArgs
local split = mw.text.split
local p = {}

function p.main(frame)
	return p._main(getArgs(frame, {removeBlanks = false}))
end

function p._main(args)
	local hero = escq(args[1] or mw.title.getCurrentTitle().subpageText)
	local heroData = cargo.query("Heroes", "MoveType,WeaponType", {
		where = ("_pageName = '%s'"):format(hero),
		limit = 1,
	})[1]
	if heroData == nil then
		return ""
	end
	local heroMoveType = heroData.MoveType
	local heroWeaponType = heroData.WeaponType

	local skills = {}
	for k, v in ipairs(args) do
		if v ~= "" and v ~= "Flexible" and k ~= 1 then
			skills[escq(v)] = true
		end
	end
	local list = ("('" .. table.concat(Hash.keys(skills), "','") .. "')") 
	local validityTable = cargo.query(
		"Skills",
		"WikiName=name,CONCAT(CanUseMove__full)=m,CONCAT(CanUseWeapon__full)=w",
		{
			where = ("CanUseMove__full IS NOT NULL AND CanUseWeapon__full IS NOT NULL AND RefinePath IS NULL AND (_pageName IN %s OR WikiName IN %s OR GroupName IN %s)"):format(list, list, list),
			groupBy = "CanUseMove__full,CanUseWeapon__full",
		}
	)
	local _, invalid = List.find_if(validityTable, function (row)
		return not (List.find((split(row.m, "%s*,%s*")), heroMoveType) and List.find((split(row.w, "%s*,%s*")), heroWeaponType))
	end)
	return invalid and invalid.name or ''
end

return p