Module:UnitEnlightenment

local p = {}

-- require("Module:Database") local dataModel = require("Module:Data").model

local skillPageName = function(iname) return 'Data:Game/MasterParam/Skill/' .. string.gsub(iname, '_', ' ') end

local abilPageName = function(iname) return 'Data:Game/MasterParam/Ability/' .. string.gsub(iname, '_', ' ') end

local tagMap = mw.loadData("Module:Data/Extra/TagMap") local statNameMap = mw.loadData("Module:Data/Extra/StatNameMap") local gateSteps = 5 -- local gateList = mw.loadData("Module:Data/MasterParam/UnitEnlightenment") local gateList = { Envy = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Envy"), Sloth = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Sloth"), Lust = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Lust"), Gluttony = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Gluttony"), Wrath = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Wrath"), Greed = mw.loadData("Module:Data/MasterParam/UnitEnlightenment/Greed"), }

local statNameFromKey = function(key) return (statNameMap[key] or key) end

local generateStatTableForGate = function(gateStats) local statPerLevel = function(level, val) return math.floor(level * val / gateSteps) end

local output = {}

table.insert(output, '{| class="wikitable"') table.insert(output, '! rowspan=2 colspan=1 |Level') table.insert(output, '! rowspan=1 colspan=5 |Stat') table.insert(output, '|-')

for ignore, tempStat in pairs(gateStats) do       if (tempStat['max'] > 0) then table.insert(output, '|'..statNameFromKey(tempStat['type'])) end end

table.insert(output, '|-') table.insert(output, '|1') table.insert(output, '| colspan = 5 | Max level +2')

for i=1,gateSteps do       table.insert(output, '|-') table.insert(output, '|'..(i == gateSteps and 'Max' or i+1)) for ignore, tempStat in pairs(gateStats) do           if (tempStat['max'] > 0) then table.insert(output, '| +'..statPerLevel(i, tempStat['max'])) end end end

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

local generateEnvyOutput = function(gateData) local output = {} table.insert(output, '=== Envy ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus (Upgraded Stats) ====') table.insert(output, '{| class="wikitable"') table.insert(output, '!Type') table.insert(output, '!Value') for ignore, tempStat in pairs(gateData['maxBonus']['stats']) do       if (tempStat['max'] > 0) then table.insert(output, '|-') table.insert(output, '|'..statNameFromKey(tempStat['type'])) table.insert(output, '| +'..tempStat['max']) end end table.insert(output, '|}') return table.concat(output, "\n") end

local generateSlothOutput = function(gateData) local output = {} table.insert(output, '=== Sloth ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus (Upgraded Ability) ====') local targetAbility local replaceAbility if gateData.maxBonus then if gateData['maxBonus']['origBuffKey'] and gateData['maxBonus']['upgradedBuffKey'] then targetAbility = dataModel.query("Ability", 'skl1', {where = 'iname="'..gateData['maxBonus']['origBuffKey']..'" and server = "gl"'})[1] or {} replaceAbility = dataModel.query("Ability", 'skl1', {where = 'iname="'..gateData['maxBonus']['upgradedBuffKey']..'" and server = "gl"'})[1] or {} if (targetAbility['skl1'] == nil or replaceAbility['skl1'] == nil) then table.insert(output, 'Upgrade data not currently available') return table.concat(output, "\n") end elseif gateData.maxBonus.abil_iname then local abilPageName = abilPageName(gateData['maxBonus']['abil_iname']) local abilExpr = dataModel.getLoc(abilPageName, 'expr') table.insert(output, abilExpr) return table.concat(output, "\n") end else table.insert(output, 'Upgrade data not currently available') return table.concat(output, "\n") end local targetPageName = skillPageName(targetAbility['skl1']) local targetName = dataModel.getLoc(targetPageName, 'name') local targetExpr = dataModel.getLoc(targetPageName, 'expr') local replacePageName = skillPageName(replaceAbility['skl1']) local replaceName = dataModel.getLoc(replacePageName, 'name') local replaceExpr = dataModel.getLoc(replacePageName, 'expr') table.insert(output, '{| class="wikitable"') table.insert(output, '!Type') table.insert(output, '!Name') table.insert(output, '!Description')

