Commit cab7184bb610910063f0c86077945f19d7b6ad59

Authored by chenyueqi
1 parent eba94a09

活动能量bug

Showing 2 changed files with 75 additions and 73 deletions   Show diff stats
src/actions/ActivityAction.lua
... ... @@ -893,9 +893,11 @@ function _M.friendHelpRpc(agent, data)
893 893 local roleId = role:getProperty("id")
894 894 local msg = MsgPack.unpack(data)
895 895 local oper = tonumber(msg.oper) or -1
896   - local actid = msg.actid
897   - local result, award
  896 + local award = {}
  897 + local result
  898 +
898 899  
  900 + local actid = 37
899 901 if not role.activity:isOpenById(actid, "FriendEnergy") then return 1 end
900 902 if oper < 1 or oper > 3 then return 2 end
901 903  
... ... @@ -916,99 +918,98 @@ function _M.friendHelpRpc(agent, data)
916 918 end
917 919  
918 920 if oper == 1 then -- 赠送好友能量
  921 + local giveAE = actData.giveAE or {}
919 922 local objId = msg.roleId
920 923 local gift = gifts[1]
921 924 local ids = {}
922 925  
923 926 if not objId then
924   - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then
925   - return 3
926   - end
927   - ids[objId] = 1
928   - else
929   - ids = getIds()
  927 + return 3
  928 + end
  929 + if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then
  930 + result = 2
  931 + end
  932 + if giveAE[objId] then
  933 + result = 1
930 934 end
931 935  
932   - local giveFE = actData.giveFE or {}
933   - redisproxy:pipelining(function(red)
934   - for friendId, _ in pairs(ids) do
935   - if not giveFE[friendId] then
936   - result = 1
937   - giveFE[friendId] = 1
938   - award[gift[1]] = (award[gift[1]] or 0) + gift[2]
939   - red:sadd(FRIEND_ENERGY:format(friendId), roleId)
940   - rpcRole(friendId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}}))
941   - end
942   - end
943   - end)
944   -
945   - actData.giveFE = giveFE
  936 + if not result then
  937 + giveAE[objId] = 1
  938 + award[gift[1]] = gift[2]
  939 + redisproxy:sadd(FRIEND_ENERGY:format(objId), roleId)
  940 + rpcRole(objId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}}))
  941 + actData.giveAE = giveAE
  942 + end
946 943 elseif oper == 2 then -- 收取能量
947 944 local objId = msg.roleId
948 945 local gift = gifts[2]
949   - local getFE = actData.getFE or {}
  946 + local getAE = actData.getAE or {}
950 947 local limit = actData.limit or 0
951 948  
952 949 if limit >= getLimit then return 4 end
953   -
954   - local ids = {}
955   - if not objId then
956   - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then
957   - return 5
958   - end
959   - if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then
960   - return 6
961   - end
962   - ids[objId] = 1
963   - else
964   - ids = getIds()
  950 + if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then
  951 + result = 3
  952 + end
  953 + if getAE[objId] then
  954 + result = 2
  955 + end
  956 + if limit >= getLimit then
  957 + result = 1
965 958 end
966 959  
967   - local getFE = actData.getFE or {}
968   - redisproxy:pipelining(function(red)
969   - for friendId, _ in pairs(ids) do
970   - if not getFE[friendId] and limit <= getLimit then
971   - result = 1
972   - limit = limit + 1
973   - getFE[friendId] = 1
974   - award[gift[1]] = (award[gift[1]] or 0) + gift[2]
975   - red:srem(FRIEND_ENERGY:format(roleId), friendId)
976   - end
977   - end
978   - end)
979   -
980   - actData.limit = limit
981   - actData.getFE = getFE
  960 + if not result then
  961 + limit = limit + 1
  962 + getAE[objId] = 1
  963 + award[gift[1]] = gift[2]
  964 + redisproxy:srem(FRIEND_ENERGY:format(roleId), objId)
  965 + actData.limit = limit
  966 + actData.getAE = getAE
  967 + end
982 968 elseif oper == 3 then -- 一键送领全部
983   - local giveFE = actData.giveFE or {}
984   - local getFE = actData.getFE or {}
  969 + local giveAE = actData.giveAE or {}
  970 + local getAE = actData.getAE or {}
985 971 local gift1 = gifts[1]
986 972 local gift2 = gifts[2]
987 973 local limit = actData.limit or 0
  974 + local cmd1, cmd2 = 0, 0
988 975 local ids = getIds()
  976 +
  977 + local members = {}
  978 + local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId))
  979 + for _, id in pairs(temp) do
  980 + members[tonumber(id)] = 1
  981 + end
  982 +
989 983 redisproxy:pipelining(function(red)
990 984 for friendId, _ in pairs(ids) do
991   - if not giveFE[friendId] then
992   - result = 1
993   - giveFE[friendId] = 1
  985 + if not giveAE[friendId] then
  986 + giveAE[friendId] = 1
994 987 award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2]
995 988 red:sadd(FRIEND_ENERGY:format(friendId), roleId)
996 989 rpcRole(friendId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}}))
  990 + cmd1 = 2
