Commit d10a9a364f5bc6b0ce50b8872a6de7e77fbe90df
1 parent
f382b4f2
fix: 一番赏增加通知信息的数据结构,掉线往capsule服务发送退出指令
1. 确定通知信息的数据结构 2. 奖励还是k=v形式 3. 掉线发送exit协议
Showing
4 changed files
with
279 additions
and
281 deletions
Show diff stats
src/actions/CapsuleAction.lua
@@ -96,11 +96,11 @@ function _M.drawRpc(agent, data) | @@ -96,11 +96,11 @@ function _M.drawRpc(agent, data) | ||
96 | local full = msg.full -- 0=单次,1=十连抽 2=全收 | 96 | local full = msg.full -- 0=单次,1=十连抽 2=全收 |
97 | local cares = msg.cares | 97 | local cares = msg.cares |
98 | 98 | ||
99 | - local ret, reward, change | 99 | + local ret, reward, change, capsule |
100 | if typ == 1 then | 100 | if typ == 1 then |
101 | - ret, reward = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) | 101 | + ret, reward, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) |
102 | else | 102 | else |
103 | - ret, reward = role:drawCapsule(capsuleId, full, cares) | 103 | + ret, reward, capsule= role:drawCapsule(capsuleId, full, cares) |
104 | end | 104 | end |
105 | if ret < 4 then | 105 | if ret < 4 then |
106 | return ret | 106 | return ret |
@@ -110,9 +110,9 @@ function _M.drawRpc(agent, data) | @@ -110,9 +110,9 @@ function _M.drawRpc(agent, data) | ||
110 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) | 110 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) |
111 | end | 111 | end |
112 | 112 | ||
113 | - reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = capsuleId, int2 = roleId}}) | 113 | + reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) |
114 | dump(reward) | 114 | dump(reward) |
115 | - SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(role:packReward(reward, change))) | 115 | + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = reward, change= change, capsule = capsule})) |
116 | return true | 116 | return true |
117 | end | 117 | end |
118 | 118 |
src/agent.lua
@@ -283,6 +283,8 @@ function CMD.close() | @@ -283,6 +283,8 @@ function CMD.close() | ||
283 | mcast_util.usub_union() | 283 | mcast_util.usub_union() |
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 | + | ||
287 | + skynet.call(agent.capsule_serv, "lua", "exit", role:getProperty("id")) | ||
286 | role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")}) | 288 | role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")}) |
287 | role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) | 289 | role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) |
288 | role:onOfflineEvent() | 290 | role:onOfflineEvent() |
src/models/Capsule.lua
@@ -6,15 +6,18 @@ function Capsule:ctor(properties) | @@ -6,15 +6,18 @@ function Capsule:ctor(properties) | ||
6 | Capsule.super.ctor(self, properties) | 6 | Capsule.super.ctor(self, properties) |
7 | end | 7 | end |
8 | 8 | ||
9 | -RewardTYpe = { | ||
10 | - GOODS = 0, | 9 | +RewardType = { |
10 | + GOODS = 1, | ||
11 | + SPECIAL = 2, | ||
12 | + INCENTIVE = 3, | ||
13 | +} | ||
14 | + | ||
15 | +SpecialType = { | ||
11 | TOP = 1, | 16 | TOP = 1, |
12 | CORE = 2, | 17 | CORE = 2, |
13 | LAST = 3, | 18 | LAST = 3, |
14 | JOKER = 4, | 19 | JOKER = 4, |
15 | KING = 5, | 20 | KING = 5, |
16 | - GOOD = 6, | ||
17 | - INCENTIVE = 7, | ||
18 | } | 21 | } |
19 | 22 | ||
20 | CapsuleType = { | 23 | CapsuleType = { |
@@ -22,10 +25,22 @@ CapsuleType = { | @@ -22,10 +25,22 @@ CapsuleType = { | ||
22 | PUBLIC = 1, | 25 | PUBLIC = 1, |
23 | } | 26 | } |
24 | 27 | ||
28 | +--[[ | ||
29 | +--通知数据结构 | ||
30 | +{ | ||
31 | +[roleId] = { | ||
32 | + [good_id1] = { | ||
33 | + }, | ||
34 | + [good_id2] = { | ||
35 | + }, | ||
36 | +} | ||
37 | +} | ||
38 | +]]-- | ||
39 | + | ||
25 | Capsule.schema = { | 40 | Capsule.schema = { |
26 | id = {"number", 0}, --扭蛋机key,配置读取 | 41 | id = {"number", 0}, --扭蛋机key,配置读取 |
27 | room = {"number", 0}, --房间号, 配置读取 | 42 | room = {"number", 0}, --房间号, 配置读取 |
28 | - name = {"string", 0}, | 43 | + name = {"string"}, |
29 | typ = {"number", 1}, -- 1=共享,2=独享 | 44 | typ = {"number", 1}, -- 1=共享,2=独享 |
30 | coin = {"number", 0}, --货币代号 | 45 | coin = {"number", 0}, --货币代号 |
31 | register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 | 46 | register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 |
@@ -35,8 +50,8 @@ Capsule.schema = { | @@ -35,8 +50,8 @@ Capsule.schema = { | ||
35 | goods = {"table", {}}, --奖励池 | 50 | goods = {"table", {}}, --奖励池 |
36 | specials = {"table", {}}, --特殊赏 | 51 | specials = {"table", {}}, --特殊赏 |
37 | incentive = {"table", {}}, --激励奖 | 52 | incentive = {"table", {}}, --激励奖 |
38 | - specialsFlag= {"table", {}}, --特殊赏是否已经领取 | ||
39 | - resetInfo = {"table", {}}, | 53 | + incentiveRecord = {"table", {}}, --激励奖记录 |
54 | + specialsRecord= {"table", {}}, --特殊赏领取记录 | ||
40 | resetTimes = {"number", 0}, --每日一次手动重置的机会 | 55 | resetTimes = {"number", 0}, --每日一次手动重置的机会 |
41 | hideTime = {"number", 0} , --隐藏时间 | 56 | hideTime = {"number", 0} , --隐藏时间 |
42 | drawEndTime = {"number", 0}, --抽完时间 | 57 | drawEndTime = {"number", 0}, --抽完时间 |
@@ -100,8 +115,7 @@ function Capsule:getResetFields() | @@ -100,8 +115,7 @@ function Capsule:getResetFields() | ||
100 | goods = {}, | 115 | goods = {}, |
101 | specials = {}, | 116 | specials = {}, |
102 | incentive = {}, | 117 | incentive = {}, |
103 | - specialsFlag= {}, | ||
104 | - resetInfo = {}, | 118 | + specialsRecord= {}, |
105 | resetTimes = 0, | 119 | resetTimes = 0, |
106 | } | 120 | } |
107 | end | 121 | end |
@@ -123,7 +137,7 @@ function Capsule:init() | @@ -123,7 +137,7 @@ function Capsule:init() | ||
123 | end | 137 | end |
124 | end | 138 | end |
125 | end | 139 | end |
126 | - for _, v in ipairs(goods) do | 140 | + for _, v in pairs(goods) do |
127 | v.weight = (v.weight or 0) * v.amount | 141 | v.weight = (v.weight or 0) * v.amount |
128 | end | 142 | end |
129 | 143 | ||
@@ -237,7 +251,7 @@ end | @@ -237,7 +251,7 @@ end | ||
237 | function Capsule:getGoodsAmount() | 251 | function Capsule:getGoodsAmount() |
238 | local goods = self:getProperty("goods") or {} | 252 | local goods = self:getProperty("goods") or {} |
239 | local amount = 0 | 253 | local amount = 0 |
240 | - for _, v in ipairs(goods) do | 254 | + for _, v in pairs(goods) do |
241 | amount = amount + v.amount | 255 | amount = amount + v.amount |
242 | end | 256 | end |
243 | return amount | 257 | return amount |
@@ -253,74 +267,89 @@ function Capsule:getSpecialByType(typ) | @@ -253,74 +267,89 @@ function Capsule:getSpecialByType(typ) | ||
253 | return nil | 267 | return nil |
254 | end | 268 | end |
255 | 269 | ||
256 | -function Capsule:getTop(record) | ||
257 | - local specialsFlag = self:getProperty("specialsFlag") or {} | ||
258 | - if specialsFlag[RewardTYpe.TOP] then return nil end | ||
259 | - | ||
260 | - local specials = self:getProperty("specials") or {} | ||
261 | - local spKey, special = self:getSpecialByType(RewardTYpe.TOP) | 270 | +function Capsule:checkSpecialFlag(typ) |
271 | + local spKey, special = self:getSpecialByType(typ) | ||
262 | if not special then return nil end | 272 | if not special then return nil end |
263 | 273 | ||
264 | - local np = special["np"] | ||
265 | - if #record >= special["np"] then | ||
266 | - local topRecord = {} | ||
267 | - local count = np | ||
268 | - for _, v in ipairs(record) do | ||
269 | - if count <= 0 then break end | 274 | + if special["amount"] <= 0 then return nil end |
275 | + return spKey, special | ||
276 | +end | ||
270 | 277 | ||
271 | - local tmpCount = 0 | ||
272 | - if count >= v.amount then | ||
273 | - count = count - v.amount | ||
274 | - tmpCount = v.amount | ||
275 | - else | ||
276 | - tmpCount = count | ||
277 | - count = 0 | ||
278 | - end | 278 | +local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
279 | + local rewardByRole = {} | ||
280 | + while(count > 0 and next(rewardRecord)) do | ||
281 | + local roleId = math.randWeight(rewardRecord, "amount") | ||
282 | + if roleId then | ||
283 | + local tmp = rewardRecord[roleId] | ||
284 | + tmp["amount"] = tmp["amount"] - 1 | ||
285 | + | ||
286 | + if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end | ||
279 | 287 | ||
280 | - if not topRecord[v.role_id]then | ||
281 | - topRecord[v.role_id] = {amount = v.amount } | 288 | + tmp = rewardByRole[roleId] |
289 | + if not tmp then | ||
290 | + tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | ||
282 | else | 291 | else |
283 | - topRecord[v.role_id] = {amount = (topRecord[v.rol_id]["amount"] or 0) + tmpCount} | 292 | + if not tmp[spKey] then |
293 | + tmp[spKey] = {good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} | ||
294 | + else | ||
295 | + tmp[spKey].amount = tmp[spKey].amount + 1 | ||
296 | + end | ||
284 | end | 297 | end |
285 | - end | 298 | + rewardByRole[roleId] = tmp |
286 | 299 | ||
287 | - count = special["amount"] | ||
288 | - local topRoleIds = {} | ||
289 | - while(count > 0 and next(topRecord)) do | ||
290 | - local roleId = math.randWeight(topRecord, "amount") | ||
291 | - if roleId then | ||
292 | - table.insert(topRoleIds, roleId) | ||
293 | - local tmpTopRecord = topRecord[roleId] | ||
294 | - tmpTopRecord["amount"] = tmpTopRecord["amount"] - 1 | 300 | + count = count - 1 |
301 | + end | ||
302 | + end | ||
303 | + return rewardByRole, count | ||
304 | +end | ||
295 | 305 | ||
296 | - if tmpTopRecord["amount"] <= 0 then topRecord[roleId] = nil end | 306 | +function Capsule:getTop(record) |
307 | + local spKey, special = self:checkSpecialFlag(SpecialType.TOP) | ||
308 | + if not special then return nil end | ||
309 | + local specials = self:getProperty("specials") or {} | ||
310 | + local specialsRecord = self:getProperty("specialsRecord") or {} | ||
297 | 311 | ||
298 | - count = count - 1 | ||
299 | - end | 312 | + if #record < special["np"] then return nil end |
313 | + local topRecord = {} | ||
314 | + local count = special["np"] | ||
315 | + for _, v in ipairs(record) do | ||
316 | + if count <= 0 then break end | ||
300 | 317 | ||
318 | + local tmpCount = 0 | ||
319 | + if count >= v.amount then | ||
320 | + count = count - v.amount | ||
321 | + tmpCount = v.amount | ||
322 | + else | ||
323 | + tmpCount = count | ||
324 | + count = 0 | ||
301 | end | 325 | end |
302 | 326 | ||
303 | - special["amount"] = count | ||
304 | - specials[spKey] = special | ||
305 | - specialsFlag[RewardTYpe.TOP] = topRoleIds | ||
306 | - self:setProperty("specialsFlag", specialsFlag) | ||
307 | - self:setProperty("specials", specials) | ||
308 | - return {role_ids = topRoleIds, award = sspecial["award"]} | 327 | + if not topRecord[v.roleId]then |
328 | + topRecord[v.roleId] = {amount = v.amount } | ||
329 | + else | ||
330 | + topRecord[v.roleId] = {amount = (topRecord[v.roleId]["amount"] or 0) + tmpCount} | ||
331 | + end | ||
309 | end | 332 | end |
310 | 333 | ||
311 | - return nil | 334 | + local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP) |
335 | + | ||
336 | + special["amount"] = count | ||
337 | + specials[spKey] = special | ||
338 | + specialsRecord[SpecialType.TOP] = rewardByRole | ||
339 | + self:setProperties({specialsRecord = specialsRecord, specials = specials}) | ||
340 | + return rewardByRole | ||
341 | + | ||
312 | end | 342 | end |
313 | 343 | ||
314 | --TODO | 344 | --TODO |
315 | function Capsule:getCore(record) | 345 | function Capsule:getCore(record) |
316 | - if self:getGoodsAmount() > 0 then return nil end | ||
317 | - | ||
318 | - local specialsFlag = self:getProperty("specialsFlag") or {} | ||
319 | - if specialsFlag[RewardTYpe.CORE] then return nil end | 346 | + local spKey, special = self:checkSpecialFlag(SpecialType.CORE) |
347 | + if not special then return nil end | ||
320 | 348 | ||
321 | local specials = self:getProperty("specials") or {} | 349 | local specials = self:getProperty("specials") or {} |
322 | - local spKey, special = self:getSpecialByType(RewardTYpe.CORE) | ||
323 | - if not special then return nil end | 350 | + local specialsRecord = self:getProperty("specialsRecord") or {} |
351 | + | ||
352 | + if self:getGoodsAmount() > 0 then return nil end | ||
324 | 353 | ||
325 | local np = special["np"] | 354 | local np = special["np"] |
326 | if np > #record then return nil end | 355 | if np > #record then return nil end |
@@ -341,54 +370,38 @@ function Capsule:getCore(record) | @@ -341,54 +370,38 @@ function Capsule:getCore(record) | ||
341 | count = 0 | 370 | count = 0 |
342 | end | 371 | end |
343 | 372 | ||
344 | - if not roleRecord[v.role_id]then | ||
345 | - roleRecord[v.role_id] = {amount = v.amount } | 373 | + if not roleRecord[v.roleId]then |
374 | + roleRecord[v.roleId] = {amount = v.amount } | ||
346 | else | 375 | else |
347 | - roleRecord[v.role_id] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} | 376 | + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} |
348 | end | 377 | end |
349 | end | 378 | end |
350 | 379 | ||
351 | end | 380 | end |
352 | 381 | ||
353 | - count = special["amount"] | ||
354 | - local roleIds = {} | ||
355 | - while(count > 0 and next(roleRecord)) do | ||
356 | - local roleId = math.randWeight(roleRecord, "amount") | ||
357 | - if roleId then | ||
358 | - table.insert(roleIds, roleId) | ||
359 | - local tmpLastRecord = roleRecord[roleId] | ||
360 | - tmpLastRecord["amount"] = tmpLastRecord["amount"] - 1 | ||
361 | - | ||
362 | - if tmpLastRecord["amount"] <= 0 then roleRecord[roleId] = nil end | 382 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.CORE) |
363 | 383 | ||
364 | - count = count - 1 | ||
365 | - end | ||
366 | - end | ||
367 | special["amount"] = count | 384 | special["amount"] = count |
368 | specials[spKey] = special | 385 | specials[spKey] = special |
369 | - specialsFlag[RewardTYpe.CORE] = roleIds | ||
370 | - self:setProperty("specialsFlag", specialsFlag) | ||
371 | - self:setProperty("specials", specials) | ||
372 | - return {role_ids = roleIds, award = special["award"]} | 386 | + specialsRecord[SpecialType.CORE] = rewardByRole |
387 | + self:setProperties({specialsRecord = specialsRecord, specials = specials}) | ||
388 | + return rewardByRole | ||
373 | end | 389 | end |
374 | 390 | ||
375 | function Capsule:getLast(record) | 391 | function Capsule:getLast(record) |
376 | - if self:getGoodsAmount() > 0 then return nil end | ||
377 | - | ||
378 | - local specialsFlag = self:getProperty("specialsFlag") or {} | ||
379 | - if specialsFlag[RewardTYpe.LAST] then return nil end | 392 | + local spKey, special = self:checkSpecialFlag(SpecialType.LAST) |
393 | + if not special then return nil end | ||
380 | 394 | ||
381 | local specials = self:getProperty("specials") or {} | 395 | local specials = self:getProperty("specials") or {} |
382 | - local spKey, special = self:getSpecialByType(RewardTYpe.LAST) | ||
383 | - if not special then return nil end | 396 | + local specialsRecord = self:getProperty("specialsRecord") or {} |
384 | 397 | ||
385 | - if not next(record) then return nil end | ||
386 | - table.sort(record, function(a, b) return a.create_time > b.create_time end) | 398 | + if self:getGoodsAmount() > 0 then return nil end |
387 | 399 | ||
400 | + table.sort(record, function(a, b) return a.create_time > b.create_time end) | ||
388 | 401 | ||
389 | local np = special["np"] | 402 | local np = special["np"] |
390 | local count = np | 403 | local count = np |
391 | - local lastRecord = {} | 404 | + local roleRecord = {} |
392 | for _, v in ipairs(record) do | 405 | for _, v in ipairs(record) do |
393 | if count <= 0 then break end | 406 | if count <= 0 then break end |
394 | 407 | ||
@@ -401,174 +414,130 @@ function Capsule:getLast(record) | @@ -401,174 +414,130 @@ function Capsule:getLast(record) | ||
401 | count = 0 | 414 | count = 0 |
402 | end | 415 | end |
403 | 416 | ||
404 | - if not lastRecord[v.role_id]then | ||
405 | - lastRecord[v.role_id] = {amount = v.amount } | 417 | + if not roleRecord[v.roleId]then |
418 | + roleRecord[v.roleId] = {amount = v.amount } | ||
406 | else | 419 | else |
407 | - lastRecord[v.role_id] = {amount = (lastRecord[v.rol_id]["amount"] or 0) + tmpCount} | 420 | + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} |
408 | end | 421 | end |
409 | end | 422 | end |
410 | 423 | ||
411 | - count = special["amount"] | ||
412 | - local lastRoleIds = {} | ||
413 | - while(count > 0 and next(lastRecord)) do | ||
414 | - local roleId = math.randWeight(lastRecord, "amount") | ||
415 | - if roleId then | ||
416 | - table.insert(lastRoleIds, roleId) | ||
417 | - local tmpLastRecord = lastRecord[roleId] | ||
418 | - tmpLastRecord["amount"] = tmpLastRecord["amount"] - 1 | 424 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.LAST) |
419 | 425 | ||
420 | - if tmpLastRecord["amount"] <= 0 then lastRecord[roleId] = nil end | ||
421 | - | ||
422 | - count = count - 1 | ||
423 | - end | ||
424 | - end | ||
425 | special["amount"] = count | 426 | special["amount"] = count |
426 | specials[spKey] = special | 427 | specials[spKey] = special |
427 | - specialsFlag[RewardTYpe.LAST] = lastRoleIds | ||
428 | - self:setProperty("specialsFlag", specialsFlag) | ||
429 | - self:setProperty("specials", specials) | ||
430 | - return {role_ids = lastRoleIds, award = special["award"]} | 428 | + specialsRecord[SpecialType.LAST] = rewardByRole |
429 | + self:setProperties({specialsRecord = specialsRecord, specials = specials}) | ||
430 | + return rewardByRole | ||
431 | end | 431 | end |
432 | 432 | ||
433 | function Capsule:getJoker(record) | 433 | function Capsule:getJoker(record) |
434 | - if self:getGoodsAmount() > 0 then return nil end | ||
435 | - local specialsFlag = self:getProperty("specialsFlag") or {} | ||
436 | - if specialsFlag[RewardTYpe.JOKER] then return nil end | 434 | + local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) |
435 | + if not special then return nil end | ||
437 | 436 | ||
438 | local specials = self:getProperty("specials") or {} | 437 | local specials = self:getProperty("specials") or {} |
439 | - local spKey, special = self:getSpecialByType(RewardTYpe.JOKER) | ||
440 | - if not special then return nil end | 438 | + local specialsRecord = self:getProperty("specialsRecord") or {} |
439 | + | ||
440 | + if self:getGoodsAmount() > 0 then return nil end | ||
441 | 441 | ||
442 | local roleRecord = {} | 442 | local roleRecord = {} |
443 | for _, v in ipairs(record) do | 443 | for _, v in ipairs(record) do |
444 | - if not roleRecord[v.role_id]then | ||
445 | - roleRecord[v.role_id] = {amount = v.amount } | 444 | + if not roleRecord[v.roleId]then |
445 | + roleRecord[v.roleId] = {amount = v.amount } | ||
446 | else | 446 | else |
447 | - roleRecord[v.role_id] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | 447 | + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} |
448 | end | 448 | end |
449 | end | 449 | end |
450 | 450 | ||
451 | - local count = special["amount"] | ||
452 | - local roleIds = {} | ||
453 | - while(count > 0 and next(roleRecord)) do | ||
454 | - local roleId = math.randWeight(roleRecord, "amount") | ||
455 | - if roleId then | ||
456 | - table.insert(roleIds, roleId) | ||
457 | - local tmpRoleRecord = roleRecord[roleId] | ||
458 | - tmpRoleRecord["amount"] = tmpRoleRecord["amount"] - 1 | ||
459 | - | ||
460 | - if tmpRoleRecord["amount"] <= 0 then roleRecord[roleId] = nil end | 451 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.JOKER) |
461 | 452 | ||
462 | - count = count - 1 | ||
463 | - end | ||
464 | - end | ||
465 | special["amount"] = count | 453 | special["amount"] = count |
466 | specials[spKey] = special | 454 | specials[spKey] = special |
467 | - specialsFlag[RewardTYpe.JOKER] = roleIds | ||
468 | - self:setProperty("specialsFlag", specialsFlag) | ||
469 | - self:setProperty("specials", specials) | ||
470 | - return {role_ids = roleIds, award = special["award"]} | 455 | + specialsRecord[SpecialType.JOKER] = rewardByRole |
456 | + self:setProperties({specialsRecord = specialsRecord, specials = specials}) | ||
457 | + return rewardByRole | ||
471 | end | 458 | end |
472 | 459 | ||
473 | function Capsule:getKing(record) | 460 | function Capsule:getKing(record) |
474 | - if self:getGoodsAmount() > 0 then return nil end | ||
475 | - local specialsFlag = self:getProperty("specialsFlag") or {} | ||
476 | - if specialsFlag[RewardTYpe.JOKER] then return nil end | 461 | + local spKey, special = self:checkSpecialFlag(SpecialType.KING) |
462 | + if not special then return nil end | ||
477 | 463 | ||
478 | local specials = self:getProperty("specials") or {} | 464 | local specials = self:getProperty("specials") or {} |
479 | - local spKey, special = self:getSpecialByType(RewardTYpe.KING) | ||
480 | - if not special then return nil end | 465 | + local specialsRecord = self:getProperty("specialsRecord") or {} |
481 | 466 | ||
467 | + if self:getGoodsAmount() > 0 then return nil end | ||
482 | 468 | ||
483 | local roleRecord = {} | 469 | local roleRecord = {} |
484 | for _, v in ipairs(record) do | 470 | for _, v in ipairs(record) do |
485 | - if not roleRecord[v.role_id]then | ||
486 | - roleRecord[v.role_id] = {amount = v.amount } | 471 | + if not roleRecord[v.roleId]then |
472 | + roleRecord[v.roleId] = {amount = v.amount } | ||
487 | else | 473 | else |
488 | - roleRecord[v.role_id] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} | 474 | + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} |
489 | end | 475 | end |
490 | end | 476 | end |
491 | 477 | ||
492 | - local count = special["amount"] | ||
493 | - local roleIds = {} | ||
494 | - while(count > 0 and next(roleRecord)) do | ||
495 | - local roleId = math.randWeight(roleRecord, "amount") | ||
496 | - if roleId then | ||
497 | - table.insert(roleIds, roleId) | ||
498 | - local tmpRoleRecord = roleRecord[roleId] | ||
499 | - tmpRoleRecord["amount"] = tmpRoleRecord["amount"] - 1 | 478 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.KING) |
479 | + special["amount"] = count | ||
480 | + specials[spKey] = special | ||
481 | + specialsRecord[SpecialType.KING] = rewardByRole | ||
482 | + self:setProperties({specialsRecord = specialsRecord, specials = specials}) | ||
483 | + return rewardByRole | ||
484 | +end | ||
500 | 485 | ||
501 | - if tmpRoleRecord["amount"] <= 0 then roleRecord[roleId] = nil end | 486 | +local rewardToNtyFunc = function(notify, tmpReward) |
487 | + for key, val in pairs(tmpReward or {}) do | ||
488 | + if not notify[key] then | ||
489 | + notify[key] = val | ||
490 | + else | ||
491 | + for k, v in pairs(val) do | ||
492 | + if not notify[key][k] then | ||
493 | + notify[key][k] = v | ||
494 | + else | ||
495 | + notify[key][k] = notify[key][k].amount + v.amount | ||
496 | + end | ||
497 | + end | ||
502 | 498 | ||
503 | - count = count - 1 | ||
504 | end | 499 | end |
505 | end | 500 | end |
506 | - special["amount"] = count | ||
507 | - specials[spKey] = special | ||
508 | - specialsFlag[RewardTYpe.KING] = roleIds | ||
509 | - self:setProperty("specialsFlag", specialsFlag) | ||
510 | - self:setProperty("specials", specials) | ||
511 | - return {role_ids = roleIds, award = special["award"]} | ||
512 | end | 501 | end |
513 | 502 | ||
514 | - | ||
515 | -function Capsule:checkSpecialReward() | 503 | +function Capsule:checkSpecialReward( now) |
516 | local specials = self:getProperty("specials") or {} | 504 | local specials = self:getProperty("specials") or {} |
517 | if not next(specials) then return nil end | 505 | if not next(specials) then return nil end |
518 | local record = self:getProperty("record") or {} | 506 | local record = self:getProperty("record") or {} |
507 | + | ||
519 | if not next(record) then return nil end | 508 | if not next(record) then return nil end |
520 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) | 509 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) |
521 | - local notify = {} | ||
522 | 510 | ||
523 | - local topReward = self:getTop(record) | ||
524 | - if topReward then | ||
525 | - for _, roleId in ipairs(topReward.role_ids) do | ||
526 | - rpcRole(roleId, "paySpecialReward", RewardTYpe.TOP, topReward.award) | ||
527 | - table.insert(notify, {role_id = roleId, typ = RewardTYpe.TOP, award = topReward.award, amount = 1, create_time= skynet.timex()}) | ||
528 | - end | ||
529 | - end | 511 | + |
512 | + local notify = self:getTop(record) or {} | ||
530 | 513 | ||
531 | local coreReward = self:getCore(record) | 514 | local coreReward = self:getCore(record) |
532 | - if coreReward then | ||
533 | - for _, roleId in ipairs(topReward.role_ids) do | ||
534 | - rpcRole(roleId, "paySpecialReward", RewardTYpe.CORE, coreReward.award) | ||
535 | - table.insert(notify, {role_id = roleId, typ = RewardTYpe.CORE, award = topReward.award, amount = 1, create_time= skynet.timex()}) | ||
536 | - end | ||
537 | - end | 515 | + rewardToNtyFunc(notify, coreReward) |
516 | + | ||
538 | local lastReward = self:getLast(record) | 517 | local lastReward = self:getLast(record) |
539 | - if lastReward then | ||
540 | - for _, roleId in ipairs(lastReward.role_ids) do | ||
541 | - rpcRole(roleId, "paySpecialReward", RewardTYpe.LAST, lastReward.award) | ||
542 | - table.insert(notify, {role_id = roleId, typ = RewardTYpe.LAST, award = topReward.award, amount = 1, create_time= skynet.timex()}) | ||
543 | - end | ||
544 | - end | 518 | + rewardToNtyFunc(notify, lastReward) |
519 | + | ||
545 | local jokerReward = self:getJoker(record) | 520 | local jokerReward = self:getJoker(record) |
546 | - if jokerReward then | ||
547 | - for _, roleId in ipairs(jokerReward.role_ids) do | ||
548 | - rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) | ||
549 | - table.insert(notify, {role_id = roleId, typ = RewardTYpe.JOKER, award = topReward.award, amount = 1, create_time= skynet.timex()}) | ||
550 | - end | ||
551 | - end | 521 | + rewardToNtyFunc(notify, jokerReward) |
522 | + | ||
552 | local kingReward = self:getKing(record) | 523 | local kingReward = self:getKing(record) |
553 | - if kingReward then | ||
554 | - for _, roleId in ipairs(kingReward.role_ids) do | ||
555 | - rpcRole(roleId, "paySpecialReward", RewardTYpe.KING, kingReward.award) | ||
556 | - table.insert(notify, {role_id = roleId, typ = RewardTYpe.KING, award = topReward.award, amount = 1, create_time= skynet.timex()}) | ||
557 | - end | ||
558 | - end | 524 | + rewardToNtyFunc(notify, kingReward) |
559 | 525 | ||
526 | + --广播出去TODO | ||
527 | + --rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) | ||
560 | return notify | 528 | return notify |
561 | end | 529 | end |
562 | 530 | ||
563 | -function Capsule:checkIncentive(roleId) | 531 | +function Capsule:checkIncentive(roleId, now) |
564 | local goods = self:getProperty("goods") or {} | 532 | local goods = self:getProperty("goods") or {} |
565 | - local record = self:getProperty("record") or {} | ||
566 | local recordByRole = self:getProperty("recordByRole") or {} | 533 | local recordByRole = self:getProperty("recordByRole") or {} |
567 | local roleRecord = recordByRole[roleId] or {} | 534 | local roleRecord = recordByRole[roleId] or {} |
535 | + local incentiveRecord = self:getProperty("incentiveRecord") or {} | ||
536 | + local incentiveByRole = incentiveRecord[roleId] or {} | ||
568 | local incentive = self:getProperty("incentive") | 537 | local incentive = self:getProperty("incentive") |
569 | 538 | ||
570 | 539 | ||
571 | - local reward | 540 | + local notify = {} |
572 | -- 最后一抽 TODO | 541 | -- 最后一抽 TODO |
573 | if incentive["last"] then | 542 | if incentive["last"] then |
574 | local last = true | 543 | local last = true |
@@ -578,7 +547,9 @@ function Capsule:checkIncentive(roleId) | @@ -578,7 +547,9 @@ function Capsule:checkIncentive(roleId) | ||
578 | break | 547 | break |
579 | end | 548 | end |
580 | end | 549 | end |
581 | - reward = incentive["last"]["award"] | 550 | + if last then |
551 | + notify["last"] = {good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} | ||
552 | + end | ||
582 | end | 553 | end |
583 | 554 | ||
584 | --次数 | 555 | --次数 |
@@ -592,9 +563,7 @@ function Capsule:checkIncentive(roleId) | @@ -592,9 +563,7 @@ function Capsule:checkIncentive(roleId) | ||
592 | 563 | ||
593 | local count = math.floor(amount / incentive["amount"]["np"]) | 564 | local count = math.floor(amount / incentive["amount"]["np"]) |
594 | local tmpCount = count * incentive["amount"]["np"] | 565 | local tmpCount = count * incentive["amount"]["np"] |
595 | - for i=1, count do | ||
596 | - reward = reward.. " " .. incentive["amount"]["award"] | ||
597 | - end | 566 | + notify["amount"] = {good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} |
598 | 567 | ||
599 | --填充v.calculated 字段,标识已经用于每x抽的计算中。 | 568 | --填充v.calculated 字段,标识已经用于每x抽的计算中。 |
600 | for _, v in pairs(roleRecord) do | 569 | for _, v in pairs(roleRecord) do |
@@ -618,21 +587,15 @@ function Capsule:checkIncentive(roleId) | @@ -618,21 +587,15 @@ function Capsule:checkIncentive(roleId) | ||
618 | if incentive["probabilities"] then | 587 | if incentive["probabilities"] then |
619 | local probabilities = math.randomInt(1, 100) | 588 | local probabilities = math.randomInt(1, 100) |
620 | if probabilities <= incentive["probabilities"]["np"] then | 589 | if probabilities <= incentive["probabilities"]["np"] then |
621 | - reward = reward .. " " .. incentive["probabilities"]["award"] | 590 | + notify["probabilities"] = {good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} |
591 | + | ||
622 | end | 592 | end |
623 | end | 593 | end |
624 | - if reward and reward ~= "" then | ||
625 | - local tmpReward, notify = {}, {} | ||
626 | - for k, v in pairs(reward:toNumMap()) do | ||
627 | - tmpReward[k] = (tmpReward[k] or 0) + v | ||
628 | - end | 594 | + table.insert(incentiveByRole, notify) |
595 | + incentiveRecord[roleId] = incentiveByRole | ||
596 | + self:setProperty("incentiveRecord", incentiveRecord) | ||
629 | 597 | ||
630 | - notify = {role_id = roleId, typ = RewardTYpe.incentive, award = reward, amount = 1, create_time= skynet.timex()} | ||
631 | - table.insert(record, notify) | ||
632 | - self:setProperty("record", record) | ||
633 | - return tmpReward,notify | ||
634 | - end | ||
635 | - return nil, nil | 598 | + return notify |
636 | end | 599 | end |
637 | 600 | ||
638 | function Capsule:drawByCount(roleId, count) | 601 | function Capsule:drawByCount(roleId, count) |
@@ -641,61 +604,74 @@ function Capsule:drawByCount(roleId, count) | @@ -641,61 +604,74 @@ function Capsule:drawByCount(roleId, count) | ||
641 | local goods = self:getProperty("goods") or {} | 604 | local goods = self:getProperty("goods") or {} |
642 | local record = self:getProperty("record") or {} | 605 | local record = self:getProperty("record") or {} |
643 | local recordByRole = self:getProperty("recordByRole") or {} | 606 | local recordByRole = self:getProperty("recordByRole") or {} |
607 | + local roleRecord = recordByRole[roleId] or {} | ||
644 | 608 | ||
645 | local id = self:getProperty("id") | 609 | local id = self:getProperty("id") |
646 | local room = self:getProperty("room") | 610 | local room = self:getProperty("room") |
647 | local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] | 611 | local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] |
648 | local goods_id = ichibankuji["goods_id"] | 612 | local goods_id = ichibankuji["goods_id"] |
613 | + local now = skynet.timex() | ||
649 | 614 | ||
650 | --奖励, 通知信息 | 615 | --奖励, 通知信息 |
651 | - local reward, notify= {}, {} | 616 | + local notify= {} |
617 | + notify[roleId] = {} | ||
618 | + | ||
652 | while (goods and next(goods) and count > 0) do | 619 | while (goods and next(goods) and count > 0) do |
653 | local good_id = math.randWeight(goods, "weight") | 620 | local good_id = math.randWeight(goods, "weight") |
654 | if good_id then | 621 | if good_id then |
655 | local good = goods[good_id] or {} | 622 | local good = goods[good_id] or {} |
656 | - if good.amount > 0 then | 623 | + if good and good.amount > 0 then |
657 | good.amount = good.amount - 1 | 624 | good.amount = good.amount - 1 |
658 | - for k, v in pairs(good.award:toNumMap()) do | ||
659 | - reward[k] = (reward[k] or 0) + v | ||
660 | - end | ||
661 | 625 | ||
662 | --插入记录 | 626 | --插入记录 |
663 | - local tmpNotify = {role_id = roleId, good_id = good_id, typ = RewardTYpe.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= skynet.timex()} | ||
664 | - | 627 | + local tmpNotify = {good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} |
665 | table.insert(record, tmpNotify) | 628 | table.insert(record, tmpNotify) |
666 | - table.insert(notify, tmpNotify) | ||
667 | 629 | ||
668 | - --记录角色的抽奖记录 | ||
669 | - local tmp = recordByRole[roleId] | ||
670 | - if not tmp then | ||
671 | - recordByRole[roleId] = {good_id=notify} | 630 | + --作为奖励记录+通知 |
631 | + if not notify[roleId][good_id] then | ||
632 | + notify[roleId][good_id] = tmpNotify | ||
672 | else | 633 | else |
673 | - if not tmp[good_id] then | ||
674 | - tmp[good_id] = notify | ||
675 | - else | ||
676 | - tmp[good_id].amount = tmp[good_id].amount + 1 | ||
677 | - end | 634 | + notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 |
678 | end | 635 | end |
679 | 636 | ||
680 | - good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id].weight | 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 | ||
643 | + | ||
644 | + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight | ||
681 | count = count - 1 | 645 | count = count - 1 |
682 | end | 646 | end |
683 | end | 647 | end |
684 | 648 | ||
685 | end | 649 | end |
650 | + recordByRole[roleId] = roleRecord | ||
651 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | ||
686 | 652 | ||
687 | - self:setProperty("recordByRole", recordByRole) | ||
688 | - self:setProperty("record", record) | ||
689 | - self:setProperty("goods", goods) | ||
690 | - local incentiveReward, tmpNotify = self:checkIncentive(roleId) | ||
691 | - for k, v in pairs(incentiveReward or {}) do | ||
692 | - reward[k] = (reward[k] or 0) + v | 653 | + local tmpNotify = self:checkIncentive(roleId, 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 | ||
659 | + end | ||
693 | end | 660 | end |
694 | - if tmpNotify then table.insert(notify, tmpNotify) end | ||
695 | 661 | ||
696 | - local speciNotify = self:checkSpecialReward(roleId) | ||
697 | - if speciNotify and next(speciNotify) then table.insert(notify, speciNotify) end | 662 | + local speciNotify = self:checkSpecialReward(now) |
663 | + rewardToNtyFunc(notify, speciNotify) | ||
698 | 664 | ||
665 | + local reward = {} | ||
666 | + for key, val in pairs(notify) do | ||
667 | + if key == roleId then | ||
668 | + for _, 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 | + end | ||
673 | + end | ||
674 | + end | ||
699 | return reward, notify | 675 | return reward, notify |
700 | end | 676 | end |
701 | 677 | ||
@@ -703,55 +679,67 @@ function Capsule:drawAll(roleId) | @@ -703,55 +679,67 @@ function Capsule:drawAll(roleId) | ||
703 | local goods = self:getProperty("goods") or {} | 679 | local goods = self:getProperty("goods") or {} |
704 | local record = self:getProperty("record") or {} | 680 | local record = self:getProperty("record") or {} |
705 | local recordByRole = self:getProperty("recordByRole") or {} | 681 | local recordByRole = self:getProperty("recordByRole") or {} |
682 | + local roleRecord = recordByRole[roleId] or {} | ||
683 | + local now = skynet.timex() | ||
706 | 684 | ||
707 | - local reward, notify = {}, {} | 685 | + local notify = {} |
686 | + notify[roleId] = {} | ||
708 | for good_id, good in pairs(goods) do | 687 | for good_id, good in pairs(goods) do |
709 | - | ||
710 | if good.amount > 0 then | 688 | if good.amount > 0 then |
711 | - notify = {role_id = roleId, good_id = good_id, typ = RewardTYpe.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = skynet.timex()} | 689 | + --插入记录 |
690 | + local tmpNotify = {role_id = roleId, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} | ||
712 | table.insert(record, notify) | 691 | table.insert(record, notify) |
713 | 692 | ||
714 | - --记录角色的抽奖记录 | ||
715 | - local tmp = recordByRole[roleId] | ||
716 | - if not tmp then | ||
717 | - recordByRole[roleId] = {good_id=notify} | 693 | + --作为奖励记录+通知 |
694 | + if not notify[roleId][good_id] then | ||
695 | + notify[roleId][good_id] = tmpNotify | ||
718 | else | 696 | else |
719 | - if not tmp[good_id] then | ||
720 | - tmp[good_id] = notify | ||
721 | - else | ||
722 | - tmp[good_id].amount = tmp[good_id].amount + good.amount | ||
723 | - end | 697 | + notify[roleId][good_id].amount = notify[roleId][good_id].amount + good.award |
724 | end | 698 | end |
725 | - end | ||
726 | 699 | ||
727 | - while(good.amount > 0) do | ||
728 | - for k, v in pairs(good.award:toNumMap()) do | ||
729 | - reward[k] = (reward[k] or 0) + v | 700 | + --记录角色的抽奖记录 |
701 | + if not roleRecord[good_id] then | ||
702 | + roleRecord[good_id] = notify | ||
703 | + else | ||
704 | + roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount | ||
730 | end | 705 | end |
731 | - good.amount = good.amount - 1 | 706 | + |
707 | + good.amount = 0 | ||
732 | end | 708 | end |
733 | 709 | ||
734 | end | 710 | end |
711 | + recordByRole[roleId] = roleRecord | ||
712 | + self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) | ||
735 | 713 | ||
736 | - local incentiveReward, tmpNotify = self:checkIncentive(roleId) | ||
737 | - for k, v in pairs(incentiveReward or {}) do | ||
738 | - reward[k] = (reward[k] or 0) + v | 714 | + local tmpNotify = self:checkIncentive(roleId, now) |
715 | + for k, v in pairs(tmpNotify) do | ||
716 | + if not notify[roleId][k] then | ||
717 | + notify[roleId][k] = v | ||
718 | + else | ||
719 | + notify[roleId][k].amount = notify[roleId][k].amount + v.amount | ||
720 | + end | ||
739 | end | 721 | end |
740 | - if tmpNotify then table.insert(notify, tmpNotify) end | ||
741 | 722 | ||
742 | - local speciNotify = self:checkSpecialReward(roleId) | ||
743 | - if speciNotify and next(speciNotify) then table.insert(notify, speciNotify) end | 723 | + local speciNotify = self:checkSpecialReward(now) |
724 | + rewardToNtyFunc(notify, speciNotify) | ||
744 | 725 | ||
745 | - self:setProperty("recordByRole", recordByRole) | ||
746 | - self:setProperty("record", record) | ||
747 | - self:setProperty("goods", goods) | 726 | + local reward = {} |
727 | + for key, val in pairs(notify) do | ||
728 | + if key == roleId then | ||
729 | + for _, v in pairs(val) do | ||
730 | + for id, count in pairs(v.award:toNumMap()) do | ||
731 | + reward[id] = (reward[id] or 0) + count | ||
732 | + end | ||
733 | + end | ||
734 | + end | ||
735 | + end | ||
748 | return reward, notify | 736 | return reward, notify |
749 | end | 737 | end |
750 | 738 | ||
751 | --@param | 739 | --@param |
752 | --[[ | 740 | --[[ |
753 | @roleId | 741 | @roleId |
754 | -@typ 1=全收 0=单次 | 742 | +@typ 0=独享,1=公开 |
755 | @cares 关注{k=v} | 743 | @cares 关注{k=v} |
756 | ]]-- | 744 | ]]-- |
757 | 745 | ||
@@ -793,7 +781,7 @@ function Capsule:data(roleId) | @@ -793,7 +781,7 @@ function Capsule:data(roleId) | ||
793 | goods = self:getProperty("goods"), | 781 | goods = self:getProperty("goods"), |
794 | specials = self:getProperty("specials"), | 782 | specials = self:getProperty("specials"), |
795 | incentive = self:getProperty("incentive"), | 783 | incentive = self:getProperty("incentive"), |
796 | - specialsFlag= self:getProperty("specialsFlag"), | 784 | + specialsRecord= self:getProperty("specialsRecord"), |
797 | } | 785 | } |
798 | end | 786 | end |
799 | 787 |
src/services/capsuled.lua
@@ -3,7 +3,7 @@ require "shared.init" | @@ -3,7 +3,7 @@ require "shared.init" | ||
3 | require "GlobalVar" | 3 | require "GlobalVar" |
4 | require "RedisKeys" | 4 | require "RedisKeys" |
5 | require "skynet.manager" | 5 | require "skynet.manager" |
6 | -local skynet = require "skynet" | 6 | +skynet = require "skynet" |
7 | csvdb = require "shared.csvdata" | 7 | csvdb = require "shared.csvdata" |
8 | redisproxy = require "shared.redisproxy" | 8 | redisproxy = require "shared.redisproxy" |
9 | datacenter = require "skynet.datacenter" | 9 | datacenter = require "skynet.datacenter" |
@@ -56,7 +56,6 @@ end | @@ -56,7 +56,6 @@ end | ||
56 | 56 | ||
57 | 57 | ||
58 | local function add(roleId, capsuleId) | 58 | local function add(roleId, capsuleId) |
59 | - print(type(capsuleId)) | ||
60 | local capsule = capsules[capsuleId] or {} | 59 | local capsule = capsules[capsuleId] or {} |
61 | if next(capsule) then | 60 | if next(capsule) then |
62 | capsule:join(roleId) | 61 | capsule:join(roleId) |
@@ -86,7 +85,7 @@ function CMD.start() | @@ -86,7 +85,7 @@ function CMD.start() | ||
86 | local now = skynet.timex() | 85 | local now = skynet.timex() |
87 | local res = redisproxy:smembers(CAPSULE_INFO) or {} | 86 | local res = redisproxy:smembers(CAPSULE_INFO) or {} |
88 | for _, key in pairs(res) do | 87 | for _, key in pairs(res) do |
89 | - local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(tonumber(key))}) | 88 | + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key)}) |
90 | capsule:load() | 89 | capsule:load() |
91 | if capsule:isShow() then | 90 | if capsule:isShow() then |
92 | if capsule:refreshing(now) then | 91 | if capsule:refreshing(now) then |
@@ -95,7 +94,7 @@ function CMD.start() | @@ -95,7 +94,7 @@ function CMD.start() | ||
95 | end | 94 | end |
96 | capsules[key] = capsule | 95 | capsules[key] = capsule |
97 | else | 96 | else |
98 | - redisproxy:del(CAPSULE_PUBLIC:format(tonumber(key))) | 97 | + redisproxy:del(CAPSULE_PUBLIC:format(key)) |
99 | redisproxy:srem(CAPSULE_INFO, key) | 98 | redisproxy:srem(CAPSULE_INFO, key) |
100 | end | 99 | end |
101 | end | 100 | end |
@@ -103,9 +102,9 @@ function CMD.start() | @@ -103,9 +102,9 @@ function CMD.start() | ||
103 | for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do | 102 | for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do |
104 | for _, val in ipairs(data) do | 103 | for _, val in ipairs(data) do |
105 | if val.type == 1 then | 104 | if val.type == 1 then |
106 | - local key = string.format("%d%d", val.id, val.room) | 105 | + local key = val.id..val.room |
107 | if not capsules[key] then | 106 | if not capsules[key] then |
108 | - local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(tonumber(key)), id= val.id, room = val.room, typ = 1, name=val.name}) | 107 | + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name}) |
109 | capsule:init() | 108 | capsule:init() |
110 | capsule:create() | 109 | capsule:create() |
111 | capsules[key] = capsule | 110 | capsules[key] = capsule |
@@ -138,10 +137,19 @@ end | @@ -138,10 +137,19 @@ end | ||
138 | 137 | ||
139 | 138 | ||
140 | function CMD.exit(roleId, capsuleId) | 139 | function CMD.exit(roleId, capsuleId) |
141 | - local capsule = capsules[capsuleId] or {} | ||
142 | - if next(capsule) then | ||
143 | - capsule:exit(roleId) | ||
144 | - broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | 140 | + if capsuleId then |
141 | + local capsule = capsules[capsuleId] or {} | ||
142 | + if next(capsule) then | ||
143 | + capsule:exit(roleId) | ||
144 | + broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | ||
145 | + end | ||
146 | + else | ||
147 | + for _, capsule in pairs(capsules) do | ||
148 | + if next(capsule) then | ||
149 | + capsule:exit(roleId) | ||
150 | + broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.EXIT, roleId = roleId}) | ||
151 | + end | ||
152 | + end | ||
145 | end | 153 | end |
146 | end | 154 | end |
147 | 155 | ||
@@ -152,7 +160,7 @@ function CMD.draw_capsule(roleId, capsuleId, full, cares) | @@ -152,7 +160,7 @@ function CMD.draw_capsule(roleId, capsuleId, full, cares) | ||
152 | --if ret > 4 then | 160 | --if ret > 4 then |
153 | -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) | 161 | -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify}) |
154 | --end | 162 | --end |
155 | - return ret, reward | 163 | + return ret, reward, capsule:data(roleId) |
156 | end | 164 | end |
157 | return nil | 165 | return nil |
158 | end | 166 | end |