Module:MaxStatsTable

local HeroTableBuilder = require 'Module:HeroTableBuilder' local FEHStatUtil = require 'Module:FEHStatUtil' local cargo = mw.ext.cargo local Hash = require 'Module:HashUtil' local Datetime = require 'Module:DatetimeUtil' local toboolean = require 'Module:Bool'.toboolean

local getMaxStat = function (rarity, b, g)	return b and g and (b + FEHStatUtil.getGrowthValue(rarity, g)) end local getMaxStatUnrounded = function (rarity, b, g)	return b and g and (b + 0.39 * g * (0.79 + rarity * 0.07)) end

local main = function (args, frame) local rarity = 5 local isResplendent = toboolean(args.resplendent) local showDragonflower = toboolean(args.dragonflower)

local units = cargo.query('UnitStats,Units',		"Units.WikiName=WikiName,Units._pageName=page,IFNULL(CONCAT(Name,': ',Title),Name)=name,Entries,MoveType,WeaponType,Lv1HP5,Lv1Atk5,Lv1Spd5,Lv1Def5,Lv1Res5,HPGR3,AtkGR3,SpdGR3,DefGR3,ResGR3,ReleaseDate", {			join = 'UnitStats.WikiName=Units.WikiName',			where = "IFNULL(Properties__full,) NOT LIKE '%enemy%'"				.. (toboolean(args.refresher) and "AND Properties HOLDS 'refresher'" or )				.. (isResplendent and "AND Properties HOLDS 'resplendent'" or ''),			groupBy = 'Units.WikiName',			orderBy = 'name',			limit = 1000,		}) if toboolean(args.common) then local HeroUtil = require 'Module:HeroUtil' local List = require 'Module:ListUtil' local commonUnits = HeroUtil.getLowestRarities {current = true, mask = {nonfocus = true}} List.keep_if(units, function (v)			local rarities = commonUnits[v.page]			return rarities and List.any(rarities.nonfocus, function (r) return r < 5 end)		end) end

local statFn = toboolean(args.unrounded) and getMaxStatUnrounded or getMaxStat for _, v in ipairs(units) do		v.hp = statFn(rarity, tonumber(v.Lv1HP5), tonumber(v.HPGR3)) v.atk = statFn(rarity, tonumber(v.Lv1Atk5), tonumber(v.AtkGR3)) v.spd = statFn(rarity, tonumber(v.Lv1Spd5), tonumber(v.SpdGR3)) v.def = statFn(rarity, tonumber(v.Lv1Def5), tonumber(v.DefGR3)) v.res = statFn(rarity, tonumber(v.Lv1Res5), tonumber(v.ResGR3)) if v.hp and v.atk and v.spd and v.def and v.res then local modifier = 0 if isResplendent then modifier = modifier + 2 end if showDragonflower then if v.ReleaseDate < '2019-02-07' and v.MoveType == 'Infantry' then modifier = modifier + 3 elseif v.ReleaseDate < '2020-08-18' then modifier = modifier + 2 else modifier = modifier + 1 end end v.hp = v.hp + modifier v.atk = v.atk + modifier v.spd = v.spd + modifier v.def = v.def + modifier v.res = v.res + modifier v.total = v.hp + v.atk + v.spd + v.def + v.res end end

local resplendentUnits = {} if isResplendent then resplendentUnits = Hash.from_ipairs(cargo.query('ResplendentHero=R,Artists=A', 'R.Unit=Unit,R.StartTime=StartTime,A.NameUSEN=ArtistNameEN,A.Name=ArtistName,A._pageName=ArtistPage', { join = 'R.Artist=A.Name', limit = 500, }), function (v) return v.Unit, v end) end

local theUnit = nil local builder = HeroTableBuilder.new

local fmt = function (x) return x and (args.unrounded and '%.3f' or '%d'):format(x) or '?' end local width = isResplendent and '7%' or '11%' builder:heroIcon('30px', isResplendent) builder:heroLink:css('width', '25em') builder:heroEntry:css('width', '6%') builder:moveType:css('width', '4%') builder:weaponType:css('width', '4%') builder:column('HP', function (elem) elem:wikitext(fmt(theUnit.hp)) end):css('width', width) builder:column('Atk', function (elem) elem:wikitext(fmt(theUnit.atk)) end):css('width', width) builder:column('Spd', function (elem) elem:wikitext(fmt(theUnit.spd)) end):css('width', width) builder:column('Def', function (elem) elem:wikitext(fmt(theUnit.def)) end):css('width', width) builder:column('Res', function (elem) elem:wikitext(fmt(theUnit.res)) end):css('width', width) builder:column('Total', function (elem) elem:wikitext(fmt(theUnit.total)) end):css('width', width) if isResplendent then builder:column('Release time', function (elem)			local t = resplendentUnits[theUnit.WikiName]			elem:wikitext(t and Datetime.ht(t.StartTime) or '???'):css('width', '12%')		end) builder:column('Artist', function (elem)			local t = resplendentUnits[theUnit.WikiName]			local artistText			if t.ArtistNameEN ~= t.ArtistName then				artistText = ('%s (%s)'):format(t.ArtistNameEN, t.ArtistName)			else				artistText = t.ArtistNameEN			end			elem:wikitext(t and ('%s'):format(t.ArtistPage, artistText) or '???'):css('width', width)		end) end

for _, v in ipairs(units) do		theUnit = v		builder:addHero(v.page, v.name, v.MoveType, v.WeaponType, v.Entries) end

return builder:build:addClass('wikitable'):css('text-align', 'center'):css('width', '100%'):attr('id', 'max-stats-table') end

return require 'Module:MakeMWModule'.makeMWModule {main = main}