「于世界交点之处,逢似曾相识之人」

本wiki目前不支持自由编辑,如果有兴趣参与wiki内容编辑,请加入WIKI建设群904200987(游戏交流勿加会被踢)
使用wiki的数据、图片、音频资源,或者搬运页面内容时,请注明出处。具体参照CC BY-NC-SA 4.0协议
感谢Hyacinth对本wiki提供的数据支持
编辑帮助BWIKI反馈

bugfix1001.2
全站通知:

模块:Character/UpCost

来自白荆回廊Wiki
跳到导航 跳到搜索

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

local p = {}
local db = require('模块:升级消耗材料数据库')
local material_order = db.material_order
local data = mw.text.jsonDecode(mw.title.new('MediaWiki:UpCost.json'):getContent())
local createItemLink = require('Module:Item/Link')
local paddingZero = require('Module:CommonTools').padding_zero

p['单级升级材料消耗'] = function(frame)
  if #frame.args['name'] == nil then
    return '错误:姓名不能为空'
  end
  if #frame.args['direction'] == nil then
    return '错误:类型不能为空'
  end
  if #frame.args['stage'] == nil then
    return '错误:等级不能为空'
  end
  local char_name = frame.args['name']
  local direction = frame.args['direction']
  local stage = tonumber(frame.args['stage'])
  local output_data = {}

  output_data = data[char_name][direction][stage]

  if output_data == {} then
    return '数据待补充'
  end

  local html = mw.html.create()

  for k, v in pairs(output_data) do
    html = html:node(createItemLink.create_link_medium(k, v, nil))
  end
  return tostring(html)
end

p['升级材料消耗'] = function(frame)
  if #frame.args['name'] == nil then
    return '错误:姓名不能为空'
  end

  local char_name = frame.args['name']

  -- 清洗数据,计算合计数量
  local output_data = p.clean_data(data[char_name])
  if output_data == nil then
    local html = mw.html.create()
    html = html:node(frame:expandTemplate{title = '暂无数据'}):done()
    return html
  end

  -- 拼接表格
  local html = mw.html.create()

  html = html:node(p.get_table_html('升阶', output_data['升阶']))
             :node(p.get_table_html('技能1升级', output_data['技能1升级']))
             :node(p.get_table_html('技能2升级', output_data['技能2升级']))

  return tostring(html)
end

function p.clean_data(dataList)
  local costList = {
    ['升阶'] = { {
      ['stage'] = 'S1',
      ['material'] = {}
     }, {
      ['stage'] = 'S2',
      ['material'] = {}
     }, {
      ['stage'] = 'S3',
      ['material'] = {}
     }, {
      ['stage'] = 'S4',
      ['material'] = {}
     }, {
      ['stage'] = 'S5',
      ['material'] = {}
     }, {
      ['stage'] = 'S6',
      ['material'] = {}
     }, {
      ['stage'] = 'S7',
      ['material'] = {}
     }, {
      ['stage'] = '总计',
      ['material'] = {}
     } },
    ['技能1升级'] = { {
      ['stage'] = 'LV2',
      ['material'] = {}
     }, {
      ['stage'] = 'LV3',
      ['material'] = {}
     }, {
      ['stage'] = 'LV4',
      ['material'] = {}
     }, {
      ['stage'] = 'LV5',
      ['material'] = {}
     }, {
      ['stage'] = 'LV6',
      ['material'] = {}
     }, {
      ['stage'] = 'LV7',
      ['material'] = {}
     }, {
      ['stage'] = 'LV8',
      ['material'] = {}
     }, {
      ['stage'] = 'LV9',
      ['material'] = {}
     }, {
      ['stage'] = 'LV10',
      ['material'] = {}
     }, {
      ['stage'] = 'LV11',
      ['material'] = {}
     }, {
      ['stage'] = 'LV12',
      ['material'] = {}
     }, {
      ['stage'] = '总计',
      ['material'] = {}
     } },
    ['技能2升级'] = { {
      ['stage'] = 'LV2',
      ['material'] = {}
     }, {
      ['stage'] = 'LV3',
      ['material'] = {}
     }, {
      ['stage'] = 'LV4',
      ['material'] = {}
     }, {
      ['stage'] = 'LV5',
      ['material'] = {}
     }, {
      ['stage'] = 'LV6',
      ['material'] = {}
     }, {
      ['stage'] = 'LV7',
      ['material'] = {}
     }, {
      ['stage'] = 'LV8',
      ['material'] = {}
     }, {
      ['stage'] = 'LV9',
      ['material'] = {}
     }, {
      ['stage'] = 'LV10',
      ['material'] = {}
     }, {
      ['stage'] = 'LV11',
      ['material'] = {}
     }, {
      ['stage'] = 'LV12',
      ['material'] = {}
     }, {
      ['stage'] = '总计',
      ['material'] = {}
     } }
  }
   
  for direction, materials in pairs(dataList) do
	if direction ~= '潜能开发' then
		local total_temp = {}
		for stage, material in pairs(materials) do
			if direction == '升阶' then
				costList[direction][stage]['material'] = material
			elseif direction == '技能1升级' or direction == '技能2升级' then
				costList[direction][stage-1]['material'] = material
			end
			
			for name , count in pairs(material) do
				if total_temp[name] == nil then
					total_temp[name] = count
				else
					total_temp[name] = total_temp[name] + count
				end
			end
		end
		costList[direction][#costList[direction]]['material'] = total_temp
	end

  end

  return costList
end

function p.get_table_html(key, list)
  local html = mw.html.create()
  html = html:tag('table'):addClass('wikitable mw-collapsible mw-collapsed'):cssText('margin:0;width:100%;')
				:tag('tr')
            		:tag('th'):attr('colspan', 2):wikitext(key):done()
            	:done()
            	:tag('tr')
            		:tag('th'):cssText('width:10%;'):wikitext('等级提升至'):done()
            		:tag('th'):wikitext('消耗材料'):done()
            	:done()
            	
  for _i, v in ipairs(list) do 
    if v['material'] ~= nil and v['material']['海隅点数'] ~= nil then
      html = html:tag('tr')
    				:tag('td'):cssText('text-align:center;'):wikitext(v['stage']):done()
    				:tag('td'):tag('div'):cssText('display:flex;flex-wrap:wrap;gap:4px;')
    				
     
	  --按顺序输出材料
      for _j, w in ipairs(material_order) do
        if v['material'][w] ~= nil and v['material'][w] > 0 then
          html = html:node(createItemLink.create_link_medium(w, v['material'][w], nil))
        end
      end
      html = html:done():done():done()
    end
  end
  html = html:done()
  return html
end

return p