Commit 0a421d342a1a68103bde99e461cb7c95470ff137
1 parent
0eb317fb
fix: 一番赏奖励 刷新协议缺少roleId参数的bug
1. 修复刷新协议 2. goods id直接使用 配置表id
Showing
3 changed files
with
71 additions
and
47 deletions
Show diff stats
src/actions/CapsuleAction.lua
@@ -135,8 +135,8 @@ function _M.drawRpc(agent, data) | @@ -135,8 +135,8 @@ function _M.drawRpc(agent, data) | ||
135 | return ret | 135 | return ret |
136 | end | 136 | end |
137 | 137 | ||
138 | - dump(reward) | ||
139 | - dump(rewardByGoods) | 138 | + --dump(rewardByGoods) |
139 | + --dump(capsule) | ||
140 | 140 | ||
141 | if ret == 5 then | 141 | if ret == 5 then |
142 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule})) | 142 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule})) |
@@ -153,15 +153,16 @@ function _M.drawRpc(agent, data) | @@ -153,15 +153,16 @@ function _M.drawRpc(agent, data) | ||
153 | return true | 153 | return true |
154 | end | 154 | end |
155 | 155 | ||
156 | -function _M.getData(agent, data) | 156 | +function _M.getDataRpc(agent, data) |
157 | local role = agent.role | 157 | local role = agent.role |
158 | local msg = MsgPack.unpack(data) | 158 | local msg = MsgPack.unpack(data) |
159 | local capsuleId = msg.capsule_id | 159 | local capsuleId = msg.capsule_id |
160 | local typ = msg.typ --0=独享,1= 公开 | 160 | local typ = msg.typ --0=独享,1= 公开 |
161 | + local roleId = role:getProperty("id") | ||
161 | 162 | ||
162 | local capsule | 163 | local capsule |
163 | if typ == 1 then | 164 | if typ == 1 then |
164 | - capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", capsuleId) | 165 | + capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", roleId, capsuleId) |
165 | else | 166 | else |
166 | capsule = role:getCapsuleData(capsuleId) | 167 | capsule = role:getCapsuleData(capsuleId) |
167 | end | 168 | end |
src/models/Capsule.lua
@@ -86,7 +86,7 @@ function Capsule:init() | @@ -86,7 +86,7 @@ function Capsule:init() | ||
86 | for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do | 86 | for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do |
87 | for _, val in pairs(data) do | 87 | for _, val in pairs(data) do |
88 | if val.key == goods_id then | 88 | if val.key == goods_id then |
89 | - goods[goods_id..val.id] = clone(val) | 89 | + goods[goods_id] = clone(val) |
90 | end | 90 | end |
91 | end | 91 | end |
92 | end | 92 | end |
@@ -304,13 +304,41 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | @@ -304,13 +304,41 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) | ||
304 | return rewardByRole, count | 304 | return rewardByRole, count |
305 | end | 305 | end |
306 | 306 | ||
307 | -function Capsule:getTop(record) | 307 | + |
308 | +local rewardToNtyFunc = function(notify, tmpReward) | ||
309 | + for key, val in pairs(tmpReward or {}) do | ||
310 | + if not notify[key] then | ||
311 | + notify[key] = clone(val) | ||
312 | + else | ||
313 | + for k, v in pairs(val) do | ||
314 | + if not notify[key][k] then | ||
315 | + notify[key][k] = v | ||
316 | + else | ||
317 | + notify[key][k] = notify[key][k].amount + v.amount | ||
318 | + end | ||
319 | + end | ||
320 | + | ||
321 | + end | ||
322 | + end | ||
323 | +end | ||
324 | + | ||
325 | +local function getRecordAmount(record) | ||
326 | + local amount = 0 | ||
327 | + for _, v in ipairs(record) do | ||
328 | + amount = amount + v.amount | ||
329 | + end | ||
330 | + return amount | ||
331 | +end | ||
332 | + | ||
333 | + | ||
334 | +function Capsule:getTop(record, recordAmount,now) | ||
308 | local spKey, special = self:checkSpecialFlag(SpecialType.TOP) | 335 | local spKey, special = self:checkSpecialFlag(SpecialType.TOP) |
309 | if not special then return nil end | 336 | if not special then return nil end |
310 | local specials = self:getProperty("specials") or {} | 337 | local specials = self:getProperty("specials") or {} |
311 | local specialsRecord = self:getProperty("specialsRecord") or {} | 338 | local specialsRecord = self:getProperty("specialsRecord") or {} |
312 | 339 | ||
313 | - if #record < special["np"] then return nil end | 340 | + if recordAmount < special["np"] then return nil end |
341 | + | ||
314 | local topRecord = {} | 342 | local topRecord = {} |
315 | local count = special["np"] | 343 | local count = special["np"] |
316 | for _, v in ipairs(record) do | 344 | for _, v in ipairs(record) do |
@@ -332,18 +360,20 @@ function Capsule:getTop(record) | @@ -332,18 +360,20 @@ function Capsule:getTop(record) | ||
332 | end | 360 | end |
333 | end | 361 | end |
334 | 362 | ||
335 | - local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP) | 363 | + local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP,now) |
336 | 364 | ||
337 | special["amount"] = count | 365 | special["amount"] = count |
338 | specials[spKey] = special | 366 | specials[spKey] = special |
339 | - specialsRecord[SpecialType.TOP] = rewardByRole | 367 | + |
368 | + rewardToNtyFunc(specialsRecord, rewardByRole) | ||
369 | + | ||
340 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 370 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
341 | return rewardByRole | 371 | return rewardByRole |
342 | 372 | ||
343 | end | 373 | end |
344 | 374 | ||
345 | --TODO | 375 | --TODO |
346 | -function Capsule:getCore(record) | 376 | +function Capsule:getCore(record, recordAmount,now) |
347 | local spKey, special = self:checkSpecialFlag(SpecialType.CORE) | 377 | local spKey, special = self:checkSpecialFlag(SpecialType.CORE) |
348 | if not special then return nil end | 378 | if not special then return nil end |
349 | 379 | ||
@@ -353,10 +383,10 @@ function Capsule:getCore(record) | @@ -353,10 +383,10 @@ function Capsule:getCore(record) | ||
353 | if self:getGoodsAmount() > 0 then return nil end | 383 | if self:getGoodsAmount() > 0 then return nil end |
354 | 384 | ||
355 | local np = special["np"] | 385 | local np = special["np"] |
356 | - if np > #record then return nil end | 386 | + if np > recordAmount then return nil end |
357 | 387 | ||
358 | 388 | ||
359 | - local left = math.ceil((np - #record)/2) or 0 | 389 | + local left = math.ceil((np - recordAmount)/2) or 0 |
360 | local count = np | 390 | local count = np |
361 | local roleRecord = {} | 391 | local roleRecord = {} |
362 | for i, v in ipairs(record) do | 392 | for i, v in ipairs(record) do |
@@ -380,16 +410,17 @@ function Capsule:getCore(record) | @@ -380,16 +410,17 @@ function Capsule:getCore(record) | ||
380 | 410 | ||
381 | end | 411 | end |
382 | 412 | ||
383 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.CORE) | 413 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.CORE,now) |
384 | 414 | ||
385 | special["amount"] = count | 415 | special["amount"] = count |
386 | specials[spKey] = special | 416 | specials[spKey] = special |
387 | - specialsRecord[SpecialType.CORE] = rewardByRole | 417 | + |
418 | + rewardToNtyFunc(specialsRecord, rewardByRole) | ||
388 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 419 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
389 | return rewardByRole | 420 | return rewardByRole |
390 | end | 421 | end |
391 | 422 | ||
392 | -function Capsule:getLast(record) | 423 | +function Capsule:getLast(record,now) |
393 | local spKey, special = self:checkSpecialFlag(SpecialType.LAST) | 424 | local spKey, special = self:checkSpecialFlag(SpecialType.LAST) |
394 | if not special then return nil end | 425 | if not special then return nil end |
395 | 426 | ||
@@ -422,16 +453,17 @@ function Capsule:getLast(record) | @@ -422,16 +453,17 @@ function Capsule:getLast(record) | ||
422 | end | 453 | end |
423 | end | 454 | end |
424 | 455 | ||
425 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.LAST) | 456 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.LAST,now) |
426 | 457 | ||
427 | special["amount"] = count | 458 | special["amount"] = count |
428 | specials[spKey] = special | 459 | specials[spKey] = special |
429 | - specialsRecord[SpecialType.LAST] = rewardByRole | 460 | + |
461 | + rewardToNtyFunc(specialsRecord, rewardByRole) | ||
430 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 462 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
431 | return rewardByRole | 463 | return rewardByRole |
432 | end | 464 | end |
433 | 465 | ||
434 | -function Capsule:getJoker(record) | 466 | +function Capsule:getJoker(record,now) |
435 | local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) | 467 | local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) |
436 | if not special then return nil end | 468 | if not special then return nil end |
437 | 469 | ||
@@ -449,16 +481,17 @@ function Capsule:getJoker(record) | @@ -449,16 +481,17 @@ function Capsule:getJoker(record) | ||
449 | end | 481 | end |
450 | end | 482 | end |
451 | 483 | ||
452 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.JOKER) | 484 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.JOKER,now) |
453 | 485 | ||
454 | special["amount"] = count | 486 | special["amount"] = count |
455 | specials[spKey] = special | 487 | specials[spKey] = special |
456 | - specialsRecord[SpecialType.JOKER] = rewardByRole | 488 | + |
489 | + rewardToNtyFunc(specialsRecord, rewardByRole) | ||
457 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 490 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
458 | return rewardByRole | 491 | return rewardByRole |
459 | end | 492 | end |
460 | 493 | ||
461 | -function Capsule:getKing(record) | 494 | +function Capsule:getKing(record,now) |
462 | local spKey, special = self:checkSpecialFlag(SpecialType.KING) | 495 | local spKey, special = self:checkSpecialFlag(SpecialType.KING) |
463 | if not special then return nil end | 496 | if not special then return nil end |
464 | 497 | ||
@@ -476,31 +509,15 @@ function Capsule:getKing(record) | @@ -476,31 +509,15 @@ function Capsule:getKing(record) | ||
476 | end | 509 | end |
477 | end | 510 | end |
478 | 511 | ||
479 | - local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.KING) | 512 | + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.KING,now) |
480 | special["amount"] = count | 513 | special["amount"] = count |
481 | specials[spKey] = special | 514 | specials[spKey] = special |
482 | - specialsRecord[SpecialType.KING] = rewardByRole | 515 | + |
516 | + rewardToNtyFunc(specialsRecord, rewardByRole) | ||
483 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) | 517 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
484 | return rewardByRole | 518 | return rewardByRole |
485 | end | 519 | end |
486 | 520 | ||
487 | -local rewardToNtyFunc = function(notify, tmpReward) | ||
488 | - for key, val in pairs(tmpReward or {}) do | ||
489 | - if not notify[key] then | ||
490 | - notify[key] = val | ||
491 | - else | ||
492 | - for k, v in pairs(val) do | ||
493 | - if not notify[key][k] then | ||
494 | - notify[key][k] = v | ||
495 | - else | ||
496 | - notify[key][k] = notify[key][k].amount + v.amount | ||
497 | - end | ||
498 | - end | ||
499 | - | ||
500 | - end | ||
501 | - end | ||
502 | -end | ||
503 | - | ||
504 | function Capsule:checkSpecialReward( now) | 521 | function Capsule:checkSpecialReward( now) |
505 | local specials = self:getProperty("specials") or {} | 522 | local specials = self:getProperty("specials") or {} |
506 | if not next(specials) then return nil end | 523 | if not next(specials) then return nil end |
@@ -509,19 +526,25 @@ function Capsule:checkSpecialReward( now) | @@ -509,19 +526,25 @@ function Capsule:checkSpecialReward( now) | ||
509 | if not next(record) then return nil end | 526 | if not next(record) then return nil end |
510 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) | 527 | table.sort(record, function(a, b) return a.create_time < b.create_time end ) |
511 | 528 | ||
529 | + local recordAmount = getRecordAmount(record) | ||
512 | 530 | ||
513 | - local notify = self:getTop(record) or {} | 531 | + local notify = self:getTop(record, recordAmount,now) or {} |
514 | 532 | ||
515 | - local coreReward = self:getCore(record) | 533 | + dump(notify) |
534 | + local coreReward = self:getCore(record, recordAmount, now) | ||
535 | + dump(coreReward) | ||
516 | rewardToNtyFunc(notify, coreReward) | 536 | rewardToNtyFunc(notify, coreReward) |
517 | 537 | ||
518 | - local lastReward = self:getLast(record) | 538 | + local lastReward = self:getLast(record, now) |
539 | + dump(lastReward) | ||
519 | rewardToNtyFunc(notify, lastReward) | 540 | rewardToNtyFunc(notify, lastReward) |
520 | 541 | ||
521 | - local jokerReward = self:getJoker(record) | 542 | + local jokerReward = self:getJoker(record, now) |
543 | + dump(jokerReward) | ||
522 | rewardToNtyFunc(notify, jokerReward) | 544 | rewardToNtyFunc(notify, jokerReward) |
523 | 545 | ||
524 | - local kingReward = self:getKing(record) | 546 | + local kingReward = self:getKing(record, now) |
547 | + dump(kingReward) | ||
525 | rewardToNtyFunc(notify, kingReward) | 548 | rewardToNtyFunc(notify, kingReward) |
526 | 549 | ||
527 | 550 |
src/services/capsuled.lua
@@ -195,9 +195,9 @@ function CMD.goods_stock(capsuleId) | @@ -195,9 +195,9 @@ function CMD.goods_stock(capsuleId) | ||
195 | return capsule:getGoodsAmount(), capsule:getProperty("token") | 195 | return capsule:getGoodsAmount(), capsule:getProperty("token") |
196 | end | 196 | end |
197 | 197 | ||
198 | -function CMD.capsule_data(capsuleId) | 198 | +function CMD.capsule_data(roleId, capsuleId) |
199 | local capsule = capsules[capsuleId] or {} | 199 | local capsule = capsules[capsuleId] or {} |
200 | - return capsule:data() | 200 | + return capsule:data(roleId) |
201 | end | 201 | end |
202 | 202 | ||
203 | skynet.start(function() | 203 | skynet.start(function() |