NickInfo.lua
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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