缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:技能信息框

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

用于模板:Template:技能信息框。 视图模块:Module:信息框/技能。 数据模块:Module:Data/Skills



local p = {}
local fstr = mw.ustring.format

local utils = require("Module:Utils")
local po = require([[Module:Po]]).po
local i18ncr = require([[Module:I18n]]).loadMessages([[Module:I18n/Duplicants]])
local infobox = require([[Module:信息框/技能]])
local getArgs = require("Module:Dev/Arguments").getArgs
local fDataPath = [[Module:Data/Skills]]
local fData = mw.loadData(fDataPath)
local DLCS = {
    [""] = "STRINGS.UI.VANILLA.NAME",
    ["EXPANSION1_ID"] = "STRINGS.UI.DLC1.NAME",
}
local exception = {
}

local function containDlc(dlcIds, dlc)
    for _, v in ipairs(dlcIds) do
        if dlc == v then
            return true
        end
    end
end

function p._main(skillData, dlc, skills)
    local out = {}
    out["ID"] = fstr("<code>%s</code>", skillData.Id)
    out["名称"] = po(skillData.Name)
    out["图片"] = fstr("%s.png", out["名称"])
    out["图片说明"] = po(skillData.Name:sub(1, -6) .. ".DESCRIPTION")

    if skillData.category ~= nil then
    	out["类型"] = po("STRINGS.DUPLICANTS.CHOREGROUPS."..skillData.skillGroup:upper()..".NAME")
    end
    if skillData.tier ~= nil then
    	out["等级"] = utils.float2str(skillData.tier)
    end
    if skillData.perks ~= nil then
        out["效果"] = {}
        for _, perk in ipairs(skillData.perks) do
            local effect = nil
            if perk.modifier ~= nil then
                local prefix = perk.modifier.IsMultiplier == true and "x" or ""
                effect = fstr(
                    "[[属性/%s]] %s%s",
                    po("STRINGS.DUPLICANTS.ATTRIBUTES."..perk.modifier.AttributeId:upper()..".NAME"),
                    prefix,
                    utils.float2str(perk.modifier.Value, nil, prefix)
                )
            else
                effect = fstr("%s", po(perk.effect))
            end
            if effect ~= nil then
                table.insert(out["效果"], effect)
            end
        end
        out['效果'] = #out["效果"] ~= 0 and table.concat(out["效果"], "<br/>") or nil
    end
    if skillData.priorSkills ~= nil then
        out["前置技能"] = {}
        for _, preskill in ipairs(skillData.priorSkills) do
            local currSkill = skills[preskill]
            currSkill = currSkill ~= nil and currSkill[dlc] or nil
            if currSkill ~= nil then
                table.insert(out["前置技能"], fstr("[[%s]]", po(currSkill.Name)))
            end
        end
        out['前置技能'] = #out["前置技能"] ~= 0 and table.concat(out["前置技能"], "<br/>") or nil
    end
    if skillData.nextSkills ~= nil then
        out["可解锁技能"] = {}
        for _, preskill in ipairs(skillData.nextSkills) do
            local currSkill = skills[preskill]
            currSkill = currSkill ~= nil and currSkill[dlc] or nil
            if currSkill ~= nil then
                table.insert(out["可解锁技能"], fstr("[[%s]]", po(currSkill.Name)))
            end
        end
        out['可解锁技能'] = #out["可解锁技能"] ~= 0 and table.concat(out["可解锁技能"], "<br/>") or nil
    end
    return out
end

-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="基础耕种"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="敏感微成像"}))
function p.main(frame)
    local args = getArgs(frame)
    local infos = {}
    local skills = {}

    if args[1] ~= nil or args.multipage ~= nil then
        local pagename_array = {}
        pagename_array = args[1] ~= nil and {args[1]} or nil
        if pagename_array == nil then
            pagename_array = args.multipage ~= nil and mw.text.split(args.multipage, ",") or {}
        end
        for _, skillId in ipairs(pagename_array) do
            local _, _, skillCode = utils.getEntry(skillId)
            if skillCode == nil then
                error(fstr("找不到技能 '%s',请使用参数1或检查 [[%s]]。", args.pagename, fDataPath))
            end
            table.insert(skills, {
                id = skillId,
                code = skillCode
            })
        end
    else
        local skillCode = i18ncr:msgRev({
            key = args.pagename,
            args = {
                prefix = "STRINGS.DUPLICANTS.ROLES."
            }
        } or "")
        if skillCode == nil then
            error(fstr("找不到技能 '%s',请使用参数1或检查 [[%s]]。", args.pagename, fDataPath))
        end
        local skillId = skillCode:match("([%u_]+).NAME$")
        table.insert(skills, {
            id = skillId,
            code = skillCode
        })
    end

    for _, skill in pairs(skills) do
        skill.id = exception[skill.id] ~= nil and exception[skill.id] or skill.id
        for k, v in pairs(fData) do
            for dlc, dlcCode in pairs(DLCS) do
                local skillData = v[dlc]
                if skillData ~= nil then
                    if skillData.Name == skill.code or k:upper() == skill.id:upper() then
                        local curr = p._main(skillData, dlc, fData)
                        table.insert(infos, {
                            label = po(dlcCode),
                            data = curr
                        })
                    end 
                end
            end
        end
    end

    if args.debug then
        mw.logObject(infos)
    end
    return infobox.main(args.pagename, infos)
end

return p