Blame view

src/models/Capsule.lua 29.1 KB
555f745e   zhangqijia   feat: 一番赏
1
2
3
4
5
6
7
8
  --扭蛋机
  local MsgPack = MsgPack
  local Capsule = class("Capsule", require("shared.ModelBase"))
  
  function Capsule:ctor(properties)
      Capsule.super.ctor(self, properties)
  end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
9
10
11
12
13
14
15
  RewardType = {
      GOODS = 1,
      SPECIAL = 2,
      INCENTIVE = 3,
  }
  
  SpecialType = {
555f745e   zhangqijia   feat: 一番赏
16
17
18
19
20
      TOP = 1,
      CORE = 2,
      LAST = 3,
      JOKER = 4,
      KING = 5,
555f745e   zhangqijia   feat: 一番赏
21
22
23
24
25
26
27
  }
  
  CapsuleType = {
      PRIVATE = 0,
      PUBLIC = 1,
  }
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
28
29
  --[[
  --通知数据结构
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
30
  { [roleId] = { [good_id1] = { }, [good_id2] = { }, } }
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
31
32
  ]]--
  
555f745e   zhangqijia   feat: 一番赏
33
34
35
  Capsule.schema = {
      id = {"number", 0}, --扭蛋机key,配置读取
      room = {"number", 0}, --房间号, 配置读取
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
36
      name = {"string"},
555f745e   zhangqijia   feat: 一番赏
37
38
      typ = {"number", 1}, -- 1=共享,2=独享
      coin = {"number", 0}, --货币代号
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
39
      token = {"table", {}}, --抽一次,货币=消耗
555f745e   zhangqijia   feat: 一番赏
40
41
42
43
44
45
46
      register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名
      record = {"table", {}}, --抽取记录  列表
      recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record}
      rank = {"table", {}}, --排行
      goods = {"table", {}}, --奖励池
      specials = {"table", {}}, --特殊赏
      incentive = {"table", {}}, --激励奖
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
47
48
      incentiveRecord = {"table", {}}, --激励奖记录 {roleId = {}, roleId={}}
      specialsRecord= {"table", {}}, --特殊赏领取记录 {1={},2={}} key=触发特殊赏的 抽奖次数, v=特殊赏商品 table
555f745e   zhangqijia   feat: 一番赏
49
50
51
52
53
      resetTimes = {"number", 0}, --每日一次手动重置的机会
      hideTime = {"number", 0} , --隐藏时间
      drawEndTime = {"number", 0}, --抽完时间
  }
  
555f745e   zhangqijia   feat: 一番赏
54
55
56
57
58
59
  function Capsule:getResetFields()
      return {
          id = self:getProperty("id"),
          room = self:getProperty("room"),
          typ = self:getProperty("typ"),
          coin = 0,
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
60
          token = {},
555f745e   zhangqijia   feat: 一番赏
61
62
63
64
65
66
67
          register = {},
          record = {},
          recordByRole = {},
          rank = {},
          goods = {},
          specials = {},
          incentive = {},
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
68
          incentiveRecord = {},
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
69
          specialsRecord= {},
555f745e   zhangqijia   feat: 一番赏
70
          resetTimes = 0,
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
71
72
          hideTime = 0,
          drawEndTime = 0,
555f745e   zhangqijia   feat: 一番赏
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
      }
  end
  
  function Capsule:init()
      local id = self:getProperty("id")
      local room = self:getProperty("room")
      self:setProperties(self:getResetFields())
  
      local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
  
      --奖励池
      local goods_id = ichibankuji["goods_id"]
      local goods, specials, incentive = {}, {}, {}
      for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do
          for _, val in pairs(data) do
              if val.key == goods_id then
50a0dd50   zhangqijia   fix: 一番赏 重新组合商品id
89
                  goods[goods_id..val.id] = clone(val)
555f745e   zhangqijia   feat: 一番赏
90
91
92
              end
          end
      end
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
93
      for _, v in pairs(goods) do
555f745e   zhangqijia   feat: 一番赏
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
          v.weight = (v.weight or 0) * v.amount
      end
  
      --特殊赏
      local special_ids = ichibankuji["special_id"]
      if special_ids ~= "" then
          for _, special_id in ipairs(special_ids:toArray(true, "=")) do
              local val = csvdb["ichibankuji_specialCsv"][special_id]
              if type(val.type) == "number" then
                  specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex}
              elseif type(val.type) == "string" then
                  local pos = val.type:find("=")
                  if pos then
                      for k, v in pairs(val.type:toNumMap()) do
                          specials[special_id] = {np= v, amount = val.amount, award = val.award, quality = k, showIndex = val.showIndex}
                      end
                  else
                      specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex}
                  end
              end
          end
      end
  
      --激励奖
      local incentive_ids = ichibankuji["incentive_id"]
      if incentive_ids ~= "" then
          for _, incentive_id in ipairs(incentive_ids:toArray(true, "=")) do
              local val = csvdb["ichibankuji_incentiveCsv"][incentive_id]
              if type(val.type) == "number" then
                  incentive["last"] = {np=val.type, award = val.award}
              elseif type(val.type) == "string" then
                  for k, v in pairs(val.type:toNumMap()) do
                      if k == 2 then
                          incentive["amount"] = {np= v, award = val.award}
                      elseif k==3 then
                          incentive["probabilities"] = {np= v, award = val.award}
                      end
                  end
              end
          end
      end
      --货币类型
      local coin = ichibankuji["token"]:toArray(true, "=")
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
137
      self:setProperties({coin = coin[1] or 0, token = coin, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive})
