模块:ItemInfo

Xiyan讨论 | 贡献2024年6月8日 (六) 07:28的版本 (oops)

可在模块:ItemInfo/doc创建此模块的帮助文档

local p = {}

function p.loadItemInfoByIndex(game, category, index)
    -- 获取索引(综合数据)
    local matIdx = mw.loadJsonData('数据:' .. game .. '/' .. category .. '/索引')
    local itemBase = matIdx[index]
    local status, data = pcall(mw.loadJsonData, '数据:' .. game .. '/' .. category .. '/' .. index)
    if status then
        return table.append(itemBase, data)
    else
        return itemBase
    end
end

-- 根据物品Id获取物品信息
function p.loadItemById(game, id)
    if game == 'AT1' then
        -- id 区间检查

        if id >= 225 and id <= 225 + 339 then
            -- 葛拉斯诺晶体
            return p.loadItemInfoByIndex(game, '葛拉斯诺晶体', id - 225 + 1)
        end
    elseif game == 'AT2' then
    elseif game == 'AT3' then
    end
end

local function recryFilter(recry)
    if recry.s_prod == -1 then
        recry.s_prod = nil
    else
        recry.s_prod = p.loadItemById(recry.s_prod).name
    end
    if recry.a_prod == -1 then
        recry.a_prod = nil
    else
        recry.a_prod = p.loadItemById(recry.a_prod).name
    end
    if recry.b_prod == -1 then
        recry.b_prod = nil
    else
        recry.b_prod = p.loadItemById(recry.b_prod).name
    end
    if recry.c_prod == -1 then
        recry.c_prod = nil
    else
        recry.c_prod = p.loadItemById(recry.c_prod).name
    end
end

-- 生成材料物品基本信息的方法,使用模板“物品信息”
function p.at1MaterialItemInfo(index)
    local item = p.loadItemInfoByIndex('AT1', '材料物品', index)

    -- local filteredRecrystalisation = recryFilter(item.recry)
    local filteredRecrystalisation = item.recry

    local arguments = {
        ["物品名"] = item.name,
        ["图像"] = item.img,
        ["原文"] = item.ori,
        ["类别"] = '材料',
        ["子类别"] = '采集',
        ["卖价"] = item.base.sell_price,
        ["游戏"] = AT1,     
        -- 重结晶S=filteredRecrystalisation.s_prod,
        -- 重结晶A=filteredRecrystalisation.a_prod,
        -- 重结晶B=filteredRecrystalisation.b_prod,
        ["重结晶C"] = filteredRecrystalisation.c_prod,
        ["其他来源"] = item.alt_src,
        ["笔记"] = item.desc
    }
    for i = 1, 5 do
        if not item.src[i] then
            arguments['来源' .. i .. '/类别'] = item.src[i].type
            arguments['来源' .. i .. '/详细'] = item.src[i].desc
        end
    end
    for i = 1, 8 do
        arguments['合成用途' .. i] = item.item_use_this[i]
    end

    return mw.getCurrentFrame():expandTemplate {
        title = '物品信息',
        args = arguments
    }
end

function p.listMaterialsInAt1()
    result = {}
    for i = 1, 34 do
        table.insert(result, p.at1MaterialItemInfo(i))
    end
    return table.concat(result, '\n')
end

return p