Module:SurpassedHeroes

local cargo = mw.ext.cargo local ListUtil = require 'Module:ListUtil' local p = {}

--TODO: Add date difference

function p.main(frame) local mainQuery = cargo.query(		"Units=u,UnitStats=s,WeaponTypes=w,UnitSkills=US,Skills=S",		"u._pageName=pgname,w.IconFile=Icon,CONCAT(u.Name,': ',u.Title)=name,u.MoveType=MoveType,u.WeaponType=WeaponType,CONCAT(Lv1HP5+FLOOR(FLOOR(HPGR3*1.14)*0.39),',',Lv1Atk5+FLOOR(FLOOR(AtkGR3*1.14)*0.39),',',Lv1Spd5+FLOOR(FLOOR(SpdGR3*1.14)*0.39),',',Lv1Def5+FLOOR(FLOOR(DefGR3*1.14)*0.39),',',Lv1Res5+FLOOR(FLOOR(ResGR3*1.14)*0.39))=stats,SUBSTRING(GROUP_CONCAT(DISTINCT S.Exclusive ORDER BY S.Exclusive DESC), 1, 1)=hasExclusive,u.Properties__full=properties",		{			join = "u.WikiName=s.WikiName,u.WeaponType=w.WikiName,u.WikiName=US.WikiName,US.skill=S.WikiName",			where = "u.Properties__full IS NULL OR (u.Properties__full NOT LIKE '%enemy%')",			groupBy = "u._pageName",			orderBy = "IFNULL(IntID,9999)",			limit=5000		}	) local function convertToNumber(x) return tonumber(x) end local tbl = mw.html.create("table") :addClass("wikitable") :addClass("sortable") :css("text-align","right")

tbl:tag("th") :attr("rowspan","2") :wikitext("Hero") tbl:tag("th") :attr("rowspan","2") :wikitext("Surpassed by") tbl:tag("th") :attr("colspan","5") :wikitext("Stat difference") tbl:tag("th") :attr("rowspan","2") :wikitext("Has exclusive skill") local tr = tbl:tag("tr") tr:tag("th"):wikitext("HP") tr:tag("th"):wikitext("Atk") tr:tag("th"):wikitext("Spd") tr:tag("th"):wikitext("Def") tr:tag("th"):wikitext("Res")

local split = mw.text.split local function isRefresher(s) for _,property in ipairs(split(s, ",")) do			if property == "refresher" then return true end end return false end for i=1,#mainQuery do		local hero1 = mainQuery[i] if not isRefresher(hero1.properties) then local h1stats = ListUtil.map_self(split(hero1.stats, ","), convertToNumber) for j=i+1,#mainQuery do				local hero2 = mainQuery[j] if hero2.MoveType == hero1.MoveType and hero2.WeaponType == hero1.WeaponType then

local h2stats = ListUtil.map_self(split(hero2.stats, ","), convertToNumber) if h2stats[1] >= h1stats[1] and h2stats[2] >= h1stats[2] and h2stats[3] >= h1stats[3] and h2stats[4] >= h1stats[4] and h2stats[5] >= h1stats[5] and (not (h2stats[1] == h1stats[1] and h2stats[2] == h1stats[2] and h2stats[3] == h1stats[3] and h2stats[4] == h1stats[4] and h2stats[5] == h1stats[5])) then

tr = tbl:tag("tr") tr:tag("td"):css("text-align","left"):wikitext(" "..hero1.name.."") tr:tag("td"):css("text-align","left"):wikitext(" "..hero2.name.."") tr:tag("td"):wikitext(h1stats[1] - h2stats[1]) tr:tag("td"):wikitext(h1stats[2] - h2stats[2]) tr:tag("td"):wikitext(h1stats[3] - h2stats[3]) tr:tag("td"):wikitext(h1stats[4] - h2stats[4]) tr:tag("td"):wikitext(h1stats[5] - h2stats[5]) tr:tag("td"):css("text-align","center"):wikitext(hero1.hasExclusive == "1" and "" or "") end end end end end return tbl end

return p