49810b00   zhangqijia   fix: 一番赏 抽奖记录 去掉a...
138
  
555f745e   zhangqijia   feat: 一番赏
139
140
  end
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
141
142
143
144
145
146
147
  function Capsule:isShow()
      if skynet.timex() >= self:getProperty("hideTime") then
          return false
      end
      return true
  end
  
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  function Capsule:reset2TimeOut(curTime, now)
      now = now or skynet.timex()
      local interval
      if now >= curTime then
          self:init()
          self:create()
      else
          interval = curTime - now
      end
      interval = (interval)* 100
      skynet.timeout(interval, handler(self,self.reset3TimeOut)(curTime))
  end
  
  function Capsule:reset3TimeOut(curTime, now)
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
      now = now or skynet.timex()
      local cur4Time = curTime or (specTime({hour = 4},now))
  
      local interval
      if cur4Time > now then
          interval = cur4Time - now
      elseif cur4Time < now then
          local nextTime = dayLater(now)
          interval = nextTime - now
      elseif cur4Time == now then
          self:init()
          self:create()
  
          local nextTime = dayLater(now)
          interval = nextTime - now
      end
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
178
179
      interval = (interval)* 100
      skynet.timeout(interval, handler(self,self.reset3TimeOut))
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  end
  
  function Capsule:reset4TimeOut(curTime, now)
      now = now or skynet.timex()
      local interval
      if curTime > now then
          interval = curTime - now
      elseif curTime < now then
          local nextTime = dayLater(now)
          interval = nextTime - now
      elseif curTime == now then
          self:init()
          self:create()
  
          return false
      end
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
196
      interval = (interval)* 100
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
197
198
199
      skynet.timeout(interval, handler(self,self.reset4TimeOut))
  end
  
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
200
201
202
203
204
205
206
207
208
209
210
  function Capsule:checkTime(reset, now)
      local resetArr = reset:toArray(true, "=")
      if not next(resetArr) then return false end
  
      if resetArr[1] == 2 then
          if self:getGoodsAmount() > 0 then return false end
          local drawEndTime = self:getProperty("drawEndTime") or 0
          if drawEndTime == 0 then return false end
          if now - drawEndTime >= resetArr[2] then return true end
          --self:reset2TimeOut(drawEndTime + resetArr[2], now)
      elseif resetArr[1] == 3 then
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
211
212
          local cur4Time = specTime({hour = 4},now)
          if now == cur4Time then return true end
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
213
214
          --self:reset3TimeOut(cur4Time, now)
      elseif resetArr[1] == 4 then
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
215
          if now == resetArr[2] then return true end
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
216
          --self:reset4TimeOut(resetArr[2], now)
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
217
      end
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
218
219
  
      return false
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
220
221
  end
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
222
223
224
225
226
227
228
229
230
  function Capsule:refreshing(now)
      local id = self:getProperty("id")
      local room = self:getProperty("room")
      local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
      local reset = tostring(ichibankuji.reset)
  
      if reset == "0" then
          return false
      elseif reset == "1" then
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
231
232
          if self:getProperty("resetTimes") == 0 then
              self:setProperty("resetTime", 1)
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
233
234
235
236
              return true
          end
          return false
      else
da026be2   zhangqijia   fix: 一番赏 扭蛋机刷新机制 ...
237
          return self:checkTime(reset, now)
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
238
239
240
241
242
      end
  
      return false
  end
  
555f745e   zhangqijia   feat: 一番赏
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
  function Capsule:getOnlineCount()
      local register = self:getProperty("register") or {}
      local reg, onlookers = 0, 0
      for _, v in pairs(register) do
          if v == 1 then
              reg = reg + 1
          else
              onlookers = onlookers + 1
          end
      end
      return {[0]=onlookers, [1]=reg, [2] = reg+onlookers}
  end
  
  function Capsule:join(roleId)
      --一个房间最多人数 TODO
      local register = self:getProperty("register") or {}
      register[roleId] = 0
      self:setProperty("register", register)
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
261
      return self:data(roleId)
555f745e   zhangqijia   feat: 一番赏
262
263
  end
  
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
264
  function Capsule:getRegisterByRoleId(roleId)
