diff --git a/src/actions/ActivityAction.lua b/src/actions/ActivityAction.lua index 982d7ad..95c6a9e 100644 --- a/src/actions/ActivityAction.lua +++ b/src/actions/ActivityAction.lua @@ -893,9 +893,11 @@ function _M.friendHelpRpc(agent, data) local roleId = role:getProperty("id") local msg = MsgPack.unpack(data) local oper = tonumber(msg.oper) or -1 - local actid = msg.actid - local result, award + local award = {} + local result + + local actid = 37 if not role.activity:isOpenById(actid, "FriendEnergy") then return 1 end if oper < 1 or oper > 3 then return 2 end @@ -916,99 +918,98 @@ function _M.friendHelpRpc(agent, data) end if oper == 1 then -- 赠送好友能量 + local giveAE = actData.giveAE or {} local objId = msg.roleId local gift = gifts[1] local ids = {} if not objId then - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then - return 3 - end - ids[objId] = 1 - else - ids = getIds() + return 3 + end + if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then + result = 2 + end + if giveAE[objId] then + result = 1 end - local giveFE = actData.giveFE or {} - redisproxy:pipelining(function(red) - for friendId, _ in pairs(ids) do - if not giveFE[friendId] then - result = 1 - giveFE[friendId] = 1 - award[gift[1]] = (award[gift[1]] or 0) + gift[2] - red:sadd(FRIEND_ENERGY:format(friendId), roleId) - rpcRole(friendId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}})) - end - end - end) - - actData.giveFE = giveFE + if not result then + giveAE[objId] = 1 + award[gift[1]] = gift[2] + redisproxy:sadd(FRIEND_ENERGY:format(objId), roleId) + rpcRole(objId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}})) + actData.giveAE = giveAE + end elseif oper == 2 then -- 收取能量 local objId = msg.roleId local gift = gifts[2] - local getFE = actData.getFE or {} + local getAE = actData.getAE or {} local limit = actData.limit or 0 if limit >= getLimit then return 4 end - - local ids = {} - if not objId then - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then - return 5 - end - if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then - return 6 - end - ids[objId] = 1 - else - ids = getIds() + if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then + result = 3 + end + if getAE[objId] then + result = 2 + end + if limit >= getLimit then + result = 1 end - local getFE = actData.getFE or {} - redisproxy:pipelining(function(red) - for friendId, _ in pairs(ids) do - if not getFE[friendId] and limit <= getLimit then - result = 1 - limit = limit + 1 - getFE[friendId] = 1 - award[gift[1]] = (award[gift[1]] or 0) + gift[2] - red:srem(FRIEND_ENERGY:format(roleId), friendId) - end - end - end) - - actData.limit = limit - actData.getFE = getFE + if not result then + limit = limit + 1 + getAE[objId] = 1 + award[gift[1]] = gift[2] + redisproxy:srem(FRIEND_ENERGY:format(roleId), objId) + actData.limit = limit + actData.getAE = getAE + end elseif oper == 3 then -- 一键送领全部 - local giveFE = actData.giveFE or {} - local getFE = actData.getFE or {} + local giveAE = actData.giveAE or {} + local getAE = actData.getAE or {} local gift1 = gifts[1] local gift2 = gifts[2] local limit = actData.limit or 0 + local cmd1, cmd2 = 0, 0 local ids = getIds() + + local members = {} + local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) + for _, id in pairs(temp) do + members[tonumber(id)] = 1 + end + redisproxy:pipelining(function(red) for friendId, _ in pairs(ids) do - if not giveFE[friendId] then - result = 1 - giveFE[friendId] = 1 + if not giveAE[friendId] then + giveAE[friendId] = 1 award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] red:sadd(FRIEND_ENERGY:format(friendId), roleId) rpcRole(friendId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}})) + cmd1 = 2 end - if not getFE[friendId] and limit <= getLimit then - result = 1 + if members[friendId] and not getAE[friendId] and limit <= getLimit then + cmd2 = 1 limit = limit + 1 - getFE[friendId] = 1 + getAE[friendId] = 1 award[gift2[1]] = (award[gift2[1]] or 0) + gift2[2] red:srem(FRIEND_ENERGY:format(roleId), friendId) end end end) + local sum = cmd1 + cmd2 + if sum == 0 then + result = 3 + elseif sum ~= 3 then + result = sum + end + actData.limit = limit - actData.giveFE = giveFE - actData.getFE = getFE + actData.giveAE = giveAE + actData.getAE = getAE elseif oper == 4 then -- 抽大奖 local magic = actData.magic or 0 local rewards = actData.reward or {} @@ -1024,7 +1025,6 @@ function _M.friendHelpRpc(agent, data) if not role:checkItemEnough(cost) then return 7 end role:costItems(cost, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}}) - award = {} if rewardCsv.reward ~= "" then result = 1 award = rewardCsv.reward:toNumMap() @@ -1056,7 +1056,10 @@ function _M.friendHelpRpc(agent, data) end) actData.new = ids - local reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}}) + local reward, change + if next(award) then + reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}}) + end role.activity:updateActData("FriendEnergy", actData) SendPacket(actionCodes.Activity_friendHelpRpc, MsgPack.pack({result = result, reward = reward})) return true diff --git a/src/models/Activity.lua b/src/models/Activity.lua index 84b8cea..a5f54fe 100644 --- a/src/models/Activity.lua +++ b/src/models/Activity.lua @@ -32,7 +32,7 @@ Activity.ActivityType = { Crisis = 26, -- 宝藏怪活动 CommonSignIn = 28, --通用签到 - FriendEnergy = 29, -- 好友互赠能量活动 + FriendEnergy = 30, -- 好友互赠能量活动 } local function checkActivityType(activityType) @@ -78,7 +78,7 @@ Activity.schema = { act26 = {"table", {}}, -- {task = {id = count}, socre = {id = status}} act28 = {"table", {}}, -- 每日活跃签到 {0=day, 1=1,2=1,3=1} - act29 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励 + act30 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励 } function Activity:data() @@ -101,7 +101,7 @@ function Activity:data() act26 = self:getProperty("act26"), act28 = self:getProperty("act28"), - act29 = self:getProperty("act29"), + act30 = self:getProperty("act30"), } end @@ -755,7 +755,7 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { self:updateActData(actType, data, not notify) end, ["login"] = function (self, actType) - local curData = self:getActData(actType) or {} + local actData = self:getActData(actType) or {} actData.new = self:getActFriendNew() self:updateActData(actType, actData, not notify) end, @@ -771,7 +771,7 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { end } -function activity:getActFriendNew() +function Activity:getActFriendNew() local roleId = self.owner:getProperty("id") local friendIds = {} local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) @@ -781,13 +781,12 @@ function activity:getActFriendNew() end local ids = {} - redisproxy:pipelining(function(red) - for id, _ in pairs(friendIds) do - if red:sismember(FRIEND_ENERGY:format(roleId), id) then - ids[id] = 1 - end + local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) + for _, id in pairs(members) do + if friendIds[tonumber(id)] then + ids[tonumber(id)] = 1 end - end) + end return ids end -- libgit2 0.21.2