Module:FEHStatUtil

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

Test cases

local ListUtil = require 'Module:ListUtil'

local arrayOrder = function (arr)
  return ListUtil.map(arr, function (lhs, i)
    return ListUtil.count_if(arr, function (rhs, j)
      return (i < j and lhs >= rhs) or (i > j and lhs > rhs)
    end)
  end)
end

local getMasterGrowthRate = function (rarity, rate)
  return math.floor(rate * (0.79 + 0.07 * rarity))
end

local getGrowthValue = function (rarity, rate)
  return math.floor(0.39 * getMasterGrowthRate(rarity, rate))
end

local getSupergrowth = function (rarity, rate)
  local neut = getGrowthValue(rarity, rate)
  if getGrowthValue(rarity, rate + 5) > neut + 2 then
    return 1
  elseif getGrowthValue(rarity, rate - 5) < neut - 2 then
    return -1
  end
  return 0
end

local findGrowthRate = function (rarity, growth)
  for rate = 0,210,5 do
    if getGrowthValue(rarity, rate) == growth then
      return rate, false
    end
  end
  for rate = 210,0,-1 do
    if getGrowthValue(rarity, rate) == growth then
      return rate, true
    end
  end
end

local getRarityBonuses = function (fiveStarLv1Stats)
  local order = {0, unpack(arrayOrder(ListUtil.sub(fiveStarLv1Stats, 2, 5)))}
  return ListUtil.generate(5, function (rarity)
    return ListUtil.map(order, function (o)
      return 2 - math.floor((5 - rarity + (o < 2 and 1 or 0)) / 2)
    end)
  end)
end

local fullLv1Stats = function (fiveStarLv1Stats)
  local order = {0, unpack(arrayOrder(ListUtil.sub(fiveStarLv1Stats, 2, 5)))}
  return ListUtil.generate(5, function (rarity)
    return ListUtil.zip(fiveStarLv1Stats, order, function (b, o)
      return b - math.floor((5 - rarity + (o < 2 and 1 or 0)) / 2)
    end)
  end)
end

local fullLv40Stats = function (rateSet, full1StatSet)
  return ListUtil.map(full1StatSet, function (statSet, rarity)
    return ListUtil.zip(statSet, rateSet, function (base, rate)
      return base + getGrowthValue(rarity, rate)
    end)
  end)
end

return {
  getMasterGrowthRate = getMasterGrowthRate,
  getGrowthValue = getGrowthValue,
  getSupergrowth = getSupergrowth,
  findGrowthRate = findGrowthRate,
  getRarityBonuses = getRarityBonuses,
  fullLv1Stats = fullLv1Stats,
  fullLv40Stats = fullLv40Stats,
}