555f745e   zhangqijia   feat: 一番赏
265
      local register = self:getProperty("register") or {}
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
266
267
268
269
270
      return register[roleId] or 0
  end
  
  function Capsule:isRegister(roleId)
      return self:getRegisterByRoleId(roleId) == 1
555f745e   zhangqijia   feat: 一番赏
271
272
273
274
  end
  
  function Capsule:register(roleId)
      local register = self:getProperty("register") or {}
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
275
276
277
      register[roleId] = 1
      self:setProperty("register", register)
      return self:data(roleId)
555f745e   zhangqijia   feat: 一番赏
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
  end
  
  function Capsule:exit(roleId)
      local register = self:getProperty("register") or {}
      if next(register) then
          register[roleId] = nil
          return true
      end
      return false
  end
  
  function Capsule:confirmed(cares)
      local goods = self:getProperty("goods") or {}
      local specials = self:getProperty("specials") or {}
      local change = {}
      for k, v in pairs(cares) do
          if v.typ == 1 then
              if goods[k] and goods[k].amount ~= v.count then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
296
                  change[k] = {typ=1, count = goods[k].amount}
555f745e   zhangqijia   feat: 一番赏
297
298
299
              end
          else
              if specials[k] and specials[k].amount ~= v.count then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
300
                  change[k] = {typ=1, count = specials[k].amount}
555f745e   zhangqijia   feat: 一番赏
301
302
303
304
305
306
307
308
309
              end
          end
      end
      return change
  end
  
  function Capsule:getGoodsAmount()
      local goods = self:getProperty("goods") or {}
      local amount = 0
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
310
      for _, v in pairs(goods) do
555f745e   zhangqijia   feat: 一番赏
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
          amount = amount + v.amount
      end
      return amount
  end
  
  function Capsule:getSpecialByType(typ)
      local specials = self:getProperty("specials") or {}
      for k, v in pairs(specials) do
          if v.quality == typ then
              return k, v
          end
      end
      return nil
  end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
326
327
  function Capsule:checkSpecialFlag(typ)
      local spKey, special = self:getSpecialByType(typ)
555f745e   zhangqijia   feat: 一番赏
328
329
      if not special then return nil end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
330
331
332
      if special["amount"] <= 0 then return nil end
      return spKey, special
  end
555f745e   zhangqijia   feat: 一番赏
333
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
334
  local function getSpecialReward(rewardRecord, count, award, spKey, typ, now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
335
336
337
338
      local rewardByRole = {}
      while(count > 0 and next(rewardRecord)) do
          local roleId = math.randWeight(rewardRecord, "amount")
          if roleId then
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
339
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
340
341
342
343
              local tmp = rewardRecord[roleId]
              tmp["amount"] = tmp["amount"] - 1
  
              if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end
555f745e   zhangqijia   feat: 一番赏
344
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
345
346
347
              local name = getNameByRoleId(roleId)
              tmp = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now}
              table.insert(rewardByRole, tmp)
555f745e   zhangqijia   feat: 一番赏
348
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
349
350
351
352
353
              count = count - 1
          end
      end
      return rewardByRole, count
  end
555f745e   zhangqijia   feat: 一番赏
354
  
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
355
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
356
357
358
359
360
  local rewardToRecordFunc = function(specialsRecord, recordAmount, rewardByRole)
      if not specialsRecord[recordAmount] then
          specialsRecord[recordAmount] = rewardByRole
      else
          table.insert(specialsRecord[recordAmount], rewardByRole)
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
361
362
363
364
      end
  end
  
  local function getRecordAmount(record)