table.insert(output, '|-') table.insert(output, '|Upgraded') table.insert(output, '|'..replaceName) table.insert(output, '|'..replaceExpr) table.insert(output, '|-') table.insert(output, '|Original') table.insert(output, '|'..targetName) table.insert(output, '|'..targetExpr) table.insert(output, '|}') return table.concat(output, "\n") end

local generateLustOutput = function(gateData) local output = {} table.insert(output, '=== Lust ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus (Upgraded Leader Skill) ====') local leaderBonus = dataModel.getLoc(skillPageName(gateData['maxBonus']), 'expr') if leaderBonus then table.insert(output, leaderBonus) else table.insert(output, gateData['maxBonus']) end return table.concat(output, "\n") end

local generateGluttonyOutput = function(gateData) local output = {} local categories = {} table.insert(output, '=== Gluttony ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus (Upgraded Stats) ====') table.insert(output, '{| class="wikitable"') table.insert(output, '!Type') table.insert(output, '!Value') for ignore, tempStat in pairs(gateData['maxBonus']['stats']) do       if (tempStat['max'] > 0) then table.insert(output, '|-') if (tempStat['type'] == 'Tokkou') then local sinTag = tagMap[tempStat['tktag']] or tempStat['tktag'] table.insert(output, '|Strong vs '..sinTag) table.insert(categories, '') else table.insert(output, '|'..statNameFromKey(tempStat['type'])) end table.insert(output, '| +'..tempStat['max']) end end table.insert(output, '|}') table.insert(output, table.concat(categories, " ")) return table.concat(output, "\n") end

local generateWrathOutput = function(gateData) local output = {} table.insert(output, '=== Wrath ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus (Upgraded Abilities) ====') for ignore, tempUpgrade in pairs(gateData['maxBonus']) do       local targetName = dataModel.getLoc(skillPageName(tempUpgrade['target']['key']), 'name') local targetExpr = dataModel.getLoc(skillPageName(tempUpgrade['target']['key']), 'expr')

local replaceName = dataModel.getLoc(skillPageName(tempUpgrade['replace']['key']), 'name') local replaceExpr = dataModel.getLoc(skillPageName(tempUpgrade['replace']['key']), 'expr') table.insert(output, '{| class="wikitable"') table.insert(output, '!Type') table.insert(output, '!Name') table.insert(output, '!Description')

table.insert(output, '|-') table.insert(output, '|Upgraded') table.insert(output, '|'..replaceName) table.insert(output, '|'..replaceExpr) table.insert(output, '|-') table.insert(output, '|Original') table.insert(output, '|'..targetName) table.insert(output, '|'..targetExpr) table.insert(output, '|}') end return table.concat(output, "\n") end

local generateGreedOutput = function(gateData) local output = {} table.insert(output, '=== Greed ===') table.insert(output, generateStatTableForGate(gateData['stats']['stats'])) table.insert(output, '==== Max Bonus ====') table.insert(output, 'Sub-Memento Slot') return table.concat(output, "\n") end

function p.unitEnlightenmentList(frame) local args = require('Module:Arguments').getArgs(frame, {       parentFirst = true,    }) local iname = args[1] return p._unitEnlightenmentList(iname) end

function p._unitEnlightenmentList(iname) if iname == nil then return 'Invalid parameter' end local finalOutput = {}

if gateList['Envy'][iname] then table.insert(finalOutput, generateEnvyOutput(gateList['Envy'][iname])) end

if gateList['Sloth'][iname] then table.insert(finalOutput, generateSlothOutput(gateList['Sloth'][iname])) end

if gateList['Lust'][iname] then table.insert(finalOutput, generateLustOutput(gateList['Lust'][iname])) end

if gateList['Gluttony'][iname] then table.insert(finalOutput, generateGluttonyOutput(gateList['Gluttony'][iname])) end

if gateList['Wrath'][iname] then table.insert(finalOutput, generateWrathOutput(gateList['Wrath'][iname])) end

if gateList['Greed'][iname] then table.insert(finalOutput, generateGreedOutput(gateList['Greed'][iname])) end

local output = table.concat(finalOutput, "\n") if output == '' then return '' else return ('== Enlightenment ==\n\n'..output) end end

function p.test local iname = 'UN_V2_L_UROB' return p._unitEnlightenmentList(iname) end

return p