Commit 7cba658816e05745b0613e35559070ee7a2cd54f

Authored by 熊润斐
2 parents 46b128fd 576c791c

Merge branch 'develop' into player

  1 +BUG_LOG = false
  2 +
  3 +function buglog(tag, advstr, ...)
  4 + if BUG_LOG then
  5 + print(string.format("[%s] %s", tag, string.format(advstr, ...)))
  6 + end
  7 +end
  8 +
  9 +
1 XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18" 10 XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18"
2 RESET_TIME = 4 11 RESET_TIME = 4
3 12
src/ProtocolCode.lua
@@ -223,6 +223,10 @@ actionCodes = { @@ -223,6 +223,10 @@ actionCodes = {
223 Activity_exchangeRpc = 657, 223 Activity_exchangeRpc = 657,
224 Activity_gachakonRpc = 658, 224 Activity_gachakonRpc = 658,
225 Activity_hangDropRpc = 659, 225 Activity_hangDropRpc = 659,
  226 + Activity_startBattleRpc = 660,
  227 + Activity_endBattleRpc = 661,
  228 + Activity_battleRankRpc = 662,
  229 + Activity_battleMilestoneRpc = 663,
226 230
227 Radio_startQuestRpc = 700, 231 Radio_startQuestRpc = 700,
228 Radio_finishQuestRpc = 701, 232 Radio_finishQuestRpc = 701,
@@ -15,6 +15,11 @@ R_STORE = "role:%d:store" -- 商店 @@ -15,6 +15,11 @@ R_STORE = "role:%d:store" -- 商店
15 R_ORDERS = "role:%d:orders" -- 订单 15 R_ORDERS = "role:%d:orders" -- 订单
16 R_ORDER = "order:%d:%d" 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 -- rank 24 -- rank
20 RANK_TOWER = "rank:tower" 25 RANK_TOWER = "rank:tower"
src/actions/ActivityAction.lua
@@ -319,7 +319,6 @@ function _M.gachakonRpc(agent, data) @@ -319,7 +319,6 @@ function _M.gachakonRpc(agent, data)
319 for i = 1, count do 319 for i = 1, count do
320 local tmpCfg = clone(actCfg) 320 local tmpCfg = clone(actCfg)
321 remain = 0 321 remain = 0
322 - print("-----------------, ", i)  
323 for id, cfg in pairs(tmpCfg) do 322 for id, cfg in pairs(tmpCfg) do
324 local num = gachakonInfo[id] or 0 323 local num = gachakonInfo[id] or 0
325 num = cfg.amount >= num and cfg.amount - num or 0 324 num = cfg.amount >= num and cfg.amount - num or 0
@@ -327,7 +326,7 @@ function _M.gachakonRpc(agent, data) @@ -327,7 +326,7 @@ function _M.gachakonRpc(agent, data)
327 if cfg.weight > 0 then 326 if cfg.weight > 0 then
328 remain = remain + num 327 remain = remain + num
329 end 328 end
330 - print("num ".. num, id, cfg.weight, cfg.amount) 329 + --print("num ".. num, id, cfg.weight, cfg.amount)
331 end 330 end
332 if remain == 0 then 331 if remain == 0 then
333 break 332 break
@@ -350,9 +349,9 @@ function _M.gachakonRpc(agent, data) @@ -350,9 +349,9 @@ function _M.gachakonRpc(agent, data)
350 role:costItems(cost, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) 349 role:costItems(cost, {log = {desc = "actGachakon", int1 = actid, int2 = count}})
351 350
352 local reward, change = role:award(award, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) 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 gachakonInfo = {} 354 gachakonInfo = {}
355 - print("hahaha")  
356 end 355 end
357 role.activity:updateActData("Gachakon", gachakonInfo) 356 role.activity:updateActData("Gachakon", gachakonInfo)
358 357
@@ -408,11 +407,329 @@ function _M.hangDropRpc(agent, data) @@ -408,11 +407,329 @@ function _M.hangDropRpc(agent, data)
408 407
409 reward, change = role:award(reward, {log = {desc = "actHangDrop", int1 = actid, int2 = num}}) 408 reward, change = role:award(reward, {log = {desc = "actHangDrop", int1 = actid, int2 = num}})
410 409
411 - role.activity:updateActData("HangDrop", timeNow) 410 + if num < 8 then
  411 + actData = actData + num * period
  412 + else
  413 + actData = timeNow
  414 + end
  415 +
  416 + role.activity:updateActData("HangDrop", actData)
412 417
413 SendPacket(actionCodes.Activity_hangDropRpc, MsgPack.pack(role:packReward(reward, change))) 418 SendPacket(actionCodes.Activity_hangDropRpc, MsgPack.pack(role:packReward(reward, change)))
414 419
415 return true 420 return true
416 end 421 end
417 422
  423 +local function getStarCount(cfg, data)
  424 + local count = 0
  425 + for i = 0, #(cfg.sweep_condition:toTableArray(true)) do
  426 + if (1 << i & data) > 0 then
  427 + count = count + 1
  428 + end
  429 + end
  430 +
  431 + return count
  432 +end
  433 +
  434 +function _M.startBattleRpc(agent, data)
  435 + local role = agent.role
  436 + local msg = MsgPack.unpack(data)
  437 + local actid = msg.actid
  438 + local id = msg.id
  439 + local count = msg.count
  440 + if not role.activity:isOpenById(actid) then return 1 end
  441 +
  442 + local actCfg = csvdb["activity_battleCsv"][actid]
  443 + if not actCfg then return 2 end
  444 +
  445 + local battleCfg = actCfg[id]
  446 + if not battleCfg then return 3 end
  447 +
  448 + local actData = role.activity:getActData("ChallengeLevel") or {}
  449 +
  450 + local preArr = battleCfg.prepose:toArray(true, "=")
  451 + for _, v in ipairs(preArr) do
  452 + local battleInfo = actData[v]
  453 + if not battleInfo then
  454 + return 4
  455 + end
  456 + local star = battleInfo["star"] or 0
  457 + if star <= 0 then
  458 + return 4
  459 + end
  460 + end
  461 + -- check cost
  462 + local changeFlag = false
  463 + local ticket = actData["ticket"]
  464 + if battleCfg.type ~= "" then
  465 + role.activity:getBattleTicket(actid)
  466 + local num = battleCfg.type:toArray(true, "=")[3]
  467 + if count and count > 0 then
  468 + if battleCfg.rank == 0 then
  469 + return 7
  470 + end
  471 + local bi = actData[id]
  472 + if not bi then return 8 end
  473 + local star = bi["star"] or 0
  474 + if star < 1 then
  475 + return 9
  476 + end
  477 + num = num * count
  478 + end
  479 + if ticket < num then
  480 + return 6
  481 + end
  482 + actData["ticket"] = ticket - num
  483 + changeFlag = true
  484 + end
  485 +
  486 + if not count then
  487 + role.__actBattleCache = {
  488 + key = tostring(math.random()),
  489 + actid = actid,
  490 + id = id,
  491 + }
  492 + SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack({key = role.__actBattleCache.key}))
  493 + else
  494 + if count <= 0 then
  495 + return
  496 + end
  497 + if battleCfg.rank == 0 then
  498 + return 7
  499 + end
  500 + local bi = actData[id]
  501 + local star = bi["star"]
  502 + local award = battleCfg.item_clear:toNumMap()
  503 + if getStarCount(battleCfg, star) == 3 then
  504 + local aw = battleCfg.perfect_reward:toNumMap()
  505 + for k, v in pairs(aw) do
  506 + award[k] = (award[k] or 0) + v
  507 + end
  508 + end
  509 + for k, v in pairs(award) do
  510 + award[k] = v * count
  511 + end
  512 + local reward, change = role:award(award, {log = {desc = "actBattle", int1 = actid, int2 = count or 0}})
  513 + SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack(role:packReward(reward, change)))
  514 +
  515 + bi["sum"] = bi["sum"] + bi["top"]
  516 + actData[id] = bi
  517 + changeFlag = true
  518 +
  519 + local rankVal = 0
  520 + if battleCfg.rank == 1 then
  521 + rankVal = bi["sum"]
  522 + elseif battleCfg.rank == 2 then
  523 + rankVal = bi["top"]
  524 + end
  525 + role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal)
  526 + end
  527 + if changeFlag then
  528 + role.activity:updateActData("ChallengeLevel", actData)
  529 + end
  530 +
  531 + return true
  532 +end
  533 +
  534 +function _M.endBattleRpc(agent, data)
  535 + local role = agent.role
  536 + local msg = MsgPack.unpack(data)
  537 + local actid = msg.actid
  538 + local id = msg.id
  539 + local key = msg.key
  540 + local isWin = msg.isWin
  541 + local heros = msg.heros
  542 + local support = msg.support
  543 + if not role.activity:isOpenById(actid) then return 1 end
  544 +
  545 + if not role.__actBattleCache then return 2 end
  546 +
  547 + if role.__actBattleCache.id ~= id or role.__actBattleCache.key ~= key and role.__actBattleCache.actid ~= actid then
  548 + SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({errorCode = 1}))
  549 + end
  550 +
  551 + local actCfg = csvdb["activity_battleCsv"][actid]
  552 + if not actCfg then return 3 end
  553 +
  554 + local battleCfg = actCfg[id]
  555 + if not battleCfg then return 4 end
  556 +
  557 + local actData = role.activity:getActData("ChallengeLevel") or {}
  558 +
  559 + local reward, change = {}, nil
  560 +
  561 + local battleInfo = actData[id] or {}
  562 + local curStar = 0
  563 + if isWin then
  564 + local herosInfo = msg.heros
  565 +
  566 + local check = {}
  567 + -- 1 通关
  568 + check[1] = function(_)
  569 + return true
  570 + end
  571 + -- 2 阵亡人数 <= N
  572 + check[2] = function(_, cond)
  573 + return msg.info.dead and msg.info.dead <= cond
  574 + end
  575 + -- 3 全员存活
  576 + check[3] = function(_)
  577 + return msg.info.dead and msg.info.dead == 0
  578 + end
  579 + -- 4 指定种族 >= N
  580 + check[4] = function(_, cond)
  581 + local count = 0
  582 + for _, one in pairs(herosInfo) do
  583 + local heroData = csvdb["unitCsv"][one.type]
  584 + if heroData.camp == cond then
  585 + count = count + 1
  586 + end
  587 + end
  588 + return count >= cond
  589 + end
  590 + -- 5 指定职业 >= N
  591 + check[5] = function(_, cond)
  592 + local count = 0
  593 + for _, one in pairs(herosInfo) do
  594 + local heroData = csvdb["unitCsv"][one.type]
  595 + if heroData.job == cond then
  596 + count = count + 1
  597 + end
  598 + end
  599 + return count >= cond
  600 + end
  601 + -- 6 含有指定角色
  602 + check[6] = function(_, cond)
  603 + for _, one in pairs(herosInfo) do
  604 + if one.type == cond then
  605 + return true
  606 + end
  607 + end
  608 + return false
  609 + end
  610 + -- 7 通关耗时 <= X 秒 msg.info.atime
  611 + check[7] = function(_, cond)
  612 + return msg.info.atime and msg.info.atime <= cond
  613 + end
  614 + curStar = 0
  615 + local sweepConds = battleCfg.sweep_condition:toTableArray(true)
  616 + for i, cond in ipairs(sweepConds) do
  617 + if check[cond[1]] and check[cond[1]](table.unpack(cond)) then
  618 + curStar = curStar + (1 << (i - 1))
  619 + end
  620 + end
  621 + else
  622 + curStar = 0
  623 + end
  624 + local oldStarNum = getStarCount(battleCfg, battleInfo["star"] or 0)
  625 + local newStarNum = getStarCount(battleCfg, curStar)
  626 + if newStarNum > oldStarNum then
  627 + battleInfo["star"] = curStar
  628 + end
  629 +
  630 + if battleCfg.rank ~= 0 then
  631 + -- 更新排行榜 最高伤害
  632 + local dmg = 0
  633 + for k, v in pairs(msg.info.damage) do
  634 + if k % 100 == 2 then
  635 + dmg = dmg + v
  636 + end
  637 + end
  638 + battleInfo["top"] = math.max(battleInfo["top"] or 0, dmg)
  639 + battleInfo["sum"] = (battleInfo["sum"] or 0) + dmg
  640 + local rankVal = 0
  641 + if battleCfg.rank == 1 then
  642 + rankVal = battleInfo["sum"]
  643 + elseif battleCfg.rank == 2 then
  644 + rankVal = battleInfo["top"]
  645 + end
  646 + if rankVal > 0 then
  647 + role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal)
  648 + end
  649 + end
  650 + actData[id] = battleInfo
  651 + role.activity:updateActData("ChallengeLevel", actData)
  652 +
  653 + if oldStarNum == 0 or battleCfg.rank ~= 0 then
  654 + reward = battleCfg.item_clear:toNumMap()
  655 + end
  656 + if (oldStarNum < 3 and newStarNum == 3) or battleCfg.rank ~= 0 then
  657 + local aw = battleCfg.perfect_reward:toNumMap()
  658 + for k, v in pairs(aw) do
  659 + reward[k] = (reward[k] or 0) + v
  660 + end
  661 + end
  662 +
  663 + role:checkBattle("act_battle", {
  664 + cfg = battleCfg,
  665 + star = newStarNum,
  666 + isWin = isWin,
  667 + info = msg.info,
  668 + reward = reward,
  669 + heros = heros,
  670 + supports = support,
  671 + })
  672 +
  673 + reward, change = role:award(reward, {log = {desc = "actBattle", int1 = actid, int2 = newStarNum}})
  674 +
  675 + SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({
  676 + reward = reward,
  677 + change = change
  678 + }))
  679 +
  680 + return true
  681 +end
  682 +
  683 +function _M.battleRankRpc(agent, data)
  684 + local role = agent.role
  685 + local msg = MsgPack.unpack(data)
  686 + local actid = msg.actid
  687 + if not role.activity:isOpenById(actid) then return 1 end
  688 +
  689 + local rankInfo = role:getRankInfoCommon(RANK_TYPE.ActBattleBoss)
  690 +
  691 + SendPacket(actionCodes.Activity_battleRankRpc, MsgPack.pack(rankInfo))
  692 + return true
  693 +end
  694 +
  695 +function _M.battleMilestoneRpc(agent, data)
  696 + local role = agent.role
  697 + local msg = MsgPack.unpack(data)
  698 + local actid = msg.actid
  699 + local id = msg.id
  700 + local index = msg.index
  701 +
  702 + if not role.activity:isOpenById(actid) then return 1 end
  703 +
  704 + local actCfg = csvdb["activity_mileageCsv"][actid]
  705 + if not actCfg then return 3 end
  706 +
  707 + local mileCfg = actCfg[index]
  708 + if not mileCfg then return 4 end
  709 +
  710 + local actData = role.activity:getActData("ChallengeLevel") or {}
  711 + local battleInfo = actData[id] or {}
  712 + local val = 0
  713 + if mileCfg.type == 1 then
  714 + val = battleInfo["sum"] or 0
  715 + elseif mileCfg.type == 2 then
  716 + val = battleInfo["top"] or 0
  717 + end
  718 +
  719 + local record = battleInfo["r"] or ""
  720 + local flag = string.char(string.getbit(record, index))
  721 + if flag == "1" then return 5 end
  722 + if mileCfg.condition > val then return 6 end
  723 +
  724 + battleInfo["r"] = string.setbit(record, index)
  725 + actData[id] = battleInfo
  726 + role.activity:updateActData("ChallengeLevel", actData)
  727 +
  728 + local award = mileCfg.reward:toNumMap()
  729 + local reward, change = role:award(award, {log = {desc = "actMilestone", int1 = actid, int2 = index}})
  730 + SendPacket(actionCodes.Activity_battleMilestoneRpc, MsgPack.pack(role:packReward(reward, change)))
  731 +
  732 + return true
  733 +end
  734 +