49810b00   zhangqijia   fix: 一番赏 抽奖记录 去掉a...
365
       return #record
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
366
367
368
369
  end
  
  
  function Capsule:getTop(record, recordAmount,now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
370
371
372
373
      local spKey, special = self:checkSpecialFlag(SpecialType.TOP)
      if not special then return nil end
      local specials = self:getProperty("specials") or {}
      local specialsRecord = self:getProperty("specialsRecord") or {}
555f745e   zhangqijia   feat: 一番赏
374
  
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
375
376
      if recordAmount < special["np"] then return  nil end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
377
378
379
380
      local topRecord = {}
      local count = special["np"]
      for _, v in ipairs(record) do
          if count <= 0 then break end
555f745e   zhangqijia   feat: 一番赏
381
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
382
383
384
385
386
387
388
          local tmpCount = 0
          if count >= v.amount then
              count = count - v.amount
              tmpCount = v.amount
          else
              tmpCount = count
              count = 0
555f745e   zhangqijia   feat: 一番赏
389
390
          end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
391
392
393
394
395
          if not topRecord[v.roleId]then
              topRecord[v.roleId]  = {amount = v.amount }
          else
              topRecord[v.roleId] = {amount = (topRecord[v.roleId]["amount"] or 0) + tmpCount}
          end
555f745e   zhangqijia   feat: 一番赏
396
397
      end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
398
      local rewardByRole, count = getSpecialReward(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP,now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
399
400
401
  
      special["amount"] = count
      specials[spKey] = special
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
402
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
403
      rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole)
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
404
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
405
406
407
      self:setProperties({specialsRecord = specialsRecord, specials = specials})
      return rewardByRole
  
555f745e   zhangqijia   feat: 一番赏
408
409
410
  end
  
  --TODO
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
411
  function Capsule:getCore(record, recordAmount,now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
412
413
      local spKey, special = self:checkSpecialFlag(SpecialType.CORE)
      if not special then return nil end
555f745e   zhangqijia   feat: 一番赏
414
415
  
      local specials = self:getProperty("specials") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
416
417
      local specialsRecord = self:getProperty("specialsRecord") or {}
  
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
418
  
555f745e   zhangqijia   feat: 一番赏
419
  
f66891be   zhangqijia   fix: 一番赏 打开激励奖导致抽...
420
421
      local count = special["np"]
      if count > recordAmount then return nil end
555f745e   zhangqijia   feat: 一番赏
422
423
  
  
f66891be   zhangqijia   fix: 一番赏 打开激励奖导致抽...
424
      local left = math.ceil((count - recordAmount)/2) or 0
555f745e   zhangqijia   feat: 一番赏
425
426
427
428
429
430
431
432
433
434
435
436
437
      local roleRecord = {}
      for i, v in ipairs(record) do
          if count <= 0 then break end
          if i > left then
              local tmpCount = 0
              if count >= v.amount then
                  count = count - v.amount
                  tmpCount = v.amount
              else
                  tmpCount = count
                  count = 0
              end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
438
439
              if not roleRecord[v.roleId]then
                  roleRecord[v.roleId]  = {amount = v.amount }
555f745e   zhangqijia   feat: 一番赏
440
              else
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
441
                  roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount}
555f745e   zhangqijia   feat: 一番赏
442
443
444
445
446
              end
          end
  
      end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
447
      local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.CORE,now)
555f745e   zhangqijia   feat: 一番赏
448
  
555f745e   zhangqijia   feat: 一番赏
449
450
      special["amount"] = count
      specials[spKey] = special
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
451
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
452
      rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
453
454
      self:setProperties({specialsRecord = specialsRecord, specials = specials})
      return rewardByRole
555f745e   zhangqijia   feat: 一番赏
455
456
  end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
457
  function Capsule:getLast(record, recordAmount, now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
458
459
      local spKey, special = self:checkSpecialFlag(SpecialType.LAST)
      if not special then return nil end
555f745e   zhangqijia   feat: 一番赏
460
461
  
      local specials = self:getProperty("specials") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
462
      local specialsRecord = self:getProperty("specialsRecord") or {}
555f745e   zhangqijia   feat: 一番赏
463
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
464
      table.sort(record, function(a, b) return a.create_time > b.create_time end)
555f745e   zhangqijia   feat: 一番赏
465
  
f66891be   zhangqijia   fix: 一番赏 打开激励奖导致抽...
466
      local count = special["np"]
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
467
      local roleRecord = {}
555f745e   zhangqijia   feat: 一番赏
468
469
470
471
472
473
474
475
476
477
478
479
      for _, v in ipairs(record) do
          if count <= 0 then break end
  
          local tmpCount = 0
          if count >= v.amount then
              count = count - v.amount
              tmpCount = v.amount
          else
              tmpCount = count
              count = 0
          end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
480
481
          if not roleRecord[v.roleId]then
              roleRecord[v.roleId]  = {amount = v.amount }
555f745e   zhangqijia   feat: 一番赏
482
          else
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
483
              roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount}
555f745e   zhangqijia   feat: 一番赏
484
485
486
          end
      end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
487
      local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.LAST,now)
555f745e   zhangqijia   feat: 一番赏
488
  
555f745e   zhangqijia   feat: 一番赏
489
490
      special["amount"] = count
      specials[spKey] = special
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
491
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
492
      rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
493
494
      self:setProperties({specialsRecord = specialsRecord, specials = specials})
      return rewardByRole
555f745e   zhangqijia   feat: 一番赏
495
496
  end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
497
  function Capsule:getJoker(record, recordAmount, now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
498
499
      local spKey, special = self:checkSpecialFlag(SpecialType.JOKER)
      if not special then return nil end
555f745e   zhangqijia   feat: 一番赏
500
501
  
      local specials = self:getProperty("specials") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
502
503
      local specialsRecord = self:getProperty("specialsRecord") or {}
  
555f745e   zhangqijia   feat: 一番赏
504
505
      local roleRecord = {}
      for _, v in ipairs(record) do
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
506
507
          if not roleRecord[v.roleId]then
              roleRecord[v.roleId]  = {amount = v.amount }
555f745e   zhangqijia   feat: 一番赏
508
          else
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
509
              roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount}
