Module:SkillCost

local p = {} local mw = mw local cargo = mw.ext.cargo local ListUtil = require 'Module:ListUtil' local getArgs = require 'Module:Arguments'.getArgs local escq = require 'Module:Util'.escq

-- Skills all available at lower rarities = Low Investment local lowInvestment = function (info) return (mw.ustring.find(info.s, '[1-4]') or mw.ustring.find(info.r, '[1-4]')) and tonumber(info.unlock) < 5 end

-- Skills only available at 5* Only Rarity Unlock = Medium Investment local mediumInvestment = function (info) return (mw.ustring.find(info.s, '[1-4]') or mw.ustring.find(info.r, '[1-4]')) and tonumber(info.unlock) ~= nil end

-- Skills only available at 5* Only Rarity = High Investment local highInvestment = function (info) return --not (mw.ustring.find(info.s, '[1-4]') or mw.ustring.find(info.r, '[1-4]')) and (mw.ustring.find(info.s, '5') or mw.ustring.find(info.r, '5')) and tonumber(info.unlock) ~= nil end

-- 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('HeroSkills,Heroes', 'Heroes._pageName,unlockRarity=unlock,SummonRarities__full=s,RewardRarities__full=r', {   where = ("HeroSkills.skill='%s' AND (Properties__full IS NULL OR NOT (Properties HOLDS 'story'))"):format(escq(skill)),    join = 'HeroSkills._pageName=Heroes._pageName',    groupBy = 'Heroes._pageName',    limit = 1000,  }) if #heroesWithSkill > 0 then if ListUtil.any(heroesWithSkill, lowInvestment) then return 'medium' end if ListUtil.any(heroesWithSkill, mediumInvestment) then return 'high' end if ListUtil.any(heroesWithSkill, highInvestment) then return 'veryhigh' end end

return 'N/A' end

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

return p