| @@ -0,0 +1,792 @@ |
| @@ -0,0 +1,792 @@ |
| |
1
| +--扭蛋机 |
| |
2
| +local MsgPack = MsgPack |
| |
3
| +local Capsule = class("Capsule", require("shared.ModelBase")) |
| |
4
| + |
| |
5
| +function Capsule:ctor(properties) |
| |
6
| + Capsule.super.ctor(self, properties) |
| |
7
| +end |
| |
8
| + |
| |
9
| +RewardType = { |
| |
10
| + GOODS = 1, |
| |
11
| + SPECIAL = 2, |
| |
12
| + INCENTIVE = 3, |
| |
13
| +} |
| |
14
| + |
| |
15
| +SpecialType = { |
| |
16
| + TOP = 1, |
| |
17
| + CORE = 2, |
| |
18
| + LAST = 3, |
| |
19
| + JOKER = 4, |
| |
20
| + KING = 5, |
| |
21
| +} |
| |
22
| + |
| |
23
| +CapsuleType = { |
| |
24
| + PRIVATE = 0, |
| |
25
| + PUBLIC = 1, |
| |
26
| +} |
| |
27
| + |
| |
28
| +--[[ |
| |
29
| +--通知数据结构 |
| |
30
| +{ [roleId] = { [good_id1] = { }, [good_id2] = { }, } } |
| |
31
| +]]-- |
| |
32
| + |
| |
33
| +Capsule.schema = { |
| |
34
| + id = {"number", 0}, --扭蛋机key,配置读取 |
| |
35
| + room = {"number", 0}, --房间号, 配置读取 |
| |
36
| + name = {"string"}, |
| |
37
| + typ = {"number", 1}, -- 1=共享,2=独享 |
| |
38
| + coin = {"number", 0}, --货币代号 |
| |
39
| + register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名 |
| |
40
| + record = {"table", {}}, --抽取记录 列表 |
| |
41
| + recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record} |
| |
42
| + rank = {"table", {}}, --排行 |
| |
43
| + goods = {"table", {}}, --奖励池 |
| |
44
| + specials = {"table", {}}, --特殊赏 |
| |
45
| + incentive = {"table", {}}, --激励奖 |
| |
46
| + incentiveRecord = {"table", {}}, --激励奖记录 |
| |
47
| + specialsRecord= {"table", {}}, --特殊赏领取记录 |
| |
48
| + resetTimes = {"number", 0}, --每日一次手动重置的机会 |
| |
49
| + hideTime = {"number", 0} , --隐藏时间 |
| |
50
| + drawEndTime = {"number", 0}, --抽完时间 |
| |
51
| +} |
| |
52
| + |
| |
53
| +function Capsule:getResetFields() |
| |
54
| + return { |
| |
55
| + id = self:getProperty("id"), |
| |
56
| + room = self:getProperty("room"), |
| |
57
| + typ = self:getProperty("typ"), |
| |
58
| + coin = 0, |
| |
59
| + register = {}, |
| |
60
| + record = {}, |
| |
61
| + recordByRole = {}, |
| |
62
| + rank = {}, |
| |
63
| + goods = {}, |
| |
64
| + specials = {}, |
| |
65
| + incentive = {}, |
| |
66
| + incentiveRecord = {}, |
| |
67
| + specialsRecord= {}, |
| |
68
| + resetTimes = 0, |
| |
69
| + hideTime = 0, |
| |
70
| + drawEndTime = 0, |
| |
71
| + } |
| |
72
| +end |
| |
73
| + |
| |
74
| +function Capsule:init() |
| |
75
| + local id = self:getProperty("id") |
| |
76
| + local room = self:getProperty("room") |
| |
77
| + self:setProperties(self:getResetFields()) |
| |
78
| + |
| |
79
| + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] |
| |
80
| + |
| |
81
| + --奖励池 |
| |
82
| + local goods_id = ichibankuji["goods_id"] |
| |
83
| + local goods, specials, incentive = {}, {}, {} |
| |
84
| + for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do |
| |
85
| + for _, val in pairs(data) do |
| |
86
| + if val.key == goods_id then |
| |
87
| + goods[goods_id..val.id] = clone(val) |
| |
88
| + end |
| |
89
| + end |
| |
90
| + end |
| |
91
| + for _, v in pairs(goods) do |
| |
92
| + v.weight = (v.weight or 0) * v.amount |
| |
93
| + end |
| |
94
| + |
| |
95
| + --特殊赏 |
| |
96
| + local special_ids = ichibankuji["special_id"] |
| |
97
| + if special_ids ~= "" then |
| |
98
| + for _, special_id in ipairs(special_ids:toArray(true, "=")) do |
| |
99
| + local val = csvdb["ichibankuji_specialCsv"][special_id] |
| |
100
| + if type(val.type) == "number" then |
| |
101
| + specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex} |
| |
102
| + elseif type(val.type) == "string" then |
| |
103
| + local pos = val.type:find("=") |
| |
104
| + if pos then |
| |
105
| + for k, v in pairs(val.type:toNumMap()) do |
| |
106
| + specials[special_id] = {np= v, amount = val.amount, award = val.award, quality = k, showIndex = val.showIndex} |
| |
107
| + end |
| |
108
| + else |
| |
109
| + specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex} |
| |
110
| + end |
| |
111
| + end |
| |
112
| + end |
| |
113
| + end |
| |
114
| + |
| |
115
| + --激励奖 |
| |
116
| + local incentive_ids = ichibankuji["incentive_id"] |
| |
117
| + if incentive_ids ~= "" then |
| |
118
| + for _, incentive_id in ipairs(incentive_ids:toArray(true, "=")) do |
| |
119
| + local val = csvdb["ichibankuji_incentiveCsv"][incentive_id] |
| |
120
| + if type(val.type) == "number" then |
| |
121
| + incentive["last"] = {np=val.type, award = val.award} |
| |
122
| + elseif type(val.type) == "string" then |
| |
123
| + for k, v in pairs(val.type:toNumMap()) do |
| |
124
| + if k == 2 then |
| |
125
| + incentive["amount"] = {np= v, award = val.award} |
| |
126
| + elseif k==3 then |
| |
127
| + incentive["probabilities"] = {np= v, award = val.award} |
| |
128
| + end |
| |
129
| + end |
| |
130
| + end |
| |
131
| + end |
| |
132
| + end |
| |
133
| + --货币类型 |
| |
134
| + local coin = ichibankuji["token"]:toArray(true, "=") |
| |
135
| + self:setProperties({coin = coin[1] or 0, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive}) |
| |
136
| +end |
| |
137
| + |
| |
138
| +function Capsule:isShow() |
| |
139
| + if skynet.timex() >= self:getProperty("hideTime") then |
| |
140
| + return false |
| |
141
| + end |
| |
142
| + return true |
| |
143
| +end |
| |
144
| + |
| |
145
| +function Capsule:refreshing(now) |
| |
146
| + local id = self:getProperty("id") |
| |
147
| + local room = self:getProperty("room") |
| |
148
| + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] |
| |
149
| + local reset = tostring(ichibankuji.reset) |
| |
150
| + |
| |
151
| + if reset == "0" then |
| |
152
| + return false |
| |
153
| + elseif reset == "1" then |
| |
154
| + if self:getProperty("resetTimes") == 1 then |
| |
155
| + return true |
| |
156
| + end |
| |
157
| + return false |
| |
158
| + else |
| |
159
| + local resetArr = reset:toArray(true, "=") |
| |
160
| + if not next(resetArr) then return false end |
| |
161
| + |
| |
162
| + if resetArr[1] == "2" then |
| |
163
| + if self:getGoodsAmount() > 0 then return false end |
| |
164
| + |
| |
165
| + local drawEndTime = self:getProperty("drawEndTime") or 0 |
| |
166
| + if drawEndTime == 0 then return false end |
| |
167
| + |
| |
168
| + if now - drawEndTime >= resetArr[2] then |
| |
169
| + return true |
| |
170
| + end |
| |
171
| + return false |
| |
172
| + |
| |
173
| + elseif resetArr[1] == "3" then |
| |
174
| + |
| |
175
| + elseif resetArr[1] == "4" then |
| |
176
| + if now >= resetArr[2] then return true end |
| |
177
| + end |
| |
178
| + end |
| |
179
| + |
| |
180
| + return false |
| |
181
| +end |
| |
182
| + |
| |
183
| +function Capsule:getOnlineCount() |
| |
184
| + local register = self:getProperty("register") or {} |
| |
185
| + local reg, onlookers = 0, 0 |
| |
186
| + for _, v in pairs(register) do |
| |
187
| + if v == 1 then |
| |
188
| + reg = reg + 1 |
| |
189
| + else |
| |
190
| + onlookers = onlookers + 1 |
| |
191
| + end |
| |
192
| + end |
| |
193
| + return {[0]=onlookers, [1]=reg, [2] = reg+onlookers} |
| |
194
| +end |
| |
195
| + |
| |
196
| +function Capsule:join(roleId) |
| |
197
| + --一个房间最多人数 TODO |
| |
198
| + local register = self:getProperty("register") or {} |
| |
199
| + register[roleId] = 0 |
| |
200
| + self:setProperty("register", register) |
| |
201
| + return self:data(roleId) |
| |
202
| +end |
| |
203
| + |
| |
204
| +function Capsule:getRegisterByRoleId(roleId) |
| |
205
| + local register = self:getProperty("register") or {} |
| |
206
| + return register[roleId] or 0 |
| |
207
| +end |
| |
208
| + |
| |
209
| +function Capsule:isRegister(roleId) |
| |
210
| + return self:getRegisterByRoleId(roleId) == 1 |
| |
211
| +end |
| |
212
| + |
| |
213
| +function Capsule:register(roleId) |
| |
214
| + local register = self:getProperty("register") or {} |
| |
215
| + register[roleId] = 1 |
| |
216
| + self:setProperty("register", register) |
| |
217
| + return self:data(roleId) |
| |
218
| +end |
| |
219
| + |
| |
220
| +function Capsule:exit(roleId) |
| |
221
| + local register = self:getProperty("register") or {} |
| |
222
| + if next(register) then |
| |
223
| + register[roleId] = nil |
| |
224
| + return true |
| |
225
| + end |
| |
226
| + return false |
| |
227
| +end |
| |
228
| + |
| |
229
| +function Capsule:confirmed(cares) |
| |
230
| + local goods = self:getProperty("goods") or {} |
| |
231
| + local specials = self:getProperty("specials") or {} |
| |
232
| + local change = {} |
| |
233
| + for k, v in pairs(cares) do |
| |
234
| + if v.typ == 1 then |
| |
235
| + if goods[k] and goods[k].amount ~= v.count then |
| |
236
| + change[k] = goods[k].amount |
| |
237
| + end |
| |
238
| + else |
| |
239
| + if specials[k] and specials[k].amount ~= v.count then |
| |
240
| + change[k] = specials[k].amount |
| |
241
| + end |
| |
242
| + end |
| |
243
| + end |
| |
244
| + return change |
| |
245
| +end |
| |
246
| + |
| |
247
| +function Capsule:getGoodsAmount() |
| |
248
| + local goods = self:getProperty("goods") or {} |
| |
249
| + local amount = 0 |
| |
250
| + for _, v in pairs(goods) do |
| |
251
| + amount = amount + v.amount |
| |
252
| + end |
| |
253
| + return amount |
| |
254
| +end |
| |
255
| + |
| |
256
| +function Capsule:getSpecialByType(typ) |
| |
257
| + local specials = self:getProperty("specials") or {} |
| |
258
| + for k, v in pairs(specials) do |
| |
259
| + if v.quality == typ then |
| |
260
| + return k, v |
| |
261
| + end |
| |
262
| + end |
| |
263
| + return nil |
| |
264
| +end |
| |
265
| + |
| |
266
| +function Capsule:checkSpecialFlag(typ) |
| |
267
| + local spKey, special = self:getSpecialByType(typ) |
| |
268
| + if not special then return nil end |
| |
269
| + |
| |
270
| + if special["amount"] <= 0 then return nil end |
| |
271
| + return spKey, special |
| |
272
| +end |
| |
273
| + |
| |
274
| +local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now) |
| |
275
| + local rewardByRole = {} |
| |
276
| + while(count > 0 and next(rewardRecord)) do |
| |
277
| + local roleId = math.randWeight(rewardRecord, "amount") |
| |
278
| + if roleId then |
| |
279
| + |
| |
280
| + local tmp = rewardRecord[roleId] |
| |
281
| + tmp["amount"] = tmp["amount"] - 1 |
| |
282
| + |
| |
283
| + if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end |
| |
284
| + |
| |
285
| + tmp = rewardByRole[roleId] |
| |
286
| + if not tmp then |
| |
287
| + local name = getNameByRoleId(roleId) |
| |
288
| + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} |
| |
289
| + else |
| |
290
| + if not tmp[spKey] then |
| |
291
| + local name = getNameByRoleId(roleId) |
| |
292
| + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now} |
| |
293
| + else |
| |
294
| + tmp[spKey].amount = tmp[spKey].amount + 1 |
| |
295
| + end |
| |
296
| + end |
| |
297
| + rewardByRole[roleId] = tmp |
| |
298
| + |
| |
299
| + count = count - 1 |
| |
300
| + end |
| |
301
| + end |
| |
302
| + return rewardByRole, count |
| |
303
| +end |
| |
304
| + |
| |
305
| +function Capsule:getTop(record) |
| |
306
| + local spKey, special = self:checkSpecialFlag(SpecialType.TOP) |
| |
307
| + if not special then return nil end |
| |
308
| + local specials = self:getProperty("specials") or {} |
| |
309
| + local specialsRecord = self:getProperty("specialsRecord") or {} |
| |
310
| + |
| |
311
| + if #record < special["np"] then return nil end |
| |
312
| + local topRecord = {} |
| |
313
| + local count = special["np"] |
| |
314
| + for _, v in ipairs(record) do |
| |
315
| + if count <= 0 then break end |
| |
316
| + |
| |
317
| + local tmpCount = 0 |
| |
318
| + if count >= v.amount then |
| |
319
| + count = count - v.amount |
| |
320
| + tmpCount = v.amount |
| |
321
| + else |
| |
322
| + tmpCount = count |
| |
323
| + count = 0 |
| |
324
| + end |
| |
325
| + |
| |
326
| + if not topRecord[v.roleId]then |
| |
327
| + topRecord[v.roleId] = {amount = v.amount } |
| |
328
| + else |
| |
329
| + topRecord[v.roleId] = {amount = (topRecord[v.roleId]["amount"] or 0) + tmpCount} |
| |
330
| + end |
| |
331
| + end |
| |
332
| + |
| |
333
| + local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP) |
| |
334
| + |
| |
335
| + special["amount"] = count |
| |
336
| + specials[spKey] = special |
| |
337
| + specialsRecord[SpecialType.TOP] = rewardByRole |
| |
338
| + self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
| |
339
| + return rewardByRole |
| |
340
| + |
| |
341
| +end |
| |
342
| + |
| |
343
| +--TODO |
| |
344
| +function Capsule:getCore(record) |
| |
345
| + local spKey, special = self:checkSpecialFlag(SpecialType.CORE) |
| |
346
| + if not special then return nil end |
| |
347
| + |
| |
348
| + local specials = self:getProperty("specials") or {} |
| |
349
| + local specialsRecord = self:getProperty("specialsRecord") or {} |
| |
350
| + |
| |
351
| + if self:getGoodsAmount() > 0 then return nil end |
| |
352
| + |
| |
353
| + local np = special["np"] |
| |
354
| + if np > #record then return nil end |
| |
355
| + |
| |
356
| + |
| |
357
| + local left = math.ceil((np - #record)/2) or 0 |
| |
358
| + local count = np |
| |
359
| + local roleRecord = {} |
| |
360
| + for i, v in ipairs(record) do |
| |
361
| + if count <= 0 then break end |
| |
362
| + if i > left then |
| |
363
| + local tmpCount = 0 |
| |
364
| + if count >= v.amount then |
| |
365
| + count = count - v.amount |
| |
366
| + tmpCount = v.amount |
| |
367
| + else |
| |
368
| + tmpCount = count |
| |
369
| + count = 0 |
| |
370
| + end |
| |
371
| + |
| |
372
| + if not roleRecord[v.roleId]then |
| |
373
| + roleRecord[v.roleId] = {amount = v.amount } |
| |
374
| + else |
| |
375
| + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} |
| |
376
| + end |
| |
377
| + end |
| |
378
| + |
| |
379
| + end |
| |
380
| + |
| |
381
| + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.CORE) |
| |
382
| + |
| |
383
| + special["amount"] = count |
| |
384
| + specials[spKey] = special |
| |
385
| + specialsRecord[SpecialType.CORE] = rewardByRole |
| |
386
| + self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
| |
387
| + return rewardByRole |
| |
388
| +end |
| |
389
| + |
| |
390
| +function Capsule:getLast(record) |
| |
391
| + local spKey, special = self:checkSpecialFlag(SpecialType.LAST) |
| |
392
| + if not special then return nil end |
| |
393
| + |
| |
394
| + local specials = self:getProperty("specials") or {} |
| |
395
| + local specialsRecord = self:getProperty("specialsRecord") or {} |
| |
396
| + |
| |
397
| + if self:getGoodsAmount() > 0 then return nil end |
| |
398
| + |
| |
399
| + table.sort(record, function(a, b) return a.create_time > b.create_time end) |
| |
400
| + |
| |
401
| + local np = special["np"] |
| |
402
| + local count = np |
| |
403
| + local roleRecord = {} |
| |
404
| + for _, v in ipairs(record) do |
| |
405
| + if count <= 0 then break end |
| |
406
| + |
| |
407
| + local tmpCount = 0 |
| |
408
| + if count >= v.amount then |
| |
409
| + count = count - v.amount |
| |
410
| + tmpCount = v.amount |
| |
411
| + else |
| |
412
| + tmpCount = count |
| |
413
| + count = 0 |
| |
414
| + end |
| |
415
| + |
| |
416
| + if not roleRecord[v.roleId]then |
| |
417
| + roleRecord[v.roleId] = {amount = v.amount } |
| |
418
| + else |
| |
419
| + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + tmpCount} |
| |
420
| + end |
| |
421
| + end |
| |
422
| + |
| |
423
| + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.LAST) |
| |
424
| + |
| |
425
| + special["amount"] = count |
| |
426
| + specials[spKey] = special |
| |
427
| + specialsRecord[SpecialType.LAST] = rewardByRole |
| |
428
| + self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
| |
429
| + return rewardByRole |
| |
430
| +end |
| |
431
| + |
| |
432
| +function Capsule:getJoker(record) |
| |
433
| + local spKey, special = self:checkSpecialFlag(SpecialType.JOKER) |
| |
434
| + if not special then return nil end |
| |
435
| + |
| |
436
| + local specials = self:getProperty("specials") or {} |
| |
437
| + local specialsRecord = self:getProperty("specialsRecord") or {} |
| |
438
| + |
| |
439
| + if self:getGoodsAmount() > 0 then return nil end |
| |
440
| + |
| |
441
| + local roleRecord = {} |
| |
442
| + for _, v in ipairs(record) do |
| |
443
| + if not roleRecord[v.roleId]then |
| |
444
| + roleRecord[v.roleId] = {amount = v.amount } |
| |
445
| + else |
| |
446
| + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} |
| |
447
| + end |
| |
448
| + end |
| |
449
| + |
| |
450
| + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.JOKER) |
| |
451
| + |
| |
452
| + special["amount"] = count |
| |
453
| + specials[spKey] = special |
| |
454
| + specialsRecord[SpecialType.JOKER] = rewardByRole |
| |
455
| + self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
| |
456
| + return rewardByRole |
| |
457
| +end |
| |
458
| + |
| |
459
| +function Capsule:getKing(record) |
| |
460
| + local spKey, special = self:checkSpecialFlag(SpecialType.KING) |
| |
461
| + if not special then return nil end |
| |
462
| + |
| |
463
| + local specials = self:getProperty("specials") or {} |
| |
464
| + local specialsRecord = self:getProperty("specialsRecord") or {} |
| |
465
| + |
| |
466
| + if self:getGoodsAmount() > 0 then return nil end |
| |
467
| + |
| |
468
| + local roleRecord = {} |
| |
469
| + for _, v in ipairs(record) do |
| |
470
| + if not roleRecord[v.roleId]then |
| |
471
| + roleRecord[v.roleId] = {amount = v.amount } |
| |
472
| + else |
| |
473
| + roleRecord[v.roleId] = {amount = (roleRecord[v.rol_id]["amount"] or 0) + v.amount} |
| |
474
| + end |
| |
475
| + end |
| |
476
| + |
| |
477
| + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], SpecialType.KING) |
| |
478
| + special["amount"] = count |
| |
479
| + specials[spKey] = special |
| |
480
| + specialsRecord[SpecialType.KING] = rewardByRole |
| |
481
| + self:setProperties({specialsRecord = specialsRecord, specials = specials}) |
| |
482
| + return rewardByRole |
| |
483
| +end |
| |
484
| + |
| |
485
| +local rewardToNtyFunc = function(notify, tmpReward) |
| |
486
| + for key, val in pairs(tmpReward or {}) do |
| |
487
| + if not notify[key] then |
| |
488
| + notify[key] = val |
| |
489
| + else |
| |
490
| + for k, v in pairs(val) do |
| |
491
| + if not notify[key][k] then |
| |
492
| + notify[key][k] = v |
| |
493
| + else |
| |
494
| + notify[key][k] = notify[key][k].amount + v.amount |
| |
495
| + end |
| |
496
| + end |
| |
497
| + |
| |
498
| + end |
| |
499
| + end |
| |
500
| +end |
| |
501
| + |
| |
502
| +function Capsule:checkSpecialReward( now) |
| |
503
| + local specials = self:getProperty("specials") or {} |
| |
504
| + if not next(specials) then return nil end |
| |
505
| + local record = self:getProperty("record") or {} |
| |
506
| + |
| |
507
| + if not next(record) then return nil end |
| |
508
| + table.sort(record, function(a, b) return a.create_time < b.create_time end ) |
| |
509
| + |
| |
510
| + |
| |
511
| + local notify = self:getTop(record) or {} |
| |
512
| + |
| |
513
| + local coreReward = self:getCore(record) |
| |
514
| + rewardToNtyFunc(notify, coreReward) |
| |
515
| + |
| |
516
| + local lastReward = self:getLast(record) |
| |
517
| + rewardToNtyFunc(notify, lastReward) |
| |
518
| + |
| |
519
| + local jokerReward = self:getJoker(record) |
| |
520
| + rewardToNtyFunc(notify, jokerReward) |
| |
521
| + |
| |
522
| + local kingReward = self:getKing(record) |
| |
523
| + rewardToNtyFunc(notify, kingReward) |
| |
524
| + |
| |
525
| + --广播出去TODO |
| |
526
| + --rpcRole(roleId, "paySpecialReward", RewardTYpe.JOKER, jokerReward.award) |
| |
527
| + return notify |
| |
528
| +end |
| |
529
| + |
| |
530
| +function Capsule:checkIncentive(roleId, name, now) |
| |
531
| + local goods = self:getProperty("goods") or {} |
| |
532
| + local recordByRole = self:getProperty("recordByRole") or {} |
| |
533
| + local roleRecord = recordByRole[roleId] or {} |
| |
534
| + local incentiveRecord = self:getProperty("incentiveRecord") or {} |
| |
535
| + local incentiveByRole = incentiveRecord[roleId] or {} |
| |
536
| + local incentive = self:getProperty("incentive") |
| |
537
| + |
| |
538
| + |
| |
539
| + local notify = {} |
| |
540
| + -- 最后一抽 TODO |
| |
541
| + if incentive["last"] then |
| |
542
| + local last = true |
| |
543
| + for k, v in pairs(goods) do |
| |
544
| + if v and v.amount then |
| |
545
| + last = false |
| |
546
| + break |
| |
547
| + end |
| |
548
| + end |
| |
549
| + if last then |
| |
550
| + notify["last"] = {name = name, good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now} |
| |
551
| + end |
| |
552
| + end |
| |
553
| + |
| |
554
| + --次数 |
| |
555
| + if incentive["amount"] then |
| |
556
| + local amount = 0 |
| |
557
| + for _, v in pairs(roleRecord) do |
| |
558
| + if (v.calculated or 0) == 0 then |
| |
559
| + amount = amount + v.amount |
| |
560
| + end |
| |
561
| + end |
| |
562
| + |
| |
563
| + local count = math.floor(amount / incentive["amount"]["np"]) |
| |
564
| + local tmpCount = count * incentive["amount"]["np"] |
| |
565
| + notify["amount"] = {name = name, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now} |
| |
566
| + |
| |
567
| + --填充v.calculated 字段,标识已经用于每x抽的计算中。 |
| |
568
| + for _, v in pairs(roleRecord) do |
| |
569
| + if tmpCount <= 0 then break end |
| |
570
| + |
| |
571
| + v.calculated = v.calculated or 0 |
| |
572
| + if v.calculated ~= v.amount then |
| |
573
| + if tmpCount <= v.amount then |
| |
574
| + v.calculated = tmpCount |
| |
575
| + tmpCount = 0 |
| |
576
| + else |
| |
577
| + v.calculated = v.amount |
| |
578
| + tmpCount = tmpCount - v.amount |
| |
579
| + end |
| |
580
| + end |
| |
581
| + |
| |
582
| + end |
| |
583
| + end |
| |
584
| + |
| |
585
| + --概率 |
| |
586
| + if incentive["probabilities"] then |
| |
587
| + local probabilities = math.randomInt(1, 100) |
| |
588
| + if probabilities <= incentive["probabilities"]["np"] then |
| |
589
| + notify["probabilities"] = {name = name, good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now} |
| |
590
| + |
| |
591
| + end |
| |
592
| + end |
| |
593
| + table.insert(incentiveByRole, notify) |
| |
594
| + incentiveRecord[roleId] = incentiveByRole |
| |
595
| + self:setProperty("incentiveRecord", incentiveRecord) |
| |
596
| + |
| |
597
| + return notify |
| |
598
| +end |
| |
599
| + |
| |
600
| +function Capsule:drawByCount(roleId, count) |
| |
601
| + if count <= 0 then return nil end |
| |
602
| + |
| |
603
| + local goods = self:getProperty("goods") or {} |
| |
604
| + local record = self:getProperty("record") or {} |
| |
605
| + local recordByRole = self:getProperty("recordByRole") or {} |
| |
606
| + local roleRecord = recordByRole[roleId] or {} |
| |
607
| + |
| |
608
| + local id = self:getProperty("id") |
| |
609
| + local room = self:getProperty("room") |
| |
610
| + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room] |
| |
611
| + local goods_id = ichibankuji["goods_id"] |
| |
612
| + local now = skynet.timex() |
| |
613
| + |
| |
614
| + --奖励, 通知信息 |
| |
615
| + local notify= {} |
| |
616
| + notify[roleId] = {} |
| |
617
| + |
| |
618
| + local name = getNameByRoleId(roleId) |
| |
619
| + while (goods and next(goods) and count > 0) do |
| |
620
| + local good_id = math.randWeight(goods, "weight") |
| |
621
| + if good_id then |
| |
622
| + local good = goods[good_id] or {} |
| |
623
| + if good and good.amount > 0 then |
| |
624
| + good.amount = good.amount - 1 |
| |
625
| + |
| |
626
| + --插入记录 |
| |
627
| + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now} |
| |
628
| + table.insert(record, tmpNotify) |
| |
629
| + |
| |
630
| + --作为奖励记录+通知 |
| |
631
| + if not notify[roleId][good_id] then |
| |
632
| + notify[roleId][good_id] = tmpNotify |
| |
633
| + else |
| |
634
| + notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1 |
| |
635
| + end |
| |
636
| + |
| |
637
| + --记录角色的抽奖记录 计算激励奖需要用到 |
| |
638
| + if not roleRecord[good_id] then |
| |
639
| + roleRecord[good_id] = tmpNotify |
| |
640
| + else |
| |
641
| + roleRecord[good_id].amount = roleRecord[good_id].amount + 1 |
| |
642
| + end |
| |
643
| + |
| |
644
| + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight |
| |
645
| + count = count - 1 |
| |
646
| + end |
| |
647
| + end |
| |
648
| + |
| |
649
| + end |
| |
650
| + recordByRole[roleId] = roleRecord |
| |
651
| + self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) |
| |
652
| + |
| |
653
| + local tmpNotify = self:checkIncentive(roleId, name, now) |
| |
654
| + for k, v in pairs(tmpNotify) do |
| |
655
| + if not notify[roleId][k] then |
| |
656
| + notify[roleId][k] = v |
| |
657
| + else |
| |
658
| + notify[roleId][k].amount = notify[roleId][k].amount + v.amount |
| |
659
| + end |
| |
660
| + end |
| |
661
| + |
| |
662
| + local speciNotify = self:checkSpecialReward(now) |
| |
663
| + rewardToNtyFunc(notify, speciNotify) |
| |
664
| + |
| |
665
| + local reward, rewardByGoods = {}, {} |
| |
666
| + for key, val in pairs(notify) do |
| |
667
| + if key == roleId then |
| |
668
| + for k, v in pairs(val) do |
| |
669
| + for id, count in pairs(v.award:toNumMap()) do |
| |
670
| + reward[id] = (reward[id] or 0) + count |
| |
671
| + end |
| |
672
| + rewardByGoods[k] = v |
| |
673
| + end |
| |
674
| + end |
| |
675
| + |
| |
676
| + end |
| |
677
| + return reward, rewardByGoods, notify |
| |
678
| +end |
| |
679
| + |
| |
680
| +function Capsule:drawAll(roleId) |
| |
681
| + local goods = self:getProperty("goods") or {} |
| |
682
| + local record = self:getProperty("record") or {} |
| |
683
| + local recordByRole = self:getProperty("recordByRole") or {} |
| |
684
| + local roleRecord = recordByRole[roleId] or {} |
| |
685
| + local now = skynet.timex() |
| |
686
| + |
| |
687
| + local name = getNameByRoleId(roleId) |
| |
688
| + local notify = {} |
| |
689
| + notify[roleId] = {} |
| |
690
| + for good_id, good in pairs(goods) do |
| |
691
| + if good.amount > 0 then |
| |
692
| + --插入记录 |
| |
693
| + local tmpNotify = {name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now} |
| |
694
| + table.insert(record, notify) |
| |
695
| + |
| |
696
| + --作为奖励记录+通知 |
| |
697
| + if not notify[roleId][good_id] then |
| |
698
| + notify[roleId][good_id] = tmpNotify |
| |
699
| + else |
| |
700
| + notify[roleId][good_id].amount = notify[roleId][good_id].amount + good.award |
| |
701
| + end |
| |
702
| + |
| |
703
| + --记录角色的抽奖记录 |
| |
704
| + if not roleRecord[good_id] then |
| |
705
| + roleRecord[good_id] = notify |
| |
706
| + else |
| |
707
| + roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount |
| |
708
| + end |
| |
709
| + |
| |
710
| + good.amount = 0 |
| |
711
| + end |
| |
712
| + |
| |
713
| + end |
| |
714
| + recordByRole[roleId] = roleRecord |
| |
715
| + self:setProperties({recordByRole = recordByRole, record = record, goods = goods}) |
| |
716
| + |
| |
717
| + local tmpNotify = self:checkIncentive(roleId, name, now) |
| |
718
| + for k, v in pairs(tmpNotify) do |
| |
719
| + if not notify[roleId][k] then |
| |
720
| + notify[roleId][k] = v |
| |
721
| + else |
| |
722
| + notify[roleId][k].amount = notify[roleId][k].amount + v.amount |
| |
723
| + end |
| |
724
| + end |
| |
725
| + |
| |
726
| + local speciNotify = self:checkSpecialReward(now) |
| |
727
| + rewardToNtyFunc(notify, speciNotify) |
| |
728
| + |
| |
729
| + local reward, rewardByGoods = {}, {} |
| |
730
| + for key, val in pairs(notify) do |
| |
731
| + if key == roleId then |
| |
732
| + for k, v in pairs(val) do |
| |
733
| + for id, count in pairs(v.award:toNumMap()) do |
| |
734
| + reward[id] = (reward[id] or 0) + count |
| |
735
| + end |
| |
736
| + rewardByGoods[k] = v |
| |
737
| + end |
| |
738
| + end |
| |
739
| + |
| |
740
| + end |
| |
741
| + return reward, rewardByGoods, notify |
| |
742
| +end |
| |
743
| + |
| |
744
| +--@param |
| |
745
| +--[[ |
| |
746
| +@roleId |
| |
747
| +@typ 0=独享,1=公开 |
| |
748
| +@cares 关注{k=v} |
| |
749
| +]]-- |
| |
750
| + |
| |
751
| +function Capsule:draw(roleId, full, cares) |
| |
752
| + if self:getGoodsAmount() == 0 then return 2 end |
| |
753
| + if self:getProperty("typ") == 1 then |
| |
754
| + --是否报名 |
| |
755
| + if self:isRegister(roleId) == false then return 3 end |
| |
756
| + |
| |
757
| + --关注的奖品的数量发生了变化 |
| |
758
| + if cares then |
| |
759
| + local change = self:confirmed(cares) |
| |
760
| + if next(change) then return 4, change end |
| |
761
| + end |
| |
762
| + end |
| |
763
| + |
| |
764
| + if full == 0 then |
| |
765
| + return 5, self:drawByCount(roleId, 1) |
| |
766
| + elseif full == 1 then |
| |
767
| + return 5, self:drawByCount(roleId, 10) |
| |
768
| + elseif full == 2 then |
| |
769
| + return 5, self:drawAll(roleId) |
| |
770
| + end |
| |
771
| +end |
| |
772
| + |
| |
773
| + |
| |
774
| +function Capsule:data(roleId) |
| |
775
| + return { |
| |
776
| + id = self:getProperty("id"), |
| |
777
| + room = self:getProperty("room"), |
| |
778
| + typ = self:getProperty("typ"), |
| |
779
| + name = self:getProperty("name"), |
| |
780
| + coin = self:getProperty("coin"), |
| |
781
| + onlineCount = self:getOnlineCount(), |
| |
782
| + playerStatus = self:getRegisterByRoleId(roleId), |
| |
783
| + record = self:getProperty("record"), |
| |
784
| + rank = self:getProperty("rank"), |
| |
785
| + goods = self:getProperty("goods"), |
| |
786
| + specials = self:getProperty("specials"), |
| |
787
| + incentive = self:getProperty("incentive"), |
| |
788
| + specialsRecord= self:getProperty("specialsRecord"), |
| |
789
| + } |
| |
790
| +end |
| |
791
| + |
| |
792
| +return Capsule |
0
| \ No newline at end of file |
793
| \ No newline at end of file |