Module:Unit/Enlightenment/sandbox

local model = require('Module:Data').model local render_item_icon = require('Module:Render/Item')._icon local render_job_icon = require('Module:Render/Job')._icon local enums = require('Module:Data/Enums') local tobira = mw.loadData("Module:Data/MasterParam/Tobira")

local p = {}

function p.getUnitData(iname) return model.query("Unit", "_pageName, iname, ability, ai, atk, birth_id, cri, def, dex, elem, height, hero, hp, img, jobsets, ls1, ls2, ls3, ls4, ls5, ls6, luk, ma_lv, ma_quest, ma_rarity, mag, matk, mcri, mdef, mdex, mdl, mhp, mluk, mmnd, mmp, mnd, mp, mspd, notsmn, piece, rare, raremax, recipe1, recipe2, recipe3, recipe4, sex, skill, skins, spd, tag, vce, weight", {where = 'iname="'..iname..'" and server = "gl"'})[1] or {} end

local function getSkill(iname) if iname == nil then return end return model.query('Skill', 't_buff', {where = 'iname = "'..iname..'" AND server = "gl"'})[1] end

local function getBuff(iname, idx) if iname == nil then return end return model.query('BuffDetail', '_pageName, type, vmax, tktag', {where = 'buff_iname = "'..iname..'" AND server = "gl"', orderBy = 'idx'})[1] end

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 gateList = { Unlock = 1, Envy = 2, Sloth = 3, Lust = 4, Gluttony = 5, Wrath = 6, Greed = 7, Pride = 8 }

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

local rowsRecipeStats = function(gate, unit) if (not gate or not unit) then return 'Invalid parameters' end local unitData = p.getUnitData(unit)

local recipeList = mw.loadData("Module:Data/MasterParam/TobiraRecipe") local gateData = tobira[unit][gateList[gate]] local statPerLevel = function(level, val) return math.floor(level* val/5) end local output = {}

for level=1,5 do		table.insert(output, '|-')

-- Level column table.insert(output, '| style="text-align:center" | ')

-- Bonuses column table.insert(output, '|') local maxStats = {} local tempBuff = getSkill(gateData['skill_iname']).t_buff for j=1,11 do			local buff = getBuff(tempBuff, j)			if tonumber(buff.vmax) > 0 then table.insert(maxStats, enums.statNameFromType(buff.type)..'+'..statPerLevel(level, buff.vmax)) end end table.insert(output, table.concat(maxStats, ' '))

-- Materials column table.insert(output, '| ') local nameRecipe = gateData['recipe_id'] or '' local level = 'lvl_'..level local recipe = recipeList[nameRecipe][level] local mats = {} local shard = unitData.piece if (shard and recipe.unit_piece_num > 0) then table.insert(mats, render_item_icon({shard, count=recipe.unit_piece_num})) end local country = enums.originItemFromKey(unitData.birth_id) if (country and recipe.unlock_birth_num > 0) then table.insert(mats, render_item_icon({country, count=recipe.unlock_birth_num})) end for _, mat in pairs(recipe['mats']) do			table.insert(mats, (render_item_icon({mat.iname, count=mat.num}) or '')) end table.insert(output, table.concat(mats, ' ')) -- Gold column table.insert(output, '| style="text-align:center" |'..recipe.cost..' ') end return table.concat(output, '\n') end

local generateUnlockTable = function(unit) if not tobira[unit][1]['enable'] then return '' end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table0"', '|- style="background:#b3b3b3; height:75px"', '| style="width:75px; text-align:center; font-weight:bolder; font-variant:small-caps" |Unlock', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Unit Lv85 \'\'\'Unlock Bonus\'\'\' : Max Level+2', '|- style="background:#b3b3b3; font-weight:bold',		'| ',		'| colspan="2" | Materials',		'| Cost'	}

local recipeList = mw.loadData("Module:Data/MasterParam/TobiraRecipe") local nameRecipe = tobira[unit][1]['recipe_id'] local recipe = recipeList[nameRecipe]['lvl_0'] table.insert(output, '|-') table.insert(output, '| style="text-align:center" |')

-- Materials column table.insert(output, '| colspan="2" | ') local mats = {} for _, mat in pairs(recipe['mats']) do		table.insert(mats, (render_item_icon({mat.iname, count=mat.num}) or '')) end table.insert(output, table.concat(mats, ' ')) -- Gold column table.insert(output, '| style="text-align:center" |'..recipe.cost..' ') table.insert(output, '|}') return table.concat(output, '\n') end