418 return _M 735 return _M
419 \ No newline at end of file 736 \ No newline at end of file
src/actions/GmAction.lua
@@ -535,6 +535,7 @@ function _M.test(role, pms) @@ -535,6 +535,7 @@ function _M.test(role, pms)
535 --hero.unlockPoolRpc({role = role}, MsgPack.pack({type = id})) 535 --hero.unlockPoolRpc({role = role}, MsgPack.pack({type = id}))
536 536
537 --role:sendMail(13, nil, "1=2", {111}) 537 --role:sendMail(13, nil, "1=2", {111})
  538 + dump(redisproxy:zrevrange("rank:tower", 0 , 10, "WITHSCORES"))
538 return "成功" 539 return "成功"
539 end 540 end
540 541
src/actions/HangAction.lua
@@ -632,7 +632,7 @@ function _M.endBonusBattleRpc(agent, data) @@ -632,7 +632,7 @@ function _M.endBonusBattleRpc(agent, data)
632 check[4] = function(_, cond) 632 check[4] = function(_, cond)
633 local count = 0 633 local count = 0
634 for _, one in pairs(herosInfo) do 634 for _, one in pairs(herosInfo) do
635 - local heroData = csv["unitCsv"][one.type] 635 + local heroData = csvdb["unitCsv"][one.type]
636 if heroData.camp == cond then 636 if heroData.camp == cond then
637 count = count + 1 637 count = count + 1
638 end 638 end
@@ -643,7 +643,7 @@ function _M.endBonusBattleRpc(agent, data) @@ -643,7 +643,7 @@ function _M.endBonusBattleRpc(agent, data)
643 check[5] = function(_, cond) 643 check[5] = function(_, cond)
644 local count = 0 644 local count = 0
645 for _, one in pairs(herosInfo) do 645 for _, one in pairs(herosInfo) do
646 - local heroData = csv["unitCsv"][one.type] 646 + local heroData = csvdb["unitCsv"][one.type]
647 if heroData.job == cond then 647 if heroData.job == cond then
648 count = count + 1 648 count = count + 1
649 end 649 end
src/actions/HeroAction.lua
@@ -477,8 +477,6 @@ function _M.referEquipsRpc(agent, data) @@ -477,8 +477,6 @@ function _M.referEquipsRpc(agent, data)
477 -- 更新角色 477 -- 更新角色
478 hero:updateProperty({field = "equip", value = curEquip}) 478 hero:updateProperty({field = "equip", value = curEquip})
479 479
480 - role:finishGuide(23)  
481 -  
482 local curAttr = hero:getTotalAttrs() 480 local curAttr = hero:getTotalAttrs()
483 local attrChange = getChangeAttrJson(oldAttr, curAttr) 481 local attrChange = getChangeAttrJson(oldAttr, curAttr)
484 for typ, data in pairs(wear) do 482 for typ, data in pairs(wear) do
src/adv/AdvBuff.lua
@@ -490,6 +490,7 @@ function Buff:createAfter(layer) @@ -490,6 +490,7 @@ function Buff:createAfter(layer)
490 self:_init() 490 self:_init()
491 end 491 end
492 self:pushBackEffect(1) 492 self:pushBackEffect(1)
  493 + buglog("Buff", "who: %s create buffId: %s", self.owner.monsterId, self.id)
