Blame view

src/models/DailyPlugin.lua 16.7 KB
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  
  local DailyPlugin = {}
  oneDay = 60*60*24
  function DailyPlugin.bind(Daily)
      --解锁
      function Daily:checkUnlock(treaval)
          local role = self.owner
          local treasureC = treaval.unlock:toArray(true, "=")
          if treasureC[1] == 1 then --通关关卡
              return self.owner:checkHangPass(treasureC[2])
          elseif treasureC[1] == 2 then --通关拾荒章节=x层
              return role:checkAdvChapterPass(treasureC[2])
          elseif treasureC[1] == 3 then --拥有指定id的角色时
              local hero = role:getHeroByID(treasureC[2])
              if hero then return true end
          else
              return true
          end
          return  false
      end
  
      --CD
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
23
      function Daily:checkTreasureExpired(treasureAttr, treasureList, isExtra)
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
24
          local curInfo = treasureList[treasureAttr.id]
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
25
          local now = skynet.timex()
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
26
27
28
29
          if curInfo then
              -- check finish
              if curInfo["expire_time"] then
                  if curInfo.cool_time > 1 then
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
30
                      if now >= curInfo["expire_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
31
32
                          treasureList[treasureAttr.id] = nil
                          curInfo = clone(treasureAttr)
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
33
                      elseif now >= curInfo["expire_time"] -  curInfo.cool_time * oneDay then --未冷却
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
34
35
36
37
38
                          curInfo = nil
                      else
                          curInfo = clone(treasureAttr)
                      end
                  else
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
39
                      if now >= curInfo["expire_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
40
41
42
43
                          treasureList[treasureAttr.id] = nil
                      end
                      curInfo = clone(treasureAttr)
                  end
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
44
45
46
47
              else
                  if isExtra then
                      curInfo = nil
                  end
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
48
49
50
51
52
53
54
55
              end
          else
              curInfo = clone(treasureAttr)
          end
  
          return curInfo
      end
  
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
56
      --绑定通关关卡 每日宝藏
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
57
58
59
60
      function Daily:checkChapters(treasureList, treasureListOther)
          local chapters = {}
          local tmp_chapters = {}
  
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
61
62
63
64
          --不可以绑定的关卡
          --1. 正在挖宝,未挖到
          --2. 已经挖到宝藏,但未领取
          --3. 正在挂机
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
65
          for _, curInfo in pairs(treasureList or {}) do
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
66
              if (not curInfo["expire_time"] and curInfo["end_time"]) then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
67
68
69
70
71
                  tmp_chapters[curInfo.chapter_id] = curInfo
              end
          end
  
          for _, curInfo in pairs(treasureListOther or {}) do
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
72
              if (not curInfo["expire_time"] and curInfo["end_time"]) then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
73
74
75
76
77
78
79
80
                  tmp_chapters[curInfo.chapter_id] = curInfo
              end
          end
  
          local hangInfo = self.owner:getProperty("hangInfo") or {}
          for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do
              if chapter_id ~= hangInfo.carbonId then
                  if self.owner:checkHangPass(chapter_id) then
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
81
82
83
84
85
86
87
88
89
90
                      if not tmp_chapters[chapter_id] then
                          chapters[chapter_id] = {treasure_weight=val.treasure_weight}
                      end
                  end
              end
  
          end
          return chapters
      end
  
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
91
      --绑定通关关卡 额外宝藏
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
92
93
94
95
96
97
98
      function Daily:checkChaptersExtra(treasureList, treasureListOther)
          local chapters = {}
          local tmp_chapters = {}
  
          --不可以绑定的关卡
          --1. 未过期(未挖,在挖,未领)
          --2. 正在挂机
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
          for _, curInfo in pairs(treasureList or {}) do
              if not curInfo["expire_time"] then
                  tmp_chapters[curInfo.chapter_id] = curInfo
              end
          end
  
          for _, curInfo in pairs(treasureListOther or {}) do
              if not curInfo["expire_time"] then
                  tmp_chapters[curInfo.chapter_id] = curInfo
              end
          end
  
          local hangInfo = self.owner:getProperty("hangInfo") or {}
          for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do
              if chapter_id ~= hangInfo.carbonId then
                  if self.owner:checkHangPass(chapter_id) then
                      if not tmp_chapters[chapter_id] then
                          chapters[chapter_id] = {treasure_weight=val.treasure_weight}
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
                      end
                  end
              end
  
          end
          return chapters
      end
  
      --权重
      function Daily:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListOther)
          local chapters = self:checkChapters(treasureList, treasureListOther)
          if not chapters or not next(chapters) then return end
  
          --扣除在挖宝列表里未过期宝藏的资源值
          for _, val in pairs(treasureList) do
              if not val["expire_time"] then
                  treasureBase = treasureBase - val["treasure_value"]
              end
          end
  
          if tmpTreasure and next(tmpTreasure) then
              table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end)
          end
  
          local treasure
          while next(tmpTreasure or {}) do
              local tmp = {}
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
144
              for _, val in pairs(tmpTreasure) do
