模块:角色属性:修订间差异

(修改数组为中日文俩个)
无编辑摘要
 
(未显示同一用户的3个中间版本)
第3行: 第3行:
local dataList = db.char_self_data
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local elementsName = {"HP", "SP", "物攻", "物防", "属攻", "属防", "会心", "速度"}


-- 生成中文日文俩个数组,键名保持一致
p["角色属性"] = function(frame)
local Data_jp = {}
    local query_num = frame.args['角色序号']
local Data_cn = {}
    local html = mw.html.create()


local function createDataList(dataList, elements)
    -- 排序属性
    for _, charData in pairs(dataList) do
    local function numvalue(char, attr, lang)
        local charData_jp = {}
        local attrValues = {}
         local charData_cn = {}
        for _, data in ipairs(dataList) do
            local value = tonumber(lang == "cn" and data.Data_cn and data.Data_cn[attr] or data.Data_jp and data.Data_jp[attr])
            if value then
                table.insert(attrValues, value)
            end
         end


         for _, element in ipairs(elements) do
         table.sort(attrValues, function(a, b) return a > b end)
            local maxKey = "MAX" .. element
            local baseKey = "Base" .. element
            charData_jp[element] = {
                MAX = charData[maxKey],
                Base = charData[baseKey]
            }


            local maxKey_cn = "MAX" .. element .. "_cn"
        local targetData = tonumber(lang == "cn" and char.Data_cn and char.Data_cn[attr] or char.Data_jp and char.Data_jp[attr])
            local baseKey_cn = "Base" .. element .. "_cn"
        for i, value in ipairs(attrValues) do
             charData_cn[element] = {
             if value == targetData then
                MAX = charData[maxKey_cn] or charData[maxKey],
                 return i
                 Base = charData[baseKey_cn] or charData[baseKey]
             end
             }
         end
         end
        return "暂无"
    end
-- 创建属性表格
    local function generateTable(char, lang)
        local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%')
local tableTitle = (lang == 'cn') and '国服' or '日服'


         charData_jp.owner_order = charData.owner_order
         tableHtml:tag('tr')
        charData_cn.owner_order = charData.owner_order
            :tag('th'):wikitext( tableTitle .. '属性'):done()
            :tag('th'):wikitext('基础满级'):done()
            :tag('th'):wikitext('6星120级'):done()
            :done()


         table.insert(Data_jp, charData_jp)
         for i, element in ipairs(elements) do
        table.insert(Data_cn, charData_cn)
            local elementName = elementsName[i]
    end
            local maxAttr = "MAX" .. element
end
            local baseAttr = "Base" .. element
            local maxAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[maxAttr] or char.Data_jp and char.Data_jp[maxAttr] or ""
            local baseAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[baseAttr] or char.Data_jp and char.Data_jp[baseAttr] or ""
 
            local maxRank = numvalue(char, maxAttr, lang)
            local baseRank = numvalue(char, baseAttr, lang)


createDataList(dataList, elements)
            tableHtml:tag('tr')
                :tag('td'):wikitext(elementName):done()
                :tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done()
                :tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done()
                :done()
        end


local function printDataKeys(dataList, title)
        return tableHtml
     print(title)
     end
     for _, charData in ipairs(dataList) do
         print("Owner Order: " .. charData.owner_order)
-- 执行查询
        for element, values in pairs(charData) do
     for _, char in ipairs(dataList) do
             if element ~= "owner_order" then
         if query_num == char.owner_order then
                 print(element .. ": MAX = " .. values.MAX .. ", Base = " .. values.Base)
            html:node(generateTable(char, "jp"))
             if char.Data_cn then
                 html:node(generateTable(char, "cn"))
             end
             end
         end
         end
        print("----------")
     end
     end
    return tostring(html)
end
end
-- Print the 日服数据 and 国服数据 (for verification purposes)
printDataKeys(Data_jp, "日服数据键名和值")
printDataKeys(Data_cn, "国服数据键名和值")


return p
return p

2024年6月28日 (五) 16:12的最新版本

可在模块:角色属性/doc创建此模块的帮助文档

local p = {}
local db = mw.loadData('模块:角色属性数据')
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local elementsName = {"HP", "SP", "物攻", "物防", "属攻", "属防", "会心", "速度"}

p["角色属性"] = function(frame)
    local query_num = frame.args['角色序号']
    local html = mw.html.create()

    -- 排序属性
    local function numvalue(char, attr, lang)
        local attrValues = {}
        for _, data in ipairs(dataList) do
            local value = tonumber(lang == "cn" and data.Data_cn and data.Data_cn[attr] or data.Data_jp and data.Data_jp[attr])
            if value then
                table.insert(attrValues, value)
            end
        end

        table.sort(attrValues, function(a, b) return a > b end)

        local targetData = tonumber(lang == "cn" and char.Data_cn and char.Data_cn[attr] or char.Data_jp and char.Data_jp[attr])
        for i, value in ipairs(attrValues) do
            if value == targetData then
                return i
            end
        end
        return "暂无"
    end
	
	-- 创建属性表格
    local function generateTable(char, lang)
        local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%')
		local tableTitle = (lang == 'cn') and '国服' or '日服'

        tableHtml:tag('tr')
            :tag('th'):wikitext( tableTitle .. '属性'):done()
            :tag('th'):wikitext('基础满级'):done()
            :tag('th'):wikitext('6星120级'):done()
            :done()

        for i, element in ipairs(elements) do
            local elementName = elementsName[i]
            local maxAttr = "MAX" .. element
            local baseAttr = "Base" .. element
            local maxAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[maxAttr] or char.Data_jp and char.Data_jp[maxAttr] or ""
            local baseAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[baseAttr] or char.Data_jp and char.Data_jp[baseAttr] or ""

            local maxRank = numvalue(char, maxAttr, lang)
            local baseRank = numvalue(char, baseAttr, lang)

            tableHtml:tag('tr')
                :tag('td'):wikitext(elementName):done()
                :tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done()
                :tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done()
                :done()
        end

        return tableHtml
    end
	
	-- 执行查询
    for _, char in ipairs(dataList) do
        if query_num == char.owner_order then
            html:node(generateTable(char, "jp"))
            if char.Data_cn then
                html:node(generateTable(char, "cn"))
            end
        end
    end

    return tostring(html)
end

return p