493 end 494 end
494 495
495 function Buff:initByDB(data) 496 function Buff:initByDB(data)
@@ -632,6 +633,7 @@ function Buff:pushBackEffect(etype) @@ -632,6 +633,7 @@ function Buff:pushBackEffect(etype)
632 end 633 end
633 634
634 function Buff:effect() 635 function Buff:effect()
  636 + buglog("Buff", "who: %s effect buffId: %s", self.owner.monsterId, self.id)
635 self:decCount() 637 self:decCount()
636 self:pushBackEffect(2) 638 self:pushBackEffect(2)
637 if self._effectValue then 639 if self._effectValue then
@@ -655,6 +657,7 @@ function Buff:endBuff() @@ -655,6 +657,7 @@ function Buff:endBuff()
655 if self._endBuff then 657 if self._endBuff then
656 self:_endBuff() 658 self:_endBuff()
657 end 659 end
  660 + buglog("Buff", "who: %s endBuff buffId: %s", self.owner.monsterId, self.id)
658 end 661 end
659 662
660 function Buff:getType() 663 function Buff:getType()
@@ -709,6 +712,7 @@ function Buff:overlay(releaser, data, layer) @@ -709,6 +712,7 @@ function Buff:overlay(releaser, data, layer)
709 end 712 end
710 713
711 self:pushBackEffect(1) 714 self:pushBackEffect(1)
  715 + buglog("Buff", "who: %s overlay buffId: %s", self.owner.monsterId, self.id)
