Module:Page/Job/Ability

local model  = require('Module:Data').model local cargo = require('Module:CargoUtil') local enums = require('Module:Data/Enums')

local p = {}

local abilityBackground = { [0] = '#ef4401', [1] = '#64d818', [2] = '#9939f9' }

local pageNameByType = function(iname, pageType) if iname == nil then return nil end return 'Data:Game/MasterParam/'..pageType..'/' .. string.gsub(iname, '_', ' ') end

function p.jobAbilityOutput(job) local abilityOutput = { '{| class="wikitable" style="width:calc(100% - 20px); background-color:#e0e0e0',   }    if job.fixabl and job.fixabl ~=  then    	local ability = cargo.query{    		tables = 'Ability, AbilityLoc',    		join = 'Ability.iname = AbilityLoc.iname',    		fields = 'name, expr',    		where = {    			'Ability.iname = "'..job.fixabl..'"',    			'server = "gl"',    			'lang="english"'    		}    	}[1]    	if ability then	        -- Main ability row	        table.insert(abilityOutput, '|-')	        table.insert(abilityOutput, '| colspan="5" style="background-color:#ef4401; text-align:center; font-weight:bold; font-size:120%"|   '..(ability.name or ))	        table.insert(abilityOutput, '|-')	        table.insert(abilityOutput, '| colspan="5" style="text-align:center; font-style:italic"|'..(ability.expr or ''))	        table.insert(abilityOutput, '|- style="font-weight:bolder"')	        table.insert(abilityOutput, '| Skill Name || Description || Jewel Cost || Charges || Cast Time') table.insert(abilityOutput, require("Module:AbilitySkill2")._AbilitySkillList(job.fixabl)) end end

-- Other rows (sub ability, reaction and support) local rows = cargo.query{ tables = 'JobRank', fields = 'idx, eqid1, eqid2, eqid3, eqid4, eqid5, eqid6, learn1, learn2', where = 'job_iname = "'..job.iname..'" and server = "gl"', }

for level, equipData in ipairs(rows) do           if equipData.learn1 and equipData.learn1 ~= '' then local abilityPageName = pageNameByType(equipData.learn1, 'Ability') local abilityName = model.getLoc(abilityPageName, 'name') local abilityDesc = model.getLoc(abilityPageName, 'expr') local abilitySlot = model.query("Ability", {'_pageName', 'slot'}, {where = 'iname="'..equipData.learn1..'" and server = "gl"'})[1]['slot'] AbilityType = enums.EAbilitySlot[abilitySlot] table.insert(abilityOutput, '|-') table.insert(abilityOutput, '! colspan="5" style="background-color:'..abilityBackground[abilitySlot]..'; text-align:center; font-weight:bold; font-size:120%"| '..abilityName) table.insert(abilityOutput, '|-') -- Add the level in parentheses if level>2 if level > 2 then table.insert(abilityOutput, '| colspan="5" style="text-align:center; font-style:italic"|'..abilityDesc..' (Learned at Rank '..(level-1)..')') else table.insert(abilityOutput, '| colspan="5" style="text-align:center; font-style:italic"|'..abilityDesc) end

table.insert(abilityOutput, require("Module:AbilitySkill2")._AbilitySkillList(equipData.learn1)) end end table.insert(abilityOutput, '|}') return table.concat(abilityOutput, "\n") end

function p.test(frame) local args = require("Module:Arguments").getArgs(frame) local job = model.query("Job", "_pageName, iname, ac2d, mdl, type, wepmdl, master, origin, role, ai, artifact, fixabl, atk, atkskl, avoid, cri, def, dex, hp, inimp, jjmp, jmov, luk, mag, mnd, mp, spd", {where = 'iname="'..args[1]..'"'}) job = job[1] return p.jobAbilityOutput(job) end

return p