Commit f382b4f2d6c0c26c00e4423bb40e85aed53920c1

Authored by zhangqijia
1 parent 555f745e

fix: 一番赏的抽奖bug

1. 抽奖,返回值4,返回奖品数量差异
2. 报名协议,返回扭蛋机详情。
src/actions/CapsuleAction.lua
... ... @@ -82,6 +82,7 @@ function _M.registerRpc(agent, data)
82 82 local capsuleId = msg.capsule_id
83 83  
84 84 local ret = skynet.call(agent.capsule_serv, "lua", "register", roleId, capsuleId)
  85 + if not ret then return 1 end
85 86 SendPacket(actionCodes.Capsule_registerRpc, MsgPack.pack(ret))
86 87 return true
87 88 end
... ... @@ -93,16 +94,21 @@ function _M.drawRpc(agent, data)
93 94 local capsuleId = msg.capsule_id
94 95 local typ = msg.typ --0=独享,1= 公开
95 96 local full = msg.full -- 0=单次,1=十连抽 2=全收
96   - local continue = msg.continue--确认次数。
97 97 local cares = msg.cares
98 98  
99 99 local ret, reward, change
100 100 if typ == 1 then
101   - ret, reward = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, continue, cares)
  101 + ret, reward = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares)
102 102 else
103 103 ret, reward = role:drawCapsule(capsuleId, full, cares)
104 104 end
105   - if ret <= 4 then return ret end
  105 + if ret < 4 then
  106 + return ret
  107 + end
  108 +
  109 + if ret == 4 then
  110 + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward))
  111 + end
106 112  
107 113 reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = capsuleId, int2 = roleId}})
108 114 dump(reward)
... ...
src/models/Capsule.lua
... ... @@ -188,21 +188,23 @@ function Capsule:join(roleId)
188 188 local register = self:getProperty("register") or {}
189 189 register[roleId] = 0
190 190 self:setProperty("register", register)
191   - return true
  191 + return self:data(roleId)
192 192 end
193 193  
194   -function Capsule:isRegister(roleId)
  194 +function Capsule:getRegisterByRoleId(roleId)
195 195 local register = self:getProperty("register") or {}
196   - return register[roleId] == 1
  196 + return register[roleId] or 0
  197 +end
  198 +
  199 +function Capsule:isRegister(roleId)
  200 + return self:getRegisterByRoleId(roleId) == 1
197 201 end
198 202  
199 203 function Capsule:register(roleId)
200 204 local register = self:getProperty("register") or {}
201   - if next(register) then
202   - register[roleId] = 1
203   - return true
204   - end
205   - return false
  205 + register[roleId] = 1
  206 + self:setProperty("register", register)
  207 + return self:data(roleId)
206 208 end
207 209  
208 210 function Capsule:exit(roleId)
... ... @@ -776,7 +778,7 @@ function Capsule:draw(roleId, full, cares)
776 778 end
777 779  
778 780  
779   -function Capsule:data()
  781 +function Capsule:data(roleId)
780 782 return {
781 783 id = self:getProperty("id"),
782 784 room = self:getProperty("room"),
... ... @@ -784,6 +786,7 @@ function Capsule:data()
784 786 name = self:getProperty("name"),
785 787 coin = self:getProperty("coin"),
786 788 onlineCount = self:getOnlineCount(),
  789 + playerStatus = self:getRegisterByRoleId(roleId),
787 790 record = self:getProperty("record"),
788 791 --recordByRole = self:getProperty("recordByRole"),
789 792 rank = self:getProperty("rank"),
... ...
src/models/RolePlugin.lua
... ... @@ -829,11 +829,16 @@ function RolePlugin.bind(Role)
829 829 for _, key in pairs(res) do
830 830 local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId,tonumber(key))})
831 831 capsule:load()
832   - if capsule:refreshing(now) then
833   - capsule:init()
834   - capsule:create()
  832 + if capsule:isShow() then
  833 + if capsule:refreshing(now) then
  834 + capsule:init()
  835 + capsule:create()
  836 + end
  837 + self.capsules[key] = capsule
  838 + else
  839 + redisproxy:del(CAPSULE_ROLE:format(roleId, tonumber(key)))
  840 + redisproxy:srem(CAPSULE_ID_ROLE, key)
835 841 end
836   - self.capsules[key] = capsule
837 842 end
838 843  
839 844 for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do
... ...
src/services/capsuled.lua
... ... @@ -61,7 +61,7 @@ local function add(roleId, capsuleId)
61 61 if next(capsule) then
62 62 capsule:join(roleId)
63 63 broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.JOIN, roleId = roleId})
64   - return capsule:data()
  64 + return capsule:data(roleId)
65 65 end
66 66 print("id 不存在: ".. capsuleId)
67 67 return nil
... ... @@ -95,8 +95,8 @@ function CMD.start()
95 95 end
96 96 capsules[key] = capsule
97 97 else
98   - redisproxy.del(CAPSULE_PUBLIC:format(tonumber(key)))
99   - redisproxy.srem(CAPSULE_INFO, key)
  98 + redisproxy:del(CAPSULE_PUBLIC:format(tonumber(key)))
  99 + redisproxy:srem(CAPSULE_INFO, key)
100 100 end
101 101 end
102 102  
... ... @@ -109,7 +109,7 @@ function CMD.start()
109 109 capsule:init()
110 110 capsule:create()
111 111 capsules[key] = capsule
112   - redisproxy.sadd(CAPSULE_INFO, key)
  112 + redisproxy:sadd(CAPSULE_INFO, key)
113 113 end
114 114 end
115 115 end
... ... @@ -145,10 +145,10 @@ function CMD.exit(roleId, capsuleId)
145 145 end
146 146 end
147 147  
148   -function CMD.draw_capsule(roleId, capsuleId, typ, cares)
  148 +function CMD.draw_capsule(roleId, capsuleId, full, cares)
149 149 local capsule = capsules[capsuleId] or {}
150 150 if next(capsule) then
151   - local ret, reward, notify = capsule:draw(roleId, typ, cares)
  151 + local ret, reward, notify = capsule:draw(roleId, full, cares)
152 152 --if ret > 4 then
153 153 -- broadCastCapsule(roleId, capsuleId, {changeType = NotifyChangeType.DRAW, roleId = roleId, notify = notify})
154 154 --end
... ... @@ -157,6 +157,14 @@ function CMD.draw_capsule(roleId, capsuleId, typ, cares)
157 157 return nil
158 158 end
159 159  
  160 +function CMD.register(roleId, capsuleId)
  161 + local capsule = capsules[capsuleId] or {}
  162 + if next(capsule) then
  163 + return capsule:register(roleId)
  164 + end
  165 + return nil
  166 +end
  167 +
160 168 skynet.start(function()
161 169 skynet.dispatch("lua", function(session, address, cmd, ...)
162 170 local f = CMD[string.lower(cmd)]
... ...