712 end 716 end
713 end 717 end
714 718
src/adv/AdvPassive.lua
@@ -354,6 +354,7 @@ function Passive:effect(triggerPms) @@ -354,6 +354,7 @@ function Passive:effect(triggerPms)
354 end 354 end
355 if hadEffect then 355 if hadEffect then
356 self.owner.battle.adv:pushBackEvent(AdvBackEventType.PassiveEffect, {id = self.id, level = self.level, roomId = self.owner.roomId, blockId = self.owner.blockId}) 356 self.owner.battle.adv:pushBackEvent(AdvBackEventType.PassiveEffect, {id = self.id, level = self.level, roomId = self.owner.roomId, blockId = self.owner.blockId})
  357 + buglog("Passive", "who: %s effect id: %s", self.owner.monsterId, self.id)
357 end 358 end
358 if self.count > 0 then 359 if self.count > 0 then
359 self.count = self.count < 999 and self.count - 1 or self.count 360 self.count = self.count < 999 and self.count - 1 or self.count
@@ -404,6 +405,8 @@ function Passive:trigger(condType, params) --触发检查 @@ -404,6 +405,8 @@ function Passive:trigger(condType, params) --触发检查
404 params = params or {} 405 params = params or {}
405 if self.isDel or self.owner.isDead then return end 406 if self.isDel or self.owner.isDead then return end
406 if self:getCondType() ~= condType then return end 407 if self:getCondType() ~= condType then return end
  408 +
  409 + buglog("Passive", "who: %s trigger id: %s", self.owner.monsterId, self.id)
