CharmInfo.lua
1.56 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
cc.exports.CharmInfo = {}
local _map = {};
--魅力值配置表信息
local function init()
local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/gd_charm.txt");
local function readLineFun(lineStr)
local info;
local contents = StringUtil.split(lineStr,'\t');
if #contents > 1 then
info = {};
info.level = tonumber(contents[1]);
info.charm = tonumber(contents[2]);
info.name = contents[3];
end
return info;
end
local index = 1;
local function readLine(str)
local a,b = string.find(str,"\r\n");
if a then
local lineStr = string.sub(str,1,a-1);
if index > 2 then
local info = readLineFun(lineStr);
if info then
_map[info.level] = info;
end
end
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
local info = readLineFun(str);
if info then
_map[info.level] = info;
end
end
end
readLine(configStr);
end
init();
--通过级别获取信息
function CharmInfo.getCharmInfo(level)
return _map[level];
end
--通过魅力值获取信息
function CharmInfo.getInfoByCharm(charm)
local info = {level=0,charm=0,name=""};
for i,v in ipairs(_map) do
if charm >= v.charm then
info = v;
end
end
if not info then
info = _map[#_map];
end
return info;
end
return CharmInfo