GiftInfo.lua
1.54 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
cc.exports.GiftInfo = {}
local xml = require("core.utils.pl.xml")
local itemMap = {};
local create_reward = "";
--奖励配置表信息
local function init()
local itemStr = cc.FileUtils:getInstance():getStringFromFile("res/config/role_reward.txt");
local function readLineFun(lineStr)
local contents = StringUtil.split(lineStr,'\t');
if #contents > 1 then
local info = {};
info.id = tonumber(contents[1]);
info.reward = contents[2];
itemMap[tostring(info.id)] = info;
end
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
readLineFun(lineStr);
end
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
readLineFun(str);
end
end
readLine(itemStr);
end
init();
function initCreateRewardConfig()
local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/create_reward.xml");
local data = xml.parse(configStr, false, true);
for k,v in pairs(data) do
if k ~= "attr" and k ~= "tag" then
create_reward = v.attr.item;
end
end
end
initCreateRewardConfig();
--通过ID获取奖励信息
function GiftInfo.getGiftInfo(id)
return itemMap[tostring(id)];
end
--通过ID创建角色奖励
function GiftInfo.getCreateRewardStr()
return create_reward;
end
return GiftInfo