407 if not self:canTrigger() then return end 410 if not self:canTrigger() then return end
408 if self._trigger then 411 if self._trigger then
409 if not self:_trigger(params) then return end --检查 412 if not self:_trigger(params) then return end --检查
@@ -600,5 +603,9 @@ function Passive:effect16(value, triggerPms, changeType) @@ -600,5 +603,9 @@ function Passive:effect16(value, triggerPms, changeType)
600 self.owner.battle.adv:blockDropChange(changeType, blocks) 603 self.owner.battle.adv:blockDropChange(changeType, blocks)
601 end 604 end
602 605
  606 +--17=玩家获得buff
  607 +function Passive:effect17(value, triggerPms)
  608 + self.owner.battle.player:addBuff(value, self.owner)
  609 +end
603 610
604 return Passive 611 return Passive
605 \ No newline at end of file 612 \ No newline at end of file
1 -Subproject commit 295feade86593a4793972e2cd2d83135d8aee247 1 +Subproject commit f019454e533ec12642ab9d7518c80b73c1cc00bb
src/models/Activity.lua
@@ -179,6 +179,7 @@ function Activity:checkActivityStatus(now, isCrossDay, notify) @@ -179,6 +179,7 @@ function Activity:checkActivityStatus(now, isCrossDay, notify)
179 179
180 if isOpen then 180 if isOpen then
181 if actime[actId] and actime[actId] == startTime then -- 还是之前的状态 开放中 181 if actime[actId] and actime[actId] == startTime then -- 还是之前的状态 开放中
  182 + self:onLoginActivity(actId)
