Module:StatsPage/sandbox

local Util = require 'Module:Util' local HeroUtil = require 'Module:HeroUtil' local getArgs = require('Module:Arguments').getArgs local List = require 'Module:ListUtil' local FEHStatUtil = require 'Module:FEHStatUtil' local cargo = mw.ext.cargo local escq = require 'Module:EscQ'.main1

local SUM_CSS_PROP = 'font-style' local SUM_CSS_VAL = 'italic'

local makeStatTableHeader = function return mw.html.create('table') :addClass('wikitable default'):css('text-align', 'center'):css('width', '500px') :tag('tr') :tag('th'):css('width', '14%'):wikitext('Rarity'):done :tag('th'):css('width', '14%'):wikitext('HP'):done :tag('th'):css('width', '14%'):wikitext('ATK'):done :tag('th'):css('width', '14%'):wikitext('SPD'):done :tag('th'):css('width', '14%'):wikitext('DEF'):done :tag('th'):css('width', '14%'):wikitext('RES'):done :tag('th'):css('width', '14%'):css(SUM_CSS_PROP, SUM_CSS_VAL):wikitext('Total'):done :done :done end

local findFour = function (direction, rateSet, rarity) if rarity == 4 or rarity == 5 then if direction == 'plus' then return List.any(rateSet, function (rate)       return FEHStatUtil.getGrowthValue(rarity, rate + 5) - FEHStatUtil.getGrowthValue(rarity, rate) > 2      end) elseif direction == 'minus' then return List.any(rateSet, function (rate)       return FEHStatUtil.getGrowthValue(rarity, rate) - FEHStatUtil.getGrowthValue(rarity, rate - 5) > 2      end) end end return false end

local GRTableRow = function (wikiGRTable, pureRates, rarity, approximationText, RARITY_TXT, correctInputFlags) local tr = wikiGRTable:tag('tr') local appliedRates = List.map(pureRates, function (rate) return math.floor(rate * (0.79 + 0.07 * rarity)) end ) local pureRateBoldTag = rarity == 3 and "" or "" local pureRateBoldTagEnd = rarity == 3 and "" or "" tr:tag('td'):wikitext( pureRateBoldTag .. RARITY_TXT[rarity] .. pureRateBoldTagEnd ) for _, rate in ipairs(appliedRates) do rateText = pureRateBoldTag .. rate .. "%" .. approximationText .. pureRateBoldTagEnd tr:tag('td'):wikitext(rateText) end tr:tag('td') :wikitext( pureRateBoldTag .. (( (correctInputFlags and List.sum(appliedRates) or '' ) .. "%" .. ( hasApproximation and approximationText or "" )) or '-') .. pureRateBoldTagEnd) :css(SUM_CSS_PROP, SUM_CSS_VAL) end

local p = {}

function p._statsPage(frame, args, isEnemy) local RARITY_TXT = Util.getRarityTexts

-- setting up variables local full1Banes = {{}, {}, {}, {}, {}} local full1Neuts = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}} local full1Boons = {{}, {}, {}, {}, {}} local full40Banes = {{}, {}, {}, {}, {}} local full40Neuts = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}} local full40Boons = {{}, {}, {}, {}, {}} local rateNeuts = {'-', '-', '-', '-', '-'}

-- parsing inputs --Hero local avail = HeroUtil.getLowestRarities {page = args.Hero} local lowestHeroRarity = isEnemy and 1 or avail and avail:bounds or 1 avail.reward = {} local lowestHeroSummon = isEnemy and 6 or avail and avail:bounds or 6 --Lv1 stats local level1Inputs = List.map({   args.Lv1HP, args.Lv1ATK, args.Lv1SPD, args.Lv1DEF, args.Lv1RES,  }, function (x) return tonumber(x) or false end) local correctInputFlag1 = List.find(level1Inputs, false) == nil

