Module:GearStats

local p = {}

local model = require('Module:Data').model local buffStats = require('Module:Data/BuffStats') local enums = require('Module:Data/Enums') local render_unit_icon = require('Module:Render/Unit')._icon local render_job_icon = require('Module:Render/Job')._icon

-- model.getLoc = function(_pageName, param) --    if _pageName == nil then return '???' end --    local where = "_pageName='".._pageName.."' and param='"..param.."' and value<>'' and lang='" --    local thisLang = mw.ext.cargo.query('Loc','value',{where=where.."english'"}) --    if #thisLang == 0 then thisLang = mw.ext.cargo.query('Loc','value',{where=where.."english'"}) end --    if #thisLang == 0 then thisLang = mw.ext.cargo.query('Loc','value',{where=where.."japanese'"}) end --    if #thisLang == 0 then thisLang =  end --    return thisLang[1].value -- end

local gear_level_map = { [1]=10,   [2]=15,    [3]=20,    [4]=25,    [5]=30, }

local maxRarity = 5

local function pageNameByType(iname, pageType) if iname == nil then return nil end if pageType == nil then return nil end return 'Data:Game/MasterParam/'..pageType..'/' .. string.gsub(iname, '_', ' ') end

local function AbilityFromKey(iname) if iname == nil then return nil end return model.query("Ability", '_pageName,skl1,jobs,elem,birth,units,sex', {where = 'iname="'..iname..'" and server = "gl"'})[1] or {} end

local function skillFromKey(iname) if iname == nil then return nil end return model.query("Skill", '_pageName,t_buff,s_buff', {where = 'iname="'..iname..'" and server = "gl"'})[1] or {} end

function p.getMaxGearLevelFromRarity(rarity) return gear_level_map[rarity] or gear_level_map[maxRarity] end

function p.getStatOutputFromRarity(gear, rarity, fieldKey) local equipSkill = skillFromKey(gear[fieldKey..rarity]) if not equipSkill then return '' end

-- Handle both types of buffs local gearStatOutput = {} local buffKeys = {'t_buff', 's_buff'} for ignore, tempBuffKey in pairs(buffKeys) do       if equipSkill[tempBuffKey] then equipBuff = buffStats.getBuffFromKey(equipSkill[tempBuffKey]) if equipBuff.iname then local gearStats = table.concat(buffStats.getBuffStatsFromLevel(equipBuff, p.getMaxGearLevelFromRarity(rarity), p.getMaxGearLevelFromRarity(maxRarity)), "\n\n") if gearStats ~= '' then table.insert(gearStatOutput, gearStats) end end end end return table.concat(gearStatOutput, "\n\n") end

function p.getAttackSkillFromRarity(gear, rarity) local attackSkill = skillFromKey(gear['attack'..rarity]) if not attackSkill then return end if not attackSkill._pageName then return end return model.getLoc(attackSkill._pageName, 'expr') end

function p.getGearAbilityRarityMap(gear) if gear.abilityList ~= nil then return gear.abilityList end local gearAbilityList = {} local minRarity = gear.abrares[1] or '' local index = 0 for ignore, abilKey in pairs(gear.abils) do       index = index + 1 local tempAbil = AbilityFromKey(abilKey) if tempAbil.skl1 ~= nil then local tempSkillPageName = pageNameByType(tempAbil.skl1, 'Skill') table.insert(gearAbilityList, {               abilKey = abilKey,                skillKey = tempAbil.skl1,                skillName = model.getLoc(tempSkillPageName, 'name'),                skillDesc = model.getLoc(tempSkillPageName, 'expr'),                minRarity = ((tonumber(string.sub(minRarity, index, index)) or 0) + 1),                abilData = tempAbil,            }) end end gear.abilityList = gearAbilityList return gear.abilityList end

