此处为全站公告,通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~

全站通知:

模块:Talent

来自星塔旅人WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Talent/doc创建

local p = {}

    local function formatSkillDesc(desc)
        if not desc then return "" end
        desc = tostring(desc)
        desc = desc:gsub("\\u000b", "<br>")
        desc = desc:gsub(string.char(11), "<br>")
        desc = desc:gsub("##([^#]+)#%d+#", "%1")
        desc = desc:gsub("<[Cc]olor=[^>]+>", '<span style="color:#fb8037;">')
        desc = desc:gsub("</[Cc]olor>", "</span>")
        return desc
    end


function p.main(frame)
    local args = frame.args or {}
    local char = args[1] or ""
    local talentType = args[2] or ""

    local IdTitle = mw.title.new('Mediawiki:Char.json')
    local itemcontent = IdTitle and IdTitle:getContent() or nil
    local IdData = mw.text.jsonDecode(itemcontent)
    local id = tostring(IdData[char])
    if not id then
        return "角色不存在"
    end

    local title = mw.title.new('Mediawiki:char/' .. id .. '.json')
    local content = title and title:getContent() or nil
    local data = mw.text.jsonDecode(content or '{}')

    local function formatTalentDesc(desc, params)
        if not desc then return "" end
        desc = formatSkillDesc(desc)
        if not params or type(params) ~= "table" then
            return desc
        end
        desc = tostring(desc):gsub("&Param(%d+)&", function(n)
            local key = "Param" .. n
            local val = params[key]
            if val == nil then
                return "&Param" .. n .. "&"
            end
            if type(val) == "table" then
                if #val > 0 then
                    val = val[#val]
                else
                    val = val[1]
                end
            end
            return tostring(val)
        end)
        return desc
    end

    local n_name = talentType:match("^天赋(%d+)名称$")
    if n_name then
        local idx = tonumber(n_name)
        if idx and idx >= 1 and idx <= 5 then
            local key = string.format("Talent_%02d", idx)
            return data.Talent and data.Talent[key] and data.Talent[key].name or ""
        end
    end

    local n_desc = talentType:match("^天赋(%d+)%s*$") 
    if n_desc then
        local idx = tonumber(n_desc)
        if idx and idx >= 1 and idx <= 5 then
            local key = string.format("Talent_%02d", idx)
            local t = data.Talent and data.Talent[key]
            if not t then return "" end
            local rawDesc = t.desc or ""
            local params = t.params or {}
            return formatTalentDesc(rawDesc, params)
        end
    end
end

return p