From 6138622586ae02e19702039b610bea02be68f836 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Mon, 24 May 2021 16:39:02 +0800 Subject: [PATCH] feat: 一键领取任务奖励(包括活跃度奖励) --- src/actions/RoleAction.lua | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 35b5ca1..72eb011 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -890,25 +890,14 @@ function _M.unLockStoryBookRpc(agent, data) return true end -function _M.taskRpc(agent, data) - local role = agent.role - local msg = MsgPack.unpack(data) - - if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end - - local taskType = msg.type -- 1 日常 2 周常 - local taskId = msg.id --任务id - local roleField = {"dTask", "wTask"} - if not roleField[taskType] then return 1 end - - local taskData = csvdb["task_loopCsv"][taskType][taskId] - if not taskData then return 2 end +local function getTaskReward(role, taskId, roleField, taskType, taskData) + if not taskData then return nil end local taskStatus = role:getProperty(roleField[taskType]) local tStatus = taskStatus["t"] or {} if (tStatus[taskId] or 0) < taskData.condition1 then - return 3 + return nil end local reward, change = role:award(taskData.reward, {log = {desc = "finishTask", int1 = taskType, int2 = taskId}}) @@ -936,30 +925,49 @@ function _M.taskRpc(agent, data) task_reward_type = taskType, --任务奖励类型,见 任务奖励类型枚举表 task_reward_detail = reward, --任务奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} }) - - SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) - return true + return reward, change end -function _M.taskActiveRpc(agent, data) +function _M.taskRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end - local taskType = msg.type -- 1 日常 2 周长 + local taskType = msg.type -- 1 日常 2 周常 local taskId = msg.id --任务id local roleField = {"dTask", "wTask"} - if not roleField[taskType] then return end + if not roleField[taskType] then return 1 end - local taskData = csvdb["task_activeCsv"][taskType][taskId] - if not taskData then return end + local reward, change = {}, {} + if not taskId then + + for id, taskData in pairs(csvdb["task_loopCsv"][taskType]) do + local tmpreward, tmpchange = getTaskReward(role, id, roleField, taskType, taskData) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + if tmpchange then table.insert(change, tmpchange) end + end + end + else + local taskData = csvdb["task_loopCsv"][taskType][taskId] + if not taskData then return 2 end + reward, change= getTaskReward(role, taskId, roleField, taskType, taskData) + end + SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + + +local function getTaskActiveReward(role, taskId, roleField, taskType, taskData) local taskStatus = role:getProperty(roleField[taskType]) local tStatus = taskStatus["at"] or {} if tStatus[taskId] == -1 or (taskStatus["a"] or 0) < taskData.active then - return + return nil end local needReward = taskData.reward:toNumMap() @@ -974,12 +982,42 @@ function _M.taskActiveRpc(agent, data) role:changeUpdates({ { type = roleField[taskType], field = {"at", taskId}, value = -1 } }) - + role:log("task_reward", { task_reward_id = taskId * 100 + taskType, --任务奖励ID task_reward_type = 3, --任务奖励类型,见 任务奖励类型枚举表 task_reward_detail = reward, --任务奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} }) + return reward, change +end + +function _M.taskActiveRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end + + local taskType = msg.type -- 1 日常 2 周长 + local taskId = msg.id --任务id + local roleField = {"dTask", "wTask"} + if not roleField[taskType] then return end + + local reward, change = {}, {} + if not taskId then + for id, taskData in pairs(csvdb["task_activeCsv"][taskType]) do + local tmpreward, tmpchange = getTaskActiveReward(role, id, roleField, taskType, taskData) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + if tmpchange then table.insert(change, tmpchange) end + end + end + else + local taskData = csvdb["task_activeCsv"][taskType][taskId] + if not taskData then return end + reward, change= getTaskActiveReward(role, taskId, roleField, taskType, taskData) + end SendPacket(actionCodes.Role_taskActiveRpc, MsgPack.pack(role:packReward(reward, change))) return true -- libgit2 0.21.2