function p.getGearStatTypesByRarity(gear, rarity) local gearStatTypes = {} table.insert(gearStatTypes, {       name = 'Max Stats',         content = p.getStatOutputFromRarity(gear, rarity, 'equip')    }) -- Get PvP Stats local pvpStats = p.getStatOutputFromRarity(gear, rarity, 'pvp_equip') if pvpStats ~= '' then table.insert(gearStatTypes, {           name = 'PvP Only Stats',             content = pvpStats        }) end -- Get Attack Skills local tempAttackSkill = p.getAttackSkillFromRarity(gear, rarity) if tempAttackSkill then table.insert(gearStatTypes, {           name = 'Attack Skill',             content = tempAttackSkill        }) end -- Get Abilities local tempAbilities = {} local tempAbilityCount = 0 local gearAbilityList = p.getGearAbilityRarityMap(gear) for ignore, abilData in pairs(gearAbilityList) do       if rarity >= abilData.minRarity then table.insert(tempAbilities, abilData['skillName']) tempAbilityCount = tempAbilityCount + 1 end end

if tempAbilityCount > 0 then table.insert(gearStatTypes, {           name = 'Gear Ability',             content = table.concat(tempAbilities, "\n")        }) end

return gearStatTypes end

function p.getGearStatOutput(gear) local output = {} table.insert(output, ' ') table.insert(output, '==Stats by Rarity==')

local gearMinRarity = gear.rini + 1

for r = maxRarity, gearMinRarity, -1 do       local gearStatTypes = p.getGearStatTypesByRarity(gear, r)        if gearStatTypes then table.insert(output, ' ') table.insert(output, '{|class="wikitable" style="width:80%; padding-left:10%;"') table.insert(output, '!'..r..'★') for ignore, statOutput in pairs(gearStatTypes) do	           table.insert(output, '|-') table.insert(output, '!'..statOutput.name) table.insert(output, '|-') table.insert(output, '|'..statOutput.content) end table.insert(output, '|}') table.insert(output, ' ') end end

table.insert(output, ' ') return table.concat(output, "\n") end

function p.gearAbilityOutput(gear) local tempAttackSkillOutput = {} local output = {} local tempAbilityCount = 0

local abilityList = p.getGearAbilityRarityMap(gear) for ignore, abilData in pairs(abilityList) do       tempAbilityCount = tempAbilityCount + 1 table.insert(tempAttackSkillOutput, ' ') table.insert(tempAttackSkillOutput, '{|class="wikitable" style="width:100%;"') table.insert(tempAttackSkillOutput, '!'..abilData['skillName']) table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|'..abilData['skillDesc']) local tempUnitList = {} local tempUnitCount = 0 for ignore,unitKey in pairs(abilData['abilData']['units']) do           local tempUnitData = model.query('Unit','iname',{where='iname="'..unitKey..'"'})[1] or {} if tempUnitData then table.insert(tempUnitList, render_unit_icon({ unitKey, size = 'small', name = 'none' })) -- table.insert(tempUnitList, unitKey) end tempUnitCount = tempUnitCount + 1 end if tempUnitCount > 0 then table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|'..table.concat(tempUnitList, ' ')) end local tempJobList = {} local tempJobCount = 0 for ignore,jobKey in pairs(abilData['abilData']['jobs']) do           local tempJobData = model.query('Job','iname',{where='iname="'..jobKey..'"'})[1] or {} if tempJobData then table.insert(tempJobList, render_job_icon({ jobKey, size = 'small', name = 'none' })) -- table.insert(tempJobList, jobKey) tempJobCount = tempJobCount + 1 end end if tempJobCount > 0 then table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|'..table.concat(tempJobList, ' ')) end mw.logObject(abilData['abilData']) if abilData['abilData']['sex'] ~= '' then local tempSex = enums.sexFromKey(abilData['abilData']['sex']) if tempSex then table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|'..tempSex) end end if abilData['abilData']['birth'] ~= '' then local tempOrigin = enums.originFromNameKey(abilData['abilData']['birth']) if tempOrigin then table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|'..tempOrigin) end end if abilData['abilData']['elem'] ~= '' then local tempElem = enums.elemFromKey(abilData['abilData']['elem']) if tempElem then table.insert(tempAttackSkillOutput, '|-') table.insert(tempAttackSkillOutput, '|') end end table.insert(tempAttackSkillOutput, '|}') table.insert(tempAttackSkillOutput, ' ') end

if tempAbilityCount > 0 then table.insert(output, ' ') table.insert(output, '==Gear Abilities==') table.insert(output, table.concat(tempAttackSkillOutput, "\n")) table.insert(output, ' ') end

return table.concat(output, "\n") end

return p