The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
Register
Advertisement

Documentation for this module may be created at Module:Page/Job/doc

local render_job_icon  = require('Module:Render/Job')._icon
local model   = require('Module:Data').model
local cargo = require('Module:CargoUtil')

local p = {}

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

function p.jobSource(iname)
    local job_data = cargo.query{tables='EventObtainableJob', fields='_pageName', where = 'job_iname="'..iname..'"'}
    return (job_data[1] and job_data[1]['_pageName']) or nil
end

function p.jobInfoBox(job)
    local jobSource = p.jobSource(job.iname)
    if jobSource and jobSource ~= nil and jobSource ~= '' then
        jobSource = "|-\n"..'| colspan="4" style="text-align:center;" | '.."'''Source:''' [["..jobSource.."]]\n"
    else
        jobSource = ''
    end
    
    local output = {
        '{| class="wikitable jobInfoBox" style="float:right; margin-left: 15px;margin-bottom:0;"',
        '| style="padding:0;width:128px;white-space: nowrap" | '..render_job_icon({job.iname, data=job, size='large', name='none'}),
        '! style="padding:12px;font-size:140%;" | '..job.name..'<span style="font-size:65%"><br/>Job</span>',
        '|-',
        '| colspan="2" style="padding:0" |',
        '{| class="wikitable jobInfoBoxInner" style="margin: 0; width: 100%"'..jobSource,
        '|-',
        '| Move',
        '| '..(job.jmov or ' 0'),
        '| Jump',
        '| '..(job.jjmp or ' 0'),
        '|-',
        '| Avoid',
        '| '..(job.avoid or ' 0'),
        '| Initial Jewels',
        '| '..(100 + (job.inimp or 0))..'%',
        '|-',
        '| HP',
        '| '..(job.hp or ' 0'),
        '| Jewels',
        '| '..(job.mp or ' 0'),
        '|-',
        '| PATK',
        '| '..(job.atk or ' 0'),
        '| PDEF',
        '| '..(job.def or ' 0'),
        '|-',
        '| MATK',
        '| '..(job.mag or ' 0'),
        '| MDEF',
        '| '..(job.mnd or ' 0'),
        '|-',
        '| DEX',
        '| '..(job.dex or ' 0'),
        '| AGI',
        '| '..(job.spd or ' 0'),
        '|-',
        '| CRIT',
        '| '..(job.cri or ' 0'),
        '| LUCK',
        '| '..(job.luk or ' 0'),
        '|}',
        '|}',
    }
    
    return table.concat(output, "\n")
end

function p.jobAbilityOutput(job)
    local abilityOutput = {
    	'{| class="wikitable" width="100%"',
    }
    
    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] or {}

        -- Main ability row
        table.insert(abilityOutput, '|-')
        table.insert(abilityOutput, '! colspan="5" style="font-size: 120%" align="center"|[[File:ActionAbilityIcon.png|20px|link=]] '..ability.name)
        table.insert(abilityOutput, '|-')
        table.insert(abilityOutput, '| colspan="5"|\'\''..ability.expr..'\'\'')
        table.insert(abilityOutput, '|-')
        table.insert(abilityOutput, '| style="font-weight:bold" | Skill Name || Description || Jewel Cost || Charges || Cast Time')
        table.insert(abilityOutput, require("Module:AbilitySkill2")._AbilitySkillList(job.fixabl))
    end
    
    -- local jobEquipList = mw.loadData("Module:Data/MasterParam/JobEquip")
    -- 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"',
    }
    -- if jobEquipList[job.iname] then
    for level, equipData in ipairs(rows) do
        -- for level,equipData in pairs(jobEquipList[job.iname]) 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')
                
                -- querying the type of ability to display the corresponding image
                -- local abilitTypeDetail = model.query("Ability", {'_pageName', 'type_detail'}, {where = 'iname="'..abilityPageName..'" and server = "gl"'})[1] or {}
                local abilityType = ''
                if abilityTypeDetail == 2 then abilityType = 'Action'
                elseif abilityTypeDetail == 3 then abilityType = 'Support'
                elseif abilityTypeDetail == 4 then abilityType = 'Reaction'
                end
                
                table.insert(abilityOutput, '|-')
                table.insert(abilityOutput, '! colspan="5" style="font-size:120%" align=center"|'..abilityName)
                table.insert(abilityOutput, '|-')
		-- Add the level in parentheses if level>2
                if level > 2 then
                	table.insert(abilityOutput, '| colspan="5"|\'\''..abilityDesc..'\'\' (Learned at Rank '..(level-1)..')')
                else
                    table.insert(abilityOutput, '| colspan="5"|\'\''..abilityDesc..'\'\'')
                end

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