--If we got 5 numbers for Lv1 stats, set up tables for all Lv1 stats if correctInputFlag1 then full1Neuts = FEHStatUtil.fullLv1Stats(level1Inputs) full1Banes = List.map(full1Neuts, function (t) return List.map(t, function (base) return base - 1 end) end) full1Boons = List.map(full1Neuts, function (t) return List.map(t, function (base) return base + 1 end) end) end

--Lv40 stats local level40Inputs = List.map({     args.Lv40HP, args.Lv40ATK, args.Lv40SPD, args.Lv40DEF, args.Lv40RES,    }, function (x) return tonumber(x) or false end) local correctInputFlag40 = List.find(level40Inputs, false) == nil --Check if there are growth rate inputs local correctInputFlagGR = (args.GRHP ~= nil and args.GRATK ~= nil and args.GRSPD ~=nil and args.GRDEF ~= nil and args.GRRES ~= nil) if correctInputFlagGR and correctInputFlag1 then rateNeuts = {args.GRHP, args.GRATK, args.GRSPD, args.GRDEF, args.GRRES} full40Neuts = FEHStatUtil.fullLv40Stats(rateNeuts, full1Neuts) full40Banes = FEHStatUtil.fullLv40Stats(List.map(rateNeuts, function (rate) return rate - 5 end), full1Banes) full40Boons = FEHStatUtil.fullLv40Stats(List.map(rateNeuts, function (rate) return rate + 5 end), full1Boons) elseif correctInputFlag1 and correctInputFlag40 then rateNeuts = List.zip(level1Inputs, level40Inputs, function (lo, hi) return FEHStatUtil.findGrowthRate(5, hi - lo) or false end) if List.find(rateNeuts, false) then return 'Error: Invalid input stats, not all instances of (Lv40Stat - Lv1Stat) produced valid growth values for rarity 5 ' end full40Neuts = FEHStatUtil.fullLv40Stats(rateNeuts, full1Neuts) full40Banes = FEHStatUtil.fullLv40Stats(List.map(rateNeuts, function (rate) return rate - 5 end), full1Banes) full40Boons = FEHStatUtil.fullLv40Stats(List.map(rateNeuts, function (rate) return rate + 5 end), full1Boons) end local cargotable = {} local cargoAddStats = function (table, rarity, var, statSet) cargotable[#cargotable + 1] = {title = table, args = { rar = rarity, var = var, hp = statSet[1], atk = statSet[2], spd = statSet[3], def = statSet[4], res = statSet[5], }} end

--Fill in rows of Lv1 table local Lv1StatTable = makeStatTableHeader for rarity, statset in ipairs(full1Neuts) do   if rarity >= lowestHeroRarity then local tr = Lv1StatTable:tag('tr') tr:tag('td'):wikitext(RARITY_TXT[rarity]) if correctInputFlag1 then if rarity >= lowestHeroSummon then cargoAddStats('Stats_Page/BaseStatDefinitions', rarity, 'Bane', full1Banes[rarity]) cargoAddStats('Stats_Page/BaseStatDefinitions', rarity, 'Boon', full1Boons[rarity]) end cargoAddStats('Stats_Page/BaseStatDefinitions', rarity, 'Neut', statset) end for stat, val in ipairs(statset) do       local statString = '' if rarity >= lowestHeroSummon then statString = correctInputFlag1 and (full1Banes[rarity][stat] .. '/' .. val .. '/' .. full1Boons[rarity][stat]) or '-/-/-' else statString = correctInputFlag1 and full1Neuts[rarity][stat] or '-' end tr:tag('td'):wikitext(statString) end tr:tag('td'):wikitext(correctInputFlag1 and (correctInputFlag40 or correctInputFlagGR) and List.sum(statset) or '-'):css(SUM_CSS_PROP, SUM_CSS_VAL) end end

--Fill in rows of Lv40 table local Lv40StatTable = makeStatTableHeader for rarity, statset in ipairs(full40Neuts) do   if rarity >= lowestHeroRarity then local tr = Lv40StatTable:tag('tr') tr:tag('td'):wikitext(RARITY_TXT[rarity]) if correctInputFlag40 then if rarity >= lowestHeroSummon then cargoAddStats('Stats_Page/MaxStatDefinitions', rarity, 'Bane', full40Banes[rarity]) cargoAddStats('Stats_Page/MaxStatDefinitions', rarity, 'Boon', full40Boons[rarity]) end cargoAddStats('Stats_Page/MaxStatDefinitions', rarity, 'Neut', statset) end for stat, val in ipairs(statset) do       local statString = '' if rarity >= lowestHeroSummon then statString = ('%s/%s/%s'):format(           correctInputFlag40 and correctInputFlag1 and full40Banes[rarity][stat] or '-',            correctInputFlag40 and (correctInputFlag1 and val or rarity == 5 and level40Inputs[stat]) or '-',            correctInputFlag40 and correctInputFlag1 and full40Boons[rarity][stat] or '-'          ) else statString = correctInputFlag40 and (correctInputFlag1 and val or rarity == 5 and level40Inputs[stat]) or '-' end tr:tag('td'):wikitext(statString) end local sumString = '-' if correctInputFlag1 and correctInputFlag40 then local sum = List.sum(statset) if rarity >= lowestHeroSummon then local lo = sum - (findFour('minus', rateNeuts, rarity) and 1 or 0) local hi = sum + (findFour('plus', rateNeuts, rarity) and 1 or 0) sumString = lo ~= hi and ('%s~%s'):format(lo, hi) or tostring(lo) else sumString = tostring(sum) end end tr:tag('td'):wikitext(sumString):css(SUM_CSS_PROP, SUM_CSS_VAL) end end

if correctInputFlag1 and correctInputFlag40 then cargotable[#cargotable + 1] = {title = 'Stats_Page/GrowthRateDefinitions', args = {hp = rateNeuts[1], atk = rateNeuts[2], spd = rateNeuts[3], def = rateNeuts[4], res = rateNeuts[5]}} end

local hasApproximation local approximationText = "" for _, rate in ipairs(rateNeuts) do   if rate % 5 ~= 0 and correctInputFlagGR == false then hasApproximation = true end end if hasApproximation then approximationText = " " .. frame:expandTemplate{ title = "Hover", args = { "*", "Approximation" } } end local correctInputFlags = correctInputFlag1 and (correctInputFlag40 or correctInputFlagGR)

--Fill in rows of GR table local wikiGRTable = makeStatTableHeader if lowestHeroRarity <= 3 then for rarity = lowestHeroRarity, 5 do 		GRTableRow(wikiGRTable, rateNeuts, rarity, approximationText, RARITY_TXT, correctInputFlags) end else GRTableRow(wikiGRTable, rateNeuts, 3, approximationText, RARITY_TXT, correctInputFlags) for rarity = lowestHeroRarity, 5 do 		GRTableRow(wikiGRTable, rateNeuts, rarity, approximationText, RARITY_TXT, correctInputFlags) end end

if not isEnemy and not mw.title.getCurrentTitle.isSubpage and mw.title.getCurrentTitle.namespace == 0 then for i = #cargotable, 1, -1 do     --frame:expandTemplate mw.logObject(cargotable[i]) end end

if isEnemy then return 'All stats have a degree of variation. The stat growth page explains how the variation works. Base Stats ' .. tostring(Lv1StatTable) .. ' Max Stats ' .. tostring(Lv40StatTable) .. ' Growth Rates This set of values determines how much each stat will increase from level 1 to level 40, see stat growth.' .. tostring(wikiGRTable) else return 'All stats have a degree of variation. The stat growth page explains how the variation works. Level 1 stats ' .. tostring(Lv1StatTable) .. ' Level 40 stats ' .. tostring(Lv40StatTable) .. ' Growth Rates This set of values determines how much each stat will increase from level 1 to level 40, see stat growth.' .. tostring(wikiGRTable) .. ' Stats between level 1 and 40 For stat values between level 1 and 40, see this page.' end end

function p.statsPage(frame) args = getArgs(frame) return p._statsPage(frame, args, false) end

return p