diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 8502a49..b8b9c52 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -498,6 +498,35 @@ function _M.buyBonusCountRpc(agent, data) return true end +local function bonusWinReward(role, bonusData) + local open, actId = role.activity:isOpen("BonusDouble") + local actData = csvdb["activity_ctrlCsv"][actId] + local extraCnt = role.storeData:getBonusExtraFightCount() + + local coef = 1 + if open and actData then + coef = tonumber(actData.condition2) + end + local bonusC = role.dailyData:getProperty("bonusC") + bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0} + if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return false, 1 end + bonusC[bonusData.type]["c"] = bonusC[bonusData.type]["c"] + 1 + role.dailyData:updateProperty({field = "bonusC", value = bonusC}) + + local reward, change + reward = bonusData.reward:toNumMap() + local chance = bonusData.chance:randWeight(true) + if chance[1] ~= 0 then + reward[chance[1]] = (reward[chance[1]] or 0) + chance[2] + end + for k, v in pairs(reward) do + reward[k] = v * (coef > 1 and actData.condition or 1) + end + reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}}) + role:checkTaskEnter("BonusPass", {id = id}) + return true, reward, change +end + function _M.startBonusBattleRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) @@ -516,9 +545,6 @@ function _M.startBonusBattleRpc(agent, data) if not bonusData then return 3 end if not role:checkHangPass(bonusData.unlock) then return 4 end - local bTeam = role:getTeamFormatByType(TeamSystemType.BonusBattle) - if not next(bTeam) then return 5 end - local bonusC = role.dailyData:getProperty("bonusC") bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0} @@ -529,15 +555,23 @@ function _M.startBonusBattleRpc(agent, data) if open and actData then coef = tonumber(actData.condition2) end - if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return 7 end + local bonusStar = role:getProperty("bonusStar") + if bonusStar[id] and bonusStar[id] >= (1 << #bonusData.sweep_condition:toTableArray(true)) - 1 then + local status, reward, change = bonusWinReward(role, bonusData) + if not status then return 10 * (reward or 0) end + SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({reward = reward, change = change})) + else + local bTeam = role:getTeamFormatByType(TeamSystemType.BonusBattle) + if not next(bTeam) then return 5 end + role.__bonusBattleCache = { + key = tostring(math.random()), + id = id, + } + SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({key = role.__bonusBattleCache.key})) + end - role.__bonusBattleCache = { - key = tostring(math.random()), - id = id, - } - SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({key = role.__bonusBattleCache.key})) return true end @@ -548,14 +582,7 @@ function _M.endBonusBattleRpc(agent, data) local key = msg.key local starNum = msg.starNum if not role.__bonusBattleCache then return 1 end - local open, actId = role.activity:isOpen("BonusDouble") - local actData = csvdb["activity_ctrlCsv"][actId] - local extraCnt = role.storeData:getBonusExtraFightCount() - - local coef = 1 - if open and actData then - coef = tonumber(actData.condition2) - end + if role.__bonusBattleCache.id ~= id or role.__bonusBattleCache.key ~= key then SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1})) @@ -564,24 +591,78 @@ function _M.endBonusBattleRpc(agent, data) local bonusData = csvdb["bonus_battleCsv"][id] local reward, change + + local bonusStar = role:getProperty("bonusStar") + local curStar = 0 if starNum and starNum > 0 then -- 胜利扣除次数 - local bonusC = role.dailyData:getProperty("bonusC") - bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0} - if globalCsv.bonus_daily_count * coef + extraCnt - bonusC[bonusData.type]["c"] <= 0 then return 3 end - bonusC[bonusData.type]["c"] = bonusC[bonusData.type]["c"] + 1 - role.dailyData:updateProperty({field = "bonusC", value = bonusC}) - - reward = bonusData.reward:toNumMap() - local chance = bonusData.chance:randWeight(true) - if chance[1] ~= 0 then - reward[chance[1]] = (reward[chance[1]] or 0) + chance[2] + + local status, reward, change = bonusWinReward(role, bonusData) + if not status then return 10 + (reward or 0) end + + local bTeam = self:getTeamFormatByType(TeamSystemType.BonusBattle) + local herosInfo = self:getTeamHerosInfo(bTeam.heros) + + local check = {} + -- 1 通关 + check[1] = function(_) + return true + end + -- 2 阵亡人数 <= N + check[2] = function(_, cond) + return msg.info.dead and msg.info.dead <= cond end - for k, v in pairs(reward) do - reward[k] = v * (coef > 1 and actData.condition or 1) + -- 3 全员存活 + check[3] = function(_) + return msg.info.dead and msg.info.dead == 0 end - reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}}) - role:checkTaskEnter("BonusPass", {id = id}) + -- 4 指定种族 >= N + check[4] = function(_, cond) + local count = 0 + for _, one in pairs(herosInfo) do + local heroData = csv["unitCsv"][one.type] + if heroData.camp == cond then + count = count + 1 + end + end + return count >= cond + end + -- 5 指定职业 >= N + check[5] = function(_, cond) + local count = 0 + for _, one in pairs(herosInfo) do + local heroData = csv["unitCsv"][one.type] + if heroData.job == cond then + count = count + 1 + end + end + return count >= cond + end + -- 6 含有指定角色 + check[6] = function(_, cond) + for _, one in pairs(herosInfo) do + if one.type == cond then + return true + end + end + return false + end + -- 7 通关耗时 <= X 秒 msg.info.atime + check[7] = function(_, cond) + return msg.info.atime and msg.info.atime <= cond + end + curStar = 0 + for i, cond in ipairs(bonusData.sweep_condition:toTableArray(true)) do + if check[cond[1]] and check[cond[1]](table.unpack(cond)) then + curStar = curStar + (1 << (i - 1)) + end + end + else + curStar = 0 + end + if curStar ~= bonusStar[id] then + bonusStar[id] = curStar + role:updateProperty({field = "bonusStar", value = bonusStar}) end role:checkBattle("bonus", { diff --git a/src/models/Role.lua b/src/models/Role.lua index 84f13ce..6d84ecd 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -114,6 +114,8 @@ Role.schema = { teamIndex = {"table", {}}, -- 各个系统使用的编队索引 type->index 见TeamSystemType advTeams = {"table", {}}, -- 拾荒自选编队 + bonusStar = {"table", {}}, -- 奖励关卡 通关星星 {[id] = 1} 三个二进制位 表示三个星 从低到高 (1 << 0) (1 << 1) (1 << 2) 满星 (1 << 3) - 1 + --引导相关 newerGuide = {"string","1=1"}, -- 新手引导 master=slave funcGuide = {"string",""}, -- 功能引导 0=0跳过次数(999永久跳过) 1=1功能1触发情况 @@ -360,6 +362,8 @@ function Role:data() hangTeams = self:getProperty("hangTeams"), teamIndex = self:getProperty("teamIndex"), advTeams = self:getProperty("advTeams"), + + bonusStar = self:getProperty("bonusStar"), newerGuide = self:getProperty("newerGuide"), funcGuide = self:getProperty("funcGuide"), -- libgit2 0.21.2