NickInfo.lua 1.17 KB
cc.exports.NickInfo = {}

local xml = require("core.utils.pl.xml")

local firstList = {};
local middleList = {};
local lastList = {};

--昵称配置表信息
local function init()
    local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/nick.xml");
    local data = xml.parse(configStr, false, true);

    for k,v in pairs(data) do
        if k ~= "attr" and k ~= "tag" then
            if v.tag == "first" then
                firstList = StringUtil.split(v.attr.str,",");
            elseif v.tag == "middle" then
                middleList = StringUtil.split(v.attr.str,",");
            else
                lastList = StringUtil.split(v.attr.str,",");
            end
        end
    end
end
init();

function NickInfo.getRandomNick()
    local id1 = math.random(1,#firstList);
    math.randomseed(tostring(os.time()+id1):reverse():sub(1, 6));
    local id2 = math.random(1,#middleList);
    math.randomseed(tostring(os.time()+id2):reverse():sub(1, 6));
    local id3 = math.random(1,#lastList);
    local nickName = firstList[id1];
    nickName = nickName .. middleList[id2];
    nickName = nickName .. lastList[id3];
    return nickName,id1,id2,id3;
end

return NickInfo