维护提醒
BWIKI 全站将于 9 月 3 日(全天)进行维护,期间无法编辑任何页面或发布新的评论。
全站通知:
模块:Bundles
刷
历
编
跳到导航
跳到搜索
local Helper = require("Module:Helper")
local ID = require("Module:ID")
local bundlesData = Helper.LazyLoad("Module:Bundles/data")
local p = {}
function ParseBundleEntry(entry)
local result = {}
local parts = {}
for part in string.gmatch(entry, "[^/]+") do
table.insert(parts, part)
end
result.name = parts[1]
local prizeParts = {}
for part in string.gmatch(parts[2], "%S+") do
table.insert(prizeParts, part)
end
result.prize = { type = prizeParts[1], ID = prizeParts[2], count = prizeParts[3] }
result.required = {}
local requiredParts = {}
for part in string.gmatch(parts[3], "%S+") do
table.insert(requiredParts, part)
end
for i = 1, #requiredParts, 3 do
local reqParts = {}
reqParts.ID = tonumber(requiredParts[i])
reqParts.count = tonumber(requiredParts[i + 1])
reqParts.quality = tonumber(requiredParts[i + 2])
table.insert(result.required, reqParts)
end
result.count = tonumber(parts[#parts - 1])
result.color = tonumber(parts[#parts - 2])
if result.color == nil and result.count ~= nil then
result.color = result.count
result.count = nil
end
result.zh = parts[#parts]
return result
end
function ProcessBundlesData(data)
local bundles = {}
for key, entry in pairs(data) do
local parsedEntry = ParseBundleEntry(entry)
bundles[key] = parsedEntry
end
return bundles
end
function p.debug()
local processedData = ProcessBundlesData(bundlesData)
mw.logObject(processedData)
end
-- mw.logObject(p.CheckItem{args={335}})
function p.ItemInfo(frame)
local arg = frame.args[1]
local optional = false
local processedData = ProcessBundlesData(bundlesData)
for key, entry in pairs(processedData) do
for _, requiredItem in ipairs(entry.required) do
if requiredItem.ID == tonumber(arg) then
if entry.count ~= nil then
if entry.count == requiredItem.count then
optional = true
else
optional = false
end
end
return { entry.zh, optional, entry.color }
end
end
end
return nil
end
-- mw.log(p.ItemRequired{args={335}})
function p.ItemRequired(frame)
if p.ItemInfo(frame) == nil then
return '否'
else
return '是'
end
end
-- mw.log(p.ItemRequiredByName{args={"鲶鱼"}})
function p.ItemRequiredByName(frame)
local id = ID.id {args = { frame.args[1] }}
if id:sub(1, 3) == "(O)" then
id = id:sub(4)
else
return '否'
end
if p.ItemInfo({args = { id }}) == nil then
return '否'
else
return '是'
end
end
return p