|
@@ -38,12 +38,12 @@ end
|
38
|
38
|
-- 请求获取背包信息
|
39
|
39
|
function root:get_info(uid)
|
40
|
40
|
log.info("get_info uid:%s", uid)
|
41
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
|
41
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
42
|
42
|
local isUpdate = false
|
43
|
43
|
|
44
|
44
|
local curTime = timeUtil.now(uid)
|
45
|
|
- for i = #(itemInfo or {}), 1, -1 do
|
46
|
|
- local item = itemInfo[i]
|
|
45
|
+ for i = #(itemList or {}), 1, -1 do
|
|
46
|
+ local item = itemList[i]
|
47
|
47
|
if item.expTime and curTime > item.expTime then
|
48
|
48
|
-- 已经过期
|
49
|
49
|
isUpdate = true
|
|
@@ -52,16 +52,16 @@ function root:get_info(uid)
|
52
|
52
|
|
53
|
53
|
if item.count == 0 then
|
54
|
54
|
isUpdate = true
|
55
|
|
- table.remove(itemInfo, i)
|
|
55
|
+ table.remove(itemList, i)
|
56
|
56
|
end
|
57
|
57
|
end
|
58
|
58
|
|
59
|
59
|
if isUpdate then
|
60
|
60
|
-- 存储
|
61
|
|
- moduleData:hset(uid, MODULE_NAME, "itemInfo", itemInfo)
|
|
61
|
+ moduleData:hset(uid, MODULE_NAME, "itemList", itemList)
|
62
|
62
|
end
|
63
|
63
|
|
64
|
|
- return itemInfo
|
|
64
|
+ return itemList
|
65
|
65
|
end
|
66
|
66
|
|
67
|
67
|
--[[ 请求增减资源列表
|
|
@@ -70,18 +70,18 @@ end
|
70
|
70
|
function root:update_items(uid, items, reason)
|
71
|
71
|
-- log.info("update_items uid:%s items:%s reason:%s", uid, tostring(items), tostring(reason))
|
72
|
72
|
|
73
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
|
73
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
74
|
74
|
|
75
|
75
|
local list = {}
|
76
|
76
|
for _, v in ipairs(items) do
|
77
|
|
- local updateItems = self:_update_item(uid, itemInfo, v.id, v.count, v.bid)
|
|
77
|
+ local updateItems = self:_update_item(uid, itemList, v.id, v.count, v.bid)
|
78
|
78
|
if updateItems then
|
79
|
79
|
table.arry_merge(list, updateItems)
|
80
|
80
|
end
|
81
|
81
|
end
|
82
|
82
|
|
83
|
83
|
-- 存储
|
84
|
|
- moduleData:hset(uid, MODULE_NAME, "itemInfo", itemInfo)
|
|
84
|
+ moduleData:hset(uid, MODULE_NAME, "itemList", itemList)
|
85
|
85
|
-- 推送
|
86
|
86
|
self:_on_res_update(uid, list, reason)
|
87
|
87
|
-- 事件
|
|
@@ -104,11 +104,11 @@ function root:is_enough(uid, items)
|
104
|
104
|
end
|
105
|
105
|
end
|
106
|
106
|
|
107
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
|
107
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
108
|
108
|
|
109
|
109
|
local ret = true
|
110
|
110
|
for k, v in pairs(tempMap) do
|
111
|
|
- local item = table.key_find(itemInfo, "id", k)
|
|
111
|
+ local item = table.key_find(itemList, "id", k)
|
112
|
112
|
if not item or not item.count or item.count < v then
|
113
|
113
|
ret = false
|
114
|
114
|
break
|
|
@@ -129,11 +129,11 @@ function root:is_enough_by_bid(uid, items)
|
129
|
129
|
end
|
130
|
130
|
end
|
131
|
131
|
|
132
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
|
132
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
133
|
133
|
|
134
|
134
|
local ret = true
|
135
|
135
|
for k, v in pairs(tempMap) do
|
136
|
|
- local item = table.key_find(itemInfo, "bid", k)
|
|
136
|
+ local item = table.key_find(itemList, "bid", k)
|
137
|
137
|
|
138
|
138
|
if not item or not item.count or item.count < v then
|
139
|
139
|
ret = false
|
|
@@ -165,8 +165,8 @@ end
|
165
|
165
|
-- 获取资源数量
|
166
|
166
|
function root:get_item_count(uid, itemId)
|
167
|
167
|
-- log.info("get_item_count uid:%s itemId:%s", uid, itemId)
|
168
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
169
|
|
- local item = table.key_find(itemInfo, "id", itemId) or {}
|
|
168
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
|
169
|
+ local item = table.key_find(itemList, "id", itemId) or {}
|
170
|
170
|
|
171
|
171
|
return item.count or 0
|
172
|
172
|
end
|
|
@@ -174,8 +174,8 @@ end
|
174
|
174
|
-- 获取资源数量
|
175
|
175
|
function root:get_item_by_bid(uid, bid)
|
176
|
176
|
-- log.info("get_item_by_bid uid:%s bid:%s", uid, bid)
|
177
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
178
|
|
- local item = table.key_find(itemInfo, "bid", bid) or {}
|
|
177
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
|
178
|
+ local item = table.key_find(itemList, "bid", bid) or {}
|
179
|
179
|
|
180
|
180
|
return item
|
181
|
181
|
end
|
|
@@ -186,8 +186,8 @@ function root:get_own_type_item_id_list(uid, resType)
|
186
|
186
|
return
|
187
|
187
|
end
|
188
|
188
|
local resIdList = {}
|
189
|
|
- local itemInfo = moduleData:hget_json(uid, MODULE_NAME, "itemInfo") or {}
|
190
|
|
- for k, v in ipairs(itemInfo) do
|
|
189
|
+ local itemList = moduleData:hget_json(uid, MODULE_NAME, "itemList") or {}
|
|
190
|
+ for k, v in ipairs(itemList) do
|
191
|
191
|
if resAdapt:is_type(v.id, resType) then
|
192
|
192
|
table.insert(resIdList, v.id)
|
193
|
193
|
end
|
|
@@ -233,7 +233,7 @@ function root:_AddExpirationTime(resConfing, uid)
|
233
|
233
|
return expTime
|
234
|
234
|
end
|
235
|
235
|
|
236
|
|
-function root:_AddItemByBid(uid, itemInfo, itemId, count, bid, resConfing, composite)
|
|
236
|
+function root:_AddItemByBid(uid, itemList, itemId, count, bid, resConfing, composite)
|
237
|
237
|
local item
|
238
|
238
|
if count > 0 and composite then
|
239
|
239
|
local newBid = self:_new_bid(uid)
|
|
@@ -242,12 +242,12 @@ function root:_AddItemByBid(uid, itemInfo, itemId, count, bid, resConfing, compo
|
242
|
242
|
count = 0,
|
243
|
243
|
bid = newBid
|
244
|
244
|
}
|
245
|
|
- table.insert(itemInfo, item)
|
|
245
|
+ table.insert(itemList, item)
|
246
|
246
|
else
|
247
|
247
|
-- 不可叠加的物品只能通过bid来获取,但只有装备是通过bid来获取.
|
248
|
|
- item = table.key_find(itemInfo, "bid", bid)
|
|
248
|
+ item = table.key_find(itemList, "bid", bid)
|
249
|
249
|
if not item and not bid then
|
250
|
|
- item = table.key_find(itemInfo, "id", itemId)
|
|
250
|
+ item = table.key_find(itemList, "id", itemId)
|
251
|
251
|
end
|
252
|
252
|
end
|
253
|
253
|
|
|
@@ -259,7 +259,7 @@ function root:_AddItemByBid(uid, itemInfo, itemId, count, bid, resConfing, compo
|
259
|
259
|
count = 0,
|
260
|
260
|
bid = newBid
|
261
|
261
|
}
|
262
|
|
- table.insert(itemInfo, item)
|
|
262
|
+ table.insert(itemList, item)
|
263
|
263
|
end
|
264
|
264
|
|
265
|
265
|
local oldCount = item.count or 0
|
|
@@ -271,14 +271,14 @@ function root:_AddItemByBid(uid, itemInfo, itemId, count, bid, resConfing, compo
|
271
|
271
|
end
|
272
|
272
|
|
273
|
273
|
-- 更新单个资源
|
274
|
|
-function root:_update_item(uid, itemInfo, itemId, count, bid)
|
|
274
|
+function root:_update_item(uid, itemList, itemId, count, bid)
|
275
|
275
|
local conf = resAdapt:get_item_conf(itemId)
|
276
|
276
|
if not conf then
|
277
|
277
|
log.error("更新资源异常,未找到[%s]资源配置", tostring(itemId))
|
278
|
278
|
return
|
279
|
279
|
end
|
280
|
280
|
|
281
|
|
- return self:_AddItemByBid(uid, itemInfo, itemId, count, bid, conf, conf.enableComposite)
|
|
281
|
+ return self:_AddItemByBid(uid, itemList, itemId, count, bid, conf, conf.enableComposite)
|
282
|
282
|
end
|
283
|
283
|
|
284
|
284
|
-- 推送资源变化
|