local generateEnvyTable = function(unit) if not tobira[unit][2]['enable'] then return '' end local masterStats = {} local ability = tobira[unit][2]['learn_abils'][1]['abil_iname'] local skill = model.query("Ability", '_pageName,iname,skl1', {where = 'iname="'..ability..'" and server = "gl"'})[1]['skl1'] local tempBuff = model.query('Skill', 't_buff', {where = 'iname = "'..skill..'" AND server = "gl"'})[1]['t_buff'] for i=1,11 do		local buff = model.query("BuffDetail", '_pageName, type, vini, vmax', {where = 'buff_iname ="'..tempBuff..'" AND server = "gl" AND idx	="'..i..'"'})[1] if tonumber(buff['vmax']) > 0 then table.insert(masterStats, enums.statNameFromType(buff['type'])..'+'..tonumber(buff['vmax'])) end end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table1"', '|- style="background:#41add8"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : None \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : Increased Attributes [Sin: Envy]: '..table.concat(masterStats, ', '), '|- style="font-weight:bold; text-align:center; background:#41add8"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Envy', unit) table.insert(output, stats) table.insert(output, '|}') return table.concat(output, '\n') end

local generateSlothTable = function(unit) if not tobira[unit][3]['enable'] then return '' end local gateData = tobira[unit][3] local master = gateData['learn_abils'][1] if master then local newAbil = model.query("Ability", 'skl1', {where = 'iname="'..master['abil_iname']..'"and server = "gl"'})[1]['skl1'] newSkill = { name = model.getLoc(skillPageName(newAbil), 'name'), expr = model.getLoc(skillPageName(newAbil), 'expr') }		local oldAbil = model.query("Ability", 'skl1', {where = 'iname="'..master['abil_overwrite']..'"and server = "gl"'})[1]['skl1'] oldSkill = { name = model.getLoc(skillPageName(oldAbil), 'name'), expr = model.getLoc(skillPageName(oldAbil), 'expr') }		targetJob = master['target_job'] end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table2"', '|- style="background:#de813b"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Gate of Envy Level 2 + '..render_job_icon({targetJob, size='small'})..' Lv11 \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : Changes '..oldSkill.name..' into '..newSkill.name..' ', '|- style="background:#de813b"', '| colspan="4"| '..oldSkill.name..' : '..oldSkill.expr, '|- style="background:#de813b"', '| colspan="4"| '..newSkill.name..' : '..newSkill.expr, '|- style="font-weight:bold; text-align:center; background:#de813b"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Sloth', unit) table.insert(output, stats) table.insert(output, '|}') return table.concat(output, '\n') end

local generateLustTable = function(unit) if not tobira[unit][4]['enable'] then return '' end local gateData = tobira[unit][4] local inameLeader = gateData['overwrite_ls_iname'] local newLeader = { name = model.getLoc(skillPageName(inameLeader), 'name'), expr = model.getLoc(skillPageName(inameLeader), 'expr') }	local inameOld = model.query("Unit", 'ls5', {where = 'iname="'..unit..'" and server="gl"'})[1]['ls5'] local oldLeader = { name = model.getLoc(skillPageName(inameOld), 'name'), expr = model.getLoc(skillPageName(inameOld), 'expr') }	local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table3"', '|- style="background:#bc3cdd"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Gate of Sloth Level 2 \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : Enhanced Leader Skill ('..newLeader.name..')', '|- style="background:#bc3cdd"', '| colspan="4"| '..oldLeader.name..' (old): '..oldLeader.expr, '|- style="background:#bc3cdd"', '| colspan="4"| '..newLeader.name..' (new): '..newLeader.expr, '|- style="font-weight:bold; text-align:center; background:#bc3cdd"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Lust', unit) table.insert(output, stats) table.insert(output, '|}') return table.concat(output, '\n') end

local generateGluttonyTable = function(unit) if not tobira[unit][5]['enable'] then return '' end local masterStats = {} local categories = {} local ability = tobira[unit][5]['learn_abils'][1]['abil_iname'] local skill = model.query("Ability", '_pageName,iname,skl1', {where = 'iname="'..ability..'" and server = "gl"'})[1]['skl1'] local tempBuff = model.query('Skill', 't_buff', {where = 'iname = "'..skill..'" AND server = "gl"'})[1]['t_buff']

