difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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
310
311
312
313
314
315
316
317
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
"use strict";
cc._RF.push(module, '836a5j+rGNDq4dZciAzepvK', 'battle_drama_model');
// Scripts/mod/battle_drama/battle_drama_model.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2018-12-25 14:56:32
// --------------------------------------------------------------------
var DramaEvent = require("battle_drama_event");
 
var MainUIController = require("mainui_controller");
 
var MainuiConst = require("mainui_const");
 
var Battle_dramaModel = cc.Class({
  "extends": BaseClass,
  properties: {
    drama_data: {
      "default": {}
    },
    last_dun_id: null,
    quick_battle_data: {
      "default": {}
    },
    // 已领取的通关奖励
    dic_drama_rewrad_ids: {
      "default": {}
    },
    mode_list: {
      "default": {}
    },
    cur_dun_list: {
      "default": {}
    },
    // 当前章节
    init_dungeon_list: {
      "default": {}
    },
    drama_res: {
      "default": {}
    }
  },
  ctor: function ctor() {},
  initConfig: function initConfig() {
    this.had_update_reward = false;
    this.is_open_quick_battle_view = false; //主要用于记录是否已经打开是红点
  },
  preloadDramaScene: function preloadDramaScene(callback) {
    var battle_res_id = 10003;
    var drama_data = this.getDramaData();
 
    if (drama_data && drama_data.mode && drama_data.chapter_id) {
      var drama_config = Config.dungeon_data.data_drama_world_info[drama_data.mode][drama_data.chapter_id];
      battle_res_id = drama_config.map_id;
    }
 
    var drama_paths = PathTool.getBattleDrameBg(battle_res_id);
    LoaderManager.getInstance().loadRes(drama_paths.f, function (path, f_bg) {
      this.drama_res.f_res = {};
      this.drama_res.f_res.path = path;
      this.drama_res.f_res.res = f_bg;
    }.bind(this, drama_paths.f));
    LoaderManager.getInstance().loadRes(drama_paths.s, function (path, s_bg) {
      this.drama_res.s_res = {};
      this.drama_res.s_res.path = path;
      this.drama_res.s_res.res = s_bg;
    }.bind(this, drama_paths.s));
  },
  getDramaScene: function getDramaScene(battle_res_id, isF, callback) {
    var drama_paths = PathTool.getBattleDrameBg(battle_res_id);
 
    if (isF) {
      if (this.drama_res.f_res && this.drama_res.f_res.path == drama_paths.f) {
        callback(this.drama_res.f_res.res);
      } else {
        LoaderManager.getInstance().loadRes(drama_paths.f, function (path, f_bg) {
          if (this.drama_res.f_res) LoaderManager.getInstance().releaseRes(this.drama_res.f_res.path);
          this.drama_res.f_res = {};
          this.drama_res.f_res.path = path;
          this.drama_res.f_res.res = f_bg;
          if (callback) callback(f_bg);
        }.bind(this, drama_paths.f));
      }
    } else {
      if (this.drama_res.s_res && this.drama_res.s_res.path == drama_paths.s) {
        callback(this.drama_res.s_res.res);
      } else {
        LoaderManager.getInstance().loadRes(drama_paths.s, function (path, s_bg) {
          if (this.drama_res.s_res) LoaderManager.getInstance().releaseRes(this.drama_res.s_res.path);
          this.drama_res.s_res = {};
          this.drama_res.s_res.path = path;
          this.drama_res.s_res.res = s_bg;
          if (callback) callback(s_bg);
        }.bind(this, drama_paths.s));
      }
    }
  },
  setDramaData: function setDramaData(data) {
    var need_event = false;
 
    if (!this.drama_data || this.drama_data.max_dun_id !== data.max_dun_id) {
      need_event = true;
    }
 
    if (!this.last_dun_id || this.last_dun_id < data.max_dun_id) {
      this.last_dun_id = data.max_dun_id || this.drama_data.max_dun_id;
    }
 
    this.drama_data.mode = data.mode; // 当前难度
 
    this.drama_data.chapter_id = data.chapter_id; // 当前章节
 
    this.drama_data.dun_id = data.dun_id; // 当前关卡
 
    this.drama_data.status = data.status; // 当前关卡状态(1:制作中 2:可挑战 3:已通关)
 
    this.drama_data.cool_time = data.cool_time; // 当前关卡冷却时间(unixtime)
 
    this.drama_data.max_dun_id = data.max_dun_id; // 最大通关关卡
 
    this.drama_data.auto_num = data.auto_num; // 今天扫荡已用次数
 
    this.drama_data.auto_num_max = data.auto_num_max; // 今天扫荡次数上限
 
    this.drama_data.is_first = data.is_first; // 是否首次挑战当前关卡
 
    this.drama_data.last_dun_id = this.last_dun_id; // 本地缓存上一个通关章节id
 
    if (data.mode_list) {
      this.mode_list = data.mode_list;
    }
 
    if (need_event) {
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Max_Id, this.drama_data.max_dun_id);
    }
 
    gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Top_Update_Data, data);
    this.initDungeonList(this.drama_data.mode, this.drama_data.chapter_id); //战斗副本界面没对应刷新函数,暂时在这里初始化
  },
  // 更新关卡信息
  updateDramaData: function updateDramaData(data) {
    if (!this.drama_data) return;
    var need_event = false;
 
    if (this.drama_data.max_dun_id != data.max_dun_id) {
      need_event = true;
    }
 
    var need_cool = false;
 
    if (this.drama_data.cool_time != data.cool_time && this.drama_data.status != data.status) {
      need_cool = true;
    }
 
    var need_dun_id = false;
 
    if (this.drama_data.dun_id != data.dun_id) {
      need_dun_id = true;
    }
 
    if (this.drama_data.max_dun_id == null || this.drama_data.max_dun_id < data.max_dun_id) {
      this.last_dun_id = this.drama_data.max_dun_id || data.max_dun_id;
    }
 
    if (this.drama_data.dun_id != data.dun_id) {
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Dun_Id, data.dun_id);
    }
 
    this.drama_data.mode = data.mode; // 当前难度
 
    this.drama_data.chapter_id = data.chapter_id; // 当前章节
 
    this.drama_data.dun_id = data.dun_id; // 当前关卡
 
    this.drama_data.status = data.status; // 当前关卡状态(1:制作中 2:可挑战 3:已通关)
 
    this.drama_data.cool_time = data.cool_time; // 当前关卡冷却时间(unixtime)
 
    this.drama_data.max_dun_id = data.max_dun_id; // 最大通关关卡
 
    this.drama_data.is_first = data.is_first; // 是否首次挑战当前关卡
 
    this.drama_data.last_dun_id = this.last_dun_id; // 本地缓存上一个通关章节id
 
    this.updateModeListInfo(data);
 
    if (this.cur_dun_list && Utils.next(this.cur_dun_list || {}) != null && this.cur_dun_list[data.dun_id]) {
      this.cur_dun_list[data.dun_id].status = data.status;
 
      if (this.cur_dun_list[data.dun_id].status == 3) {
        this.cur_dun_list[data.dun_id].is_has = true;
      }
 
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Data, data);
    }
 
    if (need_event) {
      // 以更新剧情id为最优先
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Max_Id, this.drama_data.max_dun_id);
    } else if (need_cool) {
      // 这个是更新时间的
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Cool_Time);
    }
 
    if (need_dun_id) {
      gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Update_Dun_Id);
    }
  },
  // 累积挂机时间处理
  updateHookAccumulateTime: function updateHookAccumulateTime(data) {
    this.hook_accumulate_data = data;
    gcore.GlobalEvent.fire(DramaEvent.UpdateHookAccumulateTime, data);
  },
  // 挂机时间处理
  getHookAccumulateInfo: function getHookAccumulateInfo() {
    return this.hook_accumulate_data;
  },
  getDramaData: function getDramaData() {
    return this.drama_data;
  },
  // 更新快速作战的数据
  setQuickData: function setQuickData(data) {
    this.quick_battle_data = data;
    this.checkRedPoint();
    gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Quick_Battle_Data, data);
  },
  // 获取快速作战信息
  getQuickData: function getQuickData() {
    return this.quick_battle_data;
  },
  // 更新已通关奖励
  setDramaReward: function setDramaReward(data) {
    this.checkRedPoint();
    gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Drama_Reward_Data, data);
    if (this.had_update_reward == true) return; // 为了兼容原生那边,只做一次处理,具体更新再下面
 
    this.had_update_reward = true;
    if (!data || !data.list || data.list.length == 0) return;
    this.dic_drama_rewrad_ids = {};
 
    for (var index = 0; index < data.list.length; index++) {
      var element = data.list[index];
      this.dic_drama_rewrad_ids[element.id] = true;
    } // 这里需要判断一下红点,基于当前通关的max_dun_id 和已领取的来匹配
 
  },
  //获取通关奖励的红点信息
  getDramaRewardRedPointInfo: function getDramaRewardRedPointInfo() {
    var drama_data = this.getDramaData();
 
    if (this.dic_drama_rewrad_ids && drama_data && drama_data.max_dun_id) {
      var config = Config.dungeon_data.data_drama_reward;
 
      if (config) {
        for (var i in config) {
          var v = config[i]; //当前最大关卡 比需求关卡 大 说明可领
 
          if (drama_data.max_dun_id >= v.limit_id) {
            if (!this.dic_drama_rewrad_ids[v.id]) {
              return true;
            }
          }
        }
      }
    }
 
    return false;
  },
  // 更新奖励
  updateDramaReward: function updateDramaReward(id) {
    this.dic_drama_rewrad_ids[id] = true;
    gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Drama_Reward_Data, id);
  },
  // 获取剧情通关奖励列表
  getDramaRewardPassList: function getDramaRewardPassList() {
    return this.dic_drama_rewrad_ids;
  },
  //获取已开启的总章节数
  getOpenSumChapter: function getOpenSumChapter(mode) {
    if (this.mode_list) {
      var chapter_list = this.mode_list[mode - 1].chapter_list;
      var chapter_sum = 0;
 
      if (chapter_list) {
        for (var i in chapter_list) {
          chapter_sum = chapter_sum + 1;
        }
      }
 
      return chapter_sum;
    }
  },
  checkRedPoint: function checkRedPoint() {
    var status = this.getDramaRewardRedPointInfo();
    MainUIController.getInstance().setBtnRedPoint(MainuiConst.btn_index.drama_scene, status);
  },
  //获取boss关卡预览相关信息
  getBossShowData: function getBossShowData() {
    var chapter_list = [];
    var sum_chapter = this.getOpenSumChapter(this.drama_data.mode);
 
    if (Config.dungeon_data.data_drama_world_info) {
      var world_list = Config.dungeon_data.data_drama_world_info[this.drama_data.mode];
      var boss_reward_list = Config.dungeon_data.data_drama_boss_show_reward;
 
      for (var i in world_list) {
        var boss_reward = boss_reward_list[i];
 
        if (boss_reward && world_list[i].chapter_id <= sum_chapter + 1) {
          chapter_list.push(world_list[i]);
        }
      }
    }
 
    return chapter_list;
  },
  getCurDunInfoByID: function getCurDunInfoByID(dun_id) {
    if (this.cur_dun_list) {
      var config = this.cur_dun_list[dun_id];
      return config;
    }
  },
  getInitDungeonList: function getInitDungeonList() {
    if (this.init_dungeon_list && Utils.next(this.init_dungeon_list || []) != null) {
      return this.init_dungeon_list;
    }
  },
  // 用于初始化当前显示关卡的信息展示
  initDungeonList: function initDungeonList(mode, chapter_id) {
    if (Config.dungeon_data.data_drama_info) {
      var chapter_list = Config.dungeon_data.data_drama_info[mode][chapter_id];
 
      if (chapter_list) {
        var list = [];
 
        for (var i in chapter_list) {
          list.push(chapter_list[i]);
        }
 
        list.sort(function (a, b) {
          return a.id - b.id;
        });
 
        for (var i in list) {
          var info_data = gdata("dungeon_data", "data_drama_dungeon_info", list[i].id);
          this.init_dungeon_list[i] = {
            info_data: info_data
          };
          this.cur_dun_list[list[i].id] = {
            dun_id: list[i].id,
            status: 0,
            cool_time: 0,
            auto_num: 0,
            is_has: false
          };
        }
      }
 
      this.updateHadModeListInfo(mode, chapter_id);
    }
  },
  // 获取初始化当前章节和难道所有副本信息
  updateHadModeListInfo: function updateHadModeListInfo(mode, chapter_id) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.getChapterListByID(mode, chapter_id);
 
      if (chapter_list) {
        var dun_list = chapter_list.dun_list;
 
        if (dun_list) {
          for (var i in dun_list) {
            var temp_data = this.cur_dun_list[dun_list[i].dun_id];
 
            if (temp_data) {
              temp_data.dun_id = dun_list[i].dun_id;
              temp_data.status = dun_list[i].status;
              temp_data.cool_time = dun_list[i].cool_time;
              temp_data.auto_num = dun_list[i].auto_num;
              temp_data.is_has = true;
            }
          }
        }
      }
    }
  },
  updateModeListInfo: function updateModeListInfo(data) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.getChapterListByID(data.mode, data.chapter_id);
 
      if (chapter_list) {
        var dun_list = chapter_list.dun_list;
 
        if (dun_list) {
          var temp_has = true;
 
          if (data.status == 1) {
            temp_has = false;
          }
 
          var is_has = false;
 
          for (var i in dun_list) {
            if (data.dun_id == dun_list[i].dun_id) {
              is_has = true;
              dun_list[i].dun_id = data.dun_id;
              dun_list[i].cool_time = data.cool_time;
              dun_list[i].status = data.status;
              dun_list[i].is_has = temp_has;
            }
          }
 
          if (!is_has) {
            dun_list.push({
              dun_id: data.dun_id,
              status: data.status,
              cool_time: data.cool_time,
              auto_num: 0,
              is_has: temp_has
            });
          }
        }
      }
    }
  },
  getChapterListByID: function getChapterListByID(mode, chapter_id) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.mode_list[mode - 1].chapter_list;
      var list = null;
 
      if (chapter_list) {
        for (var i in chapter_list) {
          if (chapter_list[i].chapter_id == chapter_id) {
            list = chapter_list[i];
            break;
          }
        }
 
        return list;
      }
    }
  },
  //根据难度和章节id去获取已通过的Boss关卡数
  getHasCurChapterPassListBossNum: function getHasCurChapterPassListBossNum(mode, chapter_id) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.getChapterListByID(mode, chapter_id);
      var sum = 1;
 
      if (chapter_list) {
        var dun_list = chapter_list.dun_list;
 
        if (dun_list) {
          for (var i in dun_list) {
            var config = gdata("dungeon_data", "data_drama_dungeon_info", [dun_list[i].dun_id]);
 
            if (dun_list[i].status == 3 && config && config.is_big == 1) {
              sum = sum + 1;
            }
          }
        }
      }
 
      return sum;
    }
  },
  //根据当前副本id来获取展示
  getShowDescRewad: function getShowDescRewad(dun_id) {
    var list = [];
    var index = 1;
    var config = Config.dungeon_data.data_drama_show_reward;
 
    if (config) {
      for (var k in config) {
        var v = config[k];
 
        if (dun_id < v.id && index <= 3) {
          index = index + 1;
          list.push(v);
        }
      }
 
      list.sort(Utils.tableLowerSorter(["id"]));
    }
 
    return list;
  },
  // 获取当前切换章节通过最大的关卡ID
  getHasPassChapterMaxDunId: function getHasPassChapterMaxDunId(mode, chapter_id) {
    if (this.mode_list && Utils.next(this.mode_list || {})) {
      var chapter_list = this.getChapterListByID(mode, chapter_id);
      var max_dun_id = 0;
 
      if (chapter_list) {
        var dun_list = chapter_list.dun_list;
 
        for (var i in dun_list) {
          if (dun_list[i].dun_id > max_dun_id) {
            max_dun_id = dun_list[i].dun_id;
          }
        }
      }
 
      return max_dun_id;
    }
  },
  // 获取当前通关的章节数
  getCurMaxChapterId: function getCurMaxChapterId(mode) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.mode_list[mode - 1].chapter_list;
      var chapter_id = 1;
 
      if (chapter_list) {
        for (var i in chapter_list) {
          if (chapter_list[i].status == 1) {
            if (chapter_id <= chapter_list[i].chapter_id) {
              chapter_id = chapter_list[i].chapter_id;
            }
          }
        }
      }
 
      return chapter_id;
    }
  },
  // 获取某个章节的副本总长度
  getChapterLength: function getChapterLength(model, chapter_id) {
    if (this.chapter_list == null) {
      this.chapter_list = {};
    }
 
    if (this.chapter_list[Utils.getNorKey(model, chapter_id)] == null) {
      var sum = 0;
 
      if (Config.dungeon_data.data_drama_info[model] != null) {
        var list = Config.dungeon_data.data_drama_info[model][chapter_id];
 
        if (list != null) {
          sum = Object.keys(list).length;
        }
      }
 
      this.chapter_list[Utils.getNorKey(model, chapter_id)] = sum;
    }
 
    return this.chapter_list[Utils.getNorKey(model, chapter_id)];
  },
  // 根据难度和章节id去获取已通过的关卡数
  getHasCurChapterPassListNum: function getHasCurChapterPassListNum(mode, chapter_id) {
    if (this.mode_list && Utils.next(this.mode_list || {}) != null) {
      var chapter_list = this.getChapterListByID(mode, chapter_id);
      var sum = 0;
 
      if (chapter_list) {
        var dun_list = chapter_list.dun_list;
 
        for (var i in dun_list) {
          if (dun_list[i].status == 3) {
            sum = sum + 1;
          }
        }
      }
 
      return sum;
    }
  },
  // --判断当前关卡是否已通关和有弹出提示
  getPreStatus: function getPreStatus(dun_id) {
    if (Config.dungeon_data.data_drama_pre_fun) {
      var is_show = false;
      var data;
      var sys_data = JSON.parse(cc.sys.localStorage.getItem("drama_data")); //SysEnv:getInstance():loadDramaTipsFile()
 
      cc.log(Config.dungeon_data.data_drama_pre_fun, sys_data);
 
      for (var i in Config.dungeon_data.data_drama_pre_fun) {
        var v = Config.dungeon_data.data_drama_pre_fun[i];
 
        if (v.limit_id == dun_id && !sys_data[dun_id]) {
          is_show = true;
          data = v;
          break;
        }
      }
 
      return is_show, data;
    }
  },
 
  /**
   * 设置快速作战buff显示
   * @param {*} data 
   */
  setBuffData: function setBuffData(data) {
    this.buff_data = data;
    gcore.GlobalEvent.fire(DramaEvent.BattleDrama_Drama_Buff_View);
  },
  getBuffData: function getBuffData() {
    return this.buff_data;
  },
  setOpenQuickBattleStatus: function setOpenQuickBattleStatus(status) {
    this.is_open_quick_battle_view = status;
  },
  getOpenQuickBattleStatus: function getOpenQuickBattleStatus() {
    return this.is_open_quick_battle_view;
  },
  //设置第一次快速作战花费
  setFirstFresh: function setFirstFresh(status) {
    this.is_first_fresh = status;
  },
  getFirstFresh: function getFirstFresh() {
    return this.is_first_fresh || false;
  }
});
 
cc._RF.pop();