Fire Emblem Heroes Wiki
Advertisement
Documentation for this module may be created at Module:SkillCost/doc
local p = {}
local cargo = mw.ext.cargo
local HeroUtil = require 'Module:HeroUtil'
local List = require 'Module:ListUtil'
local getArgs = require 'Module:Arguments'.getArgs
local escq = require 'Module:EscQ'.main1

-- Looks at all the heroes passed in and checks their rarity and skill rarity unlock.
function p._determineCost(skill, scategory)
	if scategory == 'weapon' then
		local queryResult = cargo.query('WeaponEvolutions', 'BaseWeapon', {
			where = ("EvolvesInto='%s'"):format(escq(skill)),
			groupBy = 'BaseWeapon',
			limit = 10,
		})
		local preEvolved = queryResult[1] and queryResult[1].BaseWeapon or ''
		skill = preEvolved ~= '' and preEvolved or skill
	end

	local heroesWithSkill = cargo.query(
		'Units,UnitSkills',
		'Units._pageName=page,IFNULL(defaultRarity,6)=default,IFNULL(unlockRarity,6)=unlock', {
			where = ("skill='%s' AND IFNULL(Properties__full,'') NOT LIKE '%%story%%' AND IFNULL(Properties__full,'') NOT LIKE '%%enemy%%'"):format(escq(skill)),
			join = 'Units.WikiName=UnitSkills.WikiName',
			groupBy = 'Units._pageName',
			limit = 1000,
		})
	local avail = HeroUtil.getLowestRarities {current = true}
	for _, v in ipairs(heroesWithSkill) do
		v.minRarity = avail[v.page] and avail[v.page]:bounds() or 6
		v.unlock = math.min(tonumber(v.default), tonumber(v.unlock))
	end

	-- Skills all available at lower rarities = Low Investment
	if List.any(heroesWithSkill, function (v) return v.minRarity <= 4 and v.unlock <= 4 end) then
		return 'medium'
	end
	-- Skills only available at 5* Only Rarity Unlock = Medium Investment
	if List.any(heroesWithSkill, function (v) return v.minRarity <= 4 and v.unlock <= 5 end) then
		return 'high'
	end
	-- Skills only available at 5* Only Rarity = High Investment
	if List.any(heroesWithSkill, function (v) return v.minRarity <= 5 and v.unlock <= 5 end) then
		return 'veryhigh'
	end
	return 'N/A'
end

function p.determineCost(frame)
	local args = getArgs(frame)
	return p._determineCost(args[1], args[2])
end

return p
Advertisement