555f745e   zhangqijia   feat: 一番赏
510
511
512
          end
      end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
513
      local rewardByRole, count = getSpecialReward(roleRecord, special["amount"], special["award"], spKey, SpecialType.JOKER,now)
555f745e   zhangqijia   feat: 一番赏
514
  
555f745e   zhangqijia   feat: 一番赏
515
516
      special["amount"] = count
      specials[spKey] = special
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
517
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
518
      rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
519
520
      self:setProperties({specialsRecord = specialsRecord, specials = specials})
      return rewardByRole
555f745e   zhangqijia   feat: 一番赏
521
522
  end
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
523
  function Capsule:getKing(record, recordAmount, now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
524
525
      local spKey, special = self:checkSpecialFlag(SpecialType.KING)
      if not special then return nil end
555f745e   zhangqijia   feat: 一番赏
526
527
  
      local specials = self:getProperty("specials") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
528
      local specialsRecord = self:getProperty("specialsRecord") or {}
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
529
530
      local rank = self:getProperty("rank") or {}
      if not next(rank) then return nil end
555f745e   zhangqijia   feat: 一番赏
531
  
555f745e   zhangqijia   feat: 一番赏
532
      local roleRecord = {}
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
533
534
535
536
537
538
  
      for roleId, count in pairs(rank) do
          table.insert(roleRecord, {roleId = roleId, count = count})
      end
      table.sort(roleRecord, function(a, b) return a.count > b.count end)
  
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
539
540
541
542
543
544
545
546
547
548
549
      local count = math.min(special["amount"], #roleRecord)
  
      local rewardByRole = {}
      local index = 1
      while (count > 0 ) do
          count  = count - 1
          local tmp = roleRecord[index]
          if not tmp then break end
          index = index + 1
  
          local name = getNameByRoleId(tmp.roleId)
f2f84157   zhangqijia   fix: 一番赏 修复king赏bug
550
          table.insert(rewardByRole, {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = special["award"], amount = 1, SpecialType.KING, create_time= now})
555f745e   zhangqijia   feat: 一番赏
551
552
      end
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
553
554
      special["amount"] = count
      specials[spKey] = special
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
555
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
556
      rewardToRecordFunc(specialsRecord, recordAmount, rewardByRole)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
557
558
559
      self:setProperties({specialsRecord = specialsRecord, specials = specials})
      return rewardByRole
  end
555f745e   zhangqijia   feat: 一番赏
560
  
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
561
  function Capsule:checkSpecialReward(now, goodsAmount)
555f745e   zhangqijia   feat: 一番赏
562
563
564
      local specials = self:getProperty("specials") or {}
      if not next(specials) then return nil end
      local record =  self:getProperty("record") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
565
  
555f745e   zhangqijia   feat: 一番赏
566
567
      if not next(record) then return nil end
      table.sort(record, function(a, b) return a.create_time < b.create_time  end )
555f745e   zhangqijia   feat: 一番赏
568
  
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
569
      local recordAmount = getRecordAmount(record)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
570
  
0a421d34   zhangqijia   fix: 一番赏奖励 刷新协议缺少...
571
      local notify = self:getTop(record, recordAmount,now) or {}
555f745e   zhangqijia   feat: 一番赏
572
  
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
573
574
      if goodsAmount == 0 then
          local coreReward = self:getCore(record, recordAmount, now)
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
575
          rewardToRecordFunc(notify, recordAmount, coreReward)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
576
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
577
578
          local lastReward = self:getLast(record, recordAmount, now)
          rewardToRecordFunc(notify, recordAmount, lastReward)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
579
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
580
581
          local jokerReward = self:getJoker(record, recordAmount, now)
          rewardToRecordFunc(notify, recordAmount, jokerReward)
555f745e   zhangqijia   feat: 一番赏
582
  
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
583
584
          local kingReward = self:getKing(record, recordAmount, now)
          rewardToRecordFunc(notify, recordAmount, kingReward)
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
585
      end
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
586
  
555f745e   zhangqijia   feat: 一番赏
587
588
589
      return notify
  end
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
590
  function Capsule:checkIncentive(roleId, name, now)
555f745e   zhangqijia   feat: 一番赏
591
      local goods = self:getProperty("goods") or {}
555f745e   zhangqijia   feat: 一番赏
592
593
      local recordByRole = self:getProperty("recordByRole") or {}
      local roleRecord = recordByRole[roleId] or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
594
595
      local incentiveRecord = self:getProperty("incentiveRecord") or {}
      local incentiveByRole = incentiveRecord[roleId] or {}
555f745e   zhangqijia   feat: 一番赏
596
597
598
      local incentive = self:getProperty("incentive")
  
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
599
      local notify = {}
555f745e   zhangqijia   feat: 一番赏
600
601
602
603
604
605
606
607
608
      -- 最后一抽 TODO
      if incentive["last"] then
          local last = true
          for k, v in pairs(goods) do
              if v and v.amount then
                  last = false
                  break
              end
          end
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
609
          if last then
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
610
               notify["last"] = {name = name, good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
611
          end
555f745e   zhangqijia   feat: 一番赏
612
613
614
615
616
617
618
619
620
621
622
623
624
      end
  
      --次数
      if incentive["amount"] then
          local amount = 0
          for _, v in pairs(roleRecord) do
              if (v.calculated or 0) == 0 then
                  amount = amount + v.amount
              end
          end
  
          local count = math.floor(amount / incentive["amount"]["np"])
          local tmpCount = count * incentive["amount"]["np"]
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
625
          notify["amount"] = {name = name, roleId= roleId, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now}
555f745e   zhangqijia   feat: 一番赏
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  
          --填充v.calculated 字段,标识已经用于每x抽的计算中。
          for _, v in pairs(roleRecord) do
              if tmpCount <= 0 then break end
  
              v.calculated = v.calculated or 0
              if v.calculated ~= v.amount then
                  if tmpCount <= v.amount then
                      v.calculated = tmpCount
                      tmpCount = 0
                  else
                      v.calculated = v.amount
                      tmpCount = tmpCount - v.amount
                  end
              end
  
          end
      end
  
      --概率
      if incentive["probabilities"] then
          local probabilities = math.randomInt(1, 100)
          if probabilities <= incentive["probabilities"]["np"] then
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
649
              notify["probabilities"] = {name = name, good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
650
  
555f745e   zhangqijia   feat: 一番赏
651
652
          end
      end
f66891be   zhangqijia   fix: 一番赏 打开激励奖导致抽...
653
654
655
656
657
658
659
      for k, v in pairs(notify) do
          if not incentiveByRole[k] then
              incentiveByRole[k] = v
          else
              incentiveByRole[k].amount = incentiveByRole[k].amount + v.amount
          end
      end
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
660
661
      incentiveRecord[roleId] = incentiveByRole
      self:setProperty("incentiveRecord", incentiveRecord)
555f745e   zhangqijia   feat: 一番赏
662
  
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
663
      return incentiveByRole
555f745e   zhangqijia   feat: 一番赏
664
665
  end
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
666
667
668
  local rewardCollect = function(reward, goods)
      for _, v in pairs(goods) do
          for id, count in pairs(v.award:toNumMap()) do
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
669
              reward[id] = (reward[id] or 0) + count * v.amount
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
670
671
672
673
674
675
          end
      end
  end
  
  local rewardCollectByRoleId = function(roleId, reward, goods)
      local tmp = {}
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
676
677
678
      for _, val in pairs(goods) do
          for _, v in ipairs(val) do
              if v.roleId == roleId then
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
679
                  for id, count in pairs(v.award:toNumMap()) do
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
680
681
682
683
684
685
                      reward[id] = (reward[id] or 0) + count * v.amount
                  end
                  if not tmp[v.good_id] then
                      tmp[v.good_id] = v
                   else
                      tmp[v.good_id].amount = tmp[v.good_id].amount + v.amount
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
686
                  end
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
687
              end
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
688
689
690
691
692
          end
      end
      return tmp
  end
  
555f745e   zhangqijia   feat: 一番赏
693
694
695
696
697
  function Capsule:drawByCount(roleId, count)
      if count <= 0 then return nil end
  
      local goods = self:getProperty("goods") or {}
      local record = self:getProperty("record") or {}
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
698
699
      local rank = self:getProperty("rank") or {}
      local rankRole = rank[roleId] or 0
555f745e   zhangqijia   feat: 一番赏
700
      local recordByRole = self:getProperty("recordByRole") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
701
      local roleRecord = recordByRole[roleId] or {}
555f745e   zhangqijia   feat: 一番赏
702
703
704
705
706
  
      local id = self:getProperty("id")
      local room = self:getProperty("room")
      local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
      local goods_id = ichibankuji["goods_id"]
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
707
      local now = skynet.timex()
555f745e   zhangqijia   feat: 一番赏
708
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
709
710
      --奖励,普通奖品信息
      local  goodsByUsual= {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
711
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
712
      local name = getNameByRoleId(roleId)
555f745e   zhangqijia   feat: 一番赏
713
714
      while (goods and next(goods) and count > 0) do
          local good_id = math.randWeight(goods, "weight")
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
715
          if not good_id then break end
555f745e   zhangqijia   feat: 一番赏
716
  
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
717
718
719
720
          local good = goods[good_id] or {}
          if good and good.amount > 0 then
              good.amount = good.amount - 1
  
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
721
722
723
              --插入rank
              rankRole = rankRole + 1
  
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
724
725
726
727
728
              --插入记录
              local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now}
              table.insert(record, tmpNotify)
  
              --作为奖励记录+通知
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
729
730
              if not goodsByUsual[good_id] then
                  goodsByUsual[good_id] = tmpNotify
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
731
              else
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
732
                  goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + 1
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
733
              end
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
734
  
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
735
736
737
738
739
              --记录角色的抽奖记录 计算激励奖需要用到
              if not roleRecord[good_id] then
                  roleRecord[good_id] = tmpNotify
              else
                  roleRecord[good_id].amount = roleRecord[good_id].amount + 1
555f745e   zhangqijia   feat: 一番赏
740
              end
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
741
742
743
  
              good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight
              count = count - 1
555f745e   zhangqijia   feat: 一番赏
744
745
746
          end
  
      end
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
747
748
  
      --奖励池重新赋值
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
749
      rank[roleId] = rankRole
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
750
      recordByRole[roleId] = roleRecord
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
751
      self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank})
555f745e   zhangqijia   feat: 一番赏
752
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
753
754
755
      --奖励收集
      local reward = {}
      rewardCollect(reward, goodsByUsual)
555f745e   zhangqijia   feat: 一番赏
756
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
757
758
      local goodsByIncentive = self:checkIncentive(roleId, name, now)
      rewardCollect(reward, goodsByIncentive)
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
759
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
760
761
762
      local goodsAmount = self:getGoodsAmount()
      if goodsAmount == 0 then
          self:setProperty("drawEndTime", now)
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
763
      end
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
764
765
766
767
768
  
      local goodsBySpecial = self:checkSpecialReward(now, goodsAmount)
      local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial)
  
      return {reward = reward, usual = goodsByUsual, incentive = goodsByIncentive, specials = goodsBySpecial, special = specialByRole}
555f745e   zhangqijia   feat: 一番赏
769
770
771
772
773
  end
  
  function Capsule:drawAll(roleId)
      local goods = self:getProperty("goods") or {}
      local record = self:getProperty("record") or {}
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
774
775
      local rank = self:getProperty("rank") or {}
      local rankRole = rank[roleId] or 0
555f745e   zhangqijia   feat: 一番赏
776
      local recordByRole = self:getProperty("recordByRole") or {}
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
777
778
      local roleRecord = recordByRole[roleId] or {}
      local now = skynet.timex()
555f745e   zhangqijia   feat: 一番赏
779
  
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
780
      local name = getNameByRoleId(roleId)
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
781
      local goodsByUsual = {}
555f745e   zhangqijia   feat: 一番赏
782
      for good_id, good in pairs(goods) do
555f745e   zhangqijia   feat: 一番赏
783
          if good.amount > 0 then
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
784
785
786
              --插入rank
              rankRole = rankRole + good.amount
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
787
              --插入记录
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
788
              local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now}
