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

全站通知:

模块:Attr

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

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

local p = {}

local nameToId = {
    ["琥珀"] = "103",
    ["缇莉娅"] = "107",
    ["卡西米拉"] = "108",
    ["鸢尾"] = "111",
    ["尘沙"] = "112",
    ["师渺"] = "113",
    ["岭川"] = "116",
    ["璟麟"] = "117",
    ["科洛妮丝"] = "118",
    ["花原"] = "119",
    ["卡娜丝"] = "120",
    ["杏子"] = "123",
    ["苍兰"] = "125",
    ["紫槿"] = "126",
    ["特丽莎"] = "127",
    ["密涅瓦"] = "132",
    ["雾语"] = "135",
    ["赤霞"] = "141",
    ["珂赛特"] = "142",
    ["千都世"] = "144",
    ["焦糖"] = "147",
    ["格芮"] = "149",
    ["菈露"] = "150",
    ["希娅"] = "155",
    ["小禾"] = "156"
}

function p.main(frame)
    local args = frame.args
    local char = args[1]
    
    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 charData = data
    
    if not charData or not charData.attribute then
        return "未找到角色属性数据"
    end
    
    local attribute = charData.attribute
    
    if attribute.CritRate then
        for i, value in ipairs(attribute.CritRate) do
            attribute.CritRate[i] = (value / 100) .. "%"
        end
    end
    
    if attribute.CritPower then
        for i, value in ipairs(attribute.CritPower) do
            attribute.CritPower[i] = (value / 100) .. "%"
        end
    end
    
    return '<div class="sora_attr_num" style="display:none">' .. mw.text.jsonEncode(attribute) .. '</div>'
end

return p