Module:Page/Stat/sandbox

-- local cargo = require('Module:CargoUtil') local p = {} local h = {}

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {parentFirst = true}) return p._main(args) end

function p._main(args) local statID = args[1] local root = mw.html.create h.tableFor(root, statID, 'buff') h.tableFor(root, statID, 'debuff') if tostring(root) == '' then return "No results found." end return tostring(root) end

function h.tableFor(root, statID, buffXORdebuff) local statName = require('Module:Data/Enums').statNameFromType(statID) mw.log(buffXORdebuff) local whereVals = { buff = ' > 0', debuff = ' < 0', }	local t = {} for i=1,11 do		t[#t+1] = '(Buff.type'..i..' = '..statID..' AND Buff.vmax'..i..whereVals[buffXORdebuff]..')' end local buffs = {} local buff_inames = {} local buff_rows = cargo.query{ tables = 'Buff', fields = {'_pageName', 'iname'}, where = { 'server = "gl"', table.concat(t,' OR ') }, groupBy = 'iname', }	for i, row in ipairs(buff_rows) do		buffs[row.iname] = { _pageName = row._pageName, }		buff_inames[i] = '"'..row.iname..'"' end mw.log(#buff_rows, 'buffs') buff_inames = table.concat(buff_inames, ',') if #buff_rows == 0 then return end

-- SKILLS local skills = {} local skill_inames = {} local skill_rows = cargo.query{ tables = 'Skill, Loc = c1, Loc = c2', fields = { 'Skill._pageName=DATAPAGE', 'Skill.iname = iname', 'Skill.s_buff = s_buff', 'Skill.t_buff = t_buff', 'c1.value = name', 'c2.value = expr', },		where = { 'Skill.server = "gl"', 'Skill.s_buff IN ('..buff_inames..') OR Skill.t_buff IN ('..buff_inames..')', 'c1.lang = "english"', 'c2.lang = "english"', 'c1.param = "name"', 'c2.param = "expr"', -- 'c1.value <> "" OR c2.value <> ""', },		groupBy = 'Skill.iname', join = 'Skill._pageName = c1._pageName, Skill._pageName = c2._pageName', }	for i, row in ipairs(skill_rows) do		skills[row.iname] = { DATAPAGE = row.DATAPAGE, s_buff = row.s_buff, t_buff = row.t_buff, name = row.name, expr = row.expr, }		skill_inames[i] = '"'..row.iname..'"' end mw.log(#skill_rows, 'skills') skill_inames = table.concat(skill_inames, ',')

-- ABILITIES local abilities = {} local ability_inames = {} local fields = { 'Ability._pageName = DATAPAGE', 'Ability.iname = iname', }	local whereSkillsOr = {} for i=1,10 do		fields[#fields+1] = 'Ability.skl'..i..' = skl'..i		whereSkillsOr[i] = 'Ability.skl'..i..' IN ('..skill_inames..')' end local ability_rows = cargo.query{ tables = 'Ability', fields = fields, where = { 'server = "gl"', table.concat(whereSkillsOr, ' OR '), }	}	for i, row in ipairs(ability_rows) do		local ab_iname = row.iname abilities[ab_iname] = { _pageName = row._pageName, }		for i=1,10 do			abilities[ab_iname]['skl'..i] = row['skl'..i]		end ability_inames[i] = '"'..row.iname..'"' end ability_inames = table.concat(ability_inames, ',') -- JOBS local jobs = {} local job_rows = cargo.query{ tables = 'Job, Pages, Loc', fields = { 'Pages._pageName=PAGENAME', 'Job._pageName=DATAPAGE', 'Job.iname=iname', 'Job.fixabl=fixabl', 'Job.mdl=mdl', 'Loc.value=name', },		where = { 'Pages.type = "Job"', 'Job.server = "gl"', 'Job.fixabl IN ('..ability_inames..')', 'Job.iname NOT LIKE "%_TRIAL"', -- ignore trial jobs 'Job.iname NOT LIKE "JB_ALC_%"', -- ignore TAC staff 'Loc.lang = "english"', 'Loc.param = "name"', 'Loc.value <> ""', },		join = 'Job.iname = Pages.iname, Job._pageName = Loc._pageName', }	mw.log(#job_rows, 'jobs') for i, row in ipairs(job_rows) do		local filename if not row.mdl then filename = 'Game,ItemIcon,IT_UNKNOWN.png' else filename = ('Game,JobIcon,%s.png'):format(row.mdl) end jobs[row.iname] = { DATAPAGE = row.DATAPAGE, PAGENAME = row.PAGENAME, icon = (''):format(filename), name = row.name, fixabl = row.fixabl, }	end -- ARTIFACTS local artifacts = {} local artifact_rows = cargo.query{ tables = 'Artifact, Artifact__abils, Pages, Loc', fields = { 'Pages._pageName = PAGENAME', 'Artifact._pageName = DATAPAGE', 'Loc.value = name', 'Artifact.iname = iname', 'Artifact.icon = icon', 'Artifact.rini = rini', 'Artifact.attack1 = attack1', 'Artifact.attack2 = attack2', 'Artifact.attack3 = attack3', 'Artifact.attack4 = attack4', 'Artifact.attack5 = attack5', 'Artifact.equip1 = equip1', 'Artifact.equip2 = equip2', 'Artifact.equip3 = equip3', 'Artifact.equip4 = equip4', 'Artifact.equip5 = equip5', 'Artifact__abils._value = ab_iname', },		where = { 'Artifact.server = "gl"', table.concat({				'Artifact__abils._value IN ('..ability_inames..')',				'Artifact.attack1 IN ('..skill_inames..')',				'Artifact.attack2 IN ('..skill_inames..')',				'Artifact.attack3 IN ('..skill_inames..')',				'Artifact.attack4 IN ('..skill_inames..')',				'Artifact.attack5 IN ('..skill_inames..')',				'Artifact.equip1 IN ('..skill_inames..')',				'Artifact.equip2 IN ('..skill_inames..')',				'Artifact.equip3 IN ('..skill_inames..')',				'Artifact.equip4 IN ('..skill_inames..')',				'Artifact.equip5 IN ('..skill_inames..')',			}, ' OR '), 'Loc.param = "name"', 'Loc.lang = "english"', },		join = 'Artifact._ID = Artifact__abils._rowID, Artifact.iname = Pages.iname, Artifact._pageName = Loc._pageName' }	for i, row in ipairs(artifact_rows) do		local filename if not row.icon then filename = 'Game,ItemIcon,IT_UNKNOWN.png' else filename = 'Game,ArtiIcon,'..row.icon..'.png' end local icon = mw.html.create('span') :addClass('item-icon'):cssText('padding:3.2px') :tag('span') :addClass('img x-'..row.rini..' y-2') :cssText('width:32px;height:32px') :wikitext((''):format(filename)) :done artifacts[row.iname] = { PAGENAME = row.PAGENAME, DATAPAGE = row.DATAPAGE, name = row.name, icon = icon, rare = row.rini, ab_iname = row.ab_iname, }		for j=1,5 do			artifacts[row.iname]['attack'..j] = row['attack'..j]			artifacts[row.iname]['equip'..j] = row['equip'..j]		end end

local items = {} local item_rows = cargo.query{ tables = 'Item, Pages, Loc = ItemName, Loc = ItemExpr', fields = { 'Pages._pageName = PAGENAME', 'Item._pageName = DATAPAGE', 'ItemName.value = name', 'ItemExpr.value = expr', 'Item.iname = iname', 'Item.skill = skill', 'Item.icon = icon', 'Item.rare = rare', 'Item.type = type', },		where = { 'Item.server = "gl"', 'ItemName.lang = "english"', 'ItemName.param = "name"', 'ItemExpr.lang = "english"', 'ItemExpr.param = "expr"', 'Item.skill IN ('..skill_inames..')', },		join = 'Item.iname = Pages.iname, Item._pageName = ItemName._pageName, Item._pageName = ItemExpr._pageName', }	for i, row in ipairs(item_rows) do		local skill = row.skill and skills[row.skill] local y = (row.type == 1 or row.type == 11) and 1 or row.type == 14 and 3 or 0 local filename if not row.icon then filename = 'Game,ItemIcon,IT_UNKNOWN.png' elseif row.icon:sub(1,3) == 'AF_' then filename = 'Game,ArtiIcon,'..row.icon..'.png' else filename = 'Game,ItemIcon,'..row.icon..'.png' end local icon = mw.html.create('span') :addClass('item-icon') :cssText('padding:3.2px') :tag('span') :cssText('width:32px;height:32px') :addClass('img x-'..row.rare..' y-'..y)			:wikitext((''):format(filename)) :done items[row.iname] = { -- DATAPAGE = row.DATAPAGE, PAGENAME = row.PAGENAME, name = row.name, expr = row.expr, skill = row.skill, icon = icon, }	end

--	-- Jobs -- --	local jobSkills = {} for jb_iname, job in pairs(jobs) do		local ability = abilities[job.fixabl] if ability then local skillData = {} for i=1,10 do				local sk_iname = ability['skl'..i]				local skill = sk_iname and skills[sk_iname] if skill and (skill.name or skill.expr) then skillData[#skillData+1] = {name = skill.name, expr = skill.expr} end end table.sort(skillData, function(a,b) return a.name < b.name end) local obj = { PAGENAME = job.PAGENAME, name = job.name, icon = job.icon, skills = skillData, }			jobSkills[#jobSkills+1] = obj end end if #jobSkills > 0 then root:wikitext('Skills which '..buffXORdebuff..' '..statName..' that are fixed to a job:') h.printSkillTable(root, {data=jobSkills, name="Job"}) end

---	-- Artifacts -- ---	local artifactSkills = {} for af_iname, artifact in pairs(artifacts) do		local skillMap = {} local ability = abilities[artifact.ab_iname] if ability then for i=1,10 do				local sk_iname = ability['skl'..i]				local skill = sk_iname and skills[sk_iname] if skill and (skill.name or skill.expr) then local k = mw.text.jsonEncode({name = skill.name, expr = skill.expr}) skillMap[k] = 1 end end end for i=1,5 do			local sk_iname = artifact['attack'..i]			local skill = sk_iname and skills[sk_iname] if skill and (skill.name or skill.expr) then local k = mw.text.jsonEncode({name = 'Passive', expr = skill.expr}) skillMap[k] = 1 end local sk_iname = artifact['equip'..i]			local skill = sk_iname and skills[sk_iname] if skill and (skill.name or skill.expr) then local k = mw.text.jsonEncode({name = 'Passive', expr = skill.expr}) skillMap[k] = 1 end end local skillData = {} for k, _ in pairs(skillMap) do			local skill = mw.text.jsonDecode(k) skillData[#skillData+1] = skill end table.sort(skillData, function(a,b) return a.name < b.name end) local obj = { PAGENAME = artifact.PAGENAME, name = artifact.name, icon = artifact.icon, skills = skillData, }		artifactSkills[#artifactSkills+1] = obj end if #artifactSkills > 0 then root:wikitext('Skills which '..buffXORdebuff..' '..statName..' that are provided by gear') h.printSkillTable(root, {data=artifactSkills, name='Gear'}) end

---	-- Items -- ---	local itemSkills = {} for it_iname, item in pairs(items) do		local skill = item.skill and skills[item.skill] if skill and (skill.name or skill.expr) then local obj = { PAGENAME = item.PAGENAME, icon = item.icon, name = item.name, expr = item.expr, }			itemSkills[#itemSkills+1] = obj end end if #itemSkills > 0 then root:wikitext('Equipment which '..buffXORdebuff..' '..statName..' when equipped') h.printItemTable(root, {data=itemSkills, name='Item'}) end end

function h.printSkillTable(root, args) local dataTable = args.data local name = args.name table.sort(dataTable, function(a,b) return a.name < b.name end) local wikitable = root:tag('table'):addClass('wikitable sortable') wikitable:tag('tr') :tag('th'):wikitext(name):done :tag('th'):wikitext('Skill'):done :tag('th'):wikitext('Description'):done for i, obj in ipairs(dataTable) do		local tr = wikitable:tag('tr') local link if obj.PAGENAME == nil then link = obj.name elseif obj.PAGENAME ~= obj.name then link = ..obj.name.. else link = ..obj.PAGENAME.. end local rowspan = #obj.skills local td = tr:tag('td') td:attr('rowspan', rowspan > 1 and rowspan or nil) td:wikitext(tostring(obj.icon), ' ', link) for j, skill in ipairs(obj.skills) do			if j > 1 then tr = wikitable:tag('tr') end tr:tag('td'):wikitext(skill.name) tr:tag('td'):wikitext(skill.expr) end end end

function h.printItemTable(root, args) local dataTable = args.data local name = args.name table.sort(dataTable, function(a,b) return a.name < b.name end) local wikitable = root:tag('table'):addClass('wikitable sortable') wikitable:tag('tr') :tag('th'):wikitext(name):done :tag('th'):wikitext('Description'):done for i, obj in ipairs(dataTable) do		local tr = wikitable:tag('tr') local link if obj.PAGENAME == nil then link = obj.name elseif obj.PAGENAME ~= obj.name then link = ..obj.name.. else link = ..obj.PAGENAME.. end local td = tr:tag('td') td:wikitext(tostring(obj.icon), ' ', link) tr:tag('td'):wikitext(obj.expr) end end

function p.test return p._main{11} end

local model = require("Module:Data").model local render_gear_icon = require("Module:Render/Gear")._icon local render_item_icon = require("Module:Render/Item")._icon local render_job_icon = require('Module:Render/Job')._icon

function p.sources(frame) local args = require('Module:Arguments').getArgs(frame, {   parentFirst = true,  }) return p._sources(args) end

function p._sources(args) local statId = args[1] local statName = args[2] local server = args.server or 'gl' local lang = args.lang local function tablesFor(whereVal, msg) local buffs = model.query('Buff', 'iname', {where = 'server="'..server..     '" AND ((type1='..statId..' AND vmax1'..whereVal      ..') OR (type2='..statId..' AND vmax2'..whereVal      ..') OR (type3='..statId..' AND vmax3'..whereVal      ..') OR (type4='..statId..' AND vmax4'..whereVal      ..') OR (type5='..statId..' AND vmax5'..whereVal      ..') OR (type6='..statId..' AND vmax6'..whereVal      ..') OR (type7='..statId..' AND vmax7'..whereVal      ..') OR (type8='..statId..' AND vmax8'..whereVal      ..') OR (type9='..statId..' AND vmax9'..whereVal      ..') OR (type10='..statId..' AND vmax10'..whereVal      ..') OR (type11='..statId..' AND vmax11'..whereVal..'))'}) local skills = model.sources.buff.skill(buffs, nil, {'name', 'expr', lang = lang}, 'server="'..server..'"') local abilities = model.sources.skill.ability(skills, nil, nil, 'server="'..server..'"') local sb = {} --   -- Jobs -- --   local jobs = model.sources.ability.job(abilities, nil, nil, 'server="'..server..'"') if #jobs > 0 then table.sort(jobs, function(a, b) return a.iname < b.iname end) -- TODO: Need to support abilities beyond main sb[#sb+1] = '\nSkills which '..msg..' '..statName..' that are fixed to a job:\n{|\n!Job\n!Skill\n!Description' for _, job in ipairs(jobs) do       -- TODO: Wire into Module:Render/Job sb[#sb+1] = '\n|-\n| '..(#job._links.skill > 1 and 'rowspan='..#job._links.skill..' | ' or '') sb[#sb+1] = render_job_icon({ job.iname, size='small' }) for i, skill in ipairs(job._links.skill) do         sb[#sb+1] = (i > 1 and '\n|-' or '')..'\n| '..skill.name..'\n| '..skill.expr end end sb[#sb+1] = '\n|}' end ---   -- Artifacts -- ---   local artifacts = model.sources.ability.artifact(abilities, 'icon,rini', nil, 'server="'..server..'"') for _, artifact in ipairs(model.sources.skill.artifact(skills, 'icon,rini', nil, 'server="'..server..'"')) do     for _, skill in ipairs(artifact._links.skill) do skill.name = 'Passive' end artifacts[#artifacts+1] = artifact end if #artifacts > 0 then table.sort(artifacts, function(a, b) return a.iname < b.iname end) sb[#sb+1] = '\nSkills which '..msg..' '..statName..' that are provided by gear:\n{|\n!Gear\n!Skill\n!Description' for _, artifact in ipairs(artifacts) do       sb[#sb+1] = '\n|-\n| '..(#artifact._links.skill > 1 and 'rowspan='..#artifact._links.skill..' | ' or '') sb[#sb+1] = render_gear_icon({artifact.iname, data = artifact, size = 'small'}) for i, skill in ipairs(artifact._links.skill) do         sb[#sb+1] = (i > 1 and '\n|-' or '')..'\n| '..skill.name..'\n| '..skill.expr end end sb[#sb+1] = '\n|}' end ---   -- Items -- ---   local items = model.sources.skill.item(skills, 'icon,rare,type', {'expr', lang = lang}, 'server="'..server..'"') if #items > 0 then table.sort(items, function(a, b) return a.iname < b.iname end) sb[#sb+1] = '\nEquipment which '..msg..' '..statName..' when equipped:\n{|\n!Item\n!Description' for _, item in ipairs(items) do       sb[#sb+1] = '\n|-\n| '..render_item_icon({item.iname, data = item, size = 'small'})..'\n| '..item.expr end sb[#sb+1] = '\n|}' end return table.concat(sb) end return tablesFor('>0', 'buff')..'\n'..tablesFor('<0', 'debuff')

end

return p --