You need to sign in before continuing.
Commit 6138622586ae02e19702039b610bea02be68f836
1 parent
7ba807d6
feat: 一键领取任务奖励(包括活跃度奖励)
Showing
1 changed file
with
62 additions
and
24 deletions
Show diff stats
src/actions/RoleAction.lua
| ... | ... | @@ -890,25 +890,14 @@ function _M.unLockStoryBookRpc(agent, data) |
| 890 | 890 | return true |
| 891 | 891 | end |
| 892 | 892 | |
| 893 | -function _M.taskRpc(agent, data) | |
| 894 | - local role = agent.role | |
| 895 | - local msg = MsgPack.unpack(data) | |
| 896 | - | |
| 897 | - if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end | |
| 898 | - | |
| 899 | - local taskType = msg.type -- 1 日常 2 周常 | |
| 900 | - local taskId = msg.id --任务id | |
| 901 | - local roleField = {"dTask", "wTask"} | |
| 902 | - if not roleField[taskType] then return 1 end | |
| 903 | - | |
| 904 | - local taskData = csvdb["task_loopCsv"][taskType][taskId] | |
| 905 | - if not taskData then return 2 end | |
| 893 | +local function getTaskReward(role, taskId, roleField, taskType, taskData) | |
| 894 | + if not taskData then return nil end | |
| 906 | 895 | |
| 907 | 896 | local taskStatus = role:getProperty(roleField[taskType]) |
| 908 | 897 | local tStatus = taskStatus["t"] or {} |
| 909 | 898 | |
| 910 | 899 | if (tStatus[taskId] or 0) < taskData.condition1 then |
| 911 | - return 3 | |
| 900 | + return nil | |
| 912 | 901 | end |
| 913 | 902 | |
| 914 | 903 | local reward, change = role:award(taskData.reward, {log = {desc = "finishTask", int1 = taskType, int2 = taskId}}) |
| ... | ... | @@ -936,30 +925,49 @@ function _M.taskRpc(agent, data) |
| 936 | 925 | task_reward_type = taskType, --任务奖励类型,见 任务奖励类型枚举表 |
| 937 | 926 | task_reward_detail = reward, --任务奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} |
| 938 | 927 | }) |
| 939 | - | |
| 940 | - SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) | |
| 941 | - return true | |
| 928 | + return reward, change | |
| 942 | 929 | end |
| 943 | 930 | |
| 944 | -function _M.taskActiveRpc(agent, data) | |
| 931 | +function _M.taskRpc(agent, data) | |
| 945 | 932 | local role = agent.role |
| 946 | 933 | local msg = MsgPack.unpack(data) |
| 947 | 934 | |
| 948 | 935 | if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end |
| 949 | 936 | |
| 950 | - local taskType = msg.type -- 1 日常 2 周长 | |
| 937 | + local taskType = msg.type -- 1 日常 2 周常 | |
| 951 | 938 | local taskId = msg.id --任务id |
| 952 | 939 | local roleField = {"dTask", "wTask"} |
| 953 | - if not roleField[taskType] then return end | |
| 940 | + if not roleField[taskType] then return 1 end | |
| 954 | 941 | |
| 955 | - local taskData = csvdb["task_activeCsv"][taskType][taskId] | |
| 956 | - if not taskData then return end | |
| 942 | + local reward, change = {}, {} | |
| 943 | + if not taskId then | |
| 944 | + | |
| 945 | + for id, taskData in pairs(csvdb["task_loopCsv"][taskType]) do | |
| 946 | + local tmpreward, tmpchange = getTaskReward(role, id, roleField, taskType, taskData) | |
| 947 | + if tmpreward then | |
| 948 | + for k, v in pairs(tmpreward) do | |
| 949 | + reward[k] = (reward[k] or 0) + v | |
| 950 | + end | |
| 951 | + if tmpchange then table.insert(change, tmpchange) end | |
| 952 | + end | |
| 953 | + end | |
| 954 | + else | |
| 955 | + local taskData = csvdb["task_loopCsv"][taskType][taskId] | |
| 956 | + if not taskData then return 2 end | |
| 957 | + reward, change= getTaskReward(role, taskId, roleField, taskType, taskData) | |
| 958 | + end | |
| 957 | 959 | |
| 960 | + SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) | |
| 961 | + return true | |
| 962 | +end | |
| 963 | + | |
| 964 | + | |
| 965 | +local function getTaskActiveReward(role, taskId, roleField, taskType, taskData) | |
| 958 | 966 | local taskStatus = role:getProperty(roleField[taskType]) |
| 959 | 967 | local tStatus = taskStatus["at"] or {} |
| 960 | 968 | |
| 961 | 969 | if tStatus[taskId] == -1 or (taskStatus["a"] or 0) < taskData.active then |
| 962 | - return | |
| 970 | + return nil | |
| 963 | 971 | end |
| 964 | 972 | |
| 965 | 973 | local needReward = taskData.reward:toNumMap() |
| ... | ... | @@ -974,12 +982,42 @@ function _M.taskActiveRpc(agent, data) |
| 974 | 982 | role:changeUpdates({ |
| 975 | 983 | { type = roleField[taskType], field = {"at", taskId}, value = -1 } |
| 976 | 984 | }) |
| 977 | - | |
| 985 | + | |
| 978 | 986 | role:log("task_reward", { |
| 979 | 987 | task_reward_id = taskId * 100 + taskType, --任务奖励ID |
| 980 | 988 | task_reward_type = 3, --任务奖励类型,见 任务奖励类型枚举表 |
| 981 | 989 | task_reward_detail = reward, --任务奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} |
| 982 | 990 | }) |
| 991 | + return reward, change | |
| 992 | +end | |
| 993 | + | |
| 994 | +function _M.taskActiveRpc(agent, data) | |
| 995 | + local role = agent.role | |
| 996 | + local msg = MsgPack.unpack(data) | |
| 997 | + | |
| 998 | + if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end | |
| 999 | + | |
| 1000 | + local taskType = msg.type -- 1 日常 2 周长 | |
| 1001 | + local taskId = msg.id --任务id | |
| 1002 | + local roleField = {"dTask", "wTask"} | |
| 1003 | + if not roleField[taskType] then return end | |
| 1004 | + | |
| 1005 | + local reward, change = {}, {} | |
| 1006 | + if not taskId then | |
| 1007 | + for id, taskData in pairs(csvdb["task_activeCsv"][taskType]) do | |
| 1008 | + local tmpreward, tmpchange = getTaskActiveReward(role, id, roleField, taskType, taskData) | |
| 1009 | + if tmpreward then | |
| 1010 | + for k, v in pairs(tmpreward) do | |
| 1011 | + reward[k] = (reward[k] or 0) + v | |
| 1012 | + end | |
| 1013 | + if tmpchange then table.insert(change, tmpchange) end | |
| 1014 | + end | |
| 1015 | + end | |
| 1016 | + else | |
| 1017 | + local taskData = csvdb["task_activeCsv"][taskType][taskId] | |
| 1018 | + if not taskData then return end | |
| 1019 | + reward, change= getTaskActiveReward(role, taskId, roleField, taskType, taskData) | |
| 1020 | + end | |
| 983 | 1021 | |
| 984 | 1022 | SendPacket(actionCodes.Role_taskActiveRpc, MsgPack.pack(role:packReward(reward, change))) |
| 985 | 1023 | return true | ... | ... |