Module:EnemyStatComparison

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

local function calculateStats(rarity, level, Lv1Stat5Set, GR3Set) local lv1Stats = FEHStatUtil.fullLv1Stats(Lv1Stat5Set)[rarity] local stats = {0,0,0,0,0} for i=1,5 do		stats[i] = lv1Stats[i] + math.floor((level-1) * math.floor(GR3Set[i] * (0.79 + (0.07 * rarity)))/100) end return stats end

function p.main local unitData = {} -- unit[wikiname] = {page name, s.Lv1HP5,s.Lv1Atk5,s.Lv1Spd5,s.Lv1Def5,s.Lv1Res5,s.HPGR3,s.AtkGR3,s.SpdGR3,s.DefGR3,s.ResGR3} for _,v in ipairs(CargoUtil.full_query( "Units=u,UnitStats=s", "u.WikiName=unit,u._pageName=pgname,s.Lv1HP5=a,s.Lv1Atk5=b,s.Lv1Spd5=c,s.Lv1Def5=d,s.Lv1Res5=e,s.HPGR3=f,s.AtkGR3=g,s.SpdGR3=h,s.DefGR3=i,s.ResGR3=j", {			join = "u.WikiName=s.WikiName", where = "u.Properties__full IS NULL OR u.Properties__full NOT LIKE '%enemy%'", groupBy = "unit", }	)) do		unitData[v.unit] = {v.pgname,{tonumber(v.a),tonumber(v.b),tonumber(v.c),tonumber(v.d),tonumber(v.e)},{tonumber(v.f),tonumber(v.g),tonumber(v.h),tonumber(v.i),tonumber(v.j)}} end local tbl = mw.html.create("table") :addClass("wikitable") :addClass("sortable") :css("text-align","center") tbl:tag("th"):wikitext("Map") tbl:tag("th"):wikitext("Unit") tbl:tag("th"):wikitext("") tbl:tag("th"):attr("colspan",5):wikitext("Representative stats / Map stats") tbl:tag("th"):attr("colspan",5):wikitext("Difference") tbl:tag("th"):attr("colspan",5):wikitext("Estimated HP % Diff")

local mapData = {} -- mapData = {map1 = list of enemies, map2 = list of enemies, ...}, list of enemies = {enemy 1 data, enemy 2 data, ... }, enemy data = {unitwikiname, level,rarity,normalStats,mapStats } for _,v in ipairs(CargoUtil.full_query( "MapUnits", "_pageName=map,Unit,HP,Atk,Spd,Def,Res,Level,Rarity,Difficulty", {			where = "Unit NOT LIKE '%ENEMY%' AND _pageName NOT LIKE '%Heroic Ordeals%' AND HP IS NOT NULL AND Atk IS NOT NULL AND Spd IS NOT NULL AND Def IS NOT NULL AND Res IS NOT NULL AND Level IS NOT NULL AND Rarity IS NOT NULL AND Level NOT LIKE '%+%'", }	)) do		local normalStats = calculateStats(tonumber(v.Rarity), tonumber(v.Level), unitData[v.Unit][2], unitData[v.Unit][3]) local mapStats = {tonumber(v.HP), tonumber(v.Atk), tonumber(v.Spd), tonumber(v.Def), tonumber(v.Res)} if not (normalStats[1] == mapStats[1]				and normalStats[2] == mapStats[2]				and normalStats[3] == mapStats[3]				and normalStats[4] == mapStats[4]				and normalStats[5] == mapStats[5]) then if not mapData[v.map] then mapData[v.map] = {} end mapData[v.map][#mapData[v.map] + 1] = {v.Unit,v.Rarity,v.Level,normalStats,mapStats,v.Difficulty} end end for map,enemies in pairs(mapData) do		for k,enemy in ipairs(enemies) do			local tr = tbl:tag("tr") if k == 1 then tr:tag("td"):attr("rowspan",#enemies*2):wikitext(""..map.."") end tr:tag("td"):attr("rowspan",2):wikitext(""..unitData[ enemy[1] ][1].."") tr:tag("td"):attr("rowspan",2):wikitext(("%s %d★ LV. %s"):format(enemy[6],enemy[2],enemy[3])) tr:tag("td"):wikitext(enemy[4][1]) tr:tag("td"):wikitext(enemy[4][2]) tr:tag("td"):wikitext(enemy[4][3]) tr:tag("td"):wikitext(enemy[4][4]) tr:tag("td"):wikitext(enemy[4][5]) tr:tag("td"):attr("rowspan",2):wikitext(enemy[5][1] - enemy[4][1]) tr:tag("td"):attr("rowspan",2):wikitext(enemy[5][2] - enemy[4][2]) tr:tag("td"):attr("rowspan",2):wikitext(enemy[5][3] - enemy[4][3]) tr:tag("td"):attr("rowspan",2):wikitext(enemy[5][4] - enemy[4][4]) tr:tag("td"):attr("rowspan",2):wikitext(enemy[5][5] - enemy[4][5]) tr:tag("td"):attr("rowspan",2):wikitext(("%.f%%"):format(enemy[5][1] * 100 / enemy[4][1])) tr = tbl:tag("tr") tr:tag("td"):wikitext(enemy[5][1]) tr:tag("td"):wikitext(enemy[5][2]) tr:tag("td"):wikitext(enemy[5][3]) tr:tag("td"):wikitext(enemy[5][4]) tr:tag("td"):wikitext(enemy[5][5]) end end return tbl end

return p