跳转到内容

模块:物品来源:修订间差异

来自Wymbot 共创站
NotBot​(留言 | 贡献)
将超市可购买信息独立存储于模板空间,保留物品来源查询;机制页不修改
NotBot​(留言 | 贡献)
恢复旧站紧凑灰底收集度折叠表格,修复来源表其他单元格的异常段落间距
第23行: 第23行:
     local planting = #groups.planting > 0 and table.concat(groups.planting, '、') or
     local planting = #groups.planting > 0 and table.concat(groups.planting, '、') or
         (#groups.travel > 0 and '他妈,种菜不掉这个!' or '他妈,种菜也不掉这个!')
         (#groups.travel > 0 and '他妈,种菜不掉这个!' or '他妈,种菜也不掉这个!')
    local otherText = #groups.other > 0 and table.concat(groups.other, '、') or '你觉得还有其他方式?'
    local otherPrefix = C.trim(otherText)
    local separator = (otherPrefix:sub(1, 2) == '{|' or otherPrefix:match('^[*#;:=]')) and '\n' or ' '
     rows = {
     rows = {
         '|-\n| 旅行 || ' .. travel,
         '|-\n| 旅行 || ' .. travel,
         '|-\n| 种菜 || ' .. planting,
         '|-\n| 种菜 || ' .. planting,
         '|-\n| [[SB洪超市]] || ' .. (#groups.shop > 0 and table.concat(groups.shop, '、') or '他妈,超市还卖这个?'),
         '|-\n| [[SB洪超市]] || ' .. (#groups.shop > 0 and table.concat(groups.shop, '、') or '他妈,超市还卖这个?'),
         '|-\n| 其他 ||\n' .. (#groups.other > 0 and table.concat(groups.other, '、') or '你觉得还有其他方式?')
         '|-\n| 其他 || class="wum-item-other" |' .. separator .. otherText
     }
     }
     local body = C.heading(c, '在哪掉的?')
     local body = C.heading(c, '在哪掉的?')

2026年10月24日 (六) 12:36的版本

此模块的文档可以在模块:物品来源/doc创建

local C = require('模块:物品通用')
local D = require('模块:物品数据')
local p = {}
local categories = { travel = '能通过旅行获取的物品', planting = '能通过种菜获取的物品', shop = '能通过超市获取的物品', other = '有其他获取方式的物品' }
function p.main(frame)
    local c = C.context(frame)
    if not c.enabled then return '' end
    local result, rows, cats = D.getSources(c.name), {}, {}
    local groups = { travel = {}, planting = {}, shop = {}, other = {} }
    local other = c.text('其他方式')
    for _, entry in ipairs(result.entries or {}) do
        if groups[entry.kind] and not (entry.kind == 'other' and other) then
            local text = entry.target and C.link(entry.target, entry.label) or C.literal(entry.label)
            -- Item acquisition lists never display probabilities, including unknown ones.
            if entry.kind == 'shop' and entry.label == 'SB洪超市' then text = C.literal(entry.availability or '能') end
            if entry.note then text = text .. '(' .. C.literal(entry.note) .. ')' end
            groups[entry.kind][#groups[entry.kind] + 1] = text
            if categories[entry.kind] then cats[#cats + 1] = categories[entry.kind] end
        end
    end
    if other then groups.other = { other }; cats[#cats + 1] = categories.other end
    local travel = #groups.travel > 0 and table.concat(groups.travel, '、') or '他妈,旅行不掉这个!'
    local planting = #groups.planting > 0 and table.concat(groups.planting, '、') or
        (#groups.travel > 0 and '他妈,种菜不掉这个!' or '他妈,种菜也不掉这个!')
    local otherText = #groups.other > 0 and table.concat(groups.other, '、') or '你觉得还有其他方式?'
    local otherPrefix = C.trim(otherText)
    local separator = (otherPrefix:sub(1, 2) == '{|' or otherPrefix:match('^[*#;:=]')) and '\n' or ' '
    rows = {
        '|-\n| 旅行 || ' .. travel,
        '|-\n| 种菜 || ' .. planting,
        '|-\n| [[SB洪超市]] || ' .. (#groups.shop > 0 and table.concat(groups.shop, '、') or '他妈,超市还卖这个?'),
        '|-\n| 其他 || class="wum-item-other" |' .. separator .. otherText
    }
    local body = C.heading(c, '在哪掉的?')
    if result.status == 'error' then body = body .. C.diagnostic(result) .. '\n'; cats[#cats + 1] = '物品数据异常的页面' end
    body = body .. '{| class="wikitable wum-item-table"\n! 获取途径 !! 能否通过该途径获得\n' .. table.concat(rows, '\n') .. '\n|}'
    return C.finish(c, 'sources', body, cats)
end
return p