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 | 135 | return ret |
136 | 136 | end |
137 | 137 | |
138 | - dump(reward) | |
139 | - dump(rewardByGoods) | |
138 | + --dump(rewardByGoods) | |
139 | + --dump(capsule) | |
140 | 140 | |
141 | 141 | if ret == 5 then |
142 | 142 | SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule})) |
... | ... | @@ -153,15 +153,16 @@ function _M.drawRpc(agent, data) |
153 | 153 | return true |
154 | 154 | end |
155 | 155 | |
156 | -function _M.getData(agent, data) | |
156 | +function _M.getDataRpc(agent, data) | |
157 | 157 | local role = agent.role |
158 | 158 | local msg = MsgPack.unpack(data) |
159 | 159 | local capsuleId = msg.capsule_id |
160 | 160 | local typ = msg.typ --0=独享,1= 公开 |
161 | + local roleId = role:getProperty("id") | |
161 | 162 | |
162 | 163 | local capsule |
163 | 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 | 166 | else |
166 | 167 | capsule = role:getCapsuleData(capsuleId) |
167 | 168 | end | ... | ... |
src/models/Capsule.lua
... | ... | @@ -86,7 +86,7 @@ function Capsule:init() |
86 | 86 | for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do |
87 | 87 | for _, val in pairs(data) do |
88 | 88 | if val.key == goods_id then |
89 | - goods[goods_id..val.id] = clone(val) | |
89 | + goods[goods_id] = clone(val) | |
90 | 90 | end |
91 | 91 | end |
92 | 92 | end |
... | ... | @@ -304,13 +304,41 @@ local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
304 | 304 | return rewardByRole, count |
305 | 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 | 335 | local spKey, special = self:checkSpecialFlag(SpecialType.TOP) |
309 | 336 | if not special then return nil end |
310 | 337 | local specials = self:getProperty("specials") or {} |
311 | 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 | 342 | local topRecord = {} |
315 | 343 | local count = special["np"] |
316 | 344 | for _, v in ipairs(record) do |
... | ... | @@ -332,18 +360,20 @@ function Capsule:getTop(record) |
332 | 360 | end |
333 | 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 | 365 | special["amount"] = count |
338 | 366 | specials[spKey] = special |
339 | - specialsRecord[SpecialType.TOP] = rewardByRole | |
367 | + | |
368 | + rewardToNtyFunc(specialsRecord, rewardByRole) | |
369 | + | |
340 | 370 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
341 | 371 | return rewardByRole |
342 | 372 | |
343 | 373 | end |
344 | 374 | |
345 | 375 | --TODO |
346 | -function Capsule:getCore(record) | |
376 | +function Capsule:getCore(record, recordAmount,now) | |
347 | 377 | local spKey, special = self:checkSpecialFlag(SpecialType.CORE) |
348 | 378 | if not special then return nil end |
349 | 379 | |
... | ... | @@ -353,10 +383,10 @@ function Capsule:getCore(record) |
353 | 383 | if self:getGoodsAmount() > 0 then return nil end |
354 | 384 | |
355 | 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 | 390 | local count = np |
361 | 391 | local roleRecord = {} |
362 | 392 | for i, v in ipairs(record) do |
... | ... | @@ -380,16 +410,17 @@ function Capsule:getCore(record) |
380 | 410 | |
381 | 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 | 415 | special["amount"] = count |
386 | 416 | specials[spKey] = special |
387 | - specialsRecord[SpecialType.CORE] = rewardByRole | |
417 | + | |
418 | + rewardToNtyFunc(specialsRecord, rewardByRole) | |
388 | 419 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
389 | 420 | return rewardByRole |
390 | 421 | end |
391 | 422 | |
392 | -function Capsule:getLast(record) | |
423 | +function Capsule:getLast(record,now) | |
393 | 424 | local spKey, special = self:checkSpecialFlag(SpecialType.LAST) |
394 | 425 | if not special then return nil end |
395 | 426 | |
... | ... | @@ -422,16 +453,17 @@ function Capsule:getLast(record) |
422 | 453 | end |
423 | 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 | 458 | special["amount"] = count |
428 | 459 | specials[spKey] = special |
429 | - specialsRecord[SpecialType.LAST] = rewardByRole | |
460 | + | |
461 | + rewardToNtyFunc(specialsRecord, rewardByRole) | |
430 | 462 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
431 | 463 | return rewardByRole |
432 | 464 | end |
433 | 465 | |
434 | -function Capsule:getJoker(record) | |
466 | +function Capsule:getJoker(record,now) | |
435 | 467 | local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) |
436 | 468 | if not special then return nil end |
437 | 469 | |
... | ... | @@ -449,16 +481,17 @@ function Capsule:getJoker(record) |
449 | 481 | end |
450 | 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 | 486 | special["amount"] = count |
455 | 487 | specials[spKey] = special |
456 | - specialsRecord[SpecialType.JOKER] = rewardByRole | |
488 | + | |
489 | + rewardToNtyFunc(specialsRecord, rewardByRole) | |
457 | 490 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
458 | 491 | return rewardByRole |
459 | 492 | end |
460 | 493 | |
461 | -function Capsule:getKing(record) | |
494 | +function Capsule:getKing(record,now) | |
462 | 495 | local spKey, special = self:checkSpecialFlag(SpecialType.KING) |
463 | 496 | if not special then return nil end |
464 | 497 | |
... | ... | @@ -476,31 +509,15 @@ function Capsule:getKing(record) |
476 | 509 | end |
477 | 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 | 513 | special["amount"] = count |
481 | 514 | specials[spKey] = special |
482 | - specialsRecord[SpecialType.KING] = rewardByRole | |
515 | + | |
516 | + rewardToNtyFunc(specialsRecord, rewardByRole) | |
483 | 517 | self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
484 | 518 | return rewardByRole |
485 | 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 | 521 | function Capsule:checkSpecialReward( now) |
505 | 522 | local specials = self:getProperty("specials") or {} |
506 | 523 | if not next(specials) then return nil end |
... | ... | @@ -509,19 +526,25 @@ function Capsule:checkSpecialReward( now) |
509 | 526 | if not next(record) then return nil end |
510 | 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 | 536 | rewardToNtyFunc(notify, coreReward) |
517 | 537 | |
518 | - local lastReward = self:getLast(record) | |
538 | + local lastReward = self:getLast(record, now) | |
539 | + dump(lastReward) | |
519 | 540 | rewardToNtyFunc(notify, lastReward) |
520 | 541 | |
521 | - local jokerReward = self:getJoker(record) | |
542 | + local jokerReward = self:getJoker(record, now) | |
543 | + dump(jokerReward) | |
522 | 544 | rewardToNtyFunc(notify, jokerReward) |
523 | 545 | |
524 | - local kingReward = self:getKing(record) | |
546 | + local kingReward = self:getKing(record, now) | |
547 | + dump(kingReward) | |
525 | 548 | rewardToNtyFunc(notify, kingReward) |
526 | 549 | |
527 | 550 | ... | ... |
src/services/capsuled.lua
... | ... | @@ -195,9 +195,9 @@ function CMD.goods_stock(capsuleId) |
195 | 195 | return capsule:getGoodsAmount(), capsule:getProperty("token") |
196 | 196 | end |
197 | 197 | |
198 | -function CMD.capsule_data(capsuleId) | |
198 | +function CMD.capsule_data(roleId, capsuleId) | |
199 | 199 | local capsule = capsules[capsuleId] or {} |
200 | - return capsule:data() | |
200 | + return capsule:data(roleId) | |
201 | 201 | end |
202 | 202 | |
203 | 203 | skynet.start(function() | ... | ... |