模块:角色属性

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

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

-- 生成中文日文俩个数组,键名保持一致
local Data_jp = {}
local Data_cn = {}

local function createDataList(dataList, elements)
    for _, charData in pairs(dataList) do
        local charData_jp = {}
        local charData_cn = {}

        for _, element in ipairs(elements) do
            local maxKey = "MAX" .. element
            local baseKey = "Base" .. element
            charData_jp[element] = {
                MAX = charData[maxKey],
                Base = charData[baseKey]
            }

            local maxKey_cn = "MAX" .. element .. "_cn"
            local baseKey_cn = "Base" .. element .. "_cn"
            charData_cn[element] = {
                MAX = charData[maxKey_cn] or charData[maxKey],
                Base = charData[baseKey_cn] or charData[baseKey]
            }
        end

        charData_jp.owner_order = charData.owner_order
        charData_cn.owner_order = charData.owner_order

        table.insert(Data_jp, charData_jp)
        table.insert(Data_cn, charData_cn)
    end
end

createDataList(dataList, elements)

local function printDataKeys(dataList, title)
    print(title)
    for _, charData in ipairs(dataList) do
        print("Owner Order: " .. charData.owner_order)
        for element, values in pairs(charData) do
            if element ~= "owner_order" then
                print(element .. ": MAX = " .. values.MAX .. ", Base = " .. values.Base)
            end
        end
        print("----------")
    end
end

-- Print the 日服数据 and 国服数据 (for verification purposes)
printDataKeys(Data_jp, "日服数据键名和值")
printDataKeys(Data_cn, "国服数据键名和值")

return p