Module:Data/BuffStats

local p = {}

local cargo = require('Module:CargoUtil') local model = require('Module:Data').model local enums = require('Module:Data/Enums')

function p.scaleStat(ini, max, currentLevel, maxLevel) return math.floor(ini + (max - ini) * 100 / (maxLevel - 1) * (currentLevel - 1) / 100) end

function p.getBuffFromKey(iname) local rows = cargo.query{ tables = 'Buff, BuffDetail', join = 'Buff.iname = BuffDetail.buff_iname', fields = { 'Buff.iname = iname', 'BuffDetail.idx = idx', 'BuffDetail.calc = calc', 'BuffDetail.tktag = tktag', 'BuffDetail.type = type', 'BuffDetail.vini = vini', 'BuffDetail.vmax = vmax', 'BuffDetail.vone = vone', },   	where = { 'Buff.iname = "'..iname..'"', 'Buff.server = "gl"', 'BuffDetail.server = "gl"', },   }    local buff = { iname = iname, details = {} }   for i, row in ipairs(rows) do    	buff.details[tonumber(row.idx)] = { calc = tonumber(row.calc), tktag = tonumber(row.tktag), type = tonumber(row.type), vini = tonumber(row.vini), vmax = tonumber(row.vmax), vone = tonumber(row.vone), }   end return buff end

function p.getBuffStatsFromLevel(buff, currentLevel, maxLevel) local stats = {} for i, detail in ipairs(buff.details) do       local type = detail.type local tkKey = detail.tktag if detail.type and detail.type ~= 0 then local tempVal = p.scaleStat(detail.vini, detail.vmax, currentLevel, maxLevel) table.insert(stats, (enums.statNameFromType(detail.type, detail.tktag) .. ' '..(tempVal >= 0 and '+' or '').. tempVal)) end end return stats end

return p