Commit eb7ce1e794e6feb40f9cbc5142e9943a991ed73e
Merge branch 'cn/develop' into cn/publish/preview
Showing
15 changed files
with
799 additions
and
311 deletions
Show diff stats
src/ProtocolCode.lua
@@ -59,7 +59,7 @@ actionCodes = { | @@ -59,7 +59,7 @@ actionCodes = { | ||
59 | Role_runeBuyRpc = 142, -- 铭文购买 | 59 | Role_runeBuyRpc = 142, -- 铭文购买 |
60 | Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 | 60 | Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 |
61 | Role_setBgRpc = 144, -- 设置看板娘 | 61 | Role_setBgRpc = 144, -- 设置看板娘 |
62 | - Role_itemExchangeRpc = 145, -- 道具兑换 | 62 | + Role_itemConvertMonthCardRpc = 145, -- 兑换月卡道具 |
63 | 63 | ||
64 | Adv_startAdvRpc = 151, | 64 | Adv_startAdvRpc = 151, |
65 | Adv_startHangRpc = 152, | 65 | Adv_startHangRpc = 152, |
@@ -279,10 +279,14 @@ actionCodes = { | @@ -279,10 +279,14 @@ actionCodes = { | ||
279 | Capsule_joinRpc = 851, --扭蛋机详情 | 279 | Capsule_joinRpc = 851, --扭蛋机详情 |
280 | Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中 | 280 | Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中 |
281 | Capsule_drawRpc = 854, --抽扭蛋机 | 281 | Capsule_drawRpc = 854, --抽扭蛋机 |
282 | - Capsule_switchRoomRpc = 855, --切换扭蛋机房间 | 282 | + --Capsule_switchRoomRpc = 855, --切换扭蛋机房间 |
283 | Capsule_notifyChange = 856, -- 通知信息变动 | 283 | Capsule_notifyChange = 856, -- 通知信息变动 |
284 | - Capsule_payReward = 857, -- 特殊赏 奖励通知 | 284 | + Capsule_specialRewardRpc = 857, -- 获取 未领取特殊赏通知 主动 |
285 | Capsule_exitRpc = 858, -- 退出 | 285 | Capsule_exitRpc = 858, -- 退出 |
286 | + Capsule_getDataRpc = 859, --获取扭蛋机信息 | ||
287 | + Capsule_convertCapsuleRpc = 860, --兑换消耗票 | ||
288 | + Capsule_pageRecordRpc = 861, --抽奖记录分页查询 | ||
289 | + Capsule_clearSpecialNtyRpc = 862, --消除特殊赏通知 | ||
286 | } | 290 | } |
287 | 291 | ||
288 | rpcResponseBegin = 10000 | 292 | rpcResponseBegin = 10000 |
src/actions/AdvAction.lua
@@ -459,11 +459,12 @@ function _M.endHangRpc(agent, data) | @@ -459,11 +459,12 @@ function _M.endHangRpc(agent, data) | ||
459 | heroCnt = heroCnt + 1 | 459 | heroCnt = heroCnt + 1 |
460 | end | 460 | end |
461 | 461 | ||
462 | - local totalReward = campSiteData.idleReward_1 .. " " .. campSiteData.idleReward_2 | ||
463 | - | ||
464 | - local idleReward = totalReward:toNumMap() | ||
465 | - for itemId, count in pairs(idleReward) do | ||
466 | - idleReward[itemId] = count * adv_idle_reward_coef | 462 | + local idleReward = {} |
463 | + for k, v in pairs(campSiteData.idleReward_1:toNumMap()) do | ||
464 | + idleReward[k] = (idleReward[k] or 0) + v * adv_idle_reward_coef | ||
465 | + end | ||
466 | + for k, v in pairs(campSiteData.idleReward_2:toNumMap()) do | ||
467 | + idleReward[k] = (idleReward[k] or 0) + v * adv_idle_reward_coef | ||
467 | end | 468 | end |
468 | 469 | ||
469 | local bnousReward = role:getBnousAdv() | 470 | local bnousReward = role:getBnousAdv() |
src/actions/CapsuleAction.lua
@@ -17,18 +17,18 @@ function _M.listRpc(agent, data) | @@ -17,18 +17,18 @@ function _M.listRpc(agent, data) | ||
17 | local role = agent.role | 17 | local role = agent.role |
18 | local msg = MsgPack.unpack(data) | 18 | local msg = MsgPack.unpack(data) |
19 | local typ = msg.typ | 19 | local typ = msg.typ |
20 | - local coin = msg.coin | 20 | + local id = msg.id |
21 | 21 | ||
22 | local capsules = {} | 22 | local capsules = {} |
23 | if typ == 1 then | 23 | if typ == 1 then |
24 | - local ret = skynet.call(agent.capsule_serv, "lua", "list", coin) | 24 | + local ret = skynet.call(agent.capsule_serv, "lua", "list", id) |
25 | if next(ret) then | 25 | if next(ret) then |
26 | for k, v in pairs(ret) do | 26 | for k, v in pairs(ret) do |
27 | capsules[k] = v | 27 | capsules[k] = v |
28 | end | 28 | end |
29 | end | 29 | end |
30 | elseif typ == 0 then | 30 | elseif typ == 0 then |
31 | - local ret = role:getCapsuleList(coin) | 31 | + local ret = role:getCapsuleList(id) |
32 | if next(ret) then | 32 | if next(ret) then |
33 | for k, v in pairs(ret) do | 33 | for k, v in pairs(ret) do |
34 | capsules[k] = v | 34 | capsules[k] = v |
@@ -51,7 +51,7 @@ function _M.joinRpc(agent, data) | @@ -51,7 +51,7 @@ function _M.joinRpc(agent, data) | ||
51 | if typ == 1 then | 51 | if typ == 1 then |
52 | ret = skynet.call(agent.capsule_serv, "lua", "join", roleId, capsuleId) | 52 | ret = skynet.call(agent.capsule_serv, "lua", "join", roleId, capsuleId) |
53 | elseif typ == 0 then | 53 | elseif typ == 0 then |
54 | - ret = role:joinCapsule() | 54 | + ret = role:joinCapsule(roleId, capsuleId) |
55 | end | 55 | end |
56 | SendPacket(actionCodes.Capsule_joinRpc, MsgPack.pack(ret)) | 56 | SendPacket(actionCodes.Capsule_joinRpc, MsgPack.pack(ret)) |
57 | return true | 57 | return true |
@@ -93,39 +93,160 @@ function _M.drawRpc(agent, data) | @@ -93,39 +93,160 @@ function _M.drawRpc(agent, data) | ||
93 | local roleId = role:getProperty("id") | 93 | local roleId = role:getProperty("id") |
94 | local capsuleId = msg.capsule_id | 94 | local capsuleId = msg.capsule_id |
95 | local typ = msg.typ --0=独享,1= 公开 | 95 | local typ = msg.typ --0=独享,1= 公开 |
96 | - local full = msg.full -- 0=单次,1=十连抽 2=全收 | 96 | + local full = msg.full or 0-- 0=单次,1=十连抽 2=全收 |
97 | local cares = msg.cares | 97 | local cares = msg.cares |
98 | 98 | ||
99 | - local ret, reward, change, rewardByGoods, capsule | 99 | + local ret, token, change, drawReward, capsule |
100 | + | ||
101 | + --检查库存 | ||
102 | + if typ == 1 then | ||
103 | + ret, token = skynet.call(agent.capsule_serv, "lua", "goods_stock", capsuleId) | ||
104 | + else | ||
105 | + ret, token = role:goodStock(capsuleId) | ||
106 | + end | ||
107 | + if ret == 0 then skynet.error("零库存 " .. capsuleId) return 0 end | ||
108 | + | ||
109 | + --检查余额 | ||
110 | + if not next(token) then skynet.error("代币未配置 " .. capsuleId) return 1 end | ||
111 | + local cost, drawsNum = {}, 0 | ||
112 | + if full == 0 then | ||
113 | + drawsNum = 1 | ||
114 | + elseif full == 1 then | ||
115 | + if ret < 10 then | ||
116 | + drawsNum = ret | ||
117 | + else | ||
118 | + drawsNum = 10 | ||
119 | + end | ||
120 | + elseif full == 2 then | ||
121 | + drawsNum = ret | ||
122 | + end | ||
123 | + cost[token[1]] = drawsNum * token[2] | ||
124 | + | ||
125 | + if not role:checkItemEnough(cost) then return 2 end | ||
126 | + role:costItems(cost, {log = {desc = "CapsuleCoinCost", int1 = token[1], int2 = cost[token[1]]}}) | ||
127 | + | ||
128 | + --开始抽奖 | ||
100 | if typ == 1 then | 129 | if typ == 1 then |
101 | - ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | 130 | + ret, drawReward, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) |
102 | else | 131 | else |
103 | - ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) | 132 | + ret, drawReward, capsule = role:drawCapsule(capsuleId, full, cares) |
133 | + end | ||
134 | + if ret < 5 then | ||
135 | + return ret | ||
136 | + end | ||
137 | + | ||
138 | + if ret == 5 then | ||
139 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = drawReward, capsule = capsule})) | ||
140 | + return true | ||
104 | end | 141 | end |
105 | - if ret < 4 then | 142 | + |
143 | + if drawReward["reward"] and next(drawReward["reward"]) then | ||
144 | + _, change = role:award(drawReward["reward"], {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | ||
145 | + drawReward["capsule"] = capsule | ||
146 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(drawReward)) | ||
147 | + else | ||
106 | return ret | 148 | return ret |
107 | end | 149 | end |
150 | + return true | ||
151 | +end | ||
152 | + | ||
153 | +function _M.getDataRpc(agent, data) | ||
154 | + local role = agent.role | ||
155 | + local msg = MsgPack.unpack(data) | ||
156 | + local capsuleId = msg.capsule_id | ||
157 | + local typ = msg.typ --0=独享,1= 公开 | ||
158 | + local roleId = role:getProperty("id") | ||
159 | + | ||
160 | + local capsule | ||
161 | + if typ == 1 then | ||
162 | + capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", roleId, capsuleId) | ||
163 | + else | ||
164 | + capsule = role:getCapsuleData(roleId, capsuleId) | ||
165 | + end | ||
166 | + if not capsule then return 1 end | ||
167 | + | ||
168 | + SendPacket(actionCodes.Capsule_getDataRpc, MsgPack.pack({capsule = capsule})) | ||
169 | + return true | ||
170 | + | ||
171 | +end | ||
172 | + | ||
173 | +function _M.convertCapsuleRpc(agent, data) | ||
174 | + local role = agent.role | ||
175 | + local msg = MsgPack.unpack(data) | ||
176 | + local coin = msg.coin | ||
177 | + local count = msg.count or 1 | ||
178 | + | ||
179 | + local cost, convert = {} | ||
180 | + for k, v in pairs(globalCsv.ichibankuji_buy_cost)do | ||
181 | + if k == coin then | ||
182 | + convert = v:toArray(true, "=") | ||
183 | + break | ||
184 | + end | ||
185 | + end | ||
186 | + cost[convert[1]] = convert[2] * count | ||
187 | + if not role:checkItemEnough(cost) then return 1 end | ||
188 | + role:costItems(cost, {log = {desc = "CapsuleConvert", int1 = convert[1], int2 = cost[convert[1]]}}) | ||
189 | + | ||
190 | + | ||
191 | + local reward, change = role:award({[coin]= count}, {log = {desc = "CapsuleConvert"}}) | ||
192 | + SendPacket(actionCodes.Capsule_convertCapsuleRpc, MsgPack.pack(role:packReward(reward, change))) | ||
193 | + return true | ||
194 | +end | ||
195 | + | ||
196 | +function _M.pageRecordRpc(agent, data) | ||
197 | + local role = agent.role | ||
198 | + local msg = MsgPack.unpack(data) | ||
199 | + local idx = msg.idx | ||
200 | + local up = msg.up or 0 | ||
201 | + local capsuleId = msg.capsule_id | ||
202 | + local typ = msg.typ --0=独享,1= 公开 | ||
108 | 203 | ||
109 | - if ret == 4 then | ||
110 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) | 204 | + local record |
205 | + if typ == 1 then | ||
206 | + record = skynet.call(agent.capsule_serv, "lua", "page_record", capsuleId, up, idx) | ||
207 | + else | ||
208 | + record = role:pageRecord(capsuleId, up, idx) | ||
111 | end | 209 | end |
210 | + if not record then return 1 end | ||
211 | + | ||
212 | + SendPacket(actionCodes.Capsule_pageRecordRpc, MsgPack.pack({record = record})) | ||
213 | + return true | ||
214 | +end | ||
215 | + | ||
216 | +function _M.specialRewardRpc(agent, data) | ||
217 | + local role = agent.role | ||
218 | + local msg = MsgPack.unpack(data) | ||
219 | + local capsuleId = msg.capsule_id | ||
220 | + local typ = msg.typ or 1 --0=独享,1= 公开 | ||
221 | + local roleId = role:getProperty("id") | ||
112 | 222 | ||
113 | - if rewardByGoods and next(rewardByGoods) then | ||
114 | - reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) | ||
115 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) | 223 | + local ret |
224 | + if typ == 1 then | ||
225 | + ret = skynet.call(agent.capsule_serv, "lua", "get_special_nty", roleId, capsuleId) | ||
116 | else | 226 | else |
117 | - return 5 | 227 | + ret = role:getSpecialNotify(roleId, capsuleId) |
118 | end | 228 | end |
229 | + if not ret or not next(ret) then return 1 end | ||
230 | + | ||
231 | + SendPacket(actionCodes.Capsule_specialRewardRpc, MsgPack.pack({special= ret})) | ||
119 | return true | 232 | return true |
120 | end | 233 | end |
121 | 234 | ||
122 | -function _M.switchRoomRpc(agent, data) | 235 | +function _M.clearSpecialNtyRpc(agent, data) |
123 | local role = agent.role | 236 | local role = agent.role |
124 | local msg = MsgPack.unpack(data) | 237 | local msg = MsgPack.unpack(data) |
238 | + local capsuleId = msg.capsule_id | ||
239 | + local typ = msg.typ --0=独享,1= 公开 | ||
240 | + local good_ids = msg.good_ids | ||
125 | local roleId = role:getProperty("id") | 241 | local roleId = role:getProperty("id") |
126 | 242 | ||
127 | - local ret = skynet.call(agent.capsule_serv, "lua", "switch_room", roleId) | ||
128 | - SendPacket(actionCodes.Capsule_switchRoomRpc, MsgPack.pack(ret)) | 243 | + local ret |
244 | + if typ == 1 then | ||
245 | + ret = skynet.call(agent.capsule_serv, "lua", "clear_special_nty", roleId, capsuleId, good_ids) | ||
246 | + end | ||
247 | + if not ret or not next(ret) then return 1 end | ||
248 | + | ||
249 | + SendPacket(actionCodes.Capsule_clearSpecialNtyRpc, MsgPack.pack({})) | ||
129 | return true | 250 | return true |
130 | end | 251 | end |
131 | 252 |
src/actions/GmAction.lua
@@ -9,7 +9,7 @@ function _M.clientRequest(agent, data) | @@ -9,7 +9,7 @@ function _M.clientRequest(agent, data) | ||
9 | SendPacket(actionCodes.Gm_receiveResponse, bin) | 9 | SendPacket(actionCodes.Gm_receiveResponse, bin) |
10 | return true | 10 | return true |
11 | end | 11 | end |
12 | - local ret = action(role, msg) | 12 | + local ret = action(role, msg, agent.capsule_serv) |
13 | bin = MsgPack.pack({ cmd = ret }) | 13 | bin = MsgPack.pack({ cmd = ret }) |
14 | SendPacket(actionCodes.Gm_receiveResponse, bin) | 14 | SendPacket(actionCodes.Gm_receiveResponse, bin) |
15 | return true | 15 | return true |
@@ -1075,4 +1075,15 @@ function _M.clear_sea(role, pms) | @@ -1075,4 +1075,15 @@ function _M.clear_sea(role, pms) | ||
1075 | return "成功" | 1075 | return "成功" |
1076 | end | 1076 | end |
1077 | 1077 | ||
1078 | +table.insert(helpDes, {"重置扭蛋机", "reset_capsule", "typ"}) | ||
1079 | +function _M.reset_capsule(role, pms, capsule_serv) | ||
1080 | + local typ = tonumber(pms.pm1) | ||
1081 | + if typ == 1 then | ||
1082 | + skynet.call(capsule_serv, "lua", "reset") | ||
1083 | + else | ||
1084 | + role:resetCapsule() | ||
1085 | + end | ||
1086 | + return "成功" | ||
1087 | +end | ||
1088 | + | ||
1078 | return _M | 1089 | return _M |
1079 | \ No newline at end of file | 1090 | \ No newline at end of file |
src/actions/RoleAction.lua
@@ -288,7 +288,9 @@ function _M.loginRpc( agent, data ) | @@ -288,7 +288,9 @@ function _M.loginRpc( agent, data ) | ||
288 | 288 | ||
289 | -- 注册全服广播 | 289 | -- 注册全服广播 |
290 | if not role._channelIdx then | 290 | if not role._channelIdx then |
291 | - local channel = math.randomInt(1, 1) | 291 | + local online = datacenter.get("onlineCount") or 0 |
292 | + local channel = math.floor(online / 500) + 1 | ||
293 | + --local channel = math.randomInt(1, 1) | ||
292 | role._channelIdx = channel | 294 | role._channelIdx = channel |
293 | end | 295 | end |
294 | if not mcast_util.channel_world() then | 296 | if not mcast_util.channel_world() then |
@@ -1710,7 +1712,7 @@ function _M.setBgRpc(agent, data) | @@ -1710,7 +1712,7 @@ function _M.setBgRpc(agent, data) | ||
1710 | return true | 1712 | return true |
1711 | end | 1713 | end |
1712 | 1714 | ||
1713 | -function _M.itemExchangeRpc(agent, data) | 1715 | +function _M.itemConvertMonthCardRpc(agent, data) |
1714 | local role = agent.role | 1716 | local role = agent.role |
1715 | local msg = MsgPack.unpack(data) | 1717 | local msg = MsgPack.unpack(data) |
1716 | local itemId = msg.item_id | 1718 | local itemId = msg.item_id |
@@ -1738,7 +1740,7 @@ function _M.itemExchangeRpc(agent, data) | @@ -1738,7 +1740,7 @@ function _M.itemExchangeRpc(agent, data) | ||
1738 | end | 1740 | end |
1739 | end | 1741 | end |
1740 | 1742 | ||
1741 | - SendPacket(actionCodes.Role_itemExchangeRpc, MsgPack.pack(role:packReward(reward))) | 1743 | + SendPacket(actionCodes.Role_itemConvertMonthCardRpc, MsgPack.pack(role:packReward(reward))) |
1742 | return status | 1744 | return status |
1743 | end | 1745 | end |
1744 | 1746 |
src/actions/SeaportAction.lua
@@ -267,7 +267,7 @@ function _M.shopRpc(agent, data) | @@ -267,7 +267,7 @@ function _M.shopRpc(agent, data) | ||
267 | local shopCsv = {} | 267 | local shopCsv = {} |
268 | local dataSet = csvdb["shop_normalCsv"] | 268 | local dataSet = csvdb["shop_normalCsv"] |
269 | for _, datat in pairs(dataSet) do | 269 | for _, datat in pairs(dataSet) do |
270 | - if datat.shop == 5 then | 270 | + if datat.shop == 4 then |
271 | shopCsv[datat.id] = datat | 271 | shopCsv[datat.id] = datat |
272 | end | 272 | end |
273 | end | 273 | end |
src/agent.lua
@@ -284,7 +284,7 @@ function CMD.close() | @@ -284,7 +284,7 @@ function CMD.close() | ||
284 | local role = agentInfo.role | 284 | local role = agentInfo.role |
285 | if not role then return end | 285 | if not role then return end |
286 | 286 | ||
287 | - skynet.call(agent.capsule_serv, "lua", "exit", role:getProperty("id")) | 287 | + skynet.call(agentInfo.capsule_serv, "lua", "exit", role:getProperty("id")) |
288 | role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")}) | 288 | role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")}) |
289 | role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) | 289 | role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) |
290 | role:onOfflineEvent() | 290 | role:onOfflineEvent() |
src/models/Capsule.lua
@@ -36,6 +36,7 @@ Capsule.schema = { | @@ -36,6 +36,7 @@ Capsule.schema = { | ||
36 | name = {"string"}, | 36 | name = {"string"}, |
37 | typ = {"number", 1}, -- 1=共享,2=独享 | 37 | typ = {"number", 1}, -- 1=共享,2=独享 |
38 | coin = {"number", 0}, --货币代号 | 38 | coin = {"number", 0}, --货币代号 |
39 | + token = {"table", {}}, --抽一次,货币=消耗 | ||
39 | register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 | 40 | register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 |
40 | record = {"table", {}}, --抽取记录 列表 | 41 | record = {"table", {}}, --抽取记录 列表 |
41 | recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record} | 42 | recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record} |
@@ -43,8 +44,8 @@ Capsule.schema = { | @@ -43,8 +44,8 @@ Capsule.schema = { | ||
43 | goods = {"table", {}}, --奖励池 | 44 | goods = {"table", {}}, --奖励池 |
44 | specials = {"table", {}}, --特殊赏 | 45 | specials = {"table", {}}, --特殊赏 |
45 | incentive = {"table", {}}, --激励奖 | 46 | incentive = {"table", {}}, --激励奖 |
46 | - incentiveRecord = {"table", {}}, --激励奖记录 | ||
47 | - specialsRecord= {"table", {}}, --特殊赏领取记录 | 47 | + incentiveRecord = {"table", {}}, --激励奖记录 {roleId = {}, roleId={}} |
48 | + specialsRecord= {"table", {}}, --特殊赏领取记录 {1={},2={}} key=触发特殊赏的 抽奖次数, v=特殊赏商品 table | ||
48 | resetTimes = {"number", 0}, --每日一次手动重置的机会 | 49 | resetTimes = {"number", 0}, --每日一次手动重置的机会 |
49 | hideTime = {"number", 0} , --隐藏时间 | 50 | hideTime = {"number", 0} , --隐藏时间 |
50 | drawEndTime = {"number", 0}, --抽完时间 | 51 | drawEndTime = {"number", 0}, --抽完时间 |
@@ -56,6 +57,7 @@ function Capsule:getResetFields() | @@ -56,6 +57,7 @@ function Capsule:getResetFields() | ||
56 | room = self:getProperty("room"), | 57 | room = self:getProperty("room"), |
57 | typ = self:getProperty("typ"), | 58 | typ = self:getProperty("typ"), |
58 | coin = 0, | 59 | coin = 0, |
60 | + token = {}, | ||
59 | register = {}, | 61 | register = {}, |
60 | record = {}, | 62 | record = {}, |
61 | recordByRole = {}, | 63 | recordByRole = {}, |
@@ -132,7 +134,8 @@ function Capsule:init() | @@ -132,7 +134,8 @@ function Capsule:init() | ||
132 | end | 134 | end |
133 | --货币类型 | 135 | --货币类型 |
134 | local coin = ichibankuji["token"]:toArray(true, "=") | 136 | local coin = ichibankuji["token"]:toArray(true, "=") |
135 | - self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) | 137 | + self:setProperties({coin = coin[1] or 0, token = coin, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) |
138 | + | ||
136 | end | 139 | end |
137 | 140 | ||
138 | function Capsule:isShow() | 141 | function Capsule:isShow() |
@@ -142,6 +145,80 @@ function Capsule:isShow() | @@ -142,6 +145,80 @@ function Capsule:isShow() | ||
142 | return true | 145 | return true |
143 | end | 146 | end |
144 | 147 | ||
148 | +function Capsule:reset2TimeOut(curTime, now) | ||
149 | + now = now or skynet.timex() | ||
150 | + local interval | ||
151 | + if now >= curTime then | ||
152 | + self:init() | ||
153 | + self:create() | ||
154 | + else | ||
155 | + interval = curTime - now | ||
156 | + end | ||
157 | + interval = (interval)* 100 | ||
158 | + skynet.timeout(interval, handler(self,self.reset3TimeOut)(curTime)) | ||
159 | +end | ||
160 | + | ||
161 | +function Capsule:reset3TimeOut(curTime, now) | ||
162 | + now = now or skynet.timex() | ||
163 | + local cur4Time = curTime or (specTime({hour = 4},now)) | ||
164 | + | ||
165 | + local interval | ||
166 | + if cur4Time > now then | ||
167 | + interval = cur4Time - now | ||
168 | + elseif cur4Time < now then | ||
169 | + local nextTime = dayLater(now) | ||
170 | + interval = nextTime - now | ||
171 | + elseif cur4Time == now then | ||
172 | + self:init() | ||
173 | + self:create() | ||
174 | + | ||
175 | + local nextTime = dayLater(now) | ||
176 | + interval = nextTime - now | ||
177 | + end | ||
178 | + interval = (interval)* 100 | ||
179 | + skynet.timeout(interval, handler(self,self.reset3TimeOut)) | ||
180 | +end | ||
181 | + | ||
182 | +function Capsule:reset4TimeOut(curTime, now) | ||
183 | + now = now or skynet.timex() | ||
184 | + local interval | ||
185 | + if curTime > now then | ||
186 | + interval = curTime - now | ||
187 | + elseif curTime < now then | ||
188 | + local nextTime = dayLater(now) | ||
189 | + interval = nextTime - now | ||
190 | + elseif curTime == now then | ||
191 | + self:init() | ||
192 | + self:create() | ||
193 | + | ||
194 | + return false | ||
195 | + end | ||
196 | + interval = (interval)* 100 | ||
197 | + skynet.timeout(interval, handler(self,self.reset4TimeOut)) | ||
198 | +end | ||
199 | + | ||
200 | +function Capsule:checkTime(reset, now) | ||
201 | + local resetArr = reset:toArray(true, "=") | ||
202 | + if not next(resetArr) then return false end | ||
203 | + | ||
204 | + if resetArr[1] == 2 then | ||
205 | + if self:getGoodsAmount() > 0 then return false end | ||
206 | + local drawEndTime = self:getProperty("drawEndTime") or 0 | ||
207 | + if drawEndTime == 0 then return false end | ||
208 | + if now - drawEndTime >= resetArr[2] then return true end | ||
209 | + --self:reset2TimeOut(drawEndTime + resetArr[2], now) | ||
210 | + elseif resetArr[1] == 3 then | ||
211 | + local cur4Time = specTime({hour = 4},now) | ||
212 | + if now == cur4Time then return true end | ||
213 | + --self:reset3TimeOut(cur4Time, now) | ||
214 | + elseif resetArr[1] == 4 then | ||
215 | + if now == resetArr[2] then return true end | ||
216 | + --self:reset4TimeOut(resetArr[2], now) | ||
217 | + end | ||
218 | + | ||
219 | + return false | ||
220 | +end | ||
221 | + | ||
145 | function Capsule:refreshing(now) | 222 | function Capsule:refreshing(now) |
146 | local id = self:getProperty("id") | 223 | local id = self:getProperty("id") |
147 | local room = self:getProperty("room") | 224 | local room = self:getProperty("room") |
@@ -151,30 +228,13 @@ function Capsule:refreshing(now) | @@ -151,30 +228,13 @@ function Capsule:refreshing(now) | ||
151 | if reset == "0" then | 228 | if reset == "0" then |
152 | return false | 229 | return false |
153 | elseif reset == "1" then | 230 | elseif reset == "1" then |
154 | - if self:getProperty("resetTimes") == 1 then | 231 | + if self:getProperty("resetTimes") == 0 then |
232 | + self:setProperty("resetTime", 1) | ||
155 | return true | 233 | return true |
156 | end | 234 | end |
157 | return false | 235 | return false |
158 | else | 236 | else |
159 | - local resetArr = reset:toArray(true, "=") | ||
160 | - if not next(resetArr) then return false end | ||
161 | - | ||
162 | - if resetArr[1] == "2" then | ||
163 | - if self:getGoodsAmount() > 0 then return false end | ||
164 | - | ||
165 | - local drawEndTime = self:getProperty("drawEndTime") or 0 | ||
166 | - if drawEndTime == 0 then return false end | ||
167 | - | ||
168 | - if now - drawEndTime >= resetArr[2] then | ||
169 | - return true | ||
170 | - end | ||
171 | - return false | ||
172 | - | ||
173 | - elseif resetArr[1] == "3" then | ||
174 | - | ||
175 | - elseif resetArr[1] == "4" then | ||
176 | - if now >= resetArr[2] then return true end | ||
177 | - end | 237 | + return self:checkTime(reset, now) |
178 | end | 238 | end |
179 | 239 | ||
180 | return false | 240 | return false |
@@ -233,11 +293,11 @@ function Capsule:confirmed(cares) | @@ -233,11 +293,11 @@ function Capsule:confirmed(cares) | ||
233 | for k, v in pairs(cares) do | 293 | for k, v in pairs(cares) do |
234 | if v.typ == 1 then | 294 | if v.typ == 1 then |
235 | if goods[k] and goods[k].amount ~= v.count then | 295 | if goods[k] and goods[k].amount ~= v.count then |
236 | - change[k] = goods[k].amount | 296 | + change[k] = {typ=1, count = goods[k].amount} |
237 | end | 297 | end |
238 | else | 298 | else |
239 | if specials[k] and specials[k].amount ~= v.count then | 299 | if specials[k] and specials[k].amount ~= v.count then |
240 | - change[k] = specials[k].amount | 300 | + change[k] = {typ=1, count = specials[k].amount} |
241 | end | 301 | end |
242 | end | 302 | end |
243 | end | 303 | end |
@@ -271,7 +331,7 @@ function Capsule:checkSpecialFlag(typ) | @@ -271,7 +331,7 @@ function Capsule:checkSpecialFlag(typ) | ||
271 | return spKey, special | 331 | return spKey, special |
272 | end | 332 | end |
273 | 333 | ||
274 | -local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | 334 | +local function getSpecialReward(rewardRecord, count, award, spKey, typ, now) |
275 | local rewardByRole = {} | 335 | local rewardByRole = {} |
276 | while(count > 0 and next(rewardRecord)) do | 336 | while(count > 0 and next(rewardRecord)) do |
277 | local roleId = math.randWeight(rewardRecord, "amount") | 337 | local roleId = math.randWeight(rewardRecord, "amount") |
@@ -282,19 +342,9 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | @@ -282,19 +342,9 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | ||
282 | 342 | ||
283 | if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end | 343 | if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end |
284 | 344 | ||
285 | - tmp = rewardByRole[roleId] | ||
286 | - if not tmp then | ||
287 | - local name = getNameByRoleId(roleId) | ||
288 | - tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | ||
289 | - else | ||
290 | - if not tmp[spKey] then | ||
291 | - local name = getNameByRoleId(roleId) | ||
292 | - tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | ||
293 | - else | ||
294 | - tmp[spKey].amount = tmp[spKey].amount + 1 | ||
295 | - end | ||
296 | - end | ||
297 | - rewardByRole[roleId] = tmp | 345 | + local name = getNameByRoleId(roleId) |
346 | + tmp = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | ||
347 | + table.insert(rewardByRole, tmp) | ||
298 | 348 | ||
299 | count = count - 1 | 349 | count = count - 1 |
300 | end | 350 | end |
@@ -302,13 +352,28 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | @@ -302,13 +352,28 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | ||
302 | return rewardByRole, count | 352 | return rewardByRole, count |
303 | end | 353 | end |
304 | 354 | ||
305 | -function Capsule:getTop(record) | 355 | + |
356 | +local rewardToRecordFunc = function(specialsRecord, recordAmount, rewardByRole) | ||
357 | + if not specialsRecord[recordAmount] then | ||
358 | + specialsRecord[recordAmount] = rewardByRole | ||
359 | + else | ||
360 | + table.insert(specialsRecord[recordAmount], rewardByRole) | ||
361 | + end | ||
362 | +end | ||
363 | + | ||
364 | +local function getRecordAmount(record) | ||
365 | + return #record | ||
366 | +end | ||
367 | + | ||
368 | + | ||
369 | +function Capsule:getTop(record, recordAmount,now) | ||
306 | local spKey, special = self:checkSpecialFlag(SpecialType.TOP) | 370 | local spKey, special = self:checkSpecialFlag(SpecialType.TOP) |
307 | if not special then return nil end | 371 | if not special then return nil end |
308 | local specials = self:getProperty("specials") or {} | 372 | local specials = self:getProperty("specials") or {} |
309 | local specialsRecord = self:getProperty("specialsRecord") or {} | 373 | local specialsRecord = self:getProperty("specialsRecord") or {} |
310 | 374 | ||
311 | - if #record < special["np"] then return nil end | 375 | + if recordAmount < special["np"] then return nil end |
376 | + | ||
312 | local topRecord = {} | 377 | local topRecord = {} |
313 | local count = special["np"] | 378 | local count = special["np"] |
314 | for _, v in ipairs(record) do | 379 | for _, v in ipairs(record) do |
@@ -330,32 +395,33 @@ function Capsule:getTop(record) | @@ -330,32 +395,33 @@ function Capsule:getTop(record) | ||
330 | end | 395 | end |
331 | end | 396 | end |
332 | 397 | ||
333 | - local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP) | 398 | + local rewardByRole, count = getSpecialReward(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP,now) |
334 | 399 | ||
335 | special["amount"] = count | 400 | special["amount"] = count |
336 | specials[spKey] = special | 401 | specials[spKey] = special |
337 | - specialsRecord[SpecialType.TOP] = rewardByRole | 402 | + |
403 | + rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole) | ||
404 | + | ||
338 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 405 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
339 | return rewardByRole | 406 | return rewardByRole |
340 | 407 | ||
341 | end | 408 | end |
342 | 409 | ||
343 | --TODO | 410 | --TODO |
344 | -function Capsule:getCore(record) | 411 | +function Capsule:getCore(record, recordAmount,now) |
345 | local spKey, special = self:checkSpecialFlag(SpecialType.CORE) | 412 | local spKey, special = self:checkSpecialFlag(SpecialType.CORE) |
346 | if not special then return nil end | 413 | if not special then return nil end |
347 | 414 | ||
348 | local specials = self:getProperty("specials") or {} | 415 | local specials = self:getProperty("specials") or {} |
349 | local specialsRecord = self:getProperty("specialsRecord") or {} | 416 | local specialsRecord = self:getProperty("specialsRecord") or {} |
350 | 417 | ||
351 | - if self:getGoodsAmount() > 0 then return nil end | ||
352 | 418 | ||
353 | - local np = special["np"] | ||
354 | - if np > #record then return nil end | 419 | + |
420 | + local count = special["np"] | ||
421 | + if count > recordAmount then return nil end | ||
355 | 422 | ||
356 | 423 | ||
357 | - local left = math.ceil((np - #record)/2) or 0 | ||
358 | - local count = np | 424 | + local left = math.ceil((count - recordAmount)/2) or 0 |
359 | local roleRecord = {} | 425 | local roleRecord = {} |
360 | for i, v in ipairs(record) do | 426 | for i, v in ipairs(record) do |
361 | if count <= 0 then break end | 427 | if count <= 0 then break end |
@@ -372,34 +438,32 @@ function Capsule:getCore(record) | @@ -372,34 +438,32 @@ function Capsule:getCore(record) | ||
372 | if not roleRecord[v.roleId]then | 438 | if not roleRecord[v.roleId]then |
373 | roleRecord[v.roleId] = {amount = v.amount } | 439 | roleRecord[v.roleId] = {amount = v.amount } |
374 | else | 440 | else |
375 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} | 441 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount} |
376 | end | 442 | end |
377 | end | 443 | end |
378 | 444 | ||
379 | end | 445 | end |
380 | 446 | ||
381 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.CORE) | 447 | + local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.CORE,now) |
382 | 448 | ||
383 | special["amount"] = count | 449 | special["amount"] = count |
384 | specials[spKey] = special | 450 | specials[spKey] = special |
385 | - specialsRecord[SpecialType.CORE] = rewardByRole | 451 | + |
452 | + rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole) | ||
386 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 453 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
387 | return rewardByRole | 454 | return rewardByRole |
388 | end | 455 | end |
389 | 456 | ||
390 | -function Capsule:getLast(record) | 457 | +function Capsule:getLast(record, recordAmount, now) |
391 | local spKey, special = self:checkSpecialFlag(SpecialType.LAST) | 458 | local spKey, special = self:checkSpecialFlag(SpecialType.LAST) |
392 | if not special then return nil end | 459 | if not special then return nil end |
393 | 460 | ||
394 | local specials = self:getProperty("specials") or {} | 461 | local specials = self:getProperty("specials") or {} |
395 | local specialsRecord = self:getProperty("specialsRecord") or {} | 462 | local specialsRecord = self:getProperty("specialsRecord") or {} |
396 | 463 | ||
397 | - if self:getGoodsAmount() > 0 then return nil end | ||
398 | - | ||
399 | table.sort(record, function(a, b) return a.create_time > b.create_time end) | 464 | table.sort(record, function(a, b) return a.create_time > b.create_time end) |
400 | 465 | ||
401 | - local np = special["np"] | ||
402 | - local count = np | 466 | + local count = special["np"] |
403 | local roleRecord = {} | 467 | local roleRecord = {} |
404 | for _, v in ipairs(record) do | 468 | for _, v in ipairs(record) do |
405 | if count <= 0 then break end | 469 | if count <= 0 then break end |
@@ -416,90 +480,85 @@ function Capsule:getLast(record) | @@ -416,90 +480,85 @@ function Capsule:getLast(record) | ||
416 | if not roleRecord[v.roleId]then | 480 | if not roleRecord[v.roleId]then |
417 | roleRecord[v.roleId] = {amount = v.amount } | 481 | roleRecord[v.roleId] = {amount = v.amount } |
418 | else | 482 | else |
419 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} | 483 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount} |
420 | end | 484 | end |
421 | end | 485 | end |
422 | 486 | ||
423 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.LAST) | 487 | + local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.LAST,now) |
424 | 488 | ||
425 | special["amount"] = count | 489 | special["amount"] = count |
426 | specials[spKey] = special | 490 | specials[spKey] = special |
427 | - specialsRecord[SpecialType.LAST] = rewardByRole | 491 | + |
492 | + rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole) | ||
428 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 493 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
429 | return rewardByRole | 494 | return rewardByRole |
430 | end | 495 | end |
431 | 496 | ||
432 | -function Capsule:getJoker(record) | 497 | +function Capsule:getJoker(record, recordAmount, now) |
433 | local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) | 498 | local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) |
434 | if not special then return nil end | 499 | if not special then return nil end |
435 | 500 | ||
436 | local specials = self:getProperty("specials") or {} | 501 | local specials = self:getProperty("specials") or {} |
437 | local specialsRecord = self:getProperty("specialsRecord") or {} | 502 | local specialsRecord = self:getProperty("specialsRecord") or {} |
438 | 503 | ||
439 | - if self:getGoodsAmount() > 0 then return nil end | ||
440 | - | ||
441 | local roleRecord = {} | 504 | local roleRecord = {} |
442 | for _, v in ipairs(record) do | 505 | for _, v in ipairs(record) do |
443 | if not roleRecord[v.roleId]then | 506 | if not roleRecord[v.roleId]then |
444 | roleRecord[v.roleId] = {amount = v.amount } | 507 | roleRecord[v.roleId] = {amount = v.amount } |
445 | else | 508 | else |
446 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | 509 | + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount} |
447 | end | 510 | end |
448 | end | 511 | end |
449 | 512 | ||
450 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.JOKER) | 513 | + local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.JOKER,now) |
451 | 514 | ||
452 | special["amount"] = count | 515 | special["amount"] = count |
453 | specials[spKey] = special | 516 | specials[spKey] = special |
454 | - specialsRecord[SpecialType.JOKER] = rewardByRole | 517 | + |
518 | + rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole) | ||
455 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 519 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
456 | return rewardByRole | 520 | return rewardByRole |
457 | end | 521 | end |
458 | 522 | ||
459 | -function Capsule:getKing(record) | 523 | +function Capsule:getKing(record, recordAmount, now) |
460 | local spKey, special = self:checkSpecialFlag(SpecialType.KING) | 524 | local spKey, special = self:checkSpecialFlag(SpecialType.KING) |
461 | if not special then return nil end | 525 | if not special then return nil end |
462 | 526 | ||
463 | local specials = self:getProperty("specials") or {} | 527 | local specials = self:getProperty("specials") or {} |
464 | local specialsRecord = self:getProperty("specialsRecord") or {} | 528 | local specialsRecord = self:getProperty("specialsRecord") or {} |
465 | - | ||
466 | - if self:getGoodsAmount() > 0 then return nil end | 529 | + local rank = self:getProperty("rank") or {} |
530 | + if not next(rank) then return nil end | ||
467 | 531 | ||
468 | local roleRecord = {} | 532 | local roleRecord = {} |
469 | - for _, v in ipairs(record) do | ||
470 | - if not roleRecord[v.roleId]then | ||
471 | - roleRecord[v.roleId] = {amount = v.amount } | ||
472 | - else | ||
473 | - roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | ||
474 | - end | 533 | + |
534 | + for roleId, count in pairs(rank) do | ||
535 | + table.insert(roleRecord, {roleId = roleId, count = count}) | ||
536 | + end | ||
537 | + table.sort(roleRecord, function(a, b) return a.count > b.count end) | ||
538 | + | ||
539 | + local count = math.min(special["amount"], #roleRecord) | ||
540 | + | ||
541 | + local rewardByRole = {} | ||
542 | + local index = 1 | ||
543 | + while (count > 0 ) do | ||
544 | + count = count - 1 | ||
545 | + local tmp = roleRecord[index] | ||
546 | + if not tmp then break end | ||
547 | + index = index + 1 | ||
548 | + | ||
549 | + local name = getNameByRoleId(tmp.roleId) | ||
550 | + table.insert(rewardByRole, {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = special["award"], amount = 1, SpecialType.KING, create_time= now}) | ||
475 | end | 551 | end |
476 | 552 | ||
477 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.KING) | ||
478 | special["amount"] = count | 553 | special["amount"] = count |
479 | specials[spKey] = special | 554 | specials[spKey] = special |
480 | - specialsRecord[SpecialType.KING] = rewardByRole | 555 | + |
556 | + rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole) | ||
481 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 557 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
482 | return rewardByRole | 558 | return rewardByRole |
483 | end | 559 | end |
484 | 560 | ||
485 | -local rewardToNtyFunc = function(notify, tmpReward) | ||
486 | - for key, val in pairs(tmpReward or {}) do | ||
487 | - if not notify[key] then | ||
488 | - notify[key] = val | ||
489 | - else | ||
490 | - for k, v in pairs(val) do | ||
491 | - if not notify[key][k] then | ||
492 | - notify[key][k] = v | ||
493 | - else | ||
494 | - notify[key][k] = notify[key][k].amount + v.amount | ||
495 | - end | ||
496 | - end | ||
497 | - | ||
498 | - end | ||
499 | - end | ||
500 | -end | ||
501 | - | ||
502 | -function Capsule:checkSpecialReward( now) | 561 | +function Capsule:checkSpecialReward(now, goodsAmount) |
503 | local specials = self:getProperty("specials") or {} | 562 | local specials = self:getProperty("specials") or {} |
504 | if not next(specials) then return nil end | 563 | if not next(specials) then return nil end |
505 | local record = self:getProperty("record") or {} | 564 | local record = self:getProperty("record") or {} |
@@ -507,23 +566,24 @@ function Capsule:checkSpecialReward( now) | @@ -507,23 +566,24 @@ function Capsule:checkSpecialReward( now) | ||
507 | if not next(record) then return nil end | 566 | if not next(record) then return nil end |
508 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) | 567 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) |
509 | 568 | ||
569 | + local recordAmount = getRecordAmount(record) | ||
510 | 570 | ||
511 | - local notify = self:getTop(record) or {} | 571 | + local notify = self:getTop(record, recordAmount,now) or {} |
512 | 572 | ||
513 | - local coreReward = self:getCore(record) | ||
514 | - rewardToNtyFunc(notify, coreReward) | 573 | + if goodsAmount == 0 then |
574 | + local coreReward = self:getCore(record, recordAmount, now) | ||
575 | + rewardToRecordFunc(notify, recordAmount, coreReward) | ||
515 | 576 | ||
516 | - local lastReward = self:getLast(record) | ||
517 | - rewardToNtyFunc(notify, lastReward) | 577 | + local lastReward = self:getLast(record, recordAmount, now) |
578 | + rewardToRecordFunc(notify, recordAmount, lastReward) | ||
518 | 579 | ||
519 | - local jokerReward = self:getJoker(record) | ||
520 | - rewardToNtyFunc(notify, jokerReward) | 580 | + local jokerReward = self:getJoker(record, recordAmount, now) |
581 | + rewardToRecordFunc(notify, recordAmount, jokerReward) | ||
521 | 582 | ||
522 | - local kingReward = self:getKing(record) | ||
523 | - rewardToNtyFunc(notify, kingReward) | 583 | + local kingReward = self:getKing(record, recordAmount, now) |
584 | + rewardToRecordFunc(notify, recordAmount, kingReward) | ||
585 | + end | ||
524 | 586 | ||
525 | - --广播出去TODO | ||
526 | - --rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) | ||
527 | return notify | 587 | return notify |
528 | end | 588 | end |
529 | 589 | ||
@@ -561,24 +621,25 @@ function Capsule:checkIncentive(roleId, name, now) | @@ -561,24 +621,25 @@ function Capsule:checkIncentive(roleId, name, now) | ||
561 | end | 621 | end |
562 | 622 | ||
563 | local count = math.floor(amount / incentive["amount"]["np"]) | 623 | local count = math.floor(amount / incentive["amount"]["np"]) |
564 | - local tmpCount = count * incentive["amount"]["np"] | ||
565 | - notify["amount"] = {name = name, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | ||
566 | - | ||
567 | - --填充v.calculated 字段,标识已经用于每x抽的计算中。 | ||
568 | - for _, v in pairs(roleRecord) do | ||
569 | - if tmpCount <= 0 then break end | ||
570 | - | ||
571 | - v.calculated = v.calculated or 0 | ||
572 | - if v.calculated ~= v.amount then | ||
573 | - if tmpCount <= v.amount then | ||
574 | - v.calculated = tmpCount | ||
575 | - tmpCount = 0 | ||
576 | - else | ||
577 | - v.calculated = v.amount | ||
578 | - tmpCount = tmpCount - v.amount | 624 | + if count > 0 then |
625 | + local tmpCount = count * incentive["amount"]["np"] | ||
626 | + notify["amount"] = {name = name, roleId= roleId, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} | ||
627 | + | ||
628 | + --填充v.calculated 字段,标识已经用于每x抽的计算中。 | ||
629 | + for _, v in pairs(roleRecord) do | ||
630 | + if tmpCount <= 0 then break end | ||
631 | + | ||
632 | + v.calculated = v.calculated or 0 | ||
633 | + if v.calculated ~= v.amount then | ||
634 | + if tmpCount <= v.amount then | ||
635 | + v.calculated = tmpCount | ||
636 | + tmpCount = 0 | ||
637 | + else | ||
638 | + v.calculated = v.amount | ||
639 | + tmpCount = tmpCount - v.amount | ||
640 | + end | ||
579 | end | 641 | end |
580 | end | 642 | end |
581 | - | ||
582 | end | 643 | end |
583 | end | 644 | end |
584 | 645 | ||
@@ -590,11 +651,44 @@ function Capsule:checkIncentive(roleId, name, now) | @@ -590,11 +651,44 @@ function Capsule:checkIncentive(roleId, name, now) | ||
590 | 651 | ||
591 | end | 652 | end |
592 | end | 653 | end |
593 | - table.insert(incentiveByRole, notify) | 654 | + for k, v in pairs(notify) do |
655 | + if not incentiveByRole[k] then | ||
656 | + incentiveByRole[k] = v | ||
657 | + else | ||
658 | + incentiveByRole[k].amount = incentiveByRole[k].amount + v.amount | ||
659 | + end | ||
660 | + end | ||
594 | incentiveRecord[roleId] = incentiveByRole | 661 | incentiveRecord[roleId] = incentiveByRole |
595 | self:setProperty("incentiveRecord", incentiveRecord) | 662 | self:setProperty("incentiveRecord", incentiveRecord) |
596 | 663 | ||
597 | - return notify | 664 | + return incentiveByRole |
665 | +end | ||
666 | + | ||
667 | +local rewardCollect = function(reward, goods) | ||
668 | + for _, v in pairs(goods) do | ||
669 | + for id, count in pairs(v.award:toNumMap()) do | ||
670 | + reward[id] = (reward[id] or 0) + count * v.amount | ||
671 | + end | ||
672 | + end | ||
673 | +end | ||
674 | + | ||
675 | +local rewardCollectByRoleId = function(roleId, reward, goods) | ||
676 | + local tmp = {} | ||
677 | + for _, val in pairs(goods) do | ||
678 | + for _, v in ipairs(val) do | ||
679 | + if v.roleId == roleId then | ||
680 | + for id, count in pairs(v.award:toNumMap()) do | ||
681 | + reward[id] = (reward[id] or 0) + count * v.amount | ||
682 | + end | ||
683 | + if not tmp[v.good_id] then | ||
684 | + tmp[v.good_id] = v | ||
685 | + else | ||
686 | + tmp[v.good_id].amount = tmp[v.good_id].amount + v.amount | ||
687 | + end | ||
688 | + end | ||
689 | + end | ||
690 | + end | ||
691 | + return tmp | ||
598 | end | 692 | end |
599 | 693 | ||
600 | function Capsule:drawByCount(roleId, count) | 694 | function Capsule:drawByCount(roleId, count) |
@@ -602,6 +696,8 @@ function Capsule:drawByCount(roleId, count) | @@ -602,6 +696,8 @@ function Capsule:drawByCount(roleId, count) | ||
602 | 696 | ||
603 | local goods = self:getProperty("goods") or {} | 697 | local goods = self:getProperty("goods") or {} |
604 | local record = self:getProperty("record") or {} | 698 | local record = self:getProperty("record") or {} |
699 | + local rank = self:getProperty("rank") or {} | ||
700 | + local rankRole = rank[roleId] or 0 | ||
605 | local recordByRole = self:getProperty("recordByRole") or {} | 701 | local recordByRole = self:getProperty("recordByRole") or {} |
606 | local roleRecord = recordByRole[roleId] or {} | 702 | local roleRecord = recordByRole[roleId] or {} |
607 | 703 | ||
@@ -611,98 +707,106 @@ function Capsule:drawByCount(roleId, count) | @@ -611,98 +707,106 @@ function Capsule:drawByCount(roleId, count) | ||
611 | local goods_id = ichibankuji["goods_id"] | 707 | local goods_id = ichibankuji["goods_id"] |
612 | local now = skynet.timex() | 708 | local now = skynet.timex() |
613 | 709 | ||
614 | - --奖励, 通知信息 | ||
615 | - local notify= {} | ||
616 | - notify[roleId] = {} | 710 | + --奖励,普通奖品信息 |
711 | + local goodsByUsual= {} | ||
617 | 712 | ||
618 | local name = getNameByRoleId(roleId) | 713 | local name = getNameByRoleId(roleId) |
619 | while (goods and next(goods) and count > 0) do | 714 | while (goods and next(goods) and count > 0) do |
620 | local good_id = math.randWeight(goods, "weight") | 715 | local good_id = math.randWeight(goods, "weight") |
621 | - if good_id then | ||
622 | - local good = goods[good_id] or {} | ||
623 | - if good and good.amount > 0 then | ||
624 | - good.amount = good.amount - 1 | ||
625 | - | ||
626 | - --插入记录 | ||
627 | - local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | ||
628 | - table.insert(record, tmpNotify) | ||
629 | - | ||
630 | - --作为奖励记录+通知 | ||
631 | - if not notify[roleId][good_id] then | ||
632 | - notify[roleId][good_id] = tmpNotify | ||
633 | - else | ||
634 | - notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 | ||
635 | - end | 716 | + if not good_id then break end |
636 | 717 | ||
637 | - --记录角色的抽奖记录 计算激励奖需要用到 | ||
638 | - if not roleRecord[good_id] then | ||
639 | - roleRecord[good_id] = tmpNotify | ||
640 | - else | ||
641 | - roleRecord[good_id].amount = roleRecord[good_id].amount + 1 | ||
642 | - end | 718 | + local good = goods[good_id] or {} |
719 | + if good and good.amount > 0 then | ||
720 | + good.amount = good.amount - 1 | ||
721 | + | ||
722 | + --插入rank | ||
723 | + rankRole = rankRole + 1 | ||
643 | 724 | ||
644 | - good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight | ||
645 | - count = count - 1 | 725 | + --插入记录 |
726 | + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} | ||
727 | + table.insert(record, tmpNotify) | ||
728 | + | ||
729 | + --作为奖励记录+通知 | ||
730 | + if not goodsByUsual[good_id] then | ||
731 | + goodsByUsual[good_id] = tmpNotify | ||
732 | + else | ||
733 | + goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + 1 | ||
646 | end | 734 | end |
647 | - end | ||
648 | 735 | ||
649 | - end | ||
650 | - recordByRole[roleId] = roleRecord | ||
651 | - self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | 736 | + --记录角色的抽奖记录 计算激励奖需要用到 |
737 | + if not roleRecord[good_id] then | ||
738 | + roleRecord[good_id] = tmpNotify | ||
739 | + else | ||
740 | + roleRecord[good_id].amount = roleRecord[good_id].amount + 1 | ||
741 | + end | ||
652 | 742 | ||
653 | - local tmpNotify = self:checkIncentive(roleId, name, now) | ||
654 | - for k, v in pairs(tmpNotify) do | ||
655 | - if not notify[roleId][k] then | ||
656 | - notify[roleId][k] = v | ||
657 | - else | ||
658 | - notify[roleId][k].amount = notify[roleId][k].amount + v.amount | 743 | + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight |
744 | + count = count - 1 | ||
659 | end | 745 | end |
746 | + | ||
660 | end | 747 | end |
661 | 748 | ||
662 | - local speciNotify = self:checkSpecialReward(now) | ||
663 | - rewardToNtyFunc(notify, speciNotify) | 749 | + --奖励池重新赋值 |
750 | + rank[roleId] = rankRole | ||
751 | + recordByRole[roleId] = roleRecord | ||
752 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) | ||
664 | 753 | ||
665 | - local reward, rewardByGoods = {}, {} | ||
666 | - for key, val in pairs(notify) do | ||
667 | - if key == roleId then | ||
668 | - for k, v in pairs(val) do | ||
669 | - for id, count in pairs(v.award:toNumMap()) do | ||
670 | - reward[id] = (reward[id] or 0) + count | ||
671 | - end | ||
672 | - rewardByGoods[k] = v | ||
673 | - end | ||
674 | - end | 754 | + --奖励收集 |
755 | + local reward = {} | ||
756 | + rewardCollect(reward, goodsByUsual) | ||
675 | 757 | ||
758 | + local goodsByIncentive = self:checkIncentive(roleId, name, now) | ||
759 | + rewardCollect(reward, goodsByIncentive) | ||
760 | + | ||
761 | + local goodsAmount = self:getGoodsAmount() | ||
762 | + if goodsAmount == 0 then | ||
763 | + self:setProperty("drawEndTime", now) | ||
676 | end | 764 | end |
677 | - return reward, rewardByGoods, notify | 765 | + |
766 | + local goodsBySpecial = self:checkSpecialReward(now, goodsAmount) | ||
767 | + local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial) | ||
768 | + | ||
769 | + local drawReward = {} | ||
770 | + drawReward["reward"] = reward | ||
771 | + drawReward["usual"] = goodsByUsual | ||
772 | + drawReward["specials"] = goodsBySpecial | ||
773 | + if next(goodsByIncentive) then drawReward["incentive"] = goodsByIncentive end | ||
774 | + if next(specialByRole) then drawReward["special"] = specialByRole end | ||
775 | + return drawReward | ||
678 | end | 776 | end |
679 | 777 | ||
680 | function Capsule:drawAll(roleId) | 778 | function Capsule:drawAll(roleId) |
681 | local goods = self:getProperty("goods") or {} | 779 | local goods = self:getProperty("goods") or {} |
682 | local record = self:getProperty("record") or {} | 780 | local record = self:getProperty("record") or {} |
781 | + local rank = self:getProperty("rank") or {} | ||
782 | + local rankRole = rank[roleId] or 0 | ||
683 | local recordByRole = self:getProperty("recordByRole") or {} | 783 | local recordByRole = self:getProperty("recordByRole") or {} |
684 | local roleRecord = recordByRole[roleId] or {} | 784 | local roleRecord = recordByRole[roleId] or {} |
685 | local now = skynet.timex() | 785 | local now = skynet.timex() |
686 | 786 | ||
687 | local name = getNameByRoleId(roleId) | 787 | local name = getNameByRoleId(roleId) |
688 | - local notify = {} | ||
689 | - notify[roleId] = {} | 788 | + local goodsByUsual = {} |
690 | for good_id, good in pairs(goods) do | 789 | for good_id, good in pairs(goods) do |
691 | if good.amount > 0 then | 790 | if good.amount > 0 then |
791 | + --插入rank | ||
792 | + rankRole = rankRole + good.amount | ||
793 | + | ||
692 | --插入记录 | 794 | --插入记录 |
693 | - local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | ||
694 | - table.insert(record, notify) | 795 | + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} |
796 | + for i = 1, good.amount do | ||
797 | + table.insert(record, {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time = now}) | ||
798 | + end | ||
695 | 799 | ||
696 | --作为奖励记录+通知 | 800 | --作为奖励记录+通知 |
697 | - if not notify[roleId][good_id] then | ||
698 | - notify[roleId][good_id] = tmpNotify | 801 | + if not goodsByUsual[good_id] then |
802 | + goodsByUsual[good_id] = tmpNotify | ||
699 | else | 803 | else |
700 | - notify[roleId][good_id].amount = notify[roleId][good_id].amount + good.award | 804 | + goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + good.award |
701 | end | 805 | end |
702 | 806 | ||
703 | --记录角色的抽奖记录 | 807 | --记录角色的抽奖记录 |
704 | if not roleRecord[good_id] then | 808 | if not roleRecord[good_id] then |
705 | - roleRecord[good_id] = notify | 809 | + roleRecord[good_id] = tmpNotify |
706 | else | 810 | else |
707 | roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount | 811 | roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount |
708 | end | 812 | end |
@@ -711,34 +815,32 @@ function Capsule:drawAll(roleId) | @@ -711,34 +815,32 @@ function Capsule:drawAll(roleId) | ||
711 | end | 815 | end |
712 | 816 | ||
713 | end | 817 | end |
818 | + rank[roleId] = rankRole | ||
714 | recordByRole[roleId] = roleRecord | 819 | recordByRole[roleId] = roleRecord |
715 | - self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | ||
716 | - | ||
717 | - local tmpNotify = self:checkIncentive(roleId, name, now) | ||
718 | - for k, v in pairs(tmpNotify) do | ||
719 | - if not notify[roleId][k] then | ||
720 | - notify[roleId][k] = v | ||
721 | - else | ||
722 | - notify[roleId][k].amount = notify[roleId][k].amount + v.amount | ||
723 | - end | ||
724 | - end | 820 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank}) |
725 | 821 | ||
726 | - local speciNotify = self:checkSpecialReward(now) | ||
727 | - rewardToNtyFunc(notify, speciNotify) | 822 | + --奖励收集 |
823 | + local reward = {} | ||
824 | + rewardCollect(reward, goodsByUsual) | ||
728 | 825 | ||
729 | - local reward, rewardByGoods = {}, {} | ||
730 | - for key, val in pairs(notify) do | ||
731 | - if key == roleId then | ||
732 | - for k, v in pairs(val) do | ||
733 | - for id, count in pairs(v.award:toNumMap()) do | ||
734 | - reward[id] = (reward[id] or 0) + count | ||
735 | - end | ||
736 | - rewardByGoods[k] = v | ||
737 | - end | ||
738 | - end | 826 | + local goodsByIncentive = self:checkIncentive(roleId, name, now) |
827 | + rewardCollect(reward, goodsByIncentive) | ||
739 | 828 | ||
829 | + local goodsAmount = self:getGoodsAmount() | ||
830 | + if goodsAmount == 0 then | ||
831 | + self:setProperty("drawEndTime", now) | ||
740 | end | 832 | end |
741 | - return reward, rewardByGoods, notify | 833 | + |
834 | + local goodsBySpecial = self:checkSpecialReward(now, goodsAmount) | ||
835 | + local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial) | ||
836 | + | ||
837 | + local drawReward = {} | ||
838 | + drawReward["reward"] = reward | ||
839 | + drawReward["usual"] = goodsByUsual | ||
840 | + drawReward["specials"] = goodsBySpecial | ||
841 | + if next(goodsByIncentive) then drawReward["incentive"] = goodsByIncentive end | ||
842 | + if next(specialByRole) then drawReward["special"] = specialByRole end | ||
843 | + return drawReward | ||
742 | end | 844 | end |
743 | 845 | ||
744 | --@param | 846 | --@param |
@@ -749,27 +851,97 @@ end | @@ -749,27 +851,97 @@ end | ||
749 | ]]-- | 851 | ]]-- |
750 | 852 | ||
751 | function Capsule:draw(roleId, full, cares) | 853 | function Capsule:draw(roleId, full, cares) |
752 | - if self:getGoodsAmount() == 0 then return 2 end | ||
753 | if self:getProperty("typ") == 1 then | 854 | if self:getProperty("typ") == 1 then |
754 | --是否报名 | 855 | --是否报名 |
755 | - if self:isRegister(roleId) == false then return 3 end | 856 | + if self:isRegister(roleId) == false then return 4 end |
756 | 857 | ||
757 | --关注的奖品的数量发生了变化 | 858 | --关注的奖品的数量发生了变化 |
758 | if cares then | 859 | if cares then |
759 | local change = self:confirmed(cares) | 860 | local change = self:confirmed(cares) |
760 | - if next(change) then return 4, change end | 861 | + if next(change) then return 5, change end |
761 | end | 862 | end |
762 | end | 863 | end |
763 | 864 | ||
764 | if full == 0 then | 865 | if full == 0 then |
765 | - return 5, self:drawByCount(roleId, 1) | 866 | + return 6, self:drawByCount(roleId, 1) |
766 | elseif full == 1 then | 867 | elseif full == 1 then |
767 | - return 5, self:drawByCount(roleId, 10) | 868 | + return 6, self:drawByCount(roleId, 10) |
768 | elseif full == 2 then | 869 | elseif full == 2 then |
769 | - return 5, self:drawAll(roleId) | 870 | + return 6, self:drawAll(roleId) |
770 | end | 871 | end |
771 | end | 872 | end |
772 | 873 | ||
874 | +function Capsule:pageRecord(up, idx) | ||
875 | + local record = self:getProperty("record") or {} | ||
876 | + if not next(record) then return nil end | ||
877 | + | ||
878 | + --默认取20条 | ||
879 | + idx = idx or #record | ||
880 | + up = up or 0 | ||
881 | + | ||
882 | + local count = 0 | ||
883 | + local tmpRecord = {} | ||
884 | + if up == 1 then | ||
885 | + --向上获取索引更大的 从上往下拉 | ||
886 | + count = math.min(#record - idx, 20) | ||
887 | + for i = idx, count do | ||
888 | + tmpRecord[i] = record[i] | ||
889 | + end | ||
890 | + else | ||
891 | + --向下获取索引更小的 从下往上拉 | ||
892 | + count = math.max(idx - 20, 0) | ||
893 | + for i = count, idx do | ||
894 | + tmpRecord[i] = record[i] | ||
895 | + end | ||
896 | + end | ||
897 | + | ||
898 | + return tmpRecord | ||
899 | +end | ||
900 | + | ||
901 | +--检查是否有未领取奖励的通知 | ||
902 | +function Capsule:getSpecialNotify(roleId) | ||
903 | + local specialsRecord = self:getProperty("specialsRecord") or {} | ||
904 | + local tmp = {} | ||
905 | + for _, goods in pairs(specialsRecord) do | ||
906 | + for _, good in ipairs(goods) do | ||
907 | + if good.roleId == roleId then | ||
908 | + if not good.nty or good.nty == 0 then | ||
909 | + tmp[good.good_id] = good | ||
910 | + end | ||
911 | + end | ||
912 | + end | ||
913 | + end | ||
914 | + self:setProperty("specialsRecord", specialsRecord) | ||
915 | + | ||
916 | + return tmp | ||
917 | +end | ||
918 | + | ||
919 | +function Capsule:clearSpecialNty(roleId, good_ids) | ||
920 | + local specialsRecord = self:getProperty("specialsRecord") or {} | ||
921 | + for _, goods in pairs(specialsRecord) do | ||
922 | + for _, good in ipairs(goods) do | ||
923 | + for _, good_id in ipairs(good_ids) do | ||
924 | + if good_id == good.good_id and good.roleId == roleId then | ||
925 | + good.nty = 1 | ||
926 | + end | ||
927 | + end | ||
928 | + end | ||
929 | + end | ||
930 | + self:setProperty("specialsRecord", specialsRecord) | ||
931 | +end | ||
932 | + | ||
933 | +function Capsule:getRoleProgress(roleId) | ||
934 | + local recordByRole = self:getProperty("recordByRole") or {} | ||
935 | + local roleRecord = recordByRole[roleId] or {} | ||
936 | + local amount = 0 | ||
937 | + for _, v in pairs(roleRecord) do | ||
938 | + v.calculated = v.calculated or 0 | ||
939 | + if v.calculated ~= v.amount then | ||
940 | + amount = amount + (v.amount - v.calculated) | ||
941 | + end | ||
942 | + end | ||
943 | + return amount | ||
944 | +end | ||
773 | 945 | ||
774 | function Capsule:data(roleId) | 946 | function Capsule:data(roleId) |
775 | return { | 947 | return { |
@@ -780,12 +952,13 @@ function Capsule:data(roleId) | @@ -780,12 +952,13 @@ function Capsule:data(roleId) | ||
780 | coin = self:getProperty("coin"), | 952 | coin = self:getProperty("coin"), |
781 | onlineCount = self:getOnlineCount(), | 953 | onlineCount = self:getOnlineCount(), |
782 | playerStatus = self:getRegisterByRoleId(roleId), | 954 | playerStatus = self:getRegisterByRoleId(roleId), |
783 | - record = self:getProperty("record"), | 955 | + record = self:pageRecord() or {}, |
784 | rank = self:getProperty("rank"), | 956 | rank = self:getProperty("rank"), |
785 | goods = self:getProperty("goods"), | 957 | goods = self:getProperty("goods"), |
786 | specials = self:getProperty("specials"), | 958 | specials = self:getProperty("specials"), |
787 | incentive = self:getProperty("incentive"), | 959 | incentive = self:getProperty("incentive"), |
788 | specialsRecord= self:getProperty("specialsRecord"), | 960 | specialsRecord= self:getProperty("specialsRecord"), |
961 | + roleProgress = self:getRoleProgress(roleId), | ||
789 | } | 962 | } |
790 | end | 963 | end |
791 | 964 |
src/models/RoleCross.lua
@@ -210,10 +210,18 @@ RoleCross.bind = function (Role) | @@ -210,10 +210,18 @@ RoleCross.bind = function (Role) | ||
210 | return "成功" | 210 | return "成功" |
211 | end | 211 | end |
212 | 212 | ||
213 | - function Role:paySpecialReward(typ, reward) | ||
214 | - local tmpReward, _= self:award(reward, {log = {desc = "specialsReward", int1=self:getKey(), int2 = typ}}) | ||
215 | - SendPacket(actionCodes.Capsule_payReward, MsgPack.pack({reward=tmpReward})) | ||
216 | - return "reward" | 213 | + function Role:paySpecialReward(roleId, notify) |
214 | + if notify and next(notify) then | ||
215 | + local reward = {} | ||
216 | + for key, val in pairs(notify) do | ||
217 | + for id, count in pairs(val.award:toNumMap()) do | ||
218 | + reward[id] = (reward[id] or 0) + count | ||
219 | + end | ||
220 | + | ||
221 | + end | ||
222 | + self:award(reward, {log = {desc = "CapsuleReward", int1=roleId}}) | ||
223 | + SendPacket(actionCodes.Capsule_notifyChange, MsgPack.pack({special = notify})) | ||
224 | + end | ||
217 | end | 225 | end |
218 | 226 | ||
219 | end | 227 | end |
@@ -376,9 +384,19 @@ function CMD.redPTag(roleId, tag, pms) | @@ -376,9 +384,19 @@ function CMD.redPTag(roleId, tag, pms) | ||
376 | end | 384 | end |
377 | end | 385 | end |
378 | 386 | ||
379 | -function CMD.paySpecialReward(roleId, typ, reward) | ||
380 | - local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) | ||
381 | - role:award(reward, {log = {desc = "specialsReward", int1=self:getKey(), int2 = typ}}) | 387 | +function CMD.paySpecialReward(roleId, notify) |
388 | + if notify and next(notify) then | ||
389 | + local reward = {} | ||
390 | + for key, val in pairs(notify) do | ||
391 | + for id, count in pairs(val.award:toNumMap()) do | ||
392 | + reward[id] = (reward[id] or 0) + count | ||
393 | + end | ||
394 | + | ||
395 | + end | ||
396 | + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) | ||
397 | + role:award(reward, {log = {desc = "CapsuleReward", int1=roleId}}) | ||
398 | + end | ||
399 | + | ||
382 | end | 400 | end |
383 | 401 | ||
384 | RoleCross.handle = function(cmd, roleId, ...) | 402 | RoleCross.handle = function(cmd, roleId, ...) |
src/models/RoleLog.lua
@@ -161,7 +161,8 @@ local ItemReason = { | @@ -161,7 +161,8 @@ local ItemReason = { | ||
161 | returner = 1410, -- 回归者奖励 | 161 | returner = 1410, -- 回归者奖励 |
162 | 162 | ||
163 | CapsuleReward = 1411, --扭蛋机奖励 | 163 | CapsuleReward = 1411, --扭蛋机奖励 |
164 | - specialsReward = 1412, --特殊赏 | 164 | + CapsuleConvert = 1412, --扭蛋机 消耗票 兑换 |
165 | + CapsuleCoinCost = 1413, --抽扭蛋机消耗 | ||
165 | } | 166 | } |
166 | 167 | ||
167 | 168 |
src/models/RolePlugin.lua
@@ -2090,7 +2090,7 @@ function RolePlugin.bind(Role) | @@ -2090,7 +2090,7 @@ function RolePlugin.bind(Role) | ||
2090 | local emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) | 2090 | local emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) |
2091 | local redret = redisproxy:pipelining(function (red) | 2091 | local redret = redisproxy:pipelining(function (red) |
2092 | for id = emailSync, globalEmail do | 2092 | for id = emailSync, globalEmail do |
2093 | - red:hgetall(string.format("globalEmail:%s", id)) | 2093 | + red:hgetall(string.format("globalEmail:%s", id)) |
2094 | end | 2094 | end |
2095 | end) | 2095 | end) |
2096 | for _, data in ipairs(redret) do | 2096 | for _, data in ipairs(redret) do |
@@ -2437,6 +2437,11 @@ function RolePlugin.bind(Role) | @@ -2437,6 +2437,11 @@ function RolePlugin.bind(Role) | ||
2437 | end | 2437 | end |
2438 | elseif rechargeData.shop == 3 then -- 礼包商店 | 2438 | elseif rechargeData.shop == 3 then -- 礼包商店 |
2439 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) | 2439 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) |
2440 | + | ||
2441 | + --增加购买记录 | ||
2442 | + local buyRecord = self.storeData:getProperty("buyR") or {} | ||
2443 | + buyRecord[id] = (buyRecord[id] or 0) + 1 | ||
2444 | + self.storeData:updateProperty({field = "buyR", value = buyRecord}) | ||
2440 | else | 2445 | else |
2441 | skynet.error("[recharge] invalid recharge shop type " .. id) | 2446 | skynet.error("[recharge] invalid recharge shop type " .. id) |
2442 | return 3 | 2447 | return 3 |
@@ -3153,10 +3158,10 @@ function RolePlugin.bind(Role) | @@ -3153,10 +3158,10 @@ function RolePlugin.bind(Role) | ||
3153 | return itemRandomOccupy | 3158 | return itemRandomOccupy |
3154 | end | 3159 | end |
3155 | 3160 | ||
3156 | - function Role:getCapsuleList(coin) | 3161 | + function Role:getCapsuleList(id) |
3157 | local capsules = {} | 3162 | local capsules = {} |
3158 | for k, v in pairs(self.capsules) do | 3163 | for k, v in pairs(self.capsules) do |
3159 | - if v:getProperty("coin") == coin then | 3164 | + if v:getProperty("id") == id then |
3160 | local onlineCount= v:getOnlineCount() | 3165 | local onlineCount= v:getOnlineCount() |
3161 | capsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")} | 3166 | capsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")} |
3162 | end | 3167 | end |
@@ -3165,17 +3170,20 @@ function RolePlugin.bind(Role) | @@ -3165,17 +3170,20 @@ function RolePlugin.bind(Role) | ||
3165 | end | 3170 | end |
3166 | 3171 | ||
3167 | function Role:drawCapsule(capsuleId, full, cares) | 3172 | function Role:drawCapsule(capsuleId, full, cares) |
3168 | - local capsule = self.capsules[capsuleId] or {} | ||
3169 | - if next(capsule) then | ||
3170 | - local roleId = self:getProperty("id") | ||
3171 | - return capsule:draw(roleId, full, cares) | ||
3172 | - end | ||
3173 | - return 1 | 3173 | + local capsule = self.capsules[capsuleId] |
3174 | + if not capsule then return nil end | ||
3175 | + | ||
3176 | + local roleId = self:getProperty("id") | ||
3177 | + local ret, drawReward = capsule:draw(roleId, full, cares) | ||
3178 | + drawReward["specials"] = nil | ||
3179 | + return ret, drawReward, capsule:data(roleId) | ||
3174 | end | 3180 | end |
3175 | 3181 | ||
3176 | - function Role:joinCapsule(capsuleId) | ||
3177 | - local capsule = self.capsules[capsuleId] or {} | ||
3178 | - return capsule:data() | 3182 | + function Role:joinCapsule(roleId, capsuleId) |
3183 | + local capsule = self.capsules[capsuleId] | ||
3184 | + if not capsule then return nil end | ||
3185 | + | ||
3186 | + return capsule:data(roleId) | ||
3179 | end | 3187 | end |
3180 | 3188 | ||
3181 | function Role:checkCapsule(now) | 3189 | function Role:checkCapsule(now) |
@@ -3186,6 +3194,58 @@ function RolePlugin.bind(Role) | @@ -3186,6 +3194,58 @@ function RolePlugin.bind(Role) | ||
3186 | end | 3194 | end |
3187 | end | 3195 | end |
3188 | end | 3196 | end |
3197 | + | ||
3198 | + function Role:goodStock(capsuleId) | ||
3199 | + local capsule = self.capsules[capsuleId] | ||
3200 | + if not capsule then return 0 end | ||
3201 | + | ||
3202 | + return capsule:getGoodsAmount(), capsule:getProperty("token") | ||
3203 | + end | ||
3204 | + | ||
3205 | + function Role:getCapsuleData(roleId, capsuleId) | ||
3206 | + local capsule = self.capsules[capsuleId] | ||
3207 | + if not capsule then return nil end | ||
3208 | + | ||
3209 | + return capsule:data(roleId) | ||
3210 | + end | ||
3211 | + | ||
3212 | + function Role:resetCapsule() | ||
3213 | + local roleId = self:getProperty("id") | ||
3214 | + local res = redisproxy:smembers(CAPSULE_ID_ROLE:format(roleId)) or {} | ||
3215 | + for _, key in pairs(res) do | ||
3216 | + redisproxy:del(CAPSULE_ROLE:format(roleId, tonumber(key))) | ||
3217 | + redisproxy:srem(CAPSULE_ID_ROLE, key) | ||
3218 | + end | ||
3219 | + | ||
3220 | + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do | ||
3221 | + for _, val in pairs(data) do | ||
3222 | + if val.typ == 0 then | ||
3223 | + local key = val.id..val.room | ||
3224 | + if not self.capsules[key] then | ||
3225 | + local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId, tonumber(key)), id= val.id, room = val.room, typ = 0, name=val.name}) | ||
3226 | + capsule:init() | ||
3227 | + capsule:create() | ||
3228 | + self.capsules[key] = capsule | ||
3229 | + redisproxy.sadd(CAPSULE_ID_ROLE:format(roleId), key) | ||
3230 | + end | ||
3231 | + end | ||
3232 | + end | ||
3233 | + end | ||
3234 | + end | ||
3235 | + | ||
3236 | + function Role:pageRecord(capsuleId, up, idx) | ||
3237 | + local capsule = self.capsules[capsuleId] | ||
3238 | + if not capsule then return nil end | ||
3239 | + | ||
3240 | + return capsule:pageRecord(up, idx) | ||
3241 | + end | ||
3242 | + | ||
3243 | + function Role:getSpecialNotify(roleId, capsuleId) | ||
3244 | + local capsule = self.capsules[capsuleId] | ||
3245 | + if not capsule then return nil end | ||
3246 | + | ||
3247 | + return capsule:getSpecialNotify(roleId) | ||
3248 | + end | ||
3189 | end | 3249 | end |
3190 | 3250 | ||
3191 | return RolePlugin | 3251 | return RolePlugin |
3192 | \ No newline at end of file | 3252 | \ No newline at end of file |
src/models/Store.lua
@@ -474,7 +474,7 @@ function Store:onBuyCard(type, duration, id, actid) | @@ -474,7 +474,7 @@ function Store:onBuyCard(type, duration, id, actid) | ||
474 | self:updateProperty({field = "bpInfo", value = bpInfo}) | 474 | self:updateProperty({field = "bpInfo", value = bpInfo}) |
475 | elseif type == CardType.ActBattleCommandCard then | 475 | elseif type == CardType.ActBattleCommandCard then |
476 | if not self.owner.activity:isOpenById(actid, "ActShopGoods") then | 476 | if not self.owner.activity:isOpenById(actid, "ActShopGoods") then |
477 | - return | 477 | + return nil |
478 | end | 478 | end |
479 | local actCfg = csvdb["activity_ctrlCsv"][actid] | 479 | local actCfg = csvdb["activity_ctrlCsv"][actid] |
480 | if not actCfg then return end | 480 | if not actCfg then return end |
@@ -486,6 +486,10 @@ function Store:onBuyCard(type, duration, id, actid) | @@ -486,6 +486,10 @@ function Store:onBuyCard(type, duration, id, actid) | ||
486 | end | 486 | end |
487 | self.owner:mylog("act_action", {desc="buyBc", int1=id, int2=actData["lvl"] or 0}) | 487 | self.owner:mylog("act_action", {desc="buyBc", int1=id, int2=actData["lvl"] or 0}) |
488 | self.owner.activity:updateActData("BattleCommand", actData) | 488 | self.owner.activity:updateActData("BattleCommand", actData) |
489 | + local rechargeData = csvdb["shop_rechargeCsv"][id] | ||
490 | + if rechargeData then | ||
491 | + return self.owner:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) | ||
492 | + end | ||
489 | end | 493 | end |
490 | return nil, nil | 494 | return nil, nil |
491 | end | 495 | end |
src/services/agent_ctrl.lua
@@ -141,10 +141,11 @@ function _M:check_agent_status() | @@ -141,10 +141,11 @@ function _M:check_agent_status() | ||
141 | end | 141 | end |
142 | end | 142 | end |
143 | 143 | ||
144 | + local count = table_nums(self.u2f) | ||
145 | + datacenter.set("onlineCount", count) | ||
144 | if now >= next_log_time and now % 60 == 0 then | 146 | if now >= next_log_time and now % 60 == 0 then |
145 | next_log_time = now + 60 | 147 | next_log_time = now + 60 |
146 | - local count = table_nums(self.u2f) | ||
147 | - datacenter.set("onlineCount", count) | 148 | + --datacenter.set("onlineCount", count) |
148 | logproxy:log({["@type"] = "online", count = count}, "log") | 149 | logproxy:log({["@type"] = "online", count = count}, "log") |
149 | end | 150 | end |
150 | end | 151 | end |
src/services/capsuled.lua
@@ -16,27 +16,44 @@ NotifyChangeType = { | @@ -16,27 +16,44 @@ NotifyChangeType = { | ||
16 | EXIT = 2, | 16 | EXIT = 2, |
17 | DRAW = 3, | 17 | DRAW = 3, |
18 | SPECIAL = 4, | 18 | SPECIAL = 4, |
19 | - INCENTIVE = 5, | 19 | +} |
20 | + | ||
21 | +skynet.register_protocol { | ||
22 | + name = "role", | ||
23 | + id = 101, | ||
24 | + pack = skynet.pack, | ||
25 | + unpack = skynet.unpack, | ||
20 | } | 26 | } |
21 | 27 | ||
22 | local function rpcRole(roleId, funcName, ...) | 28 | local function rpcRole(roleId, funcName, ...) |
23 | local fields = ... | 29 | local fields = ... |
24 | local agent = datacenter.get("agent", roleId) | 30 | local agent = datacenter.get("agent", roleId) |
25 | - local roleCross = require("models.RoleCross") | ||
26 | - if funcName == "getProperties" then | ||
27 | - return roleCross.handle(funcName, roleId, fields) | 31 | + if agent and agent.serv then |
32 | + if funcName == "getProperties" then | ||
33 | + return true, skynet.call(agent.serv, "role", funcName, fields) | ||
34 | + else | ||
35 | + return true, skynet.call(agent.serv, "role", funcName, ...) | ||
36 | + end | ||
28 | else | 37 | else |
29 | - return roleCross.handle(funcName, roleId, ...) | 38 | + local roleCross = require("models.RoleCross") |
39 | + if funcName == "getProperties" then | ||
40 | + return false, roleCross.handle(funcName, roleId, fields) | ||
41 | + else | ||
42 | + return false, roleCross.handle(funcName, roleId, ...) | ||
43 | + end | ||
30 | end | 44 | end |
31 | end | 45 | end |
32 | 46 | ||
33 | function getNameByRoleId(roleId) | 47 | function getNameByRoleId(roleId) |
34 | - return rpcRole(roleId, "getProperty", "name") | 48 | + local status, name = rpcRole(roleId, "getProperty", "name") |
49 | + return name | ||
35 | 50 | ||
36 | end | 51 | end |
37 | 52 | ||
38 | function broadCastCapsule(roleId, capsuleId, broadInfo) | 53 | function broadCastCapsule(roleId, capsuleId, broadInfo) |
39 | - local capsule = capsules[capsuleId] or {} | 54 | + local capsule = capsules[capsuleId] |
55 | + if not capsule then print("not capsule :" .. capsuleId) return end | ||
56 | + | ||
40 | local register = capsule:getProperty("register") or {} | 57 | local register = capsule:getProperty("register") or {} |
41 | if next(capsule) then | 58 | if next(capsule) then |
42 | for id, _ in pairs(register) do | 59 | for id, _ in pairs(register) do |
@@ -47,25 +64,39 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) | @@ -47,25 +64,39 @@ function broadCastCapsule(roleId, capsuleId, broadInfo) | ||
47 | end | 64 | end |
48 | end | 65 | end |
49 | 66 | ||
50 | -local function getCapsuleId(id, room) | ||
51 | - return string.format("%d%d", id, room) | ||
52 | -end | 67 | +function broadCastSpecial(roleId, capsuleId, broadInfo) |
68 | + if not broadInfo or not next(broadInfo) then return end | ||
69 | + local capsule = capsules[capsuleId] | ||
70 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return end | ||
53 | 71 | ||
72 | + local register = capsule:getProperty("register") or {} | ||
73 | + for id, _ in pairs(register) do | ||
74 | + if id ~= roleId then | ||
75 | + if broadInfo[id] then | ||
76 | + rpcRole(id, "paySpecialReward", id, broadInfo[id]) | ||
77 | + end | ||
78 | + end | ||
79 | + end | ||
80 | +end | ||
54 | 81 | ||
55 | local function add(roleId, capsuleId) | 82 | local function add(roleId, capsuleId) |
56 | - local capsule = capsules[capsuleId] or {} | 83 | + local capsule = capsules[capsuleId] |
84 | + if not capsule then skynet.error("add not capsule: " .. capsuleId) return end | ||
57 | if next(capsule) then | 85 | if next(capsule) then |
58 | capsule:join(roleId) | 86 | capsule:join(roleId) |
59 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.JOIN, roleId = roleId}) | 87 | + broadCastCapsule(roleId, capsuleId, {notifyType= NotifyChangeType.JOIN, roleId = roleId}) |
60 | return capsule:data(roleId) | 88 | return capsule:data(roleId) |
61 | end | 89 | end |
62 | print("id 不存在: ".. capsuleId) | 90 | print("id 不存在: ".. capsuleId) |
63 | return nil | 91 | return nil |
64 | end | 92 | end |
65 | 93 | ||
66 | -local function capsuleRefreshing() | 94 | +local function capsuleRefreshing(now) |
67 | for _, v in pairs(capsules) do | 95 | for _, v in pairs(capsules) do |
68 | - if v:refreshing() then | 96 | + if v:refreshing(now) then |
97 | + print("刷新机器looooook....") | ||
98 | + print(v:getProperty("id")) | ||
99 | + print(v:getProperty("room")) | ||
69 | v:init() | 100 | v:init() |
70 | v:create() | 101 | v:create() |
71 | end | 102 | end |
@@ -74,8 +105,31 @@ end | @@ -74,8 +105,31 @@ end | ||
74 | 105 | ||
75 | --扭蛋机刷新 | 106 | --扭蛋机刷新 |
76 | local function check_capsules() | 107 | local function check_capsules() |
77 | - pcall(capsuleRefreshing) | ||
78 | - skynet.timeout(60, check_capsules) | 108 | + local now = skynet.timex() |
109 | + pcall(capsuleRefreshing, now) | ||
110 | + skynet.timeout(100, check_capsules) | ||
111 | +end | ||
112 | + | ||
113 | +function CMD.reset() | ||
114 | + local now = skynet.timex() | ||
115 | + local res = redisproxy:smembers(CAPSULE_INFO) or {} | ||
116 | + for _, key in pairs(res) do | ||
117 | + redisproxy:del(CAPSULE_PUBLIC:format(key)) | ||
118 | + redisproxy:srem(CAPSULE_INFO, key) | ||
119 | + end | ||
120 | + | ||
121 | + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do | ||
122 | + for _, val in ipairs(data) do | ||
123 | + if val.type == 1 then | ||
124 | + local key = val.id..val.room | ||
125 | + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name}) | ||
126 | + capsule:init() | ||
127 | + capsule:create() | ||
128 | + capsules[key] = capsule | ||
129 | + redisproxy:sadd(CAPSULE_INFO, key) | ||
130 | + end | ||
131 | + end | ||
132 | + end | ||
79 | end | 133 | end |
80 | 134 | ||
81 | function CMD.start() | 135 | function CMD.start() |
@@ -101,11 +155,14 @@ function CMD.start() | @@ -101,11 +155,14 @@ function CMD.start() | ||
101 | if val.type == 1 then | 155 | if val.type == 1 then |
102 | local key = val.id..val.room | 156 | local key = val.id..val.room |
103 | if not capsules[key] then | 157 | if not capsules[key] then |
104 | - local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name}) | ||
105 | - capsule:init() | ||
106 | - capsule:create() | ||
107 | - capsules[key] = capsule | ||
108 | - redisproxy:sadd(CAPSULE_INFO, key) | 158 | + if now < val.hide_time then |
159 | + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name}) | ||
160 | + capsule:init() | ||
161 | + capsule:create() | ||
162 | + | ||
163 | + capsules[key] = capsule | ||
164 | + redisproxy:sadd(CAPSULE_INFO, key) | ||
165 | + end | ||
109 | end | 166 | end |
110 | end | 167 | end |
111 | end | 168 | end |
@@ -114,10 +171,10 @@ function CMD.start() | @@ -114,10 +171,10 @@ function CMD.start() | ||
114 | check_capsules() | 171 | check_capsules() |
115 | end | 172 | end |
116 | 173 | ||
117 | -function CMD.list(coin) | 174 | +function CMD.list(id) |
118 | local tmpCapsules = {} | 175 | local tmpCapsules = {} |
119 | for k, v in pairs(capsules) do | 176 | for k, v in pairs(capsules) do |
120 | - if v:getProperty("coin") == coin then | 177 | + if v:getProperty("id") == id then |
121 | local onlineCount= v:getOnlineCount() | 178 | local onlineCount= v:getOnlineCount() |
122 | tmpCapsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")} | 179 | tmpCapsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")} |
123 | end | 180 | end |
@@ -135,39 +192,74 @@ end | @@ -135,39 +192,74 @@ end | ||
135 | 192 | ||
136 | function CMD.exit(roleId, capsuleId) | 193 | function CMD.exit(roleId, capsuleId) |
137 | if capsuleId then | 194 | if capsuleId then |
138 | - local capsule = capsules[capsuleId] or {} | ||
139 | - if next(capsule) then | ||
140 | - capsule:exit(roleId) | ||
141 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | ||
142 | - end | 195 | + local capsule = capsules[capsuleId] |
196 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return end | ||
197 | + | ||
198 | + capsule:exit(roleId) | ||
199 | + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) | ||
143 | else | 200 | else |
144 | - for _, capsule in pairs(capsules) do | 201 | + for id, capsule in pairs(capsules) do |
145 | if next(capsule) then | 202 | if next(capsule) then |
146 | capsule:exit(roleId) | 203 | capsule:exit(roleId) |
147 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | 204 | + broadCastCapsule(roleId, id, {notifyType = NotifyChangeType.EXIT, roleId = roleId}) |
148 | end | 205 | end |
149 | end | 206 | end |
150 | end | 207 | end |
151 | end | 208 | end |
152 | 209 | ||
153 | -function CMD.draw_capsule(roleId, capsuleId, full, cares) | ||
154 | - local capsule = capsules[capsuleId] or {} | ||
155 | - if next(capsule) then | ||
156 | - local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, cares) | ||
157 | - --if ret > 4 then | ||
158 | - -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) | ||
159 | - --end | ||
160 | - return ret, reward, rewardByGoods, capsule:data(roleId) | 210 | +function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares) |
211 | + local capsule = capsules[capsuleId] | ||
212 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return 2 end | ||
213 | + | ||
214 | + local ret, drawReward = capsule:draw(roleId, full, drawsNum, cares) | ||
215 | + if ret > 5 then | ||
216 | + --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify}) | ||
217 | + broadCastSpecial(roleId, capsuleId, drawReward["specials"]) | ||
161 | end | 218 | end |
162 | - return 1 | 219 | + drawReward["specials"] = nil |
220 | + return ret, drawReward, capsule:data(roleId) | ||
163 | end | 221 | end |
164 | 222 | ||
165 | function CMD.register(roleId, capsuleId) | 223 | function CMD.register(roleId, capsuleId) |
166 | - local capsule = capsules[capsuleId] or {} | ||
167 | - if next(capsule) then | ||
168 | - return capsule:register(roleId) | ||
169 | - end | ||
170 | - return nil | 224 | + local capsule = capsules[capsuleId] |
225 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | ||
226 | + | ||
227 | + return capsule:register(roleId) | ||
228 | +end | ||
229 | + | ||
230 | +function CMD.goods_stock(capsuleId) | ||
231 | + local capsule = capsules[capsuleId] | ||
232 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return 0 end | ||
233 | + | ||
234 | + return capsule:getGoodsAmount(), capsule:getProperty("token") | ||
235 | +end | ||
236 | + | ||
237 | +function CMD.capsule_data(roleId, capsuleId) | ||
238 | + local capsule = capsules[capsuleId] | ||
239 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | ||
240 | + | ||
241 | + return capsule:data(roleId) | ||
242 | +end | ||
243 | + | ||
244 | +function CMD.page_record(capsuleId, up, idx) | ||
245 | + local capsule = capsules[capsuleId] | ||
246 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | ||
247 | + | ||
248 | + return capsule:pageRecord(up, idx) | ||
249 | +end | ||
250 | + | ||
251 | +function CMD.get_special_nty(roleId, capsuleId) | ||
252 | + local capsule = capsules[capsuleId] | ||
253 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | ||
254 | + | ||
255 | + return capsule:getSpecialNotify(roleId) | ||
256 | +end | ||
257 | + | ||
258 | +function CMD.clear_special_nty(roleId, capsuleId, good_ids) | ||
259 | + local capsule = capsules[capsuleId] | ||
260 | + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end | ||
261 | + | ||
262 | + return capsule:clearSpecialNty(roleId, good_ids) | ||
171 | end | 263 | end |
172 | 264 | ||
173 | skynet.start(function() | 265 | skynet.start(function() |
src/services/watchdog.lua
@@ -56,7 +56,7 @@ end | @@ -56,7 +56,7 @@ end | ||
56 | 56 | ||
57 | -- 创建world以及union channel 用于广播 | 57 | -- 创建world以及union channel 用于广播 |
58 | function create_mutilcast() | 58 | function create_mutilcast() |
59 | - for i = 1, 10 do | 59 | + for i = 1, 50 do |
60 | local chan_w = mc:new() | 60 | local chan_w = mc:new() |
61 | datacenter.set("MC_W_CHANNEL" .. i, chan_w.channel) | 61 | datacenter.set("MC_W_CHANNEL" .. i, chan_w.channel) |
62 | end | 62 | end |