跳转到内容
主菜单
主菜单
移至侧栏
隐藏
首页|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 optionalQuantity(value) return value == nil or type(value) == 'string' or (type(value) == 'number' and value >= 0 and value < math.huge and value % 1 == 0) 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 not optionalQuantity(drop.minQuantity) or not optionalQuantity(drop.maxQuantity) then return state('error', { code = 'invalid-drop-quantity' }) end if type(drop.minQuantity) == 'number' and type(drop.maxQuantity) == 'number' and drop.minQuantity > drop.maxQuantity then return state('error', { code = 'invalid-drop-quantity-range' }) end if drop.note ~= nil and type(drop.note) ~= 'string' then return state('error', { code = 'invalid-drop-note' }) 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 return source end function p.getShop(name) local source = load('shops') if source.status ~= 'known' then return source end local value = source.data[p.resolve(name)] if value == nil or value == '' then return state('none') end if type(value) ~= 'string' then return state('error', { code = 'invalid-shop-availability' }) end return state('known', { availability = value }) end function p.getShopItems() local source = load('shops') if source.status ~= 'known' then return source end local names, entries = {}, {} for name in pairs(source.data) do names[#names + 1] = name end table.sort(names) for _, name in ipairs(names) do local result = p.getShop(name) if result.status == 'error' then return result end if result.status == 'known' then entries[#entries + 1] = { item = name, availability = result.availability } end end return state('known', { entries = entries, kind = 'shop' }) end function p.getSources(name) local source = pools() if source.status == 'error' then return source end name = p.resolve(name) local entries = {} for _, pool in ipairs(source.status == 'known' and source.data.pools or {}) 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 } break -- Multiple conditional rows still represent one source pool. end end end local shop = p.getShop(name) if shop.status == 'error' then return shop end if shop.status == 'known' then entries[#entries + 1] = { kind = 'shop', label = 'SB洪超市', target = 'SB洪超市', availability = shop.availability } end return state(#entries > 0 and 'known' or (source.complete and 'none' or 'pending'), { entries = entries }) end function p.getOutputs(name) name = p.resolve(name) -- Compatibility for the already-created page awaiting manual deletion. if name == 'SB洪超市' then return p.getShopItems() end 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 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 type(level) == 'string' and mw.text.trim(level) == '' then level = nil end 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 local increase = record['合成增加收集度'] if increase == nil or (type(increase) == 'string' and mw.text.trim(increase) == '') then increase = 30 end if type(increase) ~= 'number' or increase < 0 then return state('error', { code = 'invalid-recipe-collection-increase' }) end return state('known', { name = name, quantity = quantity, materials = materials, level = level, info = info, collectionIncrease = increase }) 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
(
查看源代码
)
返回
模块:物品数据
。
搜索
搜索
查看“︁模块:物品数据”︁的源代码
添加话题