此处为全站公告:招人!招人!招人!!!Wiki起步阶段,欢迎各位馆长参与Wiki建设!!
无论是Wiki页面的搭建,或者是各种文章、吐槽,当然也包括各种意见反馈,任何与该游戏相关的内容都是有贡献的,诚邀各位馆长参与!
有相关需求者请通过B站或Q群联系站长了解详情

全站通知:

模块:MArtPieces

来自少女艺术绮谭WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

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

module = {}

-- 单个美术品信息卡片,适用于少量使用
-- 直接返回动态Wiki代码
function module.ap_card(key)
    local no = key
    if type(no) == "table" then
        if not no.args[1] or no.args[1] == "" then
            error("请传入美术品编号no")
        else
            no = no.args[1]
        end
    end
    if type(no) == "string" then
        no = string.gsub(no, "^%s*(.-)%s*$", "%1")
        if string.gsub(no, "%d", "") ~= "" then
            error("需要传入的美术品编号no只能是数字,当前传入内容为「"..no.."」")
        end
        no = tonumber(no)
    elseif type(no) ~= "number" then
        error("需要传入的美术品编号no只能是数字,当前传入内容为「"..type(no).."」类型的「"..tostring(no).."」")
    end
    if no < 1 then
        error("无效的美术品编号no「"..tostring(no).."」")
    end
    -- 感情资源图标
    local source_logo = {
        "[[file:感情资源_pathos.png|x20px|link=]]",
        "[[file:感情资源_curios.png|x20px|link=]]",
        "[[file:感情资源_logos.png|x20px|link=]]",
        "[[file:感情资源_melanchos.png|x20px|link=]]"
    }
    -- 读取美术品基本信息
    local apinfo = nil
    local data = require("Module:Data/mArtPieces.json")
    if no > #data then
        error("所传入美术品编号no「"..tostring(no).."」超过了当前版本游戏内美术品的最大编号「"..tostring(#data).."」,请检查[[Module:Data/mArtPieces.json]]中是否有此美术品的信息,并传入该美术品信息字段「catalog_no」的值")
    end
    for i, dt in ipairs(data) do
        if dt["catalog_no"] == no then
            apinfo = dt
            break
        end
    end
    package.loaded["Module:Data/mArtPieces.json"] = nil
    if not apinfo then
        error("未找到美术品信息,请确认所传入美术品编号no「"..tostring(no).."」是否在[[Module:Data/mArtPieces.json]]的字段「catalog_no」中有对应的值")
    end
    -- 读取感情资源产能、解锁上限信息
    local cnt = 0
    local lvinfo = {}
    local k = "resource_limit_amount"
    data = require("Module:Data/mArtPieceLevelGroups.json")
    for i, dt in ipairs(data) do
        if dt["group_id"] == apinfo["level_group_id"] then
            if dt["level"] == 1 then
                if lvinfo[1] then
                    k = k..lvinfo[1]
                    lvinfo[2] = dt[k]
                else
                    -- 判断所解锁感情资源种类(二分查找)并记录最小解锁上限
                    if dt["resource_limit_amount1"] + dt["resource_limit_amount2"] ~= 0 then
                        if dt["resource_limit_amount1"] ~= 0 then
                            lvinfo[1] = "1"
                            lvinfo[2] = dt["resource_limit_amount1"]
                        else
                            lvinfo[1] = "2"
                            lvinfo[2] = dt["resource_limit_amount2"]
                        end
                    else
                        if dt["resource_limit_amount3"] ~= 0 then
                            lvinfo[1] = "3"
                            lvinfo[2] = dt["resource_limit_amount3"]
                        else
                            lvinfo[1] = "4"
                            lvinfo[2] = dt["resource_limit_amount4"]
                        end
                    end
                    -- 记录各感情资源每小时产量
                    lvinfo[4] = dt["resource_item_count1"]
                    lvinfo[5] = dt["resource_item_count2"]
                    lvinfo[6] = dt["resource_item_count3"]
                    lvinfo[7] = dt["resource_item_count4"]
                end
                cnt = cnt + 1
            elseif dt["level"] == 10 then
                if lvinfo[1] then
                    k = k..lvinfo[1]
                    lvinfo[3] = dt[k]
                else
                    -- 判断所解锁感情资源种类(二分查找)并记录最大解锁上限
                    if dt["resource_limit_amount1"] + dt["resource_limit_amount2"] ~= 0 then
                        if dt["resource_limit_amount1"] ~= 0 then
                            lvinfo[1] = "1"
                            lvinfo[3] = dt["resource_limit_amount1"]
                        else
                            lvinfo[1] = "2"
                            lvinfo[3] = dt["resource_limit_amount2"]
                        end
                    else
                        if dt["resource_limit_amount3"] ~= 0 then
                            lvinfo[1] = "3"
                            lvinfo[3] = dt["resource_limit_amount3"]
                        else
                            lvinfo[1] = "4"
                            lvinfo[3] = dt["resource_limit_amount4"]
                        end
                    end
                    -- 记录各感情资源每小时产量
                    lvinfo[4] = dt["resource_item_count1"]
                    lvinfo[5] = dt["resource_item_count2"]
                    lvinfo[6] = dt["resource_item_count3"]
                    lvinfo[7] = dt["resource_item_count4"]
                end
                cnt = cnt + 1
            end
        end
        if cnt == 2 then
            break
        end
    end
    package.loaded["Module:Data/mArtPieceLevelGroups.json"] = nil
    if cnt == 0 then
        error("未找到No."..tostring(no).."美术品对应的等级信息,请检查[[Module:Data/mArtPieces.json]]的字段「level_group_id」和[[Module:Data/mArtPieceLevelGroups.json]]的「group_id」字段是否有对应相等的值")
    elseif cnt == 1 then
        error("未找全No."..tostring(no).."美术品对应的等级信息,请检查[[Module:Data/mArtPieceLevelGroups.json]]中字段「group_id」值为「"..tostring(apinfo["level_group_id"]).."」的信息组中是否包含「level」为1和10的组")
    end
    -- 判断主要生产的感情资源种类
    local product = {"", 0}
    cnt = 0
    for i = 4, 7 do
        if lvinfo[i] > product[2] then
            product[1] = tostring(i-3)
            product[2] = lvinfo[i]
            cnt = 0
        elseif lvinfo[i] == product[2] then
            cnt = cnt + 1
        end
    end
    if cnt > 0 then
        product[1] = "0"
    end
    -- 读取所在展览室相关信息
    local room_id = tonumber(string.gsub(apinfo["block_node_name"], "room", ""), 10)
    local room = nil
    local open = "0"
    data = require("Module:Data/mMuseumBlocks.json")
    for i, dt in ipairs(data) do
        if dt["id"] == room_id then
            room = dt["ml_name"]
            if dt["open_artpiece1"] == apinfo["id"] or dt["open_artpiece2"] == apinfo["id"] then
                open = "1"
            end
            break
        end
    end
    package.loaded["Module:Data/mMuseumBlocks.json"] = nil
    if not room then
        error("未找到美术品所在展览室信息,请检查[[Module:Data/mMuseumBlocks.json]]中字段「id」是否有与本No."..tonumber(no).."美术品在[[Module:Data/mArtPieces.json]]中字段「block_node_name」对应相等的值")
    end
    -- 写信息卡片
    local wikitext = "{| class=\"cardtable divsort\" style=\"max-width: 100%; width: 550px;\" data-param0=\"0\""
    -- 筛选器参数
    wikitext = wikitext.." data-param1=\""..tostring(room_id).."\"" -- 所在展室
    if apinfo["creator"] ~= "" then
        wikitext = wikitext.." data-param2=\""..apinfo["creator"].."\"" -- 作者
    else
        wikitext = wikitext.." data-param2=\"其他\""
    end
    wikitext = wikitext.." data-param3=\""..product[1].."\"" -- 主要生产
    wikitext = wikitext.." data-param4=\""..lvinfo[1].."\"" -- 解锁上限
    wikitext = wikitext.." data-param5=\""..tostring(apinfo["rarity"]).."\"" -- 创作难度
    wikitext = wikitext.." data-param6=\""..open.."\"" -- 展室开放
    wikitext = wikitext.."\n"
    -- 展示信息
    wikitext = wikitext.."|-\n| rowspan=4 colspan=2 | [[file:"..apinfo["art_piece_node_name"]..".png|200px]]\n"
    wikitext = wikitext.."! width=8% | No."..tostring(no).."\n"
    wikitext = wikitext.."| rowspan=2 width=42% | <span lang=\"ja\">"..apinfo["ml_name"][1].."</span><br>'''"..apinfo["ml_name"][2].."'''\n"
    wikitext = wikitext.."|-\n| '''★"..tostring(apinfo["rarity"]).."'''\n"
    wikitext = wikitext.."|-\n! 所在展室\n| <span lang=\"ja\">"..room[1].."</span><br>"..room[2].."\n"
    wikitext = wikitext.."|-\n! 展室开放\n"
    if open == "1" then
        wikitext = wikitext.."| ⭕是\n"
    else
        wikitext = wikitext.."| ❌否\n"
    end
    wikitext = wikitext.."|-\n! width=8% | 原型藏馆\n| width=42% | "..apinfo["proto_collector"].."\n"
    wikitext = wikitext.."! 解锁上限\n| "..source_logo[tonumber(lvinfo[1])]..tostring(lvinfo[2]).."~"..tostring(lvinfo[3]).."\n"
    wikitext = wikitext.."|-\n! rowspan=2 | 简介 \n| style=\"text-align: justify;\" rowspan=2 | "..apinfo["ml_description"][2].."\n"
    wikitext = wikitext.."! 资源产量\n| {{nobr|"..source_logo[1].."+"..tostring(lvinfo[4]).."}}{{nobr|"..source_logo[2].."+"..tostring(lvinfo[5]).."}}{{nobr|"..source_logo[3].."+"..tostring(lvinfo[6]).."}}{{nobr|"..source_logo[4].."+"..tostring(lvinfo[7]).."}}\n"
    wikitext = wikitext.."|-\n! 作者\n| "
    if apinfo["creator"] ~= "" then
        wikitext = wikitext.."[["..apinfo["creator"].."]]"
        if apinfo["proto_creator"] ~= "" then
            wikitext = wikitext.."("..apinfo["proto_creator"]..")\n"
        else
            wikitext = wikitext.."\n"
        end
    else
        wikitext = wikitext..apinfo["proto_creator"].."\n"
    end
    wikitext = wikitext.."|-\n! rowspan=2 | 备注\n| style=\"text-align: justify;\" rowspan=2 | "..apinfo["note"].."\n"
    wikitext = wikitext.."! 创作用时\n| {{hmm||"..tostring(apinfo["create_time"]).."}}\n"
    wikitext = wikitext.."|-\n! 创作组\n| "
    if apinfo["create_group"][2] then
        wikitext = wikitext.."①{{创作组|"..tostring(apinfo["create_group"][1]).."}}<br>②{{创作组|"..tostring(apinfo["create_group"][2]).."}}\n"
    else
        wikitext = wikitext.."{{创作组|"..tostring(apinfo["create_group"][1]).."}}\n"
    end
    wikitext = wikitext.."|}"
    wikitext = key:preprocess(wikitext)
    return wikitext
end

-- 所有美术品信息卡片
-- 直接返回动态Wiki代码
function module.get_all(null)
    
end

-- 美术品总数
function module.ap_count()
    local data = require("Module:Data/mArtPieces.json")
    local count = #data
    package.loaded["Module:Data/mArtPieces.json"] = nil
    return count
end

-- 各感情资源每小时最大总产量
function module.sum_product()
    -- 读取各等级组产量
    local product = {}
    local data = require("Module:Data/mArtPieceLevelGroups.json")
    for i, dt in ipairs(data) do
        if not product[dt["group_id"]] then
            product[dt["group_id"]] = {
                dt["resource_item_count1"],
                dt["resource_item_count2"],
                dt["resource_item_count3"],
                dt["resource_item_count4"]
            }
        end
    end
    package.loaded["Module:Data/mArtPieceLevelGroups.json"] = nil
    -- 遍历美术品,计算各感情资源产量总和
    local arr = {0, 0, 0, 0}
    data = require("Module:Data/mArtPieces.json")
    for i, dt in ipairs(data) do
        for t = 1, 4 do
            arr[t] = arr[t] + product[dt["level_group_id"]][t]
        end
    end
    package.loaded["Module:Data/mArtPieces.json"] = nil
    return arr
end

-- 面向Wiki调用的module.sum_product(),返回用<sep>作分隔符的字符串
function module.sum_product_str()
    return table.concat(module.sum_product(), "<sep>")
end

-- 各感情资源总最大上限
function module.max_resources()
    -- 读取各等级组最大感情资源上限
    local max_rsc = {}
    local data = require("Module:Data/mArtPieceLevelGroups.json")
    for i, dt in ipairs(data) do
        if not max_rsc[dt["group_id"]] and dt["level"] == 10 then
            max_rsc[dt["group_id"]] = {
                dt["resource_limit_amount1"],
                dt["resource_limit_amount2"],
                dt["resource_limit_amount3"],
                dt["resource_limit_amount4"]
            }
        end
    end
    package.loaded["Module:Data/mArtPieceLevelGroups.json"] = nil
    -- 遍历美术品,计算各感情资源产量总和
    local arr = {0, 0, 0, 0}
    data = require("Module:Data/mArtPieces.json")
    for i, dt in ipairs(data) do
        for t = 1, 4 do
            arr[t] = arr[t] + max_rsc[dt["level_group_id"]][t]
        end
    end
    package.loaded["Module:Data/mArtPieces.json"] = nil
    return arr
end

-- 面向Wiki调用的module.max_resources(),返回用<sep>作分隔符的字符串
function module.max_resources_str()
    return table.concat(module.max_resources(), "<sep>")
end

-- 生成[[美术品一览]]中筛选器「作者」字段的按钮
-- 直接返回动态Wiki代码
function module.ap_filter_creator_btn(null)
    -- 读取美术品中的作者信息
    local creator = {}
    local data = require("Module:Data/mArtPieces.json")
    for i, dt in ipairs(data) do
        if dt["creator"] ~= "" and not creator[dt["creator"]] then
            creator[dt["creator"]] = true
        end
    end
    package.loaded["Module:Data/mArtPieces.json"] = nil
    -- 按顺序生成按钮
    local wikitext = ""
    data = require("Module:Data/mUnits.json")
    for i, dt in ipairs(data) do
        local unit = dt["ml_name"][3] -- 当前mUnits.json中艺术家中文名在列表第3位
        if unit == "米开朗琪罗" then
            unit = "米开朗基罗"
        end
        if creator[unit] then
            wikitext = wikitext.."{{筛选项|2|"..unit.."}}\n"
        end
    end
    package.loaded["Module:Data/mUnits.json"] = nil
    wikitext = wikitext.."{{筛选项|2|其他}}\n"
    wikitext = null:preprocess(wikitext)
    return wikitext
end

return module