Commit 66fe093a89d6da9640d5a59430de5ce04027a0ff
1 parent
1be743f3
元旦关卡活动
Showing
11 changed files
with
507 additions
and
9 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -223,6 +223,10 @@ actionCodes = { |
223 | 223 | Activity_exchangeRpc = 657, |
224 | 224 | Activity_gachakonRpc = 658, |
225 | 225 | Activity_hangDropRpc = 659, |
226 | + Activity_startBattleRpc = 660, | |
227 | + Activity_endBattleRpc = 661, | |
228 | + Activity_battleRankRpc = 662, | |
229 | + Activity_battleMilestoneRpc = 663, | |
226 | 230 | |
227 | 231 | Radio_startQuestRpc = 700, |
228 | 232 | Radio_finishQuestRpc = 701, | ... | ... |
src/RedisKeys.lua
... | ... | @@ -15,6 +15,11 @@ R_STORE = "role:%d:store" -- 商店 |
15 | 15 | R_ORDERS = "role:%d:orders" -- 订单 |
16 | 16 | R_ORDER = "order:%d:%d" |
17 | 17 | |
18 | +-- 通用排行榜 | |
19 | +RANK_COMMON = "rank:common:" | |
20 | +RANK_TYPE = { | |
21 | + ActBattleBoss = "act_battle_boss", | |
22 | +} | |
18 | 23 | |
19 | 24 | -- rank |
20 | 25 | RANK_TOWER = "rank:tower" | ... | ... |
src/actions/ActivityAction.lua
... | ... | @@ -319,7 +319,6 @@ function _M.gachakonRpc(agent, data) |
319 | 319 | for i = 1, count do |
320 | 320 | local tmpCfg = clone(actCfg) |
321 | 321 | remain = 0 |
322 | - print("-----------------, ", i) | |
323 | 322 | for id, cfg in pairs(tmpCfg) do |
324 | 323 | local num = gachakonInfo[id] or 0 |
325 | 324 | num = cfg.amount >= num and cfg.amount - num or 0 |
... | ... | @@ -327,7 +326,7 @@ function _M.gachakonRpc(agent, data) |
327 | 326 | if cfg.weight > 0 then |
328 | 327 | remain = remain + num |
329 | 328 | end |
330 | - print("num ".. num, id, cfg.weight, cfg.amount) | |
329 | + --print("num ".. num, id, cfg.weight, cfg.amount) | |
331 | 330 | end |
332 | 331 | if remain == 0 then |
333 | 332 | break |
... | ... | @@ -350,9 +349,9 @@ function _M.gachakonRpc(agent, data) |
350 | 349 | role:costItems(cost, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) |
351 | 350 | |
352 | 351 | local reward, change = role:award(award, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) |
353 | - if remain <= count then | |
352 | + --print("-----------", remain, count) | |
353 | + if remain <= 1 then | |
354 | 354 | gachakonInfo = {} |
355 | - print("hahaha") | |
356 | 355 | end |
357 | 356 | role.activity:updateActData("Gachakon", gachakonInfo) |
358 | 357 | |
... | ... | @@ -415,4 +414,316 @@ function _M.hangDropRpc(agent, data) |
415 | 414 | return true |
416 | 415 | end |
417 | 416 | |
417 | +local function getStarCount(cfg, data) | |
418 | + local count = 0 | |
419 | + for i = 0, #(cfg.sweep_condition:toTableArray(true)) do | |
420 | + if (1 << i & data) > 0 then | |
421 | + count = count + 1 | |
422 | + end | |
423 | + end | |
424 | + | |
425 | + return count | |
426 | +end | |
427 | + | |
428 | +function _M.startBattleRpc(agent, data) | |
429 | + local role = agent.role | |
430 | + local msg = MsgPack.unpack(data) | |
431 | + local actid = msg.actid | |
432 | + local id = msg.id | |
433 | + local count = msg.count | |
434 | + if not role.activity:isOpenById(actid) then return 1 end | |
435 | + role.activity:getBattleTicket(role, actid) | |
436 | + | |
437 | + local actCfg = csvdb["activity_battleCsv"][actid] | |
438 | + if not actCfg then return 2 end | |
439 | + | |
440 | + local battleCfg = actCfg[id] | |
441 | + if not battleCfg then return 3 end | |
442 | + | |
443 | + local actData = role.activity:getActData("ChallengeLevel") or {} | |
444 | + | |
445 | + local preArr = battleCfg.prepose:toArray(true, "=") | |
446 | + for _, v in ipairs(preArr) do | |
447 | + local battleInfo = actData[v] | |
448 | + if not battleInfo then | |
449 | + return 4 | |
450 | + end | |
451 | + local star = battleInfo["star"] or 0 | |
452 | + if star <= 0 then | |
453 | + return 4 | |
454 | + end | |
455 | + end | |
456 | + -- check cost | |
457 | + local changeFlag = false | |
458 | + local ticket = actData["ticket"] | |
459 | + if battleCfg.type ~= "" then | |
460 | + local num = battleCfg.type:toArray(true, "=")[3] | |
461 | + if count and count > 0 then | |
462 | + if battleCfg.rank == 0 then | |
463 | + return 7 | |
464 | + end | |
465 | + local bi = actData[id] | |
466 | + if not bi then return 8 end | |
467 | + local star = bi["star"] or 0 | |
468 | + if star < 1 then | |
469 | + return 9 | |
470 | + end | |
471 | + num = num * count | |
472 | + end | |
473 | + if ticket < num then | |
474 | + return 6 | |
475 | + end | |
476 | + actData["ticket"] = ticket - num | |
477 | + changeFlag = true | |
478 | + end | |
479 | + | |
480 | + if not count then | |
481 | + role.__actBattleCache = { | |
482 | + key = tostring(math.random()), | |
483 | + actid = actid, | |
484 | + id = id, | |
485 | + } | |
486 | + SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack({key = role.__actBattleCache.key})) | |
487 | + else | |
488 | + if count <= 0 then | |
489 | + return | |
490 | + end | |
491 | + if battleCfg.rank == 0 then | |
492 | + return 7 | |
493 | + end | |
494 | + local bi = actData[id] | |
495 | + local star = bi["star"] | |
496 | + local award = battleCfg.item_clear:toNumMap() | |
497 | + if getStarCount(battleCfg, star) == 3 then | |
498 | + local aw = battleCfg.perfect_reward:toNumMap() | |
499 | + for k, v in pairs(aw) do | |
500 | + award[k] = (award[k] or 0) + v | |
501 | + end | |
502 | + end | |
503 | + for k, v in pairs(award) do | |
504 | + award[k] = v * count | |
505 | + end | |
506 | + local reward, change = role:award(award, {log = {desc = "actBattle", int1 = actid, int2 = count or 0}}) | |
507 | + SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack(role:packReward(reward, change))) | |
508 | + | |
509 | + bi["sum"] = bi["sum"] + bi["top"] | |
510 | + actData[id] = bi | |
511 | + changeFlag = true | |
512 | + | |
513 | + local rankVal = 0 | |
514 | + if battleCfg.rank == 1 then | |
515 | + rankVal = bi["sum"] | |
516 | + elseif battleCfg.rank == 2 then | |
517 | + rankVal = bi["top"] | |
518 | + end | |
519 | + role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal) | |
520 | + end | |
521 | + if changeFlag then | |
522 | + role.activity:updateActData("ChallengeLevel", actData) | |
523 | + end | |
524 | + | |
525 | + return true | |
526 | +end | |
527 | + | |
528 | +function _M.endBattleRpc(agent, data) | |
529 | + local role = agent.role | |
530 | + local msg = MsgPack.unpack(data) | |
531 | + local actid = msg.actid | |
532 | + local id = msg.id | |
533 | + local key = msg.key | |
534 | + local isWin = msg.isWin | |
535 | + local heros = msg.heros | |
536 | + local support = msg.support | |
537 | + if not role.activity:isOpenById(actid) then return 1 end | |
538 | + | |
539 | + if not role.__actBattleCache then return 2 end | |
540 | + | |
541 | + if role.__actBattleCache.id ~= id or role.__actBattleCache.key ~= key and role.__actBattleCache.actid ~= actid then | |
542 | + SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({errorCode = 1})) | |
543 | + end | |
544 | + | |
545 | + local actCfg = csvdb["activity_battleCsv"][actid] | |
546 | + if not actCfg then return 3 end | |
547 | + | |
548 | + local battleCfg = actCfg[id] | |
549 | + if not battleCfg then return 4 end | |
550 | + | |
551 | + local actData = role.activity:getActData("ChallengeLevel") or {} | |
552 | + | |
553 | + local reward, change = {}, nil | |
554 | + | |
555 | + local battleInfo = actData[id] or {} | |
556 | + local curStar = 0 | |
557 | + if isWin then | |
558 | + local herosInfo = msg.heros | |
559 | + | |
560 | + local check = {} | |
561 | + -- 1 通关 | |
562 | + check[1] = function(_) | |
563 | + return true | |
564 | + end | |
565 | + -- 2 阵亡人数 <= N | |
566 | + check[2] = function(_, cond) | |
567 | + return msg.info.dead and msg.info.dead <= cond | |
568 | + end | |
569 | + -- 3 全员存活 | |
570 | + check[3] = function(_) | |
571 | + return msg.info.dead and msg.info.dead == 0 | |
572 | + end | |
573 | + -- 4 指定种族 >= N | |
574 | + check[4] = function(_, cond) | |
575 | + local count = 0 | |
576 | + for _, one in pairs(herosInfo) do | |
577 | + local heroData = csvdb["unitCsv"][one.type] | |
578 | + if heroData.camp == cond then | |
579 | + count = count + 1 | |
580 | + end | |
581 | + end | |
582 | + return count >= cond | |
583 | + end | |
584 | + -- 5 指定职业 >= N | |
585 | + check[5] = function(_, cond) | |
586 | + local count = 0 | |
587 | + for _, one in pairs(herosInfo) do | |
588 | + local heroData = csvdb["unitCsv"][one.type] | |
589 | + if heroData.job == cond then | |
590 | + count = count + 1 | |
591 | + end | |
592 | + end | |
593 | + return count >= cond | |
594 | + end | |
595 | + -- 6 含有指定角色 | |
596 | + check[6] = function(_, cond) | |
597 | + for _, one in pairs(herosInfo) do | |
598 | + if one.type == cond then | |
599 | + return true | |
600 | + end | |
601 | + end | |
602 | + return false | |
603 | + end | |
604 | + -- 7 通关耗时 <= X 秒 msg.info.atime | |
605 | + check[7] = function(_, cond) | |
606 | + return msg.info.atime and msg.info.atime <= cond | |
607 | + end | |
608 | + curStar = 0 | |
609 | + local sweepConds = battleCfg.sweep_condition:toTableArray(true) | |
610 | + for i, cond in ipairs(sweepConds) do | |
611 | + if check[cond[1]] and check[cond[1]](table.unpack(cond)) then | |
612 | + curStar = curStar + (1 << (i - 1)) | |
613 | + end | |
614 | + end | |
615 | + else | |
616 | + curStar = 0 | |
617 | + end | |
618 | + local oldStarNum = getStarCount(battleCfg, battleInfo["star"] or 0) | |
619 | + local newStarNum = getStarCount(battleCfg, curStar) | |
620 | + if newStarNum > oldStarNum then | |
621 | + battleInfo["star"] = curStar | |
622 | + end | |
623 | + | |
624 | + if battleCfg.rank ~= 0 then | |
625 | + -- 更新排行榜 最高伤害 | |
626 | + local dmg = 0 | |
627 | + for k, v in pairs(msg.info.damage) do | |
628 | + if k % 100 == 2 then | |
629 | + dmg = dmg + v | |
630 | + end | |
631 | + end | |
632 | + battleInfo["top"] = math.max(battleInfo["top"] or 0, dmg) | |
633 | + battleInfo["sum"] = (battleInfo["sum"] or 0) + dmg | |
634 | + local rankVal = 0 | |
635 | + if battleCfg.rank == 1 then | |
636 | + rankVal = battleInfo["sum"] | |
637 | + elseif battleCfg.rank == 2 then | |
638 | + rankVal = battleInfo["top"] | |
639 | + end | |
640 | + if rankVal > 0 then | |
641 | + role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal) | |
642 | + end | |
643 | + end | |
644 | + actData[id] = battleInfo | |
645 | + role.activity:updateActData("ChallengeLevel", actData) | |
646 | + | |
647 | + if oldStarNum == 0 or battleCfg.rank ~= 0 then | |
648 | + reward = battleCfg.item_clear:toNumMap() | |
649 | + end | |
650 | + if (oldStarNum < 3 and newStarNum == 3) or battleCfg.rank ~= 0 then | |
651 | + local aw = battleCfg.perfect_reward:toNumMap() | |
652 | + for k, v in pairs(aw) do | |
653 | + reward[k] = (reward[k] or 0) + v | |
654 | + end | |
655 | + end | |
656 | + | |
657 | + role:checkBattle("act_battle", { | |
658 | + cfg = battleCfg, | |
659 | + star = newStarNum, | |
660 | + isWin = isWin, | |
661 | + info = msg.info, | |
662 | + reward = reward, | |
663 | + heros = heros, | |
664 | + supports = support, | |
665 | + }) | |
666 | + | |
667 | + reward, change = role:award(reward, {log = {desc = "actBattle", int1 = actid, int2 = newStarNum}}) | |
668 | + | |
669 | + SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({ | |
670 | + reward = reward, | |
671 | + change = change | |
672 | + })) | |
673 | + | |
674 | + return true | |
675 | +end | |
676 | + | |
677 | +function _M.battleRankRpc(agent, data) | |
678 | + local role = agent.role | |
679 | + local msg = MsgPack.unpack(data) | |
680 | + local actid = msg.actid | |
681 | + if not role.activity:isOpenById(actid) then return 1 end | |
682 | + | |
683 | + local rankInfo = role:getRankInfoCommon(RANK_TYPE.ActBattleBoss) | |
684 | + | |
685 | + SendPacket(actionCodes.Activity_battleRankRpc, MsgPack.pack(rankInfo)) | |
686 | + return true | |
687 | +end | |
688 | + | |
689 | +function _M.battleMilestoneRpc(agent, data) | |
690 | + local role = agent.role | |
691 | + local msg = MsgPack.unpack(data) | |
692 | + local actid = msg.actid | |
693 | + local id = msg.id | |
694 | + local index = msg.index | |
695 | + | |
696 | + if not role.activity:isOpenById(actid) then return 1 end | |
697 | + | |
698 | + local actCfg = csvdb["activity_mileageCsv"][actid] | |
699 | + if not actCfg then return 3 end | |
700 | + | |
701 | + local mileCfg = actCfg[index] | |
702 | + if not mileCfg then return 4 end | |
703 | + | |
704 | + local actData = role.activity:getActData("ChallengeLevel") or {} | |
705 | + local battleInfo = actData[id] or {} | |
706 | + local val = 0 | |
707 | + if mileCfg.type == 1 then | |
708 | + val = battleInfo["sum"] or 0 | |
709 | + elseif mileCfg.type == 2 then | |
710 | + val = battleInfo["top"] or 0 | |
711 | + end | |
712 | + | |
713 | + local record = battleInfo["r"] or "" | |
714 | + local flag = string.char(string.getbit(record, index)) | |
715 | + if flag == "1" then return 5 end | |
716 | + if mileCfg.condition > val then return 6 end | |
717 | + | |
718 | + battleInfo["r"] = string.setbit(record, index) | |
719 | + actData[id] = battleInfo | |
720 | + role.activity:updateActData("ChallengeLevel", actData) | |
721 | + | |
722 | + local award = mileCfg.reward:toNumMap() | |
723 | + local reward, change = role:award(award, {log = {desc = "actMilestone", int1 = actid, int2 = index}}) | |
724 | + SendPacket(actionCodes.Activity_battleMilestoneRpc, MsgPack.pack(role:packReward(reward, change))) | |
725 | + | |
726 | + return true | |
727 | +end | |
728 | + | |
418 | 729 | return _M |
419 | 730 | \ No newline at end of file | ... | ... |
src/actions/GmAction.lua
src/actions/HangAction.lua
... | ... | @@ -632,7 +632,7 @@ function _M.endBonusBattleRpc(agent, data) |
632 | 632 | check[4] = function(_, cond) |
633 | 633 | local count = 0 |
634 | 634 | for _, one in pairs(herosInfo) do |
635 | - local heroData = csv["unitCsv"][one.type] | |
635 | + local heroData = csvdb["unitCsv"][one.type] | |
636 | 636 | if heroData.camp == cond then |
637 | 637 | count = count + 1 |
638 | 638 | end |
... | ... | @@ -643,7 +643,7 @@ function _M.endBonusBattleRpc(agent, data) |
643 | 643 | check[5] = function(_, cond) |
644 | 644 | local count = 0 |
645 | 645 | for _, one in pairs(herosInfo) do |
646 | - local heroData = csv["unitCsv"][one.type] | |
646 | + local heroData = csvdb["unitCsv"][one.type] | |
647 | 647 | if heroData.job == cond then |
648 | 648 | count = count + 1 |
649 | 649 | end | ... | ... |
src/models/Activity.lua
... | ... | @@ -179,6 +179,7 @@ function Activity:checkActivityStatus(now, isCrossDay, notify) |
179 | 179 | |
180 | 180 | if isOpen then |
181 | 181 | if actime[actId] and actime[actId] == startTime then -- 还是之前的状态 开放中 |
182 | + self:onLoginActivity(actId) | |
182 | 183 | else -- 重置 |
183 | 184 | actime[actId] = startTime |
184 | 185 | self:closeActivity(actId, notify, true) |
... | ... | @@ -484,11 +485,30 @@ activityFunc[Activity.ActivityType.HangDrop] = { |
484 | 485 | end |
485 | 486 | } |
486 | 487 | |
488 | +--ChallengeLevel | |
489 | +activityFunc[Activity.ActivityType.ChallengeLevel] = { | |
490 | + ["init"] = function(self, actType, isCrossDay, notify, actId) | |
491 | + self:getBattleTicket(actId) | |
492 | + end, | |
493 | + ["login"] = function(self, actType, actId) | |
494 | + self:getBattleTicket(actId) | |
495 | + end | |
496 | +} | |
497 | + | |
498 | +function Activity:onLoginActivity(actId) | |
499 | + local actData = csvdb["activity_ctrlCsv"][actId] | |
500 | + if not actData then return end | |
501 | + local actType = actData.showType | |
502 | + if activityFunc[actType] and activityFunc[actType]['login'] then | |
503 | + activityFunc[actType]["login"](self, actType, actId) | |
504 | + end | |
505 | +end | |
506 | + | |
487 | 507 | function Activity:initActivity(actId, isCrossDay, notify) |
488 | 508 | local actData = csvdb["activity_ctrlCsv"][actId] |
489 | 509 | if not actData then return end |
490 | 510 | local actType = actData.showType |
491 | - if activityFunc[actType] and activityFunc[actType]['close'] then | |
511 | + if activityFunc[actType] and activityFunc[actType]['init'] then | |
492 | 512 | activityFunc[actType]["init"](self, actType, isCrossDay, notify, actId) |
493 | 513 | end |
494 | 514 | end |
... | ... | @@ -633,5 +653,39 @@ function Activity:recycleActItem(actId) |
633 | 653 | end |
634 | 654 | end |
635 | 655 | |
656 | +-- 活动挑战关卡计算门票 | |
657 | +function Activity:getBattleTicket(actId) | |
658 | + local role = self.owner | |
659 | + local createTs = role:getProperty("ctime") | |
660 | + local actCfg = csvdb["activity_ctrlCsv"][actId] | |
661 | + if not actCfg then return 0 end | |
662 | + | |
663 | + local actStartTime = 0 | |
664 | + local openTimes = actCfg.time:toArray(false, "=") | |
665 | + actStartTime = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME)) | |
666 | + local actData = self:getActData("ChallengeLevel") or {} | |
667 | + local startTs = actData["ts"] or math.max(actStartTime, createTs) | |
668 | + local timeNow = skynet.timex() | |
669 | + local modify = false | |
670 | + local arr = actCfg.condition2:toArray(true, "=") | |
671 | + | |
672 | + local ticketId, init, limit, duration = arr[1] or 0, arr[2] or 0, arr[3] or 0, arr[4] or 10000 | |
673 | + | |
674 | + local count = actData["ticket"] or init | |
675 | + local add = math.max(math.floor((timeNow - startTs) / (duration * 60)), 0) | |
676 | + | |
677 | + local newCount= math.min(count + add, limit) | |
678 | + if newCount ~= count or newCount >= limit then | |
679 | + modify = true | |
680 | + end | |
681 | + add = newCount - count | |
682 | + | |
683 | + if modify or not next(actData) then | |
684 | + actData["ticket"] = newCount | |
685 | + actData["ts"] = newCount >= limit and timeNow or (startTs + add * duration * 60) | |
686 | + self:updateActData("ChallengeLevel", actData) | |
687 | + end | |
688 | +end | |
689 | + | |
636 | 690 | |
637 | 691 | return Activity | ... | ... |
src/models/RoleBattle.lua
... | ... | @@ -16,6 +16,7 @@ local BattleType = { |
16 | 16 | bonus = 300, |
17 | 17 | pvpc = 500, |
18 | 18 | pvph = 501, |
19 | + act_battle = 502, | |
19 | 20 | } |
20 | 21 | |
21 | 22 | RoleBattle.bind = function (Role) |
... | ... | @@ -86,6 +87,20 @@ function Role:checkBattle(battleType, params) |
86 | 87 | enemylist[#enemylist + 1] = one["unitType"] |
87 | 88 | end |
88 | 89 | end, |
90 | + act_battle = function() | |
91 | + for slot, hero in pairs(self:getTeamHerosInfo(params.heros)) do | |
92 | + selflist[slot] = hero.type | |
93 | + end | |
94 | + heroscore = self:getTeamBattleValue(params.heros) | |
95 | + for slot , one in pairs(params.supports) do | |
96 | + teamskill[one[1]] = one[2] | |
97 | + end | |
98 | + local carbonData = params.cfg | |
99 | + local monsterData = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"] | |
100 | + for slot, one in pairs(monsterData[1]) do | |
101 | + enemylist[#enemylist + 1] = one["unitType"] | |
102 | + end | |
103 | + end, | |
89 | 104 | pvpc = function() |
90 | 105 | for slot, hero in pairs(self:getProperty("pvpTSC")) do |
91 | 106 | selflist[slot] = hero.type |
... | ... | @@ -163,7 +178,7 @@ function Role:checkBattle(battleType, params) |
163 | 178 | mission_starttime = clientInfo.start or 0, -- 战斗开始时间,格式 unixtime 秒级 |
164 | 179 | mission_roundtime = clientInfo.atime or 0, -- 对局时长(秒) |
165 | 180 | mission_result = params.isWin and 1 or 2, -- 战斗结果(0-无效,1-胜利,2-失败) |
166 | - mission_star = 0, -- 战斗完成星数,无星级的话填写0 | |
181 | + mission_star = params.star or 0, -- 战斗完成星数,无星级的话填写0 | |
167 | 182 | mission_restriction = 0, -- 周期内参与限制(0表示没有上限) |
168 | 183 | mission_difficulty = 0, -- 关卡困难度,无难度区分的话填写0 |
169 | 184 | mission_strength = 1, -- 消耗的体力或次数 | ... | ... |
src/models/RoleLog.lua
src/models/RolePlugin.lua
... | ... | @@ -1929,6 +1929,51 @@ function RolePlugin.bind(Role) |
1929 | 1929 | end |
1930 | 1930 | deleteNotify({pattern = pattern}) |
1931 | 1931 | end |
1932 | + | |
1933 | + local CommonRankTime = toUnixtime("2019010100") | |
1934 | + function Role:updateRankCommon(rankType, rankVal, reserve) | |
1935 | + if not rankType then return end | |
1936 | + reserve = reserve or 0 | |
1937 | + local now = skynet.timex() | |
1938 | + local ct = math.ceil((now - CommonRankTime) / 86400) --按天计算 365 * 27 < 10000 可以维持 27 年 | |
1939 | + ct = 10000 - ct -- 越早的排名越靠前 | |
1940 | + local score = (reserve * 10000 + ct) * 10000000 + rankVal | |
1941 | + | |
1942 | + local roleId = self:getProperty("id") | |
1943 | + redisproxy:pipelining(function (red) | |
1944 | + red:zadd(RANK_COMMON..rankType, score, roleId) --更新分数 | |
1945 | + end) | |
1946 | + end | |
1947 | + | |
1948 | + function Role:getRankInfoCommon(rankType) | |
1949 | + if not rankType then return end | |
1950 | + local list = {} | |
1951 | + local rankKey = RANK_COMMON .. rankType | |
1952 | + local ids = redisproxy:zrevrange(rankKey, 0 , 99, "WITHSCORES") | |
1953 | + for i = 1, #ids, 2 do | |
1954 | + local roleId = tonumber(ids[i]) | |
1955 | + local rankVal = tonumber(ids[i + 1]) | |
1956 | + rankVal = rankVal % 10000000 | |
1957 | + table.insert(list, {roleId = roleId, player = rankVal}) | |
1958 | + end | |
1959 | + | |
1960 | + for _, v in ipairs(list) do | |
1961 | + local _, curInfo = rpcRole(v.roleId, "friendSInfo") | |
1962 | + curInfo.ltime = nil | |
1963 | + curInfo.rankVal = v.player | |
1964 | + v.player = curInfo | |
1965 | + end | |
1966 | + | |
1967 | + local rank = redisproxy:ZREVRANK(rankKey, self:getProperty("id")) | |
1968 | + if not rank then | |
1969 | + rank = -1 | |
1970 | + else | |
1971 | + rank = rank + 1 | |
1972 | + end | |
1973 | + return {list = list, rank = rank} | |
1974 | + end | |
1975 | + | |
1976 | + | |
1932 | 1977 | end |
1933 | 1978 | |
1934 | 1979 | return RolePlugin |
1935 | 1980 | \ No newline at end of file | ... | ... |
src/services/globald.lua
... | ... | @@ -7,6 +7,7 @@ require "shared.init" |
7 | 7 | require "utils.init" |
8 | 8 | require "RedisKeys" |
9 | 9 | require "skynet.manager" |
10 | +require "GlobalVar" | |
10 | 11 | |
11 | 12 | |
12 | 13 | local ipairs = ipairs |
... | ... | @@ -16,6 +17,7 @@ local string_format = string.format |
16 | 17 | |
17 | 18 | |
18 | 19 | local CHECK_MAIL_STATUS_INTERVAL = 100 * 60 |
20 | +local CHECK_BATTLE_ACT_CLOSE_INTERVAL = 100 * 1 | |
19 | 21 | local function mailQuene() |
20 | 22 | local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email")) |
21 | 23 | if delayEmail == 0 then |
... | ... | @@ -91,6 +93,64 @@ local function check_mail_queue() |
91 | 93 | skynet.timeout(CHECK_MAIL_STATUS_INTERVAL, check_mail_queue) |
92 | 94 | end |
93 | 95 | |
96 | +-- @desc: 检测关卡活动结束 排行榜奖励发放 | |
97 | +local lastCheckBattleActTs = 0 | |
98 | +local function check_battle_act_close() | |
99 | + local csvdb = require "shared.csvdata" | |
100 | + local act = require "models.Activity" | |
101 | + local st = 0 | |
102 | + local et = 0 | |
103 | + local actId = 0 | |
104 | + local timeNow = skynet.timex() | |
105 | + for k, v in pairs(csvdb["activity_ctrlCsv"]) do | |
106 | + if v.showType == act.ActivityType.ChallengeLevel then | |
107 | + local openTimes = v.time:toArray(false, "=") | |
108 | + if openTimes[1] ~= "0" then | |
109 | + st = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME)) | |
110 | + end | |
111 | + if openTimes[2] ~= "0" then | |
112 | + et = toUnixtime(openTimes[2]..string_format("%02x", RESET_TIME)) | |
113 | + end | |
114 | + actId = k | |
115 | + break | |
116 | + end | |
117 | + end | |
118 | + if st ~= 0 and et ~= 0 and actId ~= 0 then | |
119 | + -- close | |
120 | + if lastCheckBattleActTs < et and timeNow >= et then | |
121 | + -- check rank key exist | |
122 | + local rankKey = RANK_COMMON..RANK_TYPE.ActBattleBoss | |
123 | + local flag = redisproxy:exists(rankKey) | |
124 | + if flag then | |
125 | + local actData = csvdb["activity_groupCsv"][actId] | |
126 | + local lastRank = actData[#actData].rank | |
127 | + | |
128 | + local ids = redisproxy:zrevrange(rankKey, 0 , lastRank - 1) | |
129 | + local rankIndex = 0 | |
130 | + for roleId in pairs(ids) do | |
131 | + rankIndex = rankIndex + 1 | |
132 | + for _, cfg in pairs(actData) do | |
133 | + if rankIndex <= cfg.rank then | |
134 | + redisproxy:insertEmail({ | |
135 | + roleId = roleId, | |
136 | + emailId = cfg.email_1, | |
137 | + attachments = cfg.reward_1, | |
138 | + contentPms = {rankIndex}, | |
139 | + }) | |
140 | + break | |
141 | + end | |
142 | + end | |
143 | + end | |
144 | + | |
145 | + redisproxy:del(rankKey..":bak") | |
146 | + redisproxy:rename(rankKey, rankKey..":bak") | |
147 | + end | |
148 | + end | |
149 | + end | |
150 | + lastCheckBattleActTs = skynet.timex() | |
151 | + skynet.timeout(CHECK_BATTLE_ACT_CLOSE_INTERVAL, check_battle_act_close) | |
152 | +end | |
153 | + | |
94 | 154 | |
95 | 155 | |
96 | 156 | local CMD = {} |
... | ... | @@ -115,6 +175,7 @@ end |
115 | 175 | |
116 | 176 | function CMD.start() |
117 | 177 | check_mail_queue() |
178 | + check_battle_act_close() | |
118 | 179 | end |
119 | 180 | |
120 | 181 | local function __init__() | ... | ... |