模块:Gem
来自蒙纳多研究本部
此模块的文档可以在模块:Gem/doc创建
-- 模块:Gem —— 宝珠渲染层(列表 / infobox)
-- 用法:
-- {{#invoke:Gem|list|slot=shared}} 共用宝珠列表(本模块首发目标)
-- {{#invoke:Gem|list|slot=weapon}} 武器宝珠列表(复用同管线)
-- {{#invoke:Gem|list|slot=armor}} 防具宝珠列表(复用同管线)
-- {{#invoke:Gem|infobox|id=1}} 单宝珠信息框
-- 表头用语取自游戏内官方 UI 文本(MNU_item_ms):武器·防具共用宝珠 / 武器专用宝珠 / 防具专用宝珠
local p = {}
local gemData = require("Module:GemData")
local gemSMW = require("Module:GemSMW")
local html = require("Module:Html")
local SLOTS = {
shared = { attach = 0, title = "武器·防具共用宝珠" },
weapon = { attach = 1, title = "武器专用宝珠" },
armor = { attach = 2, title = "防具专用宝珠" },
}
local ROMAN = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }
local function num(v)
if v == nil then return 0 end
return tonumber(v) or 0
end
-- 效果描述清洗:把 $1 换成各级数值
local function renderCaption(caption, val)
if not caption then return "" end
return (caption:gsub("%$1", tostring(val)))
end
-- ====== 列表 ======
function p.list(frame)
local args = require("Module:Arguments").getArgs(frame)
local slotKey = args.slot or "shared"
local slot = SLOTS[slotKey]
if not slot then
return '<strong class="error">未知 slot:' .. mw.text.nowiki(slotKey) .. '</strong>'
end
local gems = gemData.gemsByAttach(slot.attach)
if #gems == 0 then
return '<strong class="error">GemData 未返回任何 ' .. slot.title .. '(xbdb 不可达或数据为空)</strong>'
end
-- SMW 注解:列表渲染即建档(同解析内去重,见 GemSMW)
gemSMW.annotateAll(gems)
-- 表格:宝珠名(等级 I~X)|效果说明|I 级|X 级|熔炼费用
local out = {}
out[#out + 1] = '<table class="wikitable sortable">'
out[#out + 1] = '<tr><th>宝珠</th><th>效果(X 级数值)</th><th>I 级</th><th>X 级</th><th>熔炼费用 G</th></tr>'
for _, gem in ipairs(gems) do
local s = gem.data
local v1 = gemData.valueAtRank(s, 1)
local v10 = gemData.valueAtRank(s, 10)
local name = s.rvs_caption and renderCaption(s.rvs_caption, "") or ("技能#" .. gem.id)
-- 效果说明用 X 级数值填充
local effect = renderCaption(s.rvs_caption, v10)
out[#out + 1] = string.format(
'<tr><td>[[%s %s]]</td><td>%s</td><td style="text-align:right">%s</td><td style="text-align:right">%s</td><td style="text-align:right">%s</td></tr>',
name, "X", effect, v1, v10, num(s.money)
)
end
out[#out + 1] = '</table>'
out[#out + 1] = string.format('<!-- 共 %d 条 | 数据: bdat_common.BTL_skilllist attach=%d | 取数时间: %s -->',
#gems, slot.attach, os.date("%Y-%m-%d %H:%M"))
return table.concat(out, "\n")
end
-- ====== infobox ======
function p.infobox(frame)
local args = require("Module:Arguments").getArgs(frame)
local id = tonumber(args.id)
if not id then
return '<strong class="error">缺少 id 参数</strong>'
end
local s = gemData.getGem(id)
if not s then
return '<strong class="error">宝珠 #' .. id .. ' 不存在或不是可装备宝珠</strong>'
end
-- SMW 注解:infobox 渲染即建档
gemSMW.annotate(id, s)
local out = {}
out[#out + 1] = '{| class="wikitable" style="float:right; width:280px; margin-left:1em"'
out[#out + 1] = '|+ ' .. (s.rvs_caption or ("宝珠#" .. id)):gsub("%$1", "")
out[#out + 1] = '|-'
out[#out + 1] = '! 熔炼费用'
out[#out + 1] = '| ' .. num(s.money) .. ' G'
-- 等级数值 I~X
out[#out + 1] = '|-'
out[#out + 1] = '! colspan=2 | 各等级效果数值'
for rank = 1, 10 do
out[#out + 1] = '|-'
out[#out + 1] = '! ' .. ROMAN[rank]
out[#out + 1] = '| ' .. gemData.valueAtRank(s, rank)
end
out[#out + 1] = '|}'
return table.concat(out, "\n")
end
p.SLOTS = SLOTS
return p