local ipairs = ipairs local table = table local math = math local next = next local string = string local redisproxy = redisproxy local MsgPack = MsgPack local getRandomName = getRandomName local mcast_util = mcast_util local string_format = string.format local tonumber = tonumber local require = require local _M = {} function _M.listRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local typ = msg.typ local coin = msg.coin local capsules = {} if typ == 1 then local ret = skynet.call(agent.capsule_serv, "lua", "list", coin) if next(ret) then for k, v in pairs(ret) do capsules[k] = v end end elseif typ == 0 then local ret = role:getCapsuleList(coin) if next(ret) then for k, v in pairs(ret) do capsules[k] = v end end end SendPacket(actionCodes.Capsule_listRpc, MsgPack.pack(capsules)) return true end function _M.joinRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local roleId = role:getProperty("id") local capsuleId = msg.capsule_id --如果刷新则需要传递当前扭蛋机id local typ = msg.typ or 1 local ret = {} if typ == 1 then ret = skynet.call(agent.capsule_serv, "lua", "join", roleId, capsuleId) elseif typ == 0 then ret = role:joinCapsule() end SendPacket(actionCodes.Capsule_joinRpc, MsgPack.pack(ret)) return true end function _M.exitRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local roleId = role:getProperty("id") local capsuleId = msg.capsule_id --如果刷新则需要传递当前扭蛋机id local typ = msg.typ or 1 local ret = {} if typ == 1 then ret = skynet.call(agent.capsule_serv, "lua", "exit", roleId, capsuleId) elseif typ == 0 then ret = role:exitCapsule() end SendPacket(actionCodes.Capsule_exitRpc, MsgPack.pack(ret)) return true end function _M.registerRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local roleId = role:getProperty("id") local capsuleId = msg.capsule_id local ret = skynet.call(agent.capsule_serv, "lua", "register", roleId, capsuleId) if not ret then return 1 end SendPacket(actionCodes.Capsule_registerRpc, MsgPack.pack(ret)) return true end function _M.drawRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local roleId = role:getProperty("id") local capsuleId = msg.capsule_id local typ = msg.typ --0=独享,1= 公开 local full = msg.full -- 0=单次,1=十连抽 2=全收 local cares = msg.cares local ret, reward, change, rewardByGoods, capsule if typ == 1 then ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares) else ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares) end if ret < 4 then return ret end if ret == 4 then SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward)) end if rewardByGoods and next(rewardByGoods) then reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}}) SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule})) else return 5 end return true end function _M.switchRoomRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local roleId = role:getProperty("id") local ret = skynet.call(agent.capsule_serv, "lua", "switch_room", roleId) SendPacket(actionCodes.Capsule_switchRoomRpc, MsgPack.pack(ret)) return true end return _M