for i=1,11 do		local buff = getBuff(tempBuff, i)		if tonumber(buff.vmax) > 0 then if tonumber(buff.type) == 153 then local sinTag = tagMap[buff.tktag] table.insert(masterStats, 'Strong vs '..sinTag) table.insert(categories, '') else table.insert(masterStats, enums.statNameFromType(buff.type)..'+'..tonumber(buff.vmax)) end end end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table4"', '|- style="background:#7dd926"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Gate of Lust Level 2 \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : Increased attributes [Sin: Gluttony]: '..table.concat(masterStats, ', ')..' ', '|- style="font-weight:bold; text-align:center; background:#7dd926"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Gluttony', unit) table.insert(output, stats) table.insert(output, '|}') table.insert(output, table.concat(categories, '')) return table.concat(output, '\n') end

local generateWrathTable = function(unit) if not tobira[unit][6]['enable'] then return '' end local ability = tobira[unit][6]['learn_abils'][1]['abil_iname'] local tempSkill = model.query("Ability", '_pageName,iname,skl1', {where = 'iname="'..ability..'" and server = "gl"'})[1]['skl1'] local upgradeName = model.getLoc(skillPageName(tempSkill), 'expr') local Skill = model.query("Skill", '_pageName, iname, rp_chg_ids, rp_tgt_ids', {where = 'iname="'..tempSkill..'" and server = "gl"'})[1] -- names of the replaced and replacing skills in inameReplace and inameTarget respectively local inameReplace = {} local inameTarget = {} if #Skill.rp_chg_ids == #Skill.rp_tgt_ids then for i=1,#Skill.rp_chg_ids do			table.insert(inameReplace, Skill.rp_chg_ids[i]) table.insert(inameTarget, Skill.rp_tgt_ids[i]) end end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table5"', '|- style="background:#e03852"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Gate of Gluttony Level 2 \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : '..upgradeName, '|- style="font-weight:bold; text-align:center; background:#e03852"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Wrath', unit) table.insert(output, stats) table.insert(output, '|}') return table.concat(output, '\n') end

local generateGreedTable = function(unit) if not tobira[unit][7]['enable'] then return '' end local output = { '{| class="enltable mw-collapsible mw-collapsed" id="mw-customcollapsible-table6"', '|- style="background:#ecda13"', '| style="width:75px; text-align:center" |', '| colspan="3" style="padding:5px 2px" |Show/Hide Details \'\'\'Requirements\'\'\' : Gate of Wrath Level 2 \'\'\'Unlock Bonus\'\'\' : Max Level+2 \'\'\'Master Bonuses\'\'\' : Sub-Memento Slot', '|- style="font-weight:bold; text-align:center; background:#ecda13"', '| Level', '| Bonuses', '| Materials', '| Cost', }	local stats = rowsRecipeStats('Greed', unit) table.insert(output, stats) table.insert(output, '|}') return table.concat(output, '\n') end

function p._unitEnlightenmentList(iname) if iname == nil then return 'Invalid parameter' end local finalOutput = {} local gates = tobira[iname] if not gates then return '' end if gates[1]['enable'] then table.insert(finalOutput, generateUnlockTable(iname)) end if gates[2]['enable'] then table.insert(finalOutput, generateEnvyTable(iname)) if not gates[3]['enable'] then table.insert(finalOutput, '') end end if gates[3]['enable'] then table.insert(finalOutput, generateSlothTable(iname)) if not gates[4]['enable'] then table.insert(finalOutput, '') end end if gates[4]['enable'] then table.insert(finalOutput, generateLustTable(iname)) if not gates[5]['enable'] then table.insert(finalOutput, '') end end if gates[5]['enable'] then table.insert(finalOutput, generateGluttonyTable(iname)) if not gates[6]['enable'] then table.insert(finalOutput, '') end end if gates[6]['enable'] then table.insert(finalOutput, generateWrathTable(iname)) if not gates[7]['enable'] then table.insert(finalOutput, '') end end if gates[7]['enable'] then table.insert(finalOutput, generateGreedTable(iname)) table.insert(finalOutput, '') end local output = table.concat(finalOutput, '\n') return ('== Enlightenment ==\n'..output) end

function p.test(frame) local args = require("Module:Arguments").getArgs(frame) return p._unitEnlightenmentList(args[1]) end

return p