模块:物品来源:修订间差异
外观
建立模块化物品展示及用户提供的测试数据(不迁移旧掉落) |
按旧Wiki恢复完整来源表、合成样式和缺省文案;物品来源不显示概率 |
||
| 第3行: | 第3行: | ||
local p = {} | local p = {} | ||
local categories = { travel = '能通过旅行获取的物品', planting = '能通过种菜获取的物品', shop = '能通过超市获取的物品', other = '有其他获取方式的物品' } | local categories = { travel = '能通过旅行获取的物品', planting = '能通过种菜获取的物品', shop = '能通过超市获取的物品', other = '有其他获取方式的物品' } | ||
function p.main(frame) | function p.main(frame) | ||
local c = C.context(frame) | local c = C.context(frame) | ||
if not c.enabled then return '' end | if not c.enabled then return '' end | ||
local result, rows, cats = D.getSources(c.name), {}, {} | local result, rows, cats = D.getSources(c.name), {}, {} | ||
local groups = { travel = {}, planting = {}, shop = {}, other = {} } | |||
local other = c.text('其他方式') | local other = c.text('其他方式') | ||
for _, entry in ipairs(result.entries or {}) do | for _, entry in ipairs(result.entries or {}) do | ||
if not (entry.kind == 'other' and other) then | 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) | local text = entry.target and C.link(entry.target, entry.label) or C.literal(entry.label) | ||
if entry. | -- Item acquisition lists never display probabilities, including unknown ones. | ||
if entry.kind == 'shop' and entry.label == 'SB洪超市' then text = '能' end | |||
if entry.note then text = text .. '(' .. C.literal(entry.note) .. ')' 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 | if categories[entry.kind] then cats[#cats + 1] = categories[entry.kind] end | ||
end | end | ||
end | end | ||
if other then | 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 '他妈,种菜也不掉这个!') | |||
rows = { | |||
'|-\n| 旅行 || ' .. travel, | |||
'|-\n| 种菜 || ' .. planting, | |||
'|-\n| [[SB洪超市]] || ' .. (#groups.shop > 0 and table.concat(groups.shop, '、') or '他妈,超市还卖这个?'), | |||
'|-\n| 其他 ||\n' .. (#groups.other > 0 and table.concat(groups.other, '、') or '你觉得还有其他方式?') | |||
} | |||
local body = C.heading(c, '在哪掉的?') | local body = C.heading(c, '在哪掉的?') | ||
if result.status == 'error' then body = body .. C.diagnostic(result) .. '\n'; cats[#cats + 1] = '物品数据异常的页面' end | 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) | return C.finish(c, 'sources', body, cats) | ||
end | end | ||
return p | return p | ||
2026年10月24日 (六) 12:17的版本
此模块的文档可以在模块:物品来源/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 = '能' 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 '他妈,种菜也不掉这个!')
rows = {
'|-\n| 旅行 || ' .. travel,
'|-\n| 种菜 || ' .. planting,
'|-\n| [[SB洪超市]] || ' .. (#groups.shop > 0 and table.concat(groups.shop, '、') or '他妈,超市还卖这个?'),
'|-\n| 其他 ||\n' .. (#groups.other > 0 and table.concat(groups.other, '、') or '你觉得还有其他方式?')
}
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