49810b00   zhangqijia   fix: 一番赏 抽奖记录 去掉a...
789
790
791
              for i = 1, good.amount do
                  table.insert(record, {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time = now})
              end
555f745e   zhangqijia   feat: 一番赏
792
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
793
              --作为奖励记录+通知
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
794
795
              if not goodsByUsual[good_id] then
                  goodsByUsual[good_id] = tmpNotify
555f745e   zhangqijia   feat: 一番赏
796
              else
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
797
                  goodsByUsual[good_id].amount = goodsByUsual[good_id].amount + good.award
555f745e   zhangqijia   feat: 一番赏
798
              end
555f745e   zhangqijia   feat: 一番赏
799
  
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
800
801
              --记录角色的抽奖记录
              if not roleRecord[good_id] then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
802
                  roleRecord[good_id] = tmpNotify
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
803
804
              else
                  roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount
555f745e   zhangqijia   feat: 一番赏
805
              end
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
806
807
  
              good.amount = 0
555f745e   zhangqijia   feat: 一番赏
808
809
810
          end
  
      end
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
811
      rank[roleId] = rankRole
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
812
      recordByRole[roleId] = roleRecord
7f21f75b   zhangqijia   fix: 一番赏 增加rank,刷...
813
      self:setProperties({recordByRole = recordByRole, record = record, goods = goods, rank = rank})