997 991 end
998 992  
999   - if not getFE[friendId] and limit <= getLimit then
1000   - result = 1
  993 + if members[friendId] and not getAE[friendId] and limit <= getLimit then
  994 + cmd2 = 1
1001 995 limit = limit + 1
1002   - getFE[friendId] = 1
  996 + getAE[friendId] = 1
1003 997 award[gift2[1]] = (award[gift2[1]] or 0) + gift2[2]
1004 998 red:srem(FRIEND_ENERGY:format(roleId), friendId)
1005 999 end
1006 1000 end
1007 1001 end)
1008 1002  
  1003 + local sum = cmd1 + cmd2
  1004 + if sum == 0 then
  1005 + result = 3
  1006 + elseif sum ~= 3 then
  1007 + result = sum
  1008 + end
  1009 +
1009 1010 actData.limit = limit
1010   - actData.giveFE = giveFE
1011   - actData.getFE = getFE
  1011 + actData.giveAE = giveAE
  1012 + actData.getAE = getAE
1012 1013 elseif oper == 4 then -- 抽大奖
1013 1014 local magic = actData.magic or 0
1014 1015 local rewards = actData.reward or {}
... ... @@ -1024,7 +1025,6 @@ function _M.friendHelpRpc(agent, data)
1024 1025 if not role:checkItemEnough(cost) then return 7 end
1025 1026 role:costItems(cost, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}})
1026 1027  
1027   - award = {}
1028 1028 if rewardCsv.reward ~= "" then
1029 1029 result = 1
1030 1030 award = rewardCsv.reward:toNumMap()
... ... @@ -1056,7 +1056,10 @@ function _M.friendHelpRpc(agent, data)
1056 1056 end)
1057 1057 actData.new = ids
1058 1058  
1059   - local reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}})
  1059 + local reward, change
  1060 + if next(award) then
  1061 + reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}})
  1062 + end
1060 1063 role.activity:updateActData("FriendEnergy", actData)
1061 1064 SendPacket(actionCodes.Activity_friendHelpRpc, MsgPack.pack({result = result, reward = reward}))
1062 1065 return true
... ...
src/models/Activity.lua
... ... @@ -32,7 +32,7 @@ Activity.ActivityType = {
32 32 Crisis = 26, -- 宝藏怪活动
33 33  
34 34 CommonSignIn = 28, --通用签到
35   - FriendEnergy = 29, -- 好友互赠能量活动
  35 + FriendEnergy = 30, -- 好友互赠能量活动
36 36 }
37 37  
38 38 local function checkActivityType(activityType)
... ... @@ -78,7 +78,7 @@ Activity.schema = {
78 78 act26 = {"table", {}}, -- {task = {id = count}, socre = {id = status}}
79 79  
80 80 act28 = {"table", {}}, -- 每日活跃签到 {0=day, 1=1,2=1,3=1}
81   - act29 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励
  81 + act30 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励
82 82 }
83 83  
84 84 function Activity:data()
... ... @@ -101,7 +101,7 @@ function Activity:data()
101 101 act26 = self:getProperty("act26"),
102 102  
103 103 act28 = self:getProperty("act28"),
104   - act29 = self:getProperty("act29"),
  104 + act30 = self:getProperty("act30"),
105 105 }
106 106 end
107 107  
... ... @@ -755,7 +755,7 @@ activityFunc[Activity.ActivityType.FriendEnergy] = {
755 755 self:updateActData(actType, data, not notify)
756 756 end,
757 757 ["login"] = function (self, actType)
758   - local curData = self:getActData(actType) or {}
  758 + local actData = self:getActData(actType) or {}
759 759 actData.new = self:getActFriendNew()
760 760 self:updateActData(actType, actData, not notify)
761 761 end,
... ... @@ -771,7 +771,7 @@ activityFunc[Activity.ActivityType.FriendEnergy] = {
771 771 end
772 772 }
773 773  
774   -function activity:getActFriendNew()
  774 +function Activity:getActFriendNew()
775 775 local roleId = self.owner:getProperty("id")
776 776 local friendIds = {}
777 777 local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId))
... ... @@ -781,13 +781,12 @@ function activity:getActFriendNew()
781 781 end
782 782  
783 783 local ids = {}
784   - redisproxy:pipelining(function(red)
785   - for id, _ in pairs(friendIds) do
786   - if red:sismember(FRIEND_ENERGY:format(roleId), id) then
787   - ids[id] = 1
788   - end
  784 + local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId))
  785 + for _, id in pairs(members) do
  786 + if friendIds[tonumber(id)] then
  787 + ids[tonumber(id)] = 1
789 788 end
790   - end)
  789 + end
791 790 return ids
792 791 end
793 792  
... ...