From eab5a2d455e98fca9b82ab82dce1b7232a8a37a9 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 27 May 2021 10:14:28 +0800 Subject: [PATCH] feat: 讨伐电台终止派遣改为消耗虹光玉加速 --- src/actions/RadioAction.lua | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------- 1 file changed, 98 insertions(+), 75 deletions(-) diff --git a/src/actions/RadioAction.lua b/src/actions/RadioAction.lua index d19d401..852fb4f 100644 --- a/src/actions/RadioAction.lua +++ b/src/actions/RadioAction.lua @@ -35,6 +35,79 @@ local function getQuestMax(role) return count + (globalCsv.cursade_team_count_initial or 0) end +local function getCrusadeReward(role, id) + local radioTask = role:getProperty("radioTask") + local task = radioTask[id] + if not task then return 1 end + -- check id + local config = csvdb["crusadeCsv"][id] + if not config then return 2 end + local carbonData = csvdb["idle_battleCsv"][config.unlock] + if not carbonData then return 3 end + -- get heros + local totalCoef = 0 + local exp = config.time / 60 + local heroFaithMap = {} + for _, heroId in ipairs(task.heros) do + local hero = role.heros[heroId] + if hero then + totalCoef = totalCoef + getHeroCoef(hero, config.success) + -- 增加英雄信赖 + hero:addHeroFaith(exp) + heroFaithMap[heroId] = hero:getProperty("faith") + end + end + -- send award + local bigSuccess = false + local result = math.randomInt(0, 100) + if result < totalCoef then + bigSuccess = true + end + local money = math.ceil(carbonData.money / 5) * config.time * config.money_clear + local exp = math.ceil(carbonData.exp / 5) * config.time * config.exp_clear + local itemReward = config.item_clear_special:toNumMap() + itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money + itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp + if bigSuccess then + for key, value in pairs(itemReward) do + itemReward[key] = math.ceil(1.5 * value) + end + end + + local r, change = role:award(itemReward, {log = {desc = "radioQuest", int1 = id}}) + + radioTask[id] = nil + role:updateProperty({field="radioTask", value=radioTask, notNotify = true}) + + local msg = role:packReward(r, change) + msg["big"] = bigSuccess + msg["id"] = id + msg["heroFaith"] = heroFaithMap + + role:checkTaskEnter("RadioTaskStart", {heroCnt = #task.heros}) + + local herolist = {} + for _, heroId in ipairs(task.heros) do + local hero = role.heros[heroId] + if hero then + table.insert(herolist, hero:getProperty("type")) + end + end + + -- 讨伐行动 + role:log("punitive_action", { + mission_id = id, --关卡ID + mission_herolist = herolist, -- 英雄ID,排序以玩家出战设置为准,示例:[111, 222, 333, 444, 555] + mission_success_rate = totalCoef, -- 大成功几率 + mission_reward = r, -- 获得奖励,建议使用json格式记录。示例:{ itemid1: 1, itemid2: 3, itemid3: 5} + mission_result = 1, -- 战斗结果(0-无效,1-胜利,2-失败) + mission_roundtime = config.time, -- 完成耗时(秒) + mission_cleartype = 2, -- 1-开始; 2-完成(领取奖励时) + }) + role:mylog("role_action", {desc = "radioTask", int1 = id, short1 = bigSuccess and 1 or 0}) + return msg +end + function _M.startQuestRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) @@ -132,76 +205,15 @@ function _M.finishQuestRpc(agent, data) -- check finish time local radioTask = role:getProperty("radioTask") local task = radioTask[id] - if not task then return 1 end - if skynet.timex() < task.time then return 2 end - -- check id - local config = csvdb["crusadeCsv"][id] - if not config then return 3 end - local carbonData = csvdb["idle_battleCsv"][config.unlock] - if not carbonData then return 4 end - -- get heros - local totalCoef = 0 - local exp = config.time / 60 - local heroFaithMap = {} - for _, heroId in ipairs(task.heros) do - local hero = role.heros[heroId] - if hero then - totalCoef = totalCoef + getHeroCoef(hero, config.success) - -- 增加英雄信赖 - hero:addHeroFaith(exp) - heroFaithMap[heroId] = hero:getProperty("faith") - end - end - -- send award - local bigSuccess = false - local result = math.randomInt(0, 100) - if result < totalCoef then - bigSuccess = true - end - local money = math.ceil(carbonData.money / 5) * config.time * config.money_clear - local exp = math.ceil(carbonData.exp / 5) * config.time * config.exp_clear - local itemReward = config.item_clear_special:toNumMap() - itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money - itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp - if bigSuccess then - for key, value in pairs(itemReward) do - itemReward[key] = math.ceil(1.5 * value) - end - end - - local r, change = role:award(itemReward, {log = {desc = "radioQuest", int1 = id}}) - - radioTask[id] = nil - role:updateProperty({field="radioTask", value=radioTask, notNotify = true}) - - local msg = role:packReward(r, change) - msg["big"] = bigSuccess - msg["id"] = id - msg["heroFaith"] = heroFaithMap - SendPacket(actionCodes.Radio_finishQuestRpc, MsgPack.pack(msg)) - - role:checkTaskEnter("RadioTaskStart", {heroCnt = #task.heros}) - - local herolist = {} - for _, heroId in ipairs(task.heros) do - local hero = role.heros[heroId] - if hero then - table.insert(herolist, hero:getProperty("type")) - end + if not task then return 4 end + if skynet.timex() < task.time then return 5 end + + local reward = getCrusadeReward(role, id) + if type(reward) == "number" then + return reward + else + SendPacket(actionCodes.Radio_finishQuestRpc, MsgPack.pack(reward)) end - - -- 讨伐行动 - role:log("punitive_action", { - mission_id = id, --关卡ID - mission_herolist = herolist, -- 英雄ID,排序以玩家出战设置为准,示例:[111, 222, 333, 444, 555] - mission_success_rate = totalCoef, -- 大成功几率 - mission_reward = r, -- 获得奖励,建议使用json格式记录。示例:{ itemid1: 1, itemid2: 3, itemid3: 5} - mission_result = 1, -- 战斗结果(0-无效,1-胜利,2-失败) - mission_roundtime = config.time, -- 完成耗时(秒) - mission_cleartype = 2, -- 1-开始; 2-完成(领取奖励时) - }) - role:mylog("role_action", {desc = "radioTask", int1 = id, short1 = bigSuccess and 1 or 0}) - return true end @@ -212,12 +224,23 @@ function _M.cancelQuestRpc(agent, data) -- check finish time local radioTask = role:getProperty("radioTask") local task = radioTask[id] - if not task then return 1 end - if skynet.timex() > task.time then return 2 end - radioTask[id] = nil - role:updateProperty({field="radioTask", value=radioTask, notNotify = true}) - - SendPacket(actionCodes.Radio_cancelQuestRpc, MsgPack.pack({id = id})) + if not task then return 4 end + if skynet.timex() > task.time then return 5 end + + local remainT = task.time - skynet.timex() + if remainT > 0 then + local cost = math.ceil(remainT / 3600) * globalCsv.crusade_quicken + if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 6 end + role:costItems({[ItemId.Jade] = cost}, {log = {desc = "radioQuest", int1 = id}}) + local reward = getCrusadeReward(role, id) + if type(reward) == "number" then + return reward + else + SendPacket(actionCodes.Radio_cancelQuestRpc, MsgPack.pack(reward)) + end + else + SendPacket(actionCodes.Radio_cancelQuestRpc, MsgPack.pack({id = id})) + end return true end -- libgit2 0.21.2