diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 21fd15e..0dca470 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -281,11 +281,12 @@ actionCodes = { Capsule_drawRpc = 854, --抽扭蛋机 --Capsule_switchRoomRpc = 855, --切换扭蛋机房间 Capsule_notifyChange = 856, -- 通知信息变动 - Capsule_payReward = 857, -- 特殊赏 奖励通知 + Capsule_specialRewardRpc = 857, -- 获取 未领取特殊赏通知 主动 Capsule_exitRpc = 858, -- 退出 Capsule_getDataRpc = 859, --获取扭蛋机信息 - Capsule_convertCapsuleRpc = 890, --兑换消耗票 - Capsule_pageRecordRpc = 891, --抽奖记录分页查询 + Capsule_convertCapsuleRpc = 860, --兑换消耗票 + Capsule_pageRecordRpc = 861, --抽奖记录分页查询 + Capsule_clearSpecialNtyRpc = 862, --消除特殊赏通知 } rpcResponseBegin = 10000 diff --git a/src/actions/CapsuleAction.lua b/src/actions/CapsuleAction.lua index 239178d..238407b 100644 --- a/src/actions/CapsuleAction.lua +++ b/src/actions/CapsuleAction.lua @@ -51,7 +51,7 @@ function _M.joinRpc(agent, data) if typ == 1 then ret = skynet.call(agent.capsule_serv, "lua", "join", roleId, capsuleId) elseif typ == 0 then - ret = role:joinCapsule() + ret = role:joinCapsule(roleId, capsuleId) end SendPacket(actionCodes.Capsule_joinRpc, MsgPack.pack(ret)) return true @@ -143,7 +143,6 @@ function _M.drawRpc(agent, data) if drawReward["reward"] and next(drawReward["reward"]) then _, change = role:award(drawReward["reward"], {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) drawReward["capsule"] = capsule - dump(drawReward) SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(drawReward)) else return ret @@ -162,7 +161,7 @@ function _M.getDataRpc(agent, data) if typ == 1 then capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", roleId, capsuleId) else - capsule = role:getCapsuleData(capsuleId) + capsule = role:getCapsuleData(roleId, capsuleId) end if not capsule then return 1 end @@ -213,4 +212,41 @@ function _M.pageRecordRpc(agent, data) return true end +function _M.specialRewardRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local capsuleId = msg.capsule_id + local typ = msg.typ --0=独享,1= 公开 + local roleId = role:getProperty("id") + + local ret + if typ == 1 then + ret = skynet.call(agent.capsule_serv, "lua", "get_special_nty", roleId, capsuleId) + else + ret = role:getSpecialNotify(roleId, capsuleId) + end + if not ret or not next(ret) then return 1 end + + SendPacket(actionCodes.Capsule_specialRewardRpc, MsgPack.pack({special= ret})) + return true +end + +function _M.clearSpecialNtyRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local capsuleId = msg.capsule_id + local typ = msg.typ --0=独享,1= 公开 + local good_ids = msg.good_ids + local roleId = role:getProperty("id") + + local ret + if typ == 1 then + ret = skynet.call(agent.capsule_serv, "lua", "clear_special_nty", roleId, capsuleId, good_ids) + end + if not ret or not next(ret) then return 1 end + + SendPacket(actionCodes.Capsule_clearSpecialNtyRpc, MsgPack.pack({})) + return true +end + return _M \ No newline at end of file diff --git a/src/models/Capsule.lua b/src/models/Capsule.lua index 52a3c4b..aea777e 100644 --- a/src/models/Capsule.lua +++ b/src/models/Capsule.lua @@ -669,8 +669,7 @@ function Capsule:checkIncentive(roleId, name, now) incentiveRecord[roleId] = incentiveByRole self:setProperty("incentiveRecord", incentiveRecord) - --TODO 先屏蔽 - return {} + return incentiveByRole end local rewardCollect = function(reward, goods) @@ -892,6 +891,40 @@ function Capsule:pageRecord(up, idx) return tmpRecord end +--检查是否有未领取奖励的通知 +function Capsule:getSpecialNotify(roleId) + local specialsRecord = self:getProperty("specialsRecord") or {} + local specialsRecordByRole = specialsRecord[roleId] + if not specialsRecordByRole then return nil end + + local tmp = {} + for good_id, good in pairs(specialsRecordByRole) do + if not good.nty or good.nty == 0 then + tmp[good_id] = good + end + end + + specialsRecord[roleId] = specialsRecordByRole + self:setProperty("specialsRecord", specialsRecord) + + return tmp +end + +function Capsule:clearSpecialNty(roleId, good_ids) + local specialsRecord = self:getProperty("specialsRecord") or {} + local specialsRecordByRole = specialsRecord[roleId] + if not specialsRecordByRole then return nil end + + for _, good_id in ipairs(good_ids) do + if specialsRecordByRole[good_id] then + specialsRecordByRole[good_id].nty = 1 + end + end + + specialsRecord[roleId] = specialsRecordByRole + self:setProperty("specialsRecord", specialsRecord) +end + function Capsule:data(roleId) return { diff --git a/src/models/RoleCross.lua b/src/models/RoleCross.lua index 3b9889b..f304e3a 100644 --- a/src/models/RoleCross.lua +++ b/src/models/RoleCross.lua @@ -211,7 +211,6 @@ RoleCross.bind = function (Role) end function Role:paySpecialReward(roleId, notify) - dump(notify) if notify and next(notify) then local reward = {} for key, val in pairs(notify) do @@ -221,6 +220,7 @@ RoleCross.bind = function (Role) end self:award(reward, {log = {desc = "CapsuleReward", int1=roleId}}) + SendPacket(actionCodes.Capsule_notifyChange, MsgPack.pack({special = notify})) end end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index ee260e9..a8aebf8 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -2090,7 +2090,7 @@ function RolePlugin.bind(Role) local emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) local redret = redisproxy:pipelining(function (red) for id = emailSync, globalEmail do - red:hgetall(string.format("globalEmail:%s", id)) + red:hgetall(string.format("globalEmail:%s", id)) end end) for _, data in ipairs(redret) do @@ -3174,11 +3174,11 @@ function RolePlugin.bind(Role) return ret, drawReward, capsule:data(roleId) end - function Role:joinCapsule(capsuleId) + function Role:joinCapsule(roleId, capsuleId) local capsule = self.capsules[capsuleId] if not capsule then return nil end - return capsule:data() + return capsule:data(roleId) end function Role:checkCapsule(now) @@ -3197,11 +3197,11 @@ function RolePlugin.bind(Role) return capsule:getGoodsAmount(), capsule:getProperty("token") end - function Role:getCapsuleData(capsuleId) + function Role:getCapsuleData(roleId, capsuleId) local capsule = self.capsules[capsuleId] if not capsule then return nil end - return capsule:data() + return capsule:data(roleId) end function Role:resetCapsule() @@ -3234,6 +3234,13 @@ function RolePlugin.bind(Role) return capsule:pageRecord(up, idx) end + + function Role:getSpecialNotify(roleId, capsuleId) + local capsule = self.capsules[capsuleId] + if not capsule then return nil end + + return capsule:getSpecialNotify(roleId) + end end return RolePlugin \ No newline at end of file diff --git a/src/services/capsuled.lua b/src/services/capsuled.lua index 6f4aac3..0afb57e 100644 --- a/src/services/capsuled.lua +++ b/src/services/capsuled.lua @@ -73,7 +73,7 @@ function broadCastSpecial(roleId, capsuleId, broadInfo) for id, _ in pairs(register) do if id ~= roleId then if broadInfo[id] then - rpcRole(id, "paySpecialReward", id, broadInfo[id]) + rpcRole(id, "paySpecialReward", id, broadInfo[id]) end end end @@ -243,6 +243,20 @@ function CMD.page_record(capsuleId, up, idx) return capsule:pageRecord(up, idx) end +function CMD.get_special_nty(roleId, capsuleId) + local capsule = capsules[capsuleId] + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end + + return capsule:getSpecialNotify(roleId) +end + +function CMD.clear_special_nty(roleId, capsuleId, good_ids) + local capsule = capsules[capsuleId] + if not capsule then skynet.error("not capsule: " .. capsuleId) return nil end + + return capsule:clearSpecialNty(roleId, good_ids) +end + skynet.start(function() skynet.dispatch("lua", function(session, address, cmd, ...) local f = CMD[string.lower(cmd)] -- libgit2 0.21.2