Blame view

src/actions/CapsuleAction.lua 3.78 KB
555f745e   zhangqijia   feat: 一番赏
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  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)
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
85
      if not ret then return 1 end
555f745e   zhangqijia   feat: 一番赏
86
87
88
89
90
91
92
93
94
95
96
      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=全收
555f745e   zhangqijia   feat: 一番赏
97
98
      local cares = msg.cares
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
99
      local ret, reward, change, rewardByGoods, capsule
555f745e   zhangqijia   feat: 一番赏
100
      if typ == 1 then
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
101
          ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares)
555f745e   zhangqijia   feat: 一番赏
102
      else
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
103
          ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares)
555f745e   zhangqijia   feat: 一番赏
104
      end
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
105
106
107
108
109
110
111
      if ret < 4 then
          return ret
      end
  
      if ret == 4 then
          SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack(reward))
      end
555f745e   zhangqijia   feat: 一番赏
112
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
113
114
115
116
117
118
      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
555f745e   zhangqijia   feat: 一番赏
119
120
121
122
123
124
125
126
127
128
129
130
131
132
      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