b62c0a4c   zhangqijia   fix: 挂机图鉴,宝藏值使用不完...
145
                  if treasureBase >= val.treasure_value then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
146
147
148
149
150
151
152
153
154
155
                      tmp[val.id] = val
                  end
              end
              if not next(tmp) then break end
  
              local id = math.randWeight(tmp, "weight") --宝藏id
              if not id then break end
  
              treasure = tmp[id]
              if treasureBase < treasure.treasure_value  then break end
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
156
157
158
159
160
161
162
  
              local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id
              if not chapterId then break end
  
              treasure.chapter_id = chapterId
              treasureList[treasure.id] = treasure
  
b62c0a4c   zhangqijia   fix: 挂机图鉴,宝藏值使用不完...
163
164
              --扣除资源值
              treasureBase = treasureBase - treasure.treasure_value
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
165
166
167
168
169
170
171
              tmpTreasure[treasure.id] = nil
              chapters[chapterId] = nil
          end
      end
  
      --只抓一个 额外宝藏
      function Daily:getOneTreasureExtra(treasureList, tmpTreasure, treasureBase, treasureListOther)
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
172
          local chapters = self:checkChaptersExtra(treasureList, treasureListOther)
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
          if not chapters or not next(chapters) then return end
  
          --扣除在挖宝列表里未过期宝藏的资源值
          for _, val in pairs(treasureList) do
              if not val["expire_time"] then
                  treasureBase = treasureBase - val["treasure_value"]
              end
          end
  
          if tmpTreasure and next(tmpTreasure) then
              table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end)
          end
  
          local treasure
          local tmp = {}
          local tmpBase = treasureBase
          for _, val in pairs(tmpTreasure) do
              if tmpBase >= val.treasure_value then
                  tmpBase = tmpBase - val.treasure_value
                  tmp[val.id] = val
              end
          end
          if not next(tmp) then  return end
  
          local id = math.randWeight(tmp, "weight") --宝藏id
          if not id then return end
  
          treasure = tmp[id]
          if treasureBase < treasure.treasure_value  then return end
          --扣除资源值
          treasureBase =  treasureBase - treasure.treasure_value
  
          local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id
          if not chapterId then return end
  
  
          treasure.chapter_id = chapterId
          treasureList[treasure.id] = treasure
  
          return treasure
      end
  
      --chapterId
      function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId, treasureBase)
          if not curInfo then return nil end
  
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
219
          local now = skynet.timex()
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
220
221
222
223
224
          local treasure = nil
          --开始挖宝关卡ID=挂机关卡ID
          if chapterId == curInfo.chapter_id then
              --开始挖宝
              if not curInfo["end_time"] then
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
225
                  curInfo["end_time"] = now + curInfo.working_time
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
226
              else
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
227
                  if now >= curInfo["end_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
228
229
230
231
232
233
234
                      if curInfo.cool_time > 1 then
                          --宝藏冷却时间
                          if not curInfo["expire_time"] then
                              if treasureBase >= curInfo["treasure_value"] then
                                  treasureBase = treasureBase - curInfo["treasure_value"]
  
                                  treasure = treasureList[curInfo.id]
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
235
                                  curInfo["expire_time"] = now + curInfo.cool_time * oneDay
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
236
237
238
                              end
                          else
                              --已经领取宝藏 检索宝藏冷却时间
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
239
                              if now >= curInfo["expire_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
                                  treasureList[curInfo.id] = nil
                              end
                          end
                      else
                          if treasureBase >= curInfo["treasure_value"] then
                              treasureBase = treasureBase - curInfo["treasure_value"]
  
                              treasure = treasureList[curInfo.id]
                              treasureList[curInfo.id] = nil
                          end
                      end
                  end
              end
          else
              --已经开始挖宝
              if curInfo["end_time"] then
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
256
                  if now >= curInfo["end_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
257
258
259
260
261
262
263
                      if curInfo.cool_time > 1 then
                          --宝藏冷却时间
                          if not curInfo["expire_time"] then
                              if treasureBase >= curInfo["treasure_value"] then
                                  treasureBase = treasureBase - curInfo["treasure_value"]
  
                                  treasure = treasureList[curInfo.id]
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
264
                                  curInfo["expire_time"] = now + curInfo.cool_time * oneDay
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
265
266
267
268
                              end
  
                          else
                              --已经领取宝藏 检索宝藏冷却时间
78065fee   zhangqijia   fix: 额外宝藏 不可以绑定的关...
269
                              if now >= curInfo["expire_time"] then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
                                  treasureList[curInfo.id] = nil
                              end
                          end
                      else
                          if treasureBase >= curInfo["treasure_value"] then
                              treasureBase = treasureBase - curInfo["treasure_value"]
  
                              treasure = treasureList[curInfo.id]
                              treasureList[curInfo.id] = nil
                          end
                      end
                  else
                      curInfo["end_time"]	= nil
                  end
              end
          end
          return treasure
      end
  
      function Daily:buyTreasure(treasureList)
          local boughtTreasure = {}
          local treasureBase = self:getProperty("treasureBase")
          for id, val in pairs(treasureList) do
              if treasureBase >= val.treasure_value then
                  boughtTreasure[id] = val
                  treasureBase = treasureBase - val.treasure_value
              end
          end
          self:updateProperty({field = "treasureBase", value = treasureBase})
          return boughtTreasure
      end
  
      --重置宝藏图鉴
      function Daily:resetTreasureList()
          self:updateProperty({field = "treasureList", value = {}})
          self:updateProperty({field = "treasureListExtra", value = {}})
      end
  
      --宝藏图鉴
      function Daily:getTreasureList()
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
310
311
          local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新
          local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏列表 过期删除 领取奖励删除 跨天更新
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
312
313
  
          --获取宝藏列表(与额外宝藏逻辑不同) 进行随机获取宝藏
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
314
315
          local tmpTreasure = {}
          local treasureBase = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum()
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
316
317
          for _, val in pairs(csvdb["idle_treasureCsv"]) do
              if self:checkUnlock(val) then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
                  local treasure = self:checkTreasureExpired(val, treasureList)
                  if treasure then
                      table.insert(tmpTreasure, treasure)
                  end
              end
          end
  
          if not next(tmpTreasure) then return treasureList end
  
          self:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListExtra)
          self:updateProperty({field = "treasureList", value = treasureList})
          self:updateProperty({field = "treasureBase", value = treasureBase})
          return treasureList
      end
  
  
      --检索挖宝列表 获得宝藏
      function Daily:checkTreasureList(chapterId)
          local treasureList = self:getProperty("treasureList") or {}
          local treasureBase = self:getProperty("treasureBase") or {}
          local tmpTreasure = {}
          for id, val in pairs(treasureList) do
              local treasure = self:checkTreasureChapterId(val, treasureList, chapterId, treasureBase)
              if treasure then
                  tmpTreasure[id] = treasure
              end
          end
  
          if not next(tmpTreasure) then
              self:updateProperty({field = "treasureList", value = treasureList})
              return nil
          end
          local boughtTreasure = self:buyTreasure(tmpTreasure)
          self:updateProperty({field = "treasureList", value = treasureList})
          return boughtTreasure
      end
  
      --宝藏加速
      function Daily:quickTreasureList(chapterId, time)
          local treasureList = self:getProperty("treasureList") or {}
          if next(treasureList) then
              for _, val in pairs(treasureList) do
                  if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then
                      val["end_time"] = val["end_time"] - time
                  end
              end
          end
          self:updateProperty({field = "treasureList", value = treasureList})
          return self:checkTreasureList(chapterId)
      end
  
      --宝藏功能优化——增加"发现宝藏"功能
      function Daily:buyTreasureExtra(treasureList)
          local boughtTreasure = {}
aca85b6f   zhangqijia   fix: 额外宝藏 资源值字段修改...
372
          local treasureBase = self:getProperty("treasureBaseExtra")
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
373
374
375
376
377
378
          for id, val in pairs(treasureList) do
              if treasureBase >= val.treasure_value then
                  boughtTreasure[id] = val
                  treasureBase = treasureBase - val.treasure_value
              end
          end
aca85b6f   zhangqijia   fix: 额外宝藏 资源值字段修改...
379
          self:updateProperty({field = "treasureBaseExtra", value = treasureBase})
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
380
381
382
383
          return boughtTreasure
      end
  
      function Daily:getTreasureExtra(tmpBaseExtra)
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
384
385
386
          local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新
          local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏 过期删除 领取奖励删除 跨天更新
  
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
387
          --获取宝藏列表(排除未过期的宝藏) 进行随机获取宝藏
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
388
          local tmpTreasure = {}
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
389
          for _, val in pairs(csvdb["idle_treasureCsv"]) do
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
390
              if self:checkUnlock(val) then
5c6f50cb   zhangqijia   fix: 额外宝藏,在宝藏列表并且...
391
                  local treasure = self:checkTreasureExpired(val, treasureListExtra, true)
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
                  if treasure then
                      table.insert(tmpTreasure, treasure)
                  end
              end
          end
          if not next(tmpTreasure) then return nil, treasureListExtra end
  
          local tmp = self:getOneTreasureExtra(treasureListExtra, tmpTreasure, tmpBaseExtra, treasureList)
          self:updateProperty({field = "treasureListExtra", value = treasureListExtra})
          return tmp, treasureListExtra
      end
  
      --检索宝藏列表 获得额外宝藏
      function Daily:checkTreasureListExtra(chapterId)
          local treasureListExtra = self:getProperty("treasureListExtra") or {}
          local treasureBaseExtra = self:getProperty("treasureBaseExtra") or {}
          local tmpTreasure = {}
          for id, val in pairs(treasureListExtra) do
              local treasure = self:checkTreasureChapterId(val, treasureListExtra, chapterId, treasureBaseExtra)
              if treasure then
                  tmpTreasure[id] = treasure
              end
          end
  
1bbe3bb8   zhangqijia   fix: 额外宝藏bug修复
416
          if not next(tmpTreasure) then
ecf87563   zhangqijia   feat: 挂机图鉴的扩展功能——...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
              self:updateProperty({field = "treasureListExtra", value = treasureListExtra})
              return nil
          end
  
          local boughtTreasure = self:buyTreasureExtra(tmpTreasure)
          self:updateProperty({field = "treasureListExtra", value = treasureListExtra})
          return boughtTreasure
      end
  
      --额外宝藏加速
      function Daily:quickTreasureListExtra(chapterId, time)
          local treasureListExtra = self:getProperty("treasureListExtra") or {}
          if next(treasureListExtra) then
              for _, val in pairs(treasureListExtra) do
                  if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then
                      val["end_time"] = val["end_time"] - time
                  end
              end
          end
  
          self:updateProperty({field = "treasureListExtra", value = treasureListExtra})
          return self:checkTreasureListExtra(chapterId)
      end
  end
  
  
  return DailyPlugin