function p.aiPriorityOutput(ai)
    if ai == nil then return '' end

    local enums   = require('Module:Data/Enums')

    local renderSkillPriority = function(root, skillKeys)
        if skillKeys == nil or #skillKeys < 1 then return end

        root:tag('h3'):wikitext('Skill Priority')
        local ol = root:tag('ol')
    
        for index, key in ipairs(skillKeys) do
            ol:tag('li'):wikitext((enums.SkillCategory[key] or key))
        end

        root:wikitext("\n\n")
    end

    local renderBuffPriority = function(root, buffKeys, selfOnly)
        if buffKeys == nil or #buffKeys < 1 then return end

        root:tag('h3'):wikitext('Buff Priority')
    
        if selfOnly and selfOnly == 1 then
            root:tag('b'):wikitext("Self Buffs only")
            root:wikitext("\n\n")
        end
    
        local ol = root:tag('ol')
    
        for index, key in ipairs(buffKeys) do
            ol:tag('li'):wikitext((enums.statNameFromType(key) or key))
        end

        root:wikitext("\n\n")    
    end

    local renderConditionPriority = function(root, condKeys)
        if condKeys == nil or #condKeys < 1 then return end

        root:tag('h3'):wikitext('Condition Priority')
        local ol = root:tag('ol')
    
        for index, key in ipairs(condKeys) do
            ol:tag('li'):wikitext(enums.enchantTypeNameFromKey(key))
        end
    
        root:wikitext("\n\n")
    end

    local root = mw.html.create()
    
    root:tag('h2'):wikitext('AI Priority')
    
    renderSkillPriority(root, ai.skil_prio)
    renderBuffPriority(root, ai.skil_prio, ai.buff_self)
    renderConditionPriority(root, ai.cond_prio)
    
    return tostring(root)
end


local renderPage = function(iname, 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="'..iname..'"'})
    job = job[1]
    local getLoc = function(param) return model.getLoc(job._pageName, param) end

    local output = {}
    
    job.name = getLoc('name')
    
    -- If the job inherits from another job, output that information
    if job.origin and job.origin ~= '' and job.origin ~= job.iname then
        table.insert(output, job.name..' is a variation of the '..render_job_icon({job.origin, size='small'})..' job.')
    end
    
    -- Output job info box
    table.insert(output, p.jobInfoBox(job))
    
    -- Output job mastery bonus
    if job.master and job.master ~= '' then
        table.insert(output, '== Job Mastery Bonus ==')
        table.insert(output, require("Module:JobMaster")._jobMasterBonusTable(iname))
    end
    
    -- Output attack skill
    if job.atkskl and job.atkskl ~= '' then
        local attackSkillPage = pageNameByType(job.atkskl, 'Skill')
        
        local attackSkillName = model.getLoc(attackSkillPage, 'name')
        local attackSkillDesc = model.getLoc(attackSkillPage, 'expr')

        table.insert(output, '== Attack ==')        
        table.insert(output, ';'..attackSkillName)
        table.insert(output, ': '..attackSkillDesc)
    end
    
    -- Job/Page/Abilities
    table.insert(output, '== Abilities ==')
    table.insert(output, p.jobAbilityOutput(job))
    
    -- Job/Page/JobUnits
    table.insert(output, '== Units With This Job ==')
    table.insert(output, require("Module:JobUnits")._jobUnitList(iname))
    
    -- Job/Page/RelatedJobs
    table.insert(output, '== Related Jobs ==')
    table.insert(output, require("Module:JobRelationship")._relatedJobList(iname))

    -- Job/Page/Equip
    table.insert(output, '== Equipment ==')
    table.insert(output, require("Module:JobEquipmentList")._jobEquipmentList(iname))
    
    -- AI
    if job.ai and job.ai ~= '' then
        local ai = model.query("AI", "iname, buff_prio, cond_prio, skil_prio, buff_self", {where = 'iname="'..job.ai..'"'}) or {}
        if ai and ai[1] then
            table.insert(output, p.aiPriorityOutput(ai[1]))
        end
    end
  
    -- Category
    table.insert(output, '[[Category:Jobs]]')
    
    return table.concat(output, "\n")
end

local renderFuncs = {}
renderFuncs.Icon = render_job_icon

local renderTransclude = function(iname, args)
  local type = mw.text.trim(args[1])
  args[1] = iname
  return (renderFuncs[type] or renderFuncs.Name)(args)
end

p.renderPage = renderPage

function p._main(iname, args)
  if args.isPage then
    return renderPage(iname)
  else
    return renderTransclude(iname, args)
  end
end

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

return p
Advertisement