The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
Advertisement

Documentation for this module may be created at Module:Unit/Enlightenment/sandbox/doc

local cargo = require('Module:CargoUtil')
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 getBuffDetails(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

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 = {}

	local skill = getSkill(gateData['skill_iname'])
	local buffDetails = getBuffDetails(skill.t_buff)
	for level=1,5 do
		table.insert(output, '|-')

		-- Level column
		table.insert(output, '| style="text-align:center" | [[File:Kaigan icon'..level..'.png|'..10*level..'px|Level '..level..'|link=]]')

		-- Bonuses column
		table.insert(output, '|')
		local maxStats = {}
		
		for _, buff in ipairs(buffDetails) do
			if buff.vmax > 0 then
				table.insert(maxStats, enums.statNameFromType(buff.type)..'+'..statPerLevel(level, buff.vmax))
			end
		end
		table.insert(output, table.concat(maxStats, '<br>'))

		-- Materials column
		table.insert(output, '|<div style="display:flex; flex-wrap:wrap">')
		local nameRecipe = gateData['recipe_id'] or ''
		local recipe = recipeList[nameRecipe]['lvl_'..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, size='noname'}))
		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, size='noname'}))
		end
		
		for _, mat in pairs(recipe['mats']) do
			table.insert(mats, (render_item_icon({mat.iname, count=mat.num, size='noname'}) or ''))
		end
		table.insert(output, table.concat(mats, '&nbsp;'))
		
		-- Gold column
		table.insert(output, '| style="text-align:center" |'..recipe.cost..'<br>[[File:Game,ItemIcon,IT_MS_GOLD.png|20px|Zeni|link=]]')
	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" |<div class="mw-customtoggle-table0" style="float:right; display:inline; color:black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Unit Lv85<br>\'\'\'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" |<div style="display:flex; flex-wrap:wrap">')
	local mats = {}
	for _, mat in pairs(recipe['mats']) do
		table.insert(mats, (render_item_icon({mat.iname, count=mat.num, size='noname'}) or ''))
	end
	table.insert(output, table.concat(mats, '&nbsp;'))
		
	-- Gold column
	table.insert(output, '| style="text-align:center" |'..recipe.cost..'<br>[[File:Game,ItemIcon,IT_MS_GOLD.png|20px|Zeni|link=]]')
	
	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']
	local buffDetails = getBuffDetails(tempBuff)
	mw.logObject(buffDetails, 'envy buff')

	for _, buff in ipairs(buffDetails) do
		if 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" |[[File:Gate1 icon.png|75px|Gate of Envy|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table1" style="float:right; display:inline; color:black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : None<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'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]
	local newSkill = {}
	local oldSkill = {}
	local targetJob
	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" |[[File:Gate2 icon.png|75px|Gate of Sloth|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table2" style="float:right; display:inline; color: black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Gate of Envy Level 2 + '..render_job_icon({targetJob, size='small'})..' Lv11<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'Master Bonuses\'\'\' : Changes '..oldSkill.name..' into '..newSkill.name..'</div>',
		'|- style="background:#de813b"',
		'| colspan="4"| <span style="font-weight:bolder">'..oldSkill.name..'</span>: '..oldSkill.expr,
		'|- style="background:#de813b"',
		'| colspan="4"| <span style="font-weight:bolder">'..newSkill.name..'</span>: '..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" |[[File:Gate3 icon.png|75px|Gate of Lust|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table3" style="float:right; display:inline; color: black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Gate of Sloth Level 2<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'Master Bonuses\'\'\' : Enhanced Leader Skill ('..newLeader.name..')',
		'|- style="background:#bc3cdd"',
		'| colspan="4"| <span style="font-weight:bolder">'..oldLeader.name..'</span> (old): '..oldLeader.expr,
		'|- style="background:#bc3cdd"',
		'| colspan="4"| <span style="font-weight:bolder">'..newLeader.name..'</span> (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']
	local buffDetails = getBuffDetails(tempBuff)
	
	for i, buff in ipairs(buffDetails) do
		if buff.vmax > 0 then
			if buff.type == 153 then
				local sinTag = tagMap[buff.tktag]
				table.insert(masterStats, 'Strong vs '..sinTag)
				table.insert(categories, '[[Category:Strong vs '..sinTag..']]')
			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" |[[File:Gate4 icon.png|75px|Gate of Gluttony|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table4" style="float:right; display:inline; color: black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Gate of Lust Level 2<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'Master Bonuses\'\'\' : Increased attributes [Sin: Gluttony]: '..table.concat(masterStats, ', ')..'</div>',
		'|- 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]
	
	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" |[[File:Gate5 icon.png|75px|Gate of Wrath|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table5" style="float:right; display:inline; color: black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Gate of Gluttony Level 2<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'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" |[[File:Gate6 icon.png|75px|Gate of Greed|link=]]',
		'| colspan="3" style="padding:5px 2px" |<div class="mw-customtoggle-table6" style="float:right; display:inline; color: black; text-align:center; font-weight:bold; font-size:12px">Show/Hide<br>Details</div>\'\'\'Requirements\'\'\' : Gate of Wrath Level 2<br>\'\'\'Unlock Bonus\'\'\' : Max Level+2<br>\'\'\'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 '[[Category:Max Level 85]]' 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, '[[Category:Max Level 87]]') end
	end
	if gates[3]['enable'] then
		table.insert(finalOutput, generateSlothTable(iname))
		if not gates[4]['enable'] then table.insert(finalOutput, '[[Category:Max Level 89]]') end
	end
	if gates[4]['enable'] then
		table.insert(finalOutput, generateLustTable(iname))
		if not gates[5]['enable'] then table.insert(finalOutput, '[[Category:Max Level 91]]') end
	end
	if gates[5]['enable'] then
		table.insert(finalOutput, generateGluttonyTable(iname))
		if not gates[6]['enable'] then table.insert(finalOutput, '[[Category:Max Level 93]]') end
	end
	if gates[6]['enable'] then
		table.insert(finalOutput, generateWrathTable(iname))
		if not gates[7]['enable'] then table.insert(finalOutput, '[[Category:Max Level 95]]') end
	end
	if gates[7]['enable'] then
		table.insert(finalOutput, generateGreedTable(iname))
		table.insert(finalOutput, '[[Category:Max Level 97]]')
	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
Advertisement