模块

Gem:修订间差异

来自蒙纳多研究本部

头号云​(留言 | 贡献)
创建页面,内容为“-- 模块: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):武器·防具共用…”
 
头号云​(留言 | 贡献)
无编辑摘要
第1行: 第1行:
-- 模块:Gem —— 宝珠渲染层(列表 / infobox)
-- 模块:Gem —— 宝珠渲染层(列表 / infobox)
-- 用法:
-- 用法:
--  {{#invoke:Gem|list|slot=shared}}  共用宝珠列表(本模块首发目标)
--  {{#invoke:Gem|list|slot=shared}}  武器防具共用宝珠
--  {{#invoke:Gem|list|slot=weapon}}  武器宝珠列表(复用同管线)
--  {{#invoke:Gem|list|slot=weapon}}  武器专用宝珠
--  {{#invoke:Gem|list|slot=armor}}    防具宝珠列表(复用同管线)
--  {{#invoke:Gem|list|slot=armor}}    防具专用宝珠
--  {{#invoke:Gem|infobox|id=1}}      单宝珠信息框
--  {{#invoke:Gem|infobox|id=1}}      单宝珠信息框
-- 表头用语取自游戏内官方 UI 文本(MNU_item_ms):武器·防具共用宝珠 / 武器专用宝珠 / 防具专用宝珠
-- 格式对齐站内旧页面《武器防具共用宝珠》(人力维护版):
--  等级列 I~VI 对应数据六档锚点 E/D/C/B/A/S(游戏内共用宝珠只有 VI 档,没有 X)
--  颜色列 = atr_type 映射(4红 5深蓝 6黄 7浅蓝 8绿 9橙)
--  类型列 = category 映射(1能力 4支援 5场景 2攻击 3防御)
--  最大值列 = max 字段
--  名称列 = skilllist.name(线上 xbdb 已解析为中文短名)


local p = {}
local p = {}
第11行: 第16行:
local gemData = require("Module:GemData")
local gemData = require("Module:GemData")
local gemSMW = require("Module:GemSMW")
local gemSMW = require("Module:GemSMW")
local html = require("Module:Html")


local SLOTS = {
local SLOTS = {
   shared = { attach = 0, title = "武器·防具共用宝珠" },
   shared = { attach = 0, title = "武器防具共用宝珠" },
   weapon = { attach = 1, title = "武器专用宝珠" },
   weapon = { attach = 1, title = "武器专用宝珠" },
   armor  = { attach = 2, title = "防具专用宝珠" },
   armor  = { attach = 2, title = "防具专用宝珠" },
}
}


local ROMAN = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }
-- 六档锚点(游戏内宝珠等级 I~VI,对应 BTL_skilllist 的 E/D/C/B/A/S)
local ROMAN6 = { "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ" }
local KEYS6  = { "E", "D", "C", "B", "A", "S" }
 
-- 颜色映射(atr_type,原页面人力标注 → 数据字段反推)
local ATR_COLOR = {
  [4] = "红", [5] = "深蓝", [6] = "黄", [7] = "浅蓝", [8] = "绿", [9] = "橙",
}
 
-- 类型映射(category:1能力 2攻击 3防御 4支援 5场景 6成长/获得)
local CATEGORY_TYPE = {
  [1] = "能力", [2] = "攻击", [3] = "防御", [4] = "支援", [5] = "场景", [6] = "能力",
}
 
-- rvs_type:1=永续型(被动常驻)3=永续型 0/2=其他
-- 原页面「永续型」列:数据 rvs_type=1 或 3 都是常驻型;0=发动型(如无法战斗抗性97)
local RVS_LABEL = {
  [1] = "永续型", [3] = "永续型", [0] = "发动型", [2] = "发动型",
}


local function num(v)
local function num(v)
第26行: 第48行:
end
end


-- 效果描述清洗:把 $1 换成各级数值
-- 区间文本:"5-10",带百分号时 "5-10%"
local function renderCaption(caption, val)
local function rangeText(s, key)
   if not caption then return "" end
   local lo = num(s["lower_" .. key])
   return (caption:gsub("%$1", tostring(val)))
  local hi = num(s["upper_" .. key])
  local pct = num(s["percent_" .. key]) == 1 and "%" or ""
  return lo .. "-" .. hi .. pct
end
 
-- 效果说明:caption 去掉【永续型】前缀、$1 置空(说明列不填数值)
local function effectText(s)
  local cap = s.rvs_caption or ""
   cap = cap:gsub("^【[^】]*】", ""):gsub("%$1", "")
  return mw.text.trim(cap)
end
end


-- ====== 列表 ======
-- ====== 列表(格式对齐旧页面) ======
function p.list(frame)
function p.list(frame)
   local args = require("Module:Arguments").getArgs(frame)
   local args = require("Module:Arguments").getArgs(frame)
第49行: 第80行:
   gemSMW.annotateAll(gems)
   gemSMW.annotateAll(gems)


   -- 表格:宝珠名(等级 I~X)|效果说明|I 级|X 级|熔炼费用
   -- 旧页面格式:宝珠名称 | 颜色 | Ⅰ~Ⅵ 六档区间 | 最大值 | 类型 | 说明
  -- (原页面的「永续型」列与「类型」列拆开;rvs_type 已统一为永续型,可从效果文字判断)
   local out = {}
   local out = {}
   out[#out + 1] = '<table class="wikitable sortable">'
   out[#out + 1] = '{| class="wikitable"'
   out[#out + 1] = '<tr><th>宝珠</th><th>效果(X 级数值)</th><th>I 级</th><th>X 级</th><th>熔炼费用 G</th></tr>'
   out[#out + 1] = '|-'
  out[#out + 1] = '! 宝珠名称 !! 颜色 !! colspan=6 | 效果数值 !! 最大值 !! 类型 !! 说明'
  out[#out + 1] = '|-'
  out[#out + 1] = '! !! !! ' .. table.concat(ROMAN6, " !! ") .. ' !! !! !!'


   for _, gem in ipairs(gems) do
   for _, gem in ipairs(gems) do
     local s = gem.data
     local s = gem.data
     local v1 = gemData.valueAtRank(s, 1)
     local color = ATR_COLOR[num(s.atr_type)] or "?"
     local v10 = gemData.valueAtRank(s, 10)
     local cat = CATEGORY_TYPE[num(s.category)] or "?"
     local name = s.rvs_caption and renderCaption(s.rvs_caption, "") or ("技能#" .. gem.id)
     local ranges = {}
     -- 效果说明用 X 级数值填充
    for _, key in ipairs(KEYS6) do
     local effect = renderCaption(s.rvs_caption, v10)
      ranges[#ranges + 1] = rangeText(s, key)
    end
     -- 最大值:max 字段 + 百分比跟随 S 档
     local maxPct = num(s.percent_S) == 1 and "%" or ""
    out[#out + 1] = '|-'
     out[#out + 1] = string.format(
     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>',
       '| %s || %s || %s || %s || %s || %s',
       name, "X", effect, v1, v10, num(s.money)
       s.name or ("宝珠#" .. gem.id),
      color,
      table.concat(ranges, " || "),
      num(s.max) .. maxPct,
      cat,
      effectText(s)
     )
     )
   end
   end


   out[#out + 1] = '</table>'
   out[#out + 1] = '|}'
   out[#out + 1] = string.format('<!-- 共 %d 条 | 数据: bdat_common.BTL_skilllist attach=%d | 取数时间: %s -->',
   out[#out + 1] = string.format('<!-- 共 %d 条 | 数据: bdat_common.BTL_skilllist attach=%d -->', #gems, slot.attach)
    #gems, slot.attach, os.date("%Y-%m-%d %H:%M"))


   return table.concat(out, "\n")
   return table.concat(out, "\n")
第87行: 第130行:
   end
   end


   -- SMW 注解:infobox 渲染即建档
   -- SMW 注解
   gemSMW.annotate(id, s)
   gemSMW.annotate(id, s)


  local color = ATR_COLOR[num(s.atr_type)] or "?"
  local cat = CATEGORY_TYPE[num(s.category)] or "?"
   local out = {}
   local out = {}
   out[#out + 1] = '{| class="wikitable" style="float:right; width:280px; margin-left:1em"'
   out[#out + 1] = '{| class="wikitable" style="float:right; width:300px; margin-left:1em"'
   out[#out + 1] = '|+ ' .. (s.rvs_caption or ("宝珠#" .. id)):gsub("%$1", "")
   out[#out + 1] = '|+ ' .. (s.name or ("宝珠#" .. id))
   out[#out + 1] = '|-'
   out[#out + 1] = '|-'
   out[#out + 1] = '! 熔炼费用'
   out[#out + 1] = '! 颜色 || ' .. color
   out[#out + 1] = '| ' .. num(s.money) .. ' G'
   out[#out + 1] = '|-'
 
  out[#out + 1] = '! 类型 || ' .. cat
   -- 等级数值 I~X
  out[#out + 1] = '|-'
   out[#out + 1] = '! 说明 || ' .. effectText(s)
   out[#out + 1] = '|-'
   out[#out + 1] = '|-'
   out[#out + 1] = '! colspan=2 | 各等级效果数值'
   out[#out + 1] = '! colspan=2 | 效果数值(Ⅰ~Ⅵ)'
   for rank = 1, 10 do
   for i, key in ipairs(KEYS6) do
     out[#out + 1] = '|-'
     out[#out + 1] = '|-'
     out[#out + 1] = '! ' .. ROMAN[rank]
     out[#out + 1] = '! ' .. ROMAN6[i]
     out[#out + 1] = '| ' .. gemData.valueAtRank(s, rank)
     out[#out + 1] = '| ' .. rangeText(s, key)
   end
   end
  local maxPct = num(s.percent_S) == 1 and "%" or ""
  out[#out + 1] = '|-'
  out[#out + 1] = '! 最大值 || ' .. num(s.max) .. maxPct
   out[#out + 1] = '|}'
   out[#out + 1] = '|}'



2026年10月13日 (二) 21:43的版本

此模块的文档可以在模块:Gem/doc创建

-- 模块:Gem —— 宝珠渲染层(列表 / infobox)
-- 用法:
--   {{#invoke:Gem|list|slot=shared}}   武器防具共用宝珠
--   {{#invoke:Gem|list|slot=weapon}}   武器专用宝珠
--   {{#invoke:Gem|list|slot=armor}}    防具专用宝珠
--   {{#invoke:Gem|infobox|id=1}}       单宝珠信息框
-- 格式对齐站内旧页面《武器防具共用宝珠》(人力维护版):
--   等级列 I~VI 对应数据六档锚点 E/D/C/B/A/S(游戏内共用宝珠只有 VI 档,没有 X)
--   颜色列 = atr_type 映射(4红 5深蓝 6黄 7浅蓝 8绿 9橙)
--   类型列 = category 映射(1能力 4支援 5场景 2攻击 3防御)
--   最大值列 = max 字段
--   名称列 = skilllist.name(线上 xbdb 已解析为中文短名)

local p = {}

local gemData = require("Module:GemData")
local gemSMW = require("Module:GemSMW")

local SLOTS = {
  shared = { attach = 0, title = "武器防具共用宝珠" },
  weapon = { attach = 1, title = "武器专用宝珠" },
  armor  = { attach = 2, title = "防具专用宝珠" },
}

-- 六档锚点(游戏内宝珠等级 I~VI,对应 BTL_skilllist 的 E/D/C/B/A/S)
local ROMAN6 = { "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ" }
local KEYS6  = { "E", "D", "C", "B", "A", "S" }

-- 颜色映射(atr_type,原页面人力标注 → 数据字段反推)
local ATR_COLOR = {
  [4] = "红", [5] = "深蓝", [6] = "黄", [7] = "浅蓝", [8] = "绿", [9] = "橙",
}

-- 类型映射(category:1能力 2攻击 3防御 4支援 5场景 6成长/获得)
local CATEGORY_TYPE = {
  [1] = "能力", [2] = "攻击", [3] = "防御", [4] = "支援", [5] = "场景", [6] = "能力",
}

-- rvs_type:1=永续型(被动常驻)3=永续型 0/2=其他
-- 原页面「永续型」列:数据 rvs_type=1 或 3 都是常驻型;0=发动型(如无法战斗抗性97)
local RVS_LABEL = {
  [1] = "永续型", [3] = "永续型", [0] = "发动型", [2] = "发动型",
}

local function num(v)
  if v == nil then return 0 end
  return tonumber(v) or 0
end

-- 区间文本:"5-10",带百分号时 "5-10%"
local function rangeText(s, key)
  local lo = num(s["lower_" .. key])
  local hi = num(s["upper_" .. key])
  local pct = num(s["percent_" .. key]) == 1 and "%" or ""
  return lo .. "-" .. hi .. pct
end

-- 效果说明:caption 去掉【永续型】前缀、$1 置空(说明列不填数值)
local function effectText(s)
  local cap = s.rvs_caption or ""
  cap = cap:gsub("^【[^】]*】", ""):gsub("%$1", "")
  return mw.text.trim(cap)
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)

  -- 旧页面格式:宝珠名称 | 颜色 | Ⅰ~Ⅵ 六档区间 | 最大值 | 类型 | 说明
  -- (原页面的「永续型」列与「类型」列拆开;rvs_type 已统一为永续型,可从效果文字判断)
  local out = {}
  out[#out + 1] = '{| class="wikitable"'
  out[#out + 1] = '|-'
  out[#out + 1] = '! 宝珠名称 !! 颜色 !! colspan=6 | 效果数值 !! 最大值 !! 类型 !! 说明'
  out[#out + 1] = '|-'
  out[#out + 1] = '! !! !! ' .. table.concat(ROMAN6, " !! ") .. ' !! !! !!'

  for _, gem in ipairs(gems) do
    local s = gem.data
    local color = ATR_COLOR[num(s.atr_type)] or "?"
    local cat = CATEGORY_TYPE[num(s.category)] or "?"
    local ranges = {}
    for _, key in ipairs(KEYS6) do
      ranges[#ranges + 1] = rangeText(s, key)
    end
    -- 最大值:max 字段 + 百分比跟随 S 档
    local maxPct = num(s.percent_S) == 1 and "%" or ""
    out[#out + 1] = '|-'
    out[#out + 1] = string.format(
      '| %s || %s || %s || %s || %s || %s',
      s.name or ("宝珠#" .. gem.id),
      color,
      table.concat(ranges, " || "),
      num(s.max) .. maxPct,
      cat,
      effectText(s)
    )
  end

  out[#out + 1] = '|}'
  out[#out + 1] = string.format('<!-- 共 %d 条 | 数据: bdat_common.BTL_skilllist attach=%d -->', #gems, slot.attach)

  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 注解
  gemSMW.annotate(id, s)

  local color = ATR_COLOR[num(s.atr_type)] or "?"
  local cat = CATEGORY_TYPE[num(s.category)] or "?"
  local out = {}
  out[#out + 1] = '{| class="wikitable" style="float:right; width:300px; margin-left:1em"'
  out[#out + 1] = '|+ ' .. (s.name or ("宝珠#" .. id))
  out[#out + 1] = '|-'
  out[#out + 1] = '! 颜色 || ' .. color
  out[#out + 1] = '|-'
  out[#out + 1] = '! 类型 || ' .. cat
  out[#out + 1] = '|-'
  out[#out + 1] = '! 说明 || ' .. effectText(s)
  out[#out + 1] = '|-'
  out[#out + 1] = '! colspan=2 | 效果数值(Ⅰ~Ⅵ)'
  for i, key in ipairs(KEYS6) do
    out[#out + 1] = '|-'
    out[#out + 1] = '! ' .. ROMAN6[i]
    out[#out + 1] = '| ' .. rangeText(s, key)
  end
  local maxPct = num(s.percent_S) == 1 and "%" or ""
  out[#out + 1] = '|-'
  out[#out + 1] = '! 最大值 || ' .. num(s.max) .. maxPct
  out[#out + 1] = '|}'

  return table.concat(out, "\n")
end

p.SLOTS = SLOTS

return p