555f745e   zhangqijia   feat: 一番赏
814
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
815
816
817
      --奖励收集
      local reward = {}
      rewardCollect(reward, goodsByUsual)
cd2a7a67   zhangqijia   fix: 一番赏奖励中加入得奖者的...
818
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
819
820
      local goodsByIncentive = self:checkIncentive(roleId, name, now)
      rewardCollect(reward, goodsByIncentive)
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
821
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
822
      local goodsAmount = self:getGoodsAmount()
49df162b   zhangqijia   fix: 一番赏 增加drawEn...
823
824
825
826
      if goodsAmount == 0 then
          self:setProperty("drawEndTime", now)
      end
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
827
828
829
830
      local goodsBySpecial = self:checkSpecialReward(now, goodsAmount)
      local specialByRole = rewardCollectByRoleId(roleId, reward, goodsBySpecial)
  
      return {reward = reward, usual = goodsByUsual, incentive = goodsByIncentive, specials = goodsBySpecial, special = specialByRole}
555f745e   zhangqijia   feat: 一番赏
831
832
833
834
835
  end
  
  --@param
  --[[
  @roleId
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
836
  @typ 0=独享,1=公开
555f745e   zhangqijia   feat: 一番赏
837
838
839
840
  @cares 关注{k=v}
  ]]--
  
  function Capsule:draw(roleId, full, cares)
