跳转到内容
主菜单
主菜单
移至侧栏
隐藏
首页|Wiki首页
Wymbot新手引导|新手入门
WymboTrip|旅行模块
指令一览|指令目录
旅行地点|旅行地点
物品来源速查|物品资料
Wums|wum图鉴
合成配方|合成配方
科研|科研
共创指南|参与编写
https://wum.hetonger.cn/|共创站首页
https://wum.hetonger.cn/game/|网页端
https://wum.hetonger.cn/command/|指令检索
搜索
搜索
外观
创建账号
登录
个人工具
创建账号
登录
查看“︁模块:物品数据”︁的源代码
模块
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
页面信息
外观
移至侧栏
隐藏
←
模块:物品数据
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local config = require('模块:物品配置') local p = {} local cache = {} local function state(status, extra) local result = extra or {} result.status = status return result end local function load(kind) if cache[kind] then return cache[kind] end local spec = config[kind] if not spec or not spec.enabled then return state('pending') end local ok, value = pcall(mw.loadJsonData, spec.page) if not ok or type(value) ~= 'table' then cache[kind] = state('error', { code = 'data-load-failed', page = spec.page }) else local records = kind ~= 'sources' and (value.records or value) or value if type(records) ~= 'table' then cache[kind] = state('error', { code = 'invalid-data-envelope', page = spec.page }) else cache[kind] = state('known', { data = records, complete = spec.complete == true }) end end return cache[kind] end function p.resolve(name) -- One explicit alias step; do not lowercase or strip disambiguation suffixes. return config.aliases[name] or name end function p.getItem(name) return state('pending', { name = p.resolve(name) }) end local function pools() local source = load('sources') if source.status ~= 'known' then return source end if source.data.schemaVersion ~= 1 or type(source.data.pools) ~= 'table' then return state('error', { code = 'invalid-drop-schema' }) end local seen = {} for _, pool in ipairs(source.data.pools) do if type(pool.name) ~= 'string' or mw.text.trim(pool.name) == '' or seen[pool.name] or (pool.kind ~= 'travel' and pool.kind ~= 'planting' and pool.kind ~= 'shop' and pool.kind ~= 'other') or type(pool.drops) ~= 'table' then return state('error', { code = 'invalid-drop-pool' }) end seen[pool.name] = true for _, drop in ipairs(pool.drops) do if type(drop.item) ~= 'string' or mw.text.trim(drop.item) == '' then return state('error', { code = 'invalid-drop-item' }) end if drop.probabilityStatus == 'known' then if type(drop.probability) ~= 'number' or drop.probability < 0 or drop.probability > 1 then return state('error', { code = 'invalid-drop-probability' }) end elseif drop.probabilityStatus ~= 'unknown' or drop.probability ~= nil then return state('error', { code = 'invalid-drop-probability-status' }) end end end for _, shop in ipairs(source.data.shops or {}) do if type(shop.name) ~= 'string' or mw.text.trim(shop.name) == '' or type(shop.items) ~= 'table' then return state('error', { code = 'invalid-shop' }) end for _, item in ipairs(shop.items) do if type(item) ~= 'string' or mw.text.trim(item) == '' then return state('error', { code = 'invalid-shop-item' }) end end end return source end function p.getSources(name) local source = pools() if source.status ~= 'known' then return source end name = p.resolve(name) local entries = {} for _, pool in ipairs(source.data.pools) do for _, drop in ipairs(pool.drops) do if p.resolve(drop.item) == name then entries[#entries + 1] = { kind = pool.kind, label = pool.name, target = pool.name, probability = drop.probability, probabilityStatus = drop.probabilityStatus } end end end for _, shop in ipairs(source.data.shops or {}) do for _, item in ipairs(shop.items) do if p.resolve(item) == name then entries[#entries + 1] = { kind = 'shop', label = shop.name, target = shop.name } end end end return state(#entries > 0 and 'known' or (source.complete and 'none' or 'pending'), { entries = entries }) end function p.getOutputs(name) local source = pools() if source.status ~= 'known' then return source end name = p.resolve(name) for _, pool in ipairs(source.data.pools) do if p.resolve(pool.name) == name then return state('known', { entries = pool.drops, kind = pool.kind }) end end for _, shop in ipairs(source.data.shops or {}) do if p.resolve(shop.name) == name then local entries = {} for _, item in ipairs(shop.items) do entries[#entries + 1] = { item = item } end return state('known', { entries = entries, kind = 'shop' }) end end return state('pending', { entries = {} }) end function p.getCollection(name, requested) local source = load('collection') if source.status ~= 'known' then return source end local record = source.data[p.resolve(name)] if record == nil then return state(source.complete and 'none' or 'pending', { entries = {} }) end if type(record) ~= 'table' then return state('error', { code = 'invalid-collection-record' }) end local levels, seen = {}, {} local function add(level) local number = tonumber(level) if not number or number <= 0 or number % 1 ~= 0 then return false end if not seen[number] then levels[#levels + 1], seen[number] = number, true end return true end if requested and requested ~= '' then local count = 0 for level in (requested .. ','):gmatch('(.-),') do count = count + 1 if not add(mw.text.trim(level)) then return state('error', { code = 'invalid-collection-levels' }) end end if count == 0 then return state('error', { code = 'invalid-collection-levels' }) end else add(100); add(300); add(500) for level in pairs(record) do if not add(level) then return state('error', { code = 'invalid-collection-level' }) end end end table.sort(levels) local entries, known, pending = {}, false, false for _, level in ipairs(levels) do local value = record[tostring(level)] if value == nil then value = record[level] end if value ~= nil and type(value) ~= 'string' then return state('error', { code = 'invalid-collection-text' }) end local status = value == '无' and 'none' or (value and mw.text.trim(value) ~= '' and 'known' or 'pending') entries[#entries + 1] = { level = level, status = status, text = value } known, pending = known or status == 'known', pending or status == 'pending' end return state(known and 'known' or (pending and 'pending' or 'none'), { entries = entries }) end local function recipe(name, record) if type(record) ~= 'table' or type(record['配方']) ~= 'table' then return state('error', { code = 'invalid-recipe-record' }) end local raw = record['配方'] local quantity = raw[1] if type(quantity) ~= 'number' or quantity <= 0 or quantity % 1 ~= 0 then return state('error', { code = 'invalid-recipe-output' }) end local materials = {} for index, entry in ipairs(raw) do if index > 1 then if type(entry) ~= 'table' or type(entry[1]) ~= 'string' or mw.text.trim(entry[1]) == '' or type(entry[2]) ~= 'number' or entry[2] <= 0 or entry[2] % 1 ~= 0 then return state('error', { code = 'invalid-recipe-material' }) end materials[#materials + 1] = { name = entry[1], quantity = entry[2] } end end if #materials == 0 then return state('error', { code = 'empty-recipe-materials' }) end local level = record['等级'] if level ~= nil and (type(level) ~= 'number' or level < 0) then return state('error', { code = 'invalid-recipe-level' }) end local info = record['信息'] if info ~= nil and type(info) ~= 'string' then return state('error', { code = 'invalid-recipe-info' }) end return state('known', { name = name, quantity = quantity, materials = materials, level = level, info = info }) end function p.getRecipes(name) local source = load('recipes') if source.status ~= 'known' then return source end name = p.resolve(name) local record = source.data[name] if record == nil then return state(source.complete and 'none' or 'pending', { recipes = {} }) end local result = recipe(name, record) if result.status == 'error' then return result end return state('known', { recipes = { result } }) end function p.getUses(name) local source = load('recipes') if source.status ~= 'known' then return source end name = p.resolve(name) local products = {} for product, record in pairs(source.data) do local result = recipe(product, record) if result.status == 'error' then return result end for _, material in ipairs(result.materials) do if p.resolve(material.name) == name then products[#products + 1] = product; break end end end table.sort(products) return state(#products > 0 and 'known' or (source.complete and 'none' or 'pending'), { products = products }) end return p
此页面嵌入的页面:
模块:物品数据/doc
(
查看源代码
)
返回
模块:物品数据
。
搜索
搜索
查看“︁模块:物品数据”︁的源代码
添加话题