ItemInfo.lua
2.21 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
cc.exports.ItemInfo = {}
local itemMap = {};
--道具配置表信息
local function init()
local itemStr = cc.FileUtils:getInstance():getStringFromFile("res/config/item.txt");
local function readLineFun(lineStr)
local contents = StringUtil.split(lineStr,'\t');
if #contents > 1 then
local info = {};
info.id = tonumber(contents[1]);
info.name = contents[2];
info.describe = string.gsub(contents[3],"@br@","\n");
info.icon = contents[4];
info.shopID = tonumber(contents[5]);
info.amount = tonumber(contents[6]);
itemMap[contents[1]] = 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();
--通过ID获取道具信息
function ItemInfo.getItemInfo(id)
return itemMap[tostring(id)];
end
--获取道具
function ItemInfo.getItemList()
local _list = {};
for i,v in pairs(itemMap) do
if v.id ~= 100000 and v.id ~= 100001 and v.id ~= 100004 then
local myNum = UserModel.getItemNum(v.id);
if myNum > 0 then
_list[#_list + 1] = v;
end
end
end
table.sort(_list,function (aa,bb)
return aa.id < bb.id;
end);
return _list;
end
--获取房间内使用的道具
function ItemInfo.getRoomUseItemList()
local _list = {};
for i,v in pairs(itemMap) do
if v.id == 100002 or v.id == 100003 then
local info = TableUtil.copyTab(v);
info.item_cnt = 1;
_list[#_list + 1] = info;
info = TableUtil.copyTab(v);
info.item_cnt = 10;
_list[#_list + 1] = info;
end
end
return _list;
end
function ItemInfo.isMedal(id)
if id > 600000 and id < 700000 then
return true;
else
return false;
end
end
return ItemInfo