Commit 091912ed095c19f249a57fe099c142b3c51cc43d
1 parent
ac885527
未测试版好友能量助力活动
Showing
6 changed files
with
207 additions
and
2 deletions
Show diff stats
src/ProtocolCode.lua
src/RedisKeys.lua
... | ... | @@ -47,6 +47,7 @@ FRIEND_KEY = "role:%d:friend" --哈希表 好友 |
47 | 47 | FRIEND_APPLY_KEY = "role:%d:apply" -- sort set 申请列表 |
48 | 48 | FRIEND_BLACK_KEY = "role:%d:black" -- set 黑名单 |
49 | 49 | FRIEND_POINT = "role:%d:point" -- set 当天送给我心的人 |
50 | +FRIEND_ENERGY = "role:%d:energy" -- set 送给我活动能量的好友 | |
50 | 51 | FRIEND_RECOMMEND = "friend:recommend" -- sort set 登录排序 获取推荐好友 |
51 | 52 | CHAT_OFFLINE = "chat:offline:%d" --消息离线缓存 |
52 | 53 | ... | ... |
src/actions/ActivityAction.lua
... | ... | @@ -888,4 +888,173 @@ function _M.commonSignRpc(agent, data) |
888 | 888 | return true |
889 | 889 | end |
890 | 890 | |
891 | +function _M.friendHelpRpc(agent, data) | |
892 | + local role = agent.role | |
893 | + local roleId = role:getProperty("id") | |
894 | + local msg = MsgPack.unpack(data) | |
895 | + local oper = tonumber(msg.oper) or -1 | |
896 | + local actid = msg.actid | |
897 | + local result, award | |
898 | + | |
899 | + if not role.activity:isOpenById(actid, "FriendEnergy") then return 1 end | |
900 | + if oper < 0 or oper > 3 then return 2 end | |
901 | + | |
902 | + local actCsv = csvdb["activity_ctrlCsv"][actid] | |
903 | + local getLimit = actCsv.condition | |
904 | + local gifts = actCsv.condition2:toTableArray(true) | |
905 | + | |
906 | + local actData = role.activity:getActData("FriendEnergy") or {} | |
907 | + | |
908 | + local function getIds() | |
909 | + local ids = {} | |
910 | + local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | |
911 | + for i = 1, #friends , 2 do | |
912 | + local objId = tonumber(friends[i]) | |
913 | + ids[objId] = 1 | |
914 | + end | |
915 | + return ids | |
916 | + end | |
917 | + | |
918 | + if oper == 0 then | |
919 | + local ids = {} | |
920 | + local friendIds = getIds() | |
921 | + for id, _ in pairs(friendIds) do | |
922 | + if redisproxy:sismember(FRIEND_ENERGY:format(roleId), id) then | |
923 | + ids[id] = 1 | |
924 | + end | |
925 | + end | |
926 | + SendPacket(actionCodes.Activity_friendHelpRpc, MsgPack.pack({result = 1, ids = ids})) | |
927 | + return true | |
928 | + elseif oper == 1 then -- 赠送好友能量 | |
929 | + local objId = msg.roleId | |
930 | + local gift = gifts[1] | |
931 | + local ids = {} | |
932 | + | |
933 | + if not objId then | |
934 | + if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then | |
935 | + return 3 | |
936 | + end | |
937 | + ids[objId] = 1 | |
938 | + else | |
939 | + ids = getIds() | |
940 | + end | |
941 | + | |
942 | + local giveFE = actData.giveFE or {} | |
943 | + redisproxy:pipelining(function(red) | |
944 | + for friendId, _ in pairs(ids) do | |
945 | + if not giveFE[friendId] then | |
946 | + result = 1 | |
947 | + giveFE[friendId] = 1 | |
948 | + award[gift[1]] = (award[gift[1]] or 0) + gift[2] | |
949 | + red:sadd(FRIEND_ENERGY:format(friendId), roleId) | |
950 | + end | |
951 | + end | |
952 | + end) | |
953 | + | |
954 | + actData.giveFE = giveFE | |
955 | + elseif oper == 2 then -- 收取能量 | |
956 | + local objId = msg.roleId | |
957 | + local gift = gifts[2] | |
958 | + local getFE = actData.getFE or {} | |
959 | + local limit = actData.limit or 0 | |
960 | + | |
961 | + if limit >= getLimit then return 4 end | |
962 | + | |
963 | + local ids = {} | |
964 | + if not objId then | |
965 | + if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then | |
966 | + return 5 | |
967 | + end | |
968 | + if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then | |
969 | + return 6 | |
970 | + end | |
971 | + ids[objId] = 1 | |
972 | + else | |
973 | + ids = getIds() | |
974 | + end | |
975 | + | |
976 | + local getFE = actData.getFE or {} | |
977 | + redisproxy:pipelining(function(red) | |
978 | + for friendId, _ in pairs(ids) do | |
979 | + if not getFE[friendId] and limit <= getLimit then | |
980 | + result = 1 | |
981 | + limit = limit + 1 | |
982 | + getFE[friendId] = 1 | |
983 | + award[gift[1]] = (award[gift[1]] or 0) + gift[2] | |
984 | + red:srem(FRIEND_ENERGY:format(roleId), friendId) | |
985 | + end | |
986 | + end | |
987 | + end) | |
988 | + | |
989 | + actData.limit = limit | |
990 | + actData.getFE = getFE | |
991 | + elseif oper == 3 then -- 一键送领全部 | |
992 | + local giveFE = actData.giveFE or {} | |
993 | + local getFE = actData.getFE or {} | |
994 | + local gift1 = gifts[1] | |
995 | + local gift2 = gifts[2] | |
996 | + local limit = actData.limit or 0 | |
997 | + local ids = getIds() | |
998 | + redisproxy:pipelining(function(red) | |
999 | + for friendId, _ in pairs(ids) do | |
1000 | + if not giveFE[friendId] then | |
1001 | + result = 1 | |
1002 | + giveFE[friendId] = 1 | |
1003 | + award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] | |
1004 | + red:sadd(FRIEND_ENERGY:format(friendId), roleId) | |
1005 | + end | |
1006 | + | |
1007 | + if not getFE[friendId] and limit <= getLimit then | |
1008 | + result = 1 | |
1009 | + limit = limit + 1 | |
1010 | + getFE[friendId] = 1 | |
1011 | + award[gift2[1]] = (award[gift2[1]] or 0) + gift2[2] | |
1012 | + red:srem(FRIEND_ENERGY:format(roleId), friendId) | |
1013 | + end | |
1014 | + end | |
1015 | + end) | |
1016 | + | |
1017 | + actData.limit = limit | |
1018 | + actData.giveFE = giveFE | |
1019 | + actData.getFE = getFE | |
1020 | + elseif oper == 4 then -- 抽大奖 | |
1021 | + local magic = actData.magic or 0 | |
1022 | + local rewards = actData.reward or {} | |
1023 | + local rewardCsv = csvdb["activity_orderRewardsCsv"][actid] | |
1024 | + local itemId1 = gifts[1][1] | |
1025 | + local itemId2 = gifts[2][1] | |
1026 | + | |
1027 | + local level = math.min(magic + 1,#rewardCsv) | |
1028 | + local rewardData = rewardCsv[level] | |
1029 | + | |
1030 | + local cost = {[itemId1] = rewardData.condition1, [itemId2] = rewardData.condition2} | |
1031 | + | |
1032 | + if not role:checkItemEnough(cost) then return 7 end | |
1033 | + role:costItems(cost, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}}) | |
1034 | + | |
1035 | + award = {} | |
1036 | + if rewardCsv.reward ~= "" then | |
1037 | + result = 1 | |
1038 | + award = rewardCsv.reward:toNumMap() | |
1039 | + end | |
1040 | + if rewardCsv.reward_random ~= "" then | |
1041 | + result = 1 | |
1042 | + local pool = {} | |
1043 | + for _, temp in pairs(rewardCsv.reward_random:toArray()) do | |
1044 | + table.insert(pool, temp:toArray(true, "=")) | |
1045 | + end | |
1046 | + local gift = pool(math.randWeight(pool, 3)) | |
1047 | + award[gift[1]] = (award[gift[1]] or 0) + gift[2] | |
1048 | + end | |
1049 | + rewards[level] = 1 | |
1050 | + actData.reward = rewards | |
1051 | + actData.magic = level | |
1052 | + end | |
1053 | + | |
1054 | + local reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}}) | |
1055 | + role.activity:updateActData("FriendEnergy", actData) | |
1056 | + SendPacket(actionCodes.Activity_friendHelpRpc, MsgPack.pack({result = result, reward = reward})) | |
1057 | + return true | |
1058 | +end | |
1059 | + | |
891 | 1060 | return _M |
892 | 1061 | \ No newline at end of file | ... | ... |
src/models/Activity.lua
... | ... | @@ -32,6 +32,7 @@ Activity.ActivityType = { |
32 | 32 | Crisis = 26, -- 宝藏怪活动 |
33 | 33 | |
34 | 34 | CommonSignIn = 28, --通用签到 |
35 | + FriendEnergy = 29, -- 好友互赠能量活动 | |
35 | 36 | } |
36 | 37 | |
37 | 38 | local function checkActivityType(activityType) |
... | ... | @@ -77,6 +78,7 @@ Activity.schema = { |
77 | 78 | act26 = {"table", {}}, -- {task = {id = count}, socre = {id = status}} |
78 | 79 | |
79 | 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表示领取过奖励 | |
80 | 82 | } |
81 | 83 | |
82 | 84 | function Activity:data() |
... | ... | @@ -99,6 +101,7 @@ function Activity:data() |
99 | 101 | act26 = self:getProperty("act26"), |
100 | 102 | |
101 | 103 | act28 = self:getProperty("act28"), |
104 | + act29 = self:getProperty("act29"), | |
102 | 105 | } |
103 | 106 | end |
104 | 107 | |
... | ... | @@ -746,7 +749,22 @@ activityFunc[Activity.ActivityType.ActShopGoods] = { |
746 | 749 | end, |
747 | 750 | } |
748 | 751 | |
749 | - | |
752 | +activityFunc[Activity.ActivityType.FriendEnergy] = { | |
753 | + ["init"] = function (self, actType, isCrossDay, notify, actId) | |
754 | + local data = {magic = 0, limit = 0, reward = {}, giveAE = {}, getAE = {}} | |
755 | + self:updateActData(actType, data, not notify) | |
756 | + end, | |
757 | + ["crossDay"] = function(self, actType, notify) | |
758 | + local actData = self:getActData(actType) | |
759 | + actData.limit = 0 | |
760 | + actData.giveAE = {} | |
761 | + actData.getAE = {} | |
762 | + self:updateActData(actType, actData, not notify) | |
763 | + end, | |
764 | + ["close"] = function (self, actType, notify, actId) | |
765 | + redisproxy:del(FRIEND_ENERGY:format(self.owner:getProperty("id"))) | |
766 | + end | |
767 | +} | |
750 | 768 | |
751 | 769 | activityFunc[Activity.ActivityType.Crisis] = { |
752 | 770 | ["check"] = function(self, actType, notify, atype, count) -- 检查 | ... | ... |
src/models/RoleLog.lua
src/models/RolePlugin.lua
... | ... | @@ -1515,6 +1515,7 @@ function RolePlugin.bind(Role) |
1515 | 1515 | local breathes = { |
1516 | 1516 | ["email"] = breath(120, "email"), -- email |
1517 | 1517 | ["pvphg"] = breath(300, "pvphg"), -- 高级竞技场 奖励满的红点 |
1518 | + ["actfriend"] = breath(180, "actfriend"), -- 好友能量助力活动 | |
1518 | 1519 | } |
1519 | 1520 | function Role:checkNewEvent(now) |
1520 | 1521 | if now - self:getProperty("ltime") < 5 then |
... | ... | @@ -1576,7 +1577,21 @@ function RolePlugin.bind(Role) |
1576 | 1577 | if table.pack(next(newReward))[2] >= divisionData.limit then |
1577 | 1578 | return true |
1578 | 1579 | end |
1579 | - | |
1580 | + end | |
1581 | + | |
1582 | + checks["actfriend"] = function () | |
1583 | + local ids = {} | |
1584 | + local roleId = self:getProperty("id") | |
1585 | + local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | |
1586 | + for i = 1, #friends , 2 do | |
1587 | + local objId = tonumber(friends[i]) | |
1588 | + ids[objId] = 1 | |
1589 | + end | |
1590 | + for friendId, _ in pairs(ids) do | |
1591 | + if redisproxy:sismember(FRIEND_ENERGY:format(roleId), friendId) then | |
1592 | + return true | |
1593 | + end | |
1594 | + end | |
1580 | 1595 | end |
1581 | 1596 | |
1582 | 1597 | local events = {} | ... | ... |