Module:Page/Stat

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

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 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', }

-- SKILLS local skills = {} local skill_inames = {} local skill_rows = cargo.query{ tables = { 'Skill', 'BuffDetail = B1', 'BuffDetail = B2', '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.t_buff IS NOT NULL AND B1.server = "gl" AND B1.type = '..statID..' AND B1.vmax '..whereVals[buffXORdebuff]..') OR (Skill.s_buff IS NOT NULL AND B2.server = "gl" AND B2.type = '..statID..' AND B2.vmax '..whereVals[buffXORdebuff]..')', 'C1.lang = "english"', 'C2.lang = "english"', 'C1.param = "name"', 'C2.param = "expr"', -- 'c1.value <> "" OR c2.value <> ""', },		groupBy = 'Skill.iname', join = { 'Skill.t_buff = B1.buff_iname', 'Skill.s_buff = B2.buff_iname', '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, ',') if #skill_inames == 0 then return end

-- 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 or '', 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 or '', 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 or '', 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 or '', 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 or '', 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) skill.name = skill.name or '' 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 or '', 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._sources{11} end

return p --