Commit 3c51e6d4a0938e606d030fe0c0716f8afedb5839

Authored by zhouhaihai
1 parent 42dcb7da

奖励副本 完成

Showing 2 changed files with 116 additions and 31 deletions   Show diff stats
src/actions/HangAction.lua
... ... @@ -498,6 +498,35 @@ function _M.buyBonusCountRpc(agent, data)
498 498 return true
499 499 end
500 500  
  501 +local function bonusWinReward(role, bonusData)
  502 + local open, actId = role.activity:isOpen("BonusDouble")
  503 + local actData = csvdb["activity_ctrlCsv"][actId]
  504 + local extraCnt = role.storeData:getBonusExtraFightCount()
  505 +
  506 + local coef = 1
  507 + if open and actData then
  508 + coef = tonumber(actData.condition2)
  509 + end
  510 + local bonusC = role.dailyData:getProperty("bonusC")
  511 + bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0}
  512 + if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return false, 1 end
  513 + bonusC[bonusData.type]["c"] = bonusC[bonusData.type]["c"] + 1
  514 + role.dailyData:updateProperty({field = "bonusC", value = bonusC})
  515 +
  516 + local reward, change
  517 + reward = bonusData.reward:toNumMap()
  518 + local chance = bonusData.chance:randWeight(true)
  519 + if chance[1] ~= 0 then
  520 + reward[chance[1]] = (reward[chance[1]] or 0) + chance[2]
  521 + end
  522 + for k, v in pairs(reward) do
  523 + reward[k] = v * (coef > 1 and actData.condition or 1)
  524 + end
  525 + reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}})
  526 + role:checkTaskEnter("BonusPass", {id = id})
  527 + return true, reward, change
  528 +end
  529 +
501 530 function _M.startBonusBattleRpc(agent, data)
502 531 local role = agent.role
503 532 local msg = MsgPack.unpack(data)
... ... @@ -516,9 +545,6 @@ function _M.startBonusBattleRpc(agent, data)
516 545 if not bonusData then return 3 end
517 546 if not role:checkHangPass(bonusData.unlock) then return 4 end
518 547  
519   - local bTeam = role:getTeamFormatByType(TeamSystemType.BonusBattle)
520   - if not next(bTeam) then return 5 end
521   -
522 548 local bonusC = role.dailyData:getProperty("bonusC")
523 549 bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0}
524 550  
... ... @@ -529,15 +555,23 @@ function _M.startBonusBattleRpc(agent, data)
529 555 if open and actData then
530 556 coef = tonumber(actData.condition2)
531 557 end
532   -
533 558 if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return 7 end
534 559  
  560 + local bonusStar = role:getProperty("bonusStar")
  561 + if bonusStar[id] and bonusStar[id] >= (1 << #bonusData.sweep_condition:toTableArray(true)) - 1 then
  562 + local status, reward, change = bonusWinReward(role, bonusData)
  563 + if not status then return 10 * (reward or 0) end
  564 + SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({reward = reward, change = change}))
  565 + else
  566 + local bTeam = role:getTeamFormatByType(TeamSystemType.BonusBattle)
  567 + if not next(bTeam) then return 5 end
  568 + role.__bonusBattleCache = {
  569 + key = tostring(math.random()),
  570 + id = id,
  571 + }
  572 + SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({key = role.__bonusBattleCache.key}))
  573 + end
535 574  
536   - role.__bonusBattleCache = {
537   - key = tostring(math.random()),
538   - id = id,
539   - }
540   - SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({key = role.__bonusBattleCache.key}))
541 575 return true
542 576 end
543 577  
... ... @@ -548,14 +582,7 @@ function _M.endBonusBattleRpc(agent, data)
548 582 local key = msg.key
549 583 local starNum = msg.starNum
550 584 if not role.__bonusBattleCache then return 1 end
551   - local open, actId = role.activity:isOpen("BonusDouble")
552   - local actData = csvdb["activity_ctrlCsv"][actId]
553   - local extraCnt = role.storeData:getBonusExtraFightCount()
554   -
555   - local coef = 1
556   - if open and actData then
557   - coef = tonumber(actData.condition2)
558   - end
  585 +
559 586  
560 587 if role.__bonusBattleCache.id ~= id or role.__bonusBattleCache.key ~= key then
561 588 SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1}))
... ... @@ -564,24 +591,78 @@ function _M.endBonusBattleRpc(agent, data)
564 591 local bonusData = csvdb["bonus_battleCsv"][id]
565 592  
566 593 local reward, change
  594 +
  595 + local bonusStar = role:getProperty("bonusStar")
  596 + local curStar = 0