555f745e   zhangqijia   feat: 一番赏
841
842
      if self:getProperty("typ") == 1 then
          --是否报名
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
843
          if self:isRegister(roleId) == false then return 4 end
555f745e   zhangqijia   feat: 一番赏
844
845
846
847
  
          --关注的奖品的数量发生了变化
          if cares then
              local change = self:confirmed(cares)
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
848
              if next(change) then return 5, change end
555f745e   zhangqijia   feat: 一番赏
849
850
851
852
          end
      end
  
      if full == 0 then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
853
          return 6, self:drawByCount(roleId, 1)
555f745e   zhangqijia   feat: 一番赏
854
      elseif full == 1 then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
855
          return 6, self:drawByCount(roleId, 10)
555f745e   zhangqijia   feat: 一番赏
856
      elseif full == 2 then
0eb317fb   zhangqijia   fix: 一番赏奖励抽奖的bug与...
857
          return 6, self:drawAll(roleId)
555f745e   zhangqijia   feat: 一番赏
858
859
860
      end
  end
  
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
  function Capsule:pageRecord(up, idx)
      local record = self:getProperty("record") or {}
      if not next(record) then return nil end
  
      --默认取20条
      idx = idx or #record
      up = up or 0
  
      local count = 0
      local tmpRecord = {}
      if up == 1 then
          --向上获取索引更大的  从上往下拉
          count = math.min(#record - idx, 20)
          for i = idx, count do
              tmpRecord[i] = record[i]
          end
      else
          --向下获取索引更小的 从下往上拉
          count = math.max(idx - 20, 0)
          for i = count, idx do
              tmpRecord[i] = record[i]
          end
      end
  
      return tmpRecord
  end
  
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
888
889
890
  --检查是否有未领取奖励的通知
  function Capsule:getSpecialNotify(roleId)
      local specialsRecord = self:getProperty("specialsRecord") or {}
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
891
      local tmp = {}
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
892
893
894
895
896
897
898
      for _, goods in pairs(specialsRecord)  do
          for _, good in ipairs(goods) do
              if good.roleId == roleId then
                  if not good.nty or good.nty == 0 then
                      tmp[good.good_id] = good
                  end
              end
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
899
900
          end
      end
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
901
902
903
904
905
906
907
      self:setProperty("specialsRecord", specialsRecord)
  
      return tmp
  end
  
  function Capsule:clearSpecialNty(roleId, good_ids)
      local specialsRecord = self:getProperty("specialsRecord") or {}
078bdb2f   zhangqijia   fix: 一番赏 特殊赏的抽奖记录...
908
909
910
911
912
913
914
      for _, goods in pairs(specialsRecord)  do
          for _, good in ipairs(goods) do
              for _, good_id in ipairs(good_ids) do
                  if good_id == good.good_id and good.roleId == roleId then
                      good.nty = 1
                  end
              end
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
915
916
          end
      end
da20e384   zhangqijia   feat: 一番赏 特殊赏 通知
917
918
919
      self:setProperty("specialsRecord", specialsRecord)
  end
  
555f745e   zhangqijia   feat: 一番赏
920
  
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
921
  function Capsule:data(roleId)
555f745e   zhangqijia   feat: 一番赏
922
923
924
925
926
927
928
      return {
          id = self:getProperty("id"),
          room = self:getProperty("room"),
          typ = self:getProperty("typ"),
          name = self:getProperty("name"),
          coin = self:getProperty("coin"),
          onlineCount = self:getOnlineCount(),
f382b4f2   zhangqijia   fix: 一番赏的抽奖bug
929
          playerStatus = self:getRegisterByRoleId(roleId),
01ff9b4b   zhangqijia   fix: 一番赏 优化; 抽奖记录...
930
          record = self:pageRecord() or {},
555f745e   zhangqijia   feat: 一番赏
931
932
933
934
          rank = self:getProperty("rank"),
          goods = self:getProperty("goods"),
          specials = self:getProperty("specials"),
          incentive = self:getProperty("incentive"),
d10a9a36   zhangqijia   fix: 一番赏增加通知信息的数据...
935
          specialsRecord= self:getProperty("specialsRecord"),
555f745e   zhangqijia   feat: 一番赏
936
937
938
939
      }
  end
  
  return Capsule