Documentation for this module may be created at Module:Page/Job/Stats/sandbox/doc
local cargo = require('Module:CargoUtil')
local model = require('Module:Data').model
local enums = require('Module:Data/Enums')
local p = {}
local pageNameByType = function(iname, pageType)
return 'Data:Game/MasterParam/'..pageType..'/' .. string.gsub(iname, '_', ' ')
end
local function getItem(iname)
if iname == nil then return end
return model.query('Item', '_pageName, iname, skill', {where = 'iname = "'..iname..'" AND server = "gl"'})[1]
end
local function getSkill(iname)
if iname == nil then return end
return model.query('Skill', '_pageName, iname, t_buff', {where = 'iname = "'..iname..'" AND server = "gl"'})[1]
end
local function getBuff(iname)
if iname == nil then return end
local buffDetails = {}
local numericFields = {'idx', 'calc', 'type', 'vini', 'vmax', 'vone'}
for i, row in ipairs(cargo.query{
tables = 'BuffDetail',
fields = {
'_pageName',
'idx',
'calc',
'tktag',
'type',
'vini',
'vmax',
'vone',
},
where = 'buff_iname = "'..iname..'" AND server = "gl"',
orderBy = 'idx',
}) do
for _, field in ipairs(numericFields) do
row[field] = tonumber(row[field]) or 0
end
buffDetails[tonumber(row.idx)] = row
end
return buffDetails
end
function p.equipStats(iname)
if iname == nil then return end
local jobs = cargo.query{
tables = 'JobRank',
fields = 'idx, eqid1, eqid2, eqid3, eqid4, eqid5, eqid6, learn1, learn2',
where = 'job_iname = "'.. iname ..'" AND server = "gl"',
}
local stats = {}
for _, entry in pairs(jobs) do
-- looping through the levels and checking each item
for equip=1, 6 do
local tempKey = 'eqid'..equip
local item = getItem(entry[tempKey])
if item.skill then
local skill = getSkill(item.skill)
local buff = getBuff(skill.t_buff)
-- having the buff, we check the data and put it in a table where the index match the stat type
for _, buff in ipairs(buff) do
if buff.vini > 0 then
if stats[buff.type] then
stats[buff.type] = stats[buff.type] + buff.vini
else
stats[buff.type] = buff.vini
end
end
end
end
end
end
return stats
end
function p.masterStats(iname)
if iname == nil then return end
local job = model.query('Job', '_pageName, iname, master', {where = 'iname = "'..iname..'" AND server = "gl"'})[1]
local skill = getSkill(job.master)
local buff = getBuff(skill.t_buff)
local stats = {}
for _, buff in ipairs(buff) do
-- every stat not in percentage goes in postive indexes
if buff.vini > 0 and buff.calc == 0 then
if stats[buff.type] then
stats[buff.type] = stats[buff.type] + buff.vini
else
stats[buff.type] = buff.vini
end
-- every stat in percentage goes in negative indexesT
elseif buff.vini > 0 and buff.calc == 1 then
if stats[-buff.type] then
stats[-buff.type] = stats[-buff.type] + buff.vini
else
stats[-buff.type] = buff.vini
end
end
end
return stats
end
function p.modifierStats(iname)
local job = model.query("Job", "_pageName, iname, ac2d, mdl, type, wepmdl, master, origin, role, ai, artifact, fixabl, atk, atkskl, avoid, cri, def, dex, hp, inimp, jjmp, jmov, luk, mag, mnd, mp, spd", {where = 'iname="'..iname..'"'})[1]
local statNameMap = {['avoid'] = 80, ['hp'] = 2, ['mp'] = 3, ['atk'] = 5, ['def'] = 6, ['mag'] = 7, ['mnd'] = 8, ['dex'] = 10, ['spd'] = 11, ['cri'] = 12, ['luk'] = 13}
stats = {}
for stat, i in pairs(statNameMap) do
if job[stat] and job[stat] ~= 0 then
stats[-i] = job[stat]
end
end
return stats
end
function p.statTable(iname)
if iname == nil then return end
-- table containing all the stats
stats = {
p.equipStats(iname),
p.modifierStats(iname),
p.masterStats(iname)
}
-- hp, patk, pdef, matk, mdef, dex, agi, crit, luck, max jewels
basicStats = {2, 5, 6, 7, 8, 10, 11, 12, 13, 3}
output = {
'{| class="wikitable" style="width:calc(100% - 20px); background-color:#e0e0e0; text-align:center"',
'|-',
'| colspan="4" style="background-color:#33ccff; text-align:center; font-weight:bold"| Primary Stats',
'|- style="background-color:#33ccff; text-align:center; font-weight:bold',
'| Type || Equipment || Modifier || Master Bonus'
}
for _, stat in pairs(basicStats) do
table.insert(output, '|-')
table.insert(output, '|'..enums.statNameFromType(stat))
for i=1,3 do
st1 = stats[i][stat] or 0 -- stat not in percentage, equals 0 if nil
st2 = stats[i][-stat] or 0 -- stat in percentage, equals 0 if nil
-- disgusting piece of code here but didn't find any other solution.
-- I have to check the sign of each stat as well as if it is in percentage or not
if st1 > 0 and st2 > 0 then
table.insert(output, '| +'..st1..', +'..st2..'%')
elseif st1 > 0 and st2 < 0 then
table.insert(output, '| +'..st1..', '..st2..'%')
elseif st1 < 0 and st2 > 0 then
table.insert(output, '| '..st1..', +'..st2..'%')
elseif st1 < 0 and st2 < 0 then
table.insert(output, '| '..st1..', '..st2..'%')
elseif st1 == 0 and st2 > 0 then
table.insert(output, '| +'..st2..'%')
elseif st1 == 0 and st2 < 0 then
table.insert(output, '| '..st2..'%')
elseif st1 > 0 and st2 == 0 then
table.insert(output, '| +'..st1)
elseif st1 < 0 and st2 == 0 then
table.insert(output, '| '..st1)
elseif st1 == 0 and st2 == 0 then
table.insert(output, '| –')
end
end
end
table.insert(output, '|}')
return table.concat(output, '\n')
end
function p.test(frame)
local args = require("Module:Arguments").getArgs(frame)
return p.statTable(args[1])
end
return p