182 else -- 重置 183 else -- 重置
183 actime[actId] = startTime 184 actime[actId] = startTime
184 self:closeActivity(actId, notify, true) 185 self:closeActivity(actId, notify, true)
@@ -419,7 +420,8 @@ activityFunc[Activity.ActivityType.CalendaTask] = { @@ -419,7 +420,8 @@ activityFunc[Activity.ActivityType.CalendaTask] = {
419 local towerInfo = role:getProperty("towerInfo") 420 local towerInfo = role:getProperty("towerInfo")
420 role:checkTaskEnter("TowerPass", {level = towerInfo.l}) 421 role:checkTaskEnter("TowerPass", {level = towerInfo.l})
421 --"PvpWin" 422 --"PvpWin"
422 - role:checkTaskEnter("HangPass", {}) 423 + --role:checkTaskEnter("HangPass", {id = 0})
  424 + role:checkCalendaTask(true, 15, 3)
423 role:checkTaskEnter("HeroStarCollect", {}) 425 role:checkTaskEnter("HeroStarCollect", {})
424 role:checkTaskEnter("RuneQualityCollect", {}) 426 role:checkTaskEnter("RuneQualityCollect", {})
425 427
@@ -475,7 +477,8 @@ activityFunc[Activity.ActivityType.Gachakon] = { @@ -475,7 +477,8 @@ activityFunc[Activity.ActivityType.Gachakon] = {
475 activityFunc[Activity.ActivityType.HangDrop] = { 477 activityFunc[Activity.ActivityType.HangDrop] = {
476 ["init"] = function(self, actType, isCrossDay, notify, actId) 478 ["init"] = function(self, actType, isCrossDay, notify, actId)
477 local actime = self:getProperty("actime") 479 local actime = self:getProperty("actime")
478 - local startTime = actime[actId] 480 + local ctime = self.owner:getProperty("ctime")
  481 + local startTime = math.max(actime[actId], ctime)
479 local actData = self:getActData(actType) or 0 482 local actData = self:getActData(actType) or 0
480 local cfg = csvdb["activity_putCsv"][actId] 483 local cfg = csvdb["activity_putCsv"][actId]
481 if not cfg then return end 484 if not cfg then return end
@@ -484,11 +487,30 @@ activityFunc[Activity.ActivityType.HangDrop] = { @@ -484,11 +487,30 @@ activityFunc[Activity.ActivityType.HangDrop] = {
484 end 487 end
485 } 488 }
486 489
  490 +--ChallengeLevel
  491 +activityFunc[Activity.ActivityType.ChallengeLevel] = {
  492 + ["init"] = function(self, actType, isCrossDay, notify, actId)
  493 + self:getBattleTicket(actId)
  494 + end,
  495 + ["login"] = function(self, actType, actId)
  496 + self:getBattleTicket(actId)
  497 + end
  498 +}
  499 +
  500 +function Activity:onLoginActivity(actId)
  501 + local actData = csvdb["activity_ctrlCsv"][actId]
  502 + if not actData then return end
  503 + local actType = actData.showType
  504 + if activityFunc[actType] and activityFunc[actType]['login'] then
  505 + activityFunc[actType]["login"](self, actType, actId)
  506 + end
  507 +end
  508 +
487 function Activity:initActivity(actId, isCrossDay, notify) 509 function Activity:initActivity(actId, isCrossDay, notify)
488 local actData = csvdb["activity_ctrlCsv"][actId] 510 local actData = csvdb["activity_ctrlCsv"][actId]
489 if not actData then return end 511 if not actData then return end
490 local actType = actData.showType 512 local actType = actData.showType
491 - if activityFunc[actType] and activityFunc[actType]['close'] then 513 + if activityFunc[actType] and activityFunc[actType]['init'] then
492 activityFunc[actType]["init"](self, actType, isCrossDay, notify, actId) 514 activityFunc[actType]["init"](self, actType, isCrossDay, notify, actId)
493 end 515 end
494 end 516 end
@@ -633,5 +655,39 @@ function Activity:recycleActItem(actId) @@ -633,5 +655,39 @@ function Activity:recycleActItem(actId)
633 end 655 end
634 end 656 end
635 657
  658 +-- 活动挑战关卡计算门票
  659 +function Activity:getBattleTicket(actId)
  660 + local role = self.owner
  661 + local createTs = role:getProperty("ctime")
  662 + local actCfg = csvdb["activity_ctrlCsv"][actId]
  663 + if not actCfg then return 0 end
  664 +
  665 + local actStartTime = 0
  666 + local openTimes = actCfg.time:toArray(false, "=")
  667 + actStartTime = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME))
  668 + local actData = self:getActData("ChallengeLevel") or {}
  669 + local startTs = actData["ts"] or math.max(actStartTime, createTs)
  670 + local timeNow = skynet.timex()
  671 + local modify = false
  672 + local arr = actCfg.condition2:toArray(true, "=")
  673 +
  674 + local ticketId, init, limit, duration = arr[1] or 0, arr[2] or 0, arr[3] or 0, arr[4] or 10000
  675 +
  676 + local count = actData["ticket"] or init
  677 + local add = math.max(math.floor((timeNow - startTs) / (duration * 60)), 0)
  678 +
  679 + local newCount= math.min(count + add, limit)
  680 + if newCount ~= count or newCount >= limit then
  681 + modify = true
  682 + end
  683 + add = newCount - count
  684 +
  685 + if modify or not next(actData) then
  686 + actData["ticket"] = newCount
  687 + actData["ts"] = newCount >= limit and timeNow or (startTs + add * duration * 60)
  688 + self:updateActData("ChallengeLevel", actData)
  689 + end
  690 +end
  691 +
636 692
637 return Activity 693 return Activity
src/models/RoleBattle.lua
@@ -16,6 +16,7 @@ local BattleType = { @@ -16,6 +16,7 @@ local BattleType = {
16 bonus = 300, 16 bonus = 300,
17 pvpc = 500, 17 pvpc = 500,
18 pvph = 501, 18 pvph = 501,
  19 + act_battle = 502,
19 } 20 }
20 21
21 RoleBattle.bind = function (Role) 22 RoleBattle.bind = function (Role)
@@ -86,6 +87,20 @@ function Role:checkBattle(battleType, params) @@ -86,6 +87,20 @@ function Role:checkBattle(battleType, params)
86 enemylist[#enemylist + 1] = one["unitType"] 87 enemylist[#enemylist + 1] = one["unitType"]
87 end 88 end
88 end, 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 pvpc = function() 104 pvpc = function()
90 for slot, hero in pairs(self:getProperty("pvpTSC")) do 105 for slot, hero in pairs(self:getProperty("pvpTSC")) do
91 selflist[slot] = hero.type 106 selflist[slot] = hero.type
@@ -163,7 +178,7 @@ function Role:checkBattle(battleType, params) @@ -163,7 +178,7 @@ function Role:checkBattle(battleType, params)
163 mission_starttime = clientInfo.start or 0, -- 战斗开始时间,格式 unixtime 秒级 178 mission_starttime = clientInfo.start or 0, -- 战斗开始时间,格式 unixtime 秒级
164 mission_roundtime = clientInfo.atime or 0, -- 对局时长(秒) 179 mission_roundtime = clientInfo.atime or 0, -- 对局时长(秒)
165 mission_result = params.isWin and 1 or 2, -- 战斗结果(0-无效,1-胜利,2-失败) 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 mission_restriction = 0, -- 周期内参与限制(0表示没有上限) 182 mission_restriction = 0, -- 周期内参与限制(0表示没有上限)
168 mission_difficulty = 0, -- 关卡困难度,无难度区分的话填写0 183 mission_difficulty = 0, -- 关卡困难度,无难度区分的话填写0
169 mission_strength = 1, -- 消耗的体力或次数 184 mission_strength = 1, -- 消耗的体力或次数
src/models/RoleLog.lua
@@ -47,6 +47,8 @@ local ItemReason = { @@ -47,6 +47,8 @@ local ItemReason = {
47 actGachakon = 132, -- 扭蛋活动 47 actGachakon = 132, -- 扭蛋活动
48 totalRecharge = 133, -- 累计充值奖励 48 totalRecharge = 133, -- 累计充值奖励
49 actHangDrop = 134, -- 掉落活动奖励 49 actHangDrop = 134, -- 掉落活动奖励
  50 + actBattle = 135, -- 活动关卡
  51 + actMilestone = 136, -- 活动关卡boss伤害里程碑
50 52
51 53
52 advHang = 301, -- 拾荒挂机 54 advHang = 301, -- 拾荒挂机
src/models/RolePlugin.lua
@@ -1929,6 +1929,53 @@ function RolePlugin.bind(Role) @@ -1929,6 +1929,53 @@ function RolePlugin.bind(Role)
1929 end 1929 end
1930 deleteNotify({pattern = pattern}) 1930 deleteNotify({pattern = pattern})
1931 end 1931 end
  1932 +
  1933 + local CommonRankTime = toUnixtime("2019010100")
  1934 + local CommonCoef1 = 10000
  1935 + local CommonCoef2 = 10000
  1936 + function Role:updateRankCommon(rankType, rankVal, reserve)
  1937 + if not rankType then return end
  1938 + reserve = reserve or 0
  1939 + local now = skynet.timex()
  1940 + local ct = math.ceil((now - CommonRankTime) / 86400) --按天计算 365 * 27 < 10000 可以维持 27 年
  1941 + ct = 10000 - ct -- 越早的排名越靠前
  1942 + local score = (rankVal * CommonCoef1 + ct) * CommonCoef2 + reserve
  1943 +
  1944 + local roleId = self:getProperty("id")
  1945 + redisproxy:pipelining(function (red)
  1946 + red:zadd(RANK_COMMON..rankType, score, roleId) --更新分数
  1947 + end)
  1948 + end
  1949 +
  1950 + function Role:getRankInfoCommon(rankType)
  1951 + if not rankType then return end
  1952 + local list = {}
  1953 + local rankKey = RANK_COMMON .. rankType
  1954 + local ids = redisproxy:zrevrange(rankKey, 0 , 99, "WITHSCORES")
  1955 + for i = 1, #ids, 2 do
  1956 + local roleId = tonumber(ids[i])
  1957 + local rankVal = tonumber(ids[i + 1])
  1958 + rankVal = math.floor(math.floor(rankVal / CommonCoef2) / CommonCoef1)
  1959 + table.insert(list, {roleId = roleId, player = rankVal})
  1960 + end
  1961 +
  1962 + for _, v in ipairs(list) do
  1963 + local _, curInfo = rpcRole(v.roleId, "friendSInfo")
  1964 + curInfo.ltime = nil
  1965 + curInfo.rankVal = v.player
  1966 + v.player = curInfo
  1967 + end
  1968 +
  1969 + local rank = redisproxy:ZREVRANK(rankKey, self:getProperty("id"))
  1970 + if not rank then
  1971 + rank = -1
  1972 + else
  1973 + rank = rank + 1
  1974 + end
  1975 + return {list = list, rank = rank}
  1976 + end
  1977 +
  1978 +
1932 end 1979 end
1933 1980
1934 return RolePlugin 1981 return RolePlugin
1935 \ No newline at end of file 1982 \ No newline at end of file
src/services/globald.lua
@@ -7,6 +7,7 @@ require &quot;shared.init&quot; @@ -7,6 +7,7 @@ require &quot;shared.init&quot;
7 require "utils.init" 7 require "utils.init"
8 require "RedisKeys" 8 require "RedisKeys"
9 require "skynet.manager" 9 require "skynet.manager"
  10 +require "GlobalVar"
10 11
11 12
12 local ipairs = ipairs 13 local ipairs = ipairs
@@ -16,6 +17,7 @@ local string_format = string.format @@ -16,6 +17,7 @@ local string_format = string.format
16 17
17 18
18 local CHECK_MAIL_STATUS_INTERVAL = 100 * 60 19 local CHECK_MAIL_STATUS_INTERVAL = 100 * 60
  20 +local CHECK_BATTLE_ACT_CLOSE_INTERVAL = 100 * 1
19 local function mailQuene() 21 local function mailQuene()
20 local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email")) 22 local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email"))
21 if delayEmail == 0 then 23 if delayEmail == 0 then
@@ -91,6 +93,64 @@ local function check_mail_queue() @@ -91,6 +93,64 @@ local function check_mail_queue()
91 skynet.timeout(CHECK_MAIL_STATUS_INTERVAL, check_mail_queue) 93 skynet.timeout(CHECK_MAIL_STATUS_INTERVAL, check_mail_queue)
92 end 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 local CMD = {} 156 local CMD = {}
@@ -115,6 +175,7 @@ end @@ -115,6 +175,7 @@ end
115 175
116 function CMD.start() 176 function CMD.start()
117 check_mail_queue() 177 check_mail_queue()
  178 + check_battle_act_close()
118 end 179 end
119 180
120 local function __init__() 181 local function __init__()