|
@@ -0,0 +1,97 @@
|
|
1
|
+--[[
|
|
2
|
+Descripttion:玩家事件
|
|
3
|
+version:
|
|
4
|
+Author: Neo,Huang
|
|
5
|
+Date: 2022-07-05 19:59:16
|
|
6
|
+LastEditors: Neo,Huang
|
|
7
|
+LastEditTime: 2022-07-05 20:08:31
|
|
8
|
+--]]
|
|
9
|
+local lib_game_redis = require("lib_game_redis")
|
|
10
|
+local timeUtil = require("utils.timeUtil")
|
|
11
|
+local redisUtil = require("utils.redisUtil")
|
|
12
|
+local util_player = require("utils.util_player")
|
|
13
|
+
|
|
14
|
+local baseAdapt = require("base.baseAdapt")
|
|
15
|
+local boxAdapt = require("adapt.boxAdapt")
|
|
16
|
+local resAdapt = require("adapt.resAdapt")
|
|
17
|
+
|
|
18
|
+local MODULE_NAME = "box"
|
|
19
|
+
|
|
20
|
+local root = {}
|
|
21
|
+
|
|
22
|
+local function _get_box_key(boxId)
|
|
23
|
+ return string.format("%s:%s", MODULE_NAME, tostring(boxId))
|
|
24
|
+end
|
|
25
|
+
|
|
26
|
+-- 获取开箱物品
|
|
27
|
+function root:get_box_drop_item_and_count(boxId)
|
|
28
|
+ local confList = boxAdapt:blind_get_box_item_list(boxId)
|
|
29
|
+ if is_empty(confList) then
|
|
30
|
+ return
|
|
31
|
+ end
|
|
32
|
+ -- 更新权重
|
|
33
|
+ for _, v in ipairs(confList) do
|
|
34
|
+ v.weight = 0
|
|
35
|
+ local price = resAdapt:get_item_price(v.itemId)
|
|
36
|
+ if not is_empty(price) then
|
|
37
|
+ v.weight = math.floor(v.weightByPrice / price)
|
|
38
|
+ end
|
|
39
|
+ end
|
|
40
|
+ local index = random_list_by_weight(confList)
|
|
41
|
+ return confList[index].itemId, confList[index].count
|
|
42
|
+end
|
|
43
|
+
|
|
44
|
+-- 新增开箱记录
|
|
45
|
+function root:add_record(uid, boxId, itemId, count)
|
|
46
|
+ if is_empty(uid) or is_empty(boxId) or is_empty(itemId) then
|
|
47
|
+ return false
|
|
48
|
+ end
|
|
49
|
+ local currTime = timeUtil.now(uid)
|
|
50
|
+ local key = _get_box_key(boxId)
|
|
51
|
+ local dropList = redisUtil.hget_json(key, "dropList")
|
|
52
|
+ table.insert(dropList, {uid = uid, time = currTime, itemId = itemId, count = count})
|
|
53
|
+ -- 限制数量
|
|
54
|
+ if #dropList > 20 then
|
|
55
|
+ table.remove(dropList, 1)
|
|
56
|
+ end
|
|
57
|
+ redisUtil.hset(key, "dropList", dropList)
|
|
58
|
+ return true
|
|
59
|
+end
|
|
60
|
+
|
|
61
|
+-- 打包箱子信息
|
|
62
|
+function root:pack_box_info(boxId)
|
|
63
|
+ if is_empty(boxId) then
|
|
64
|
+ return
|
|
65
|
+ end
|
|
66
|
+ local key = _get_box_key(boxId)
|
|
67
|
+ local dropList = redisUtil.hget_json(key, "dropList")
|
|
68
|
+ for _, v in ipairs(dropList) do
|
|
69
|
+ v.playerInfo = util_player:get_base_info(v.uid)
|
|
70
|
+ end
|
|
71
|
+ local info = {
|
|
72
|
+ id = boxId,
|
|
73
|
+ dropList = dropList
|
|
74
|
+ }
|
|
75
|
+ return info
|
|
76
|
+end
|
|
77
|
+-- 打包所有箱子信息
|
|
78
|
+function root:pack_box_info_list(boxId)
|
|
79
|
+ local boxInfoList = {}
|
|
80
|
+ if is_empty(boxId) then
|
|
81
|
+ local conf = baseAdapt:getConfig("BlindBoxConfig")
|
|
82
|
+ for _, v in ipairs(conf) do
|
|
83
|
+ local info = self:pack_box_info(v.boxId)
|
|
84
|
+ if not is_empty(info) then
|
|
85
|
+ table.insert(boxInfoList, info)
|
|
86
|
+ end
|
|
87
|
+ end
|
|
88
|
+ else
|
|
89
|
+ local info = self:pack_box_info(boxId)
|
|
90
|
+ if not is_empty(info) then
|
|
91
|
+ table.insert(boxInfoList, info)
|
|
92
|
+ end
|
|
93
|
+ end
|
|
94
|
+ return boxInfoList
|
|
95
|
+end
|
|
96
|
+
|
|
97
|
+return root
|