567 597 if starNum and starNum > 0 then
568 598 -- 胜利扣除次数
569   - local bonusC = role.dailyData:getProperty("bonusC")
570   - bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0}
571   - if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return 3 end
572   - bonusC[bonusData.type]["c"] = bonusC[bonusData.type]["c"] + 1
573   - role.dailyData:updateProperty({field = "bonusC", value = bonusC})
574   -
575   - reward = bonusData.reward:toNumMap()
576   - local chance = bonusData.chance:randWeight(true)
577   - if chance[1] ~= 0 then
578   - reward[chance[1]] = (reward[chance[1]] or 0) + chance[2]
  599 +
  600 + local status, reward, change = bonusWinReward(role, bonusData)
  601 + if not status then return 10 + (reward or 0) end
  602 +
  603 + local bTeam = self:getTeamFormatByType(TeamSystemType.BonusBattle)
  604 + local herosInfo = self:getTeamHerosInfo(bTeam.heros)
  605 +
  606 + local check = {}
  607 + -- 1 通关
  608 + check[1] = function(_)
  609 + return true
  610 + end
  611 + -- 2 阵亡人数 <= N
  612 + check[2] = function(_, cond)
  613 + return msg.info.dead and msg.info.dead <= cond
579 614 end
580   - for k, v in pairs(reward) do
581   - reward[k] = v * (coef > 1 and actData.condition or 1)
  615 + -- 3 全员存活
  616 + check[3] = function(_)
  617 + return msg.info.dead and msg.info.dead == 0
582 618 end
583   - reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}})
584   - role:checkTaskEnter("BonusPass", {id = id})
  619 + -- 4 指定种族 >= N
  620 + check[4] = function(_, cond)
  621 + local count = 0
  622 + for _, one in pairs(herosInfo) do
  623 + local heroData = csv["unitCsv"][one.type]
  624 + if heroData.camp == cond then
  625 + count = count + 1
  626 + end
  627 + end
  628 + return count >= cond
  629 + end
  630 + -- 5 指定职业 >= N
  631 + check[5] = function(_, cond)
  632 + local count = 0
  633 + for _, one in pairs(herosInfo) do
  634 + local heroData = csv["unitCsv"][one.type]
  635 + if heroData.job == cond then
  636 + count = count + 1
  637 + end
  638 + end
  639 + return count >= cond
  640 + end
  641 + -- 6 含有指定角色
  642 + check[6] = function(_, cond)
  643 + for _, one in pairs(herosInfo) do
  644 + if one.type == cond then
  645 + return true
  646 + end
  647 + end
  648 + return false
  649 + end
  650 + -- 7 通关耗时 <= X 秒 msg.info.atime
  651 + check[7] = function(_, cond)
  652 + return msg.info.atime and msg.info.atime <= cond
  653 + end
  654 + curStar = 0
  655 + for i, cond in ipairs(bonusData.sweep_condition:toTableArray(true)) do
  656 + if check[cond[1]] and check[cond[1]](table.unpack(cond)) then
  657 + curStar = curStar + (1 << (i - 1))
  658 + end
  659 + end
  660 + else
  661 + curStar = 0
  662 + end
  663 + if curStar ~= bonusStar[id] then
  664 + bonusStar[id] = curStar
  665 + role:updateProperty({field = "bonusStar", value = bonusStar})
585 666 end
586 667  
587 668 role:checkBattle("bonus", {
... ...
src/models/Role.lua
... ... @@ -114,6 +114,8 @@ Role.schema = {
114 114 teamIndex = {"table", {}}, -- 各个系统使用的编队索引 type->index 见TeamSystemType
115 115 advTeams = {"table", {}}, -- 拾荒自选编队
116 116  
  117 + bonusStar = {"table", {}}, -- 奖励关卡 通关星星 {[id] = 1} 三个二进制位 表示三个星 从低到高 (1 << 0) (1 << 1) (1 << 2) 满星 (1 << 3) - 1
  118 +
117 119 --引导相关
118 120 newerGuide = {"string","1=1"}, -- 新手引导 master=slave
119 121 funcGuide = {"string",""}, -- 功能引导 0=0跳过次数(999永久跳过) 1=1功能1触发情况
... ... @@ -360,6 +362,8 @@ function Role:data()
360 362 hangTeams = self:getProperty("hangTeams"),
361 363 teamIndex = self:getProperty("teamIndex"),
362 364 advTeams = self:getProperty("advTeams"),
  365 +
  366 + bonusStar = self:getProperty("bonusStar"),
363 367  
364 368 newerGuide = self:getProperty("newerGuide"),
365 369 funcGuide = self:getProperty("funcGuide"),
... ...