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
"use strict";
cc._RF.push(module, '186e0AtYd5Fi5LuGWBDvVMY', 'hallows_model');
// Scripts/mod/hallows/hallows_model.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-02-18 14:15:05
// --------------------------------------------------------------------
var HallowsVo = require("hallows_vo");
 
var MainuiController = require("mainui_controller");
 
var HeroController = require("hero_controller");
 
var RoleController = require("role_controller");
 
var BackpackController = require("backpack_controller");
 
var HallowsEvent = require("hallows_event");
 
var HallowsConst = require("hallows_const");
 
var MainuiConst = require("mainui_const");
 
var HallowsModel = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.ctrl = require("hallows_controller").getInstance();
    this.initConfig();
  },
  properties: {},
  initConfig: function initConfig() {
    this.hallows_list = [];
    this.open_flag = false; // 该玩家是否打开过神器界面
 
    this.had_request = false;
    this.attr_ratio_list = [];
    this.hallows_red_list = []; // 红点数据
  },
  //更新圣器数据
  updateHallowsInfo: function updateHallowsInfo(data) {
    if (!data) return;
 
    for (var i in data.hallows) {
      var hallows_vo = this.hallows_list[data.hallows[i].id];
 
      if (!hallows_vo) {
        hallows_vo = new HallowsVo();
        this.hallows_list[data.hallows[i].id] = hallows_vo;
      }
 
      hallows_vo.initAttributeData(data.hallows[i]);
    } //计算神器红点
 
 
    this.updateRedPoint();
  },
  //新增或者更新一个圣器
  updateHallowsData: function updateHallowsData(data) {
    var hallows_vo = this.getHallowsById(data.id);
 
    if (!hallows_vo) {
      hallows_vo = new HallowsVo();
      this.hallows_list[data.id] = hallows_vo;
    }
 
    hallows_vo.initAttributeData(data); // 计算神器红点
 
    this.updateRedPoint();
  },
  //监测红点
  updateHallowsRedStatus: function updateHallowsRedStatus(bid, status) {
    var _status = this.hallows_red_list[bid];
    if (_status == status) return;
    this.hallows_red_list[bid] = status;
    MainuiController.getInstance().setBtnRedPoint(MainuiConst.btn_index.hallows, {
      bid: bid,
      status: status
    });
    gcore.GlobalEvent.fire(HallowsEvent.HallowsRedStatus, bid, status);
  },
  // 根据红点类型判断是否显示红点
  checkRedIsShowByRedType: function checkRedIsShowByRedType(redType) {
    return this.hallows_red_list[redType] || false;
  },
  //判断神器是否有红点
  getHallowsRedStatus: function getHallowsRedStatus() {
    var red_status = false;
 
    for (var i in this.hallows_red_list) {
      if (this.hallows_red_list[i]) {
        red_status = true;
        break;
      }
    }
 
    return red_status;
  },
  updateRedPoint: function updateRedPoint() {
    RedMgr.getInstance().addCalHandler(this.checkHallowsRedStatus.bind(this), RedIds.Hallow);
  },
  checkHallowsRedStatus: function checkHallowsRedStatus() {
    var show_red = false;
 
    if (this.checkIsHaveAllHallows()) {
      //是否激活所有神器
      //按照等级、进度、id排序,取出第一个神器来判断红点
      var sort_func = function sort_func(objA, objB) {
        if (objA.step != objB.step) {
          return objB.step - objA.step;
        } else if (objA.lucky != objB.lucky) {
          return objB.lucky - objA.lucky;
        } else {
          return objB.id - objA.id;
        }
      };
 
      var hallows_list = Utils.deepCopy(this.hallows_list);
      hallows_list.sort(sort_func);
      var hallows_vo = hallows_list[0];
 
      if (hallows_vo) {
        this.setRedHallowsId(hallows_vo.id);
        var role_vo = RoleController.getInstance().getRoleVo(); // 神器升级
 
        var hallows_config = gdata("hallows_data", "data_info", Utils.getNorKey(hallows_vo.id, hallows_vo.step));
        var cost_config = hallows_config.loss;
 
        if (cost_config && Utils.next(cost_config) != null) {
          for (var i in cost_config) {
            var bid = cost_config[i][0];
            var num = cost_config[i][1];
            var have_num = 0;
            var assert = Config.item_data.data_assets_id2label[bid];
 
            if (assert) {
              have_num = role_vo[assert];
            } else {
              have_num = BackpackController.getInstance().getModel().getItemNumByBid(bid);
            }
 
            if (have_num < num) {
              show_red = false;
              break;
            } else {
              show_red = true;
            }
          }
        }
 
        this.updateHallowsRedStatus(HallowsConst.Red_Index.hallows_lvup, show_red); // 神器技能升级
 
        show_red = false; // 神器技能升级
 
        var skill_config = gdata("hallows_data", "data_skill_up", Utils.getNorKey(hallows_vo.id, hallows_vo.skill_lev));
 
        if (skill_config && skill_config.lev_limit != 0 && skill_config.lev_limit <= hallows_vo.step) {
          var cost_config = skill_config.lose;
 
          if (cost_config && Utils.next(cost_config) != null) {
            for (var j in cost_config) {
              var bid = cost_config[j][0];
              var num = cost_config[j][1];
              var have_num = 0;
              var assert = Config.item_data.data_assets_id2label[bid];
 
              if (assert) {
                have_num = role_vo[assert];
              } else {
                have_num = BackpackController.getInstance().getModel().getItemNumByBid(bid);
              }
 
              if (have_num < num) {
                show_red = false;
                break;
              } else {
                show_red = true;
              }
            }
          }
        }
 
        this.updateHallowsRedStatus(HallowsConst.Red_Index.skill_lvup, show_red); // 是否可以使用圣印石
 
        show_red = false;
        var trace_config = gdata("hallows_data", "data_trace_cost", Utils.getNorKey(hallows_vo.id, hallows_vo.step));
        var id_stone_config = Config.hallows_data.data_const["id_stone"];
 
        if (trace_config && id_stone_config) {
          var have_num = BackpackController.getInstance().getModel().getBackPackItemNumByBid(id_stone_config.val);
 
          if (hallows_vo.seal < trace_config.num && have_num > 0) {
            show_red = true;
          }
        }
 
        this.updateHallowsRedStatus(HallowsConst.Red_Index.stone_use, show_red);
      } // 当从神器任务界面变为神器界面时,要先清一下任务的红点
 
 
      if (this.checkRedIsShowByRedType(HallowsConst.Red_Index.task_award)) {
        this.updateHallowsRedStatus(HallowsConst.Red_Index.task_award, false);
      }
    } else {
      show_red = this.checkHallowsAwardTips();
      this.updateHallowsRedStatus(HallowsConst.Red_Index.task_award, show_red);
    }
  },
  // 保存一下显示红点的神器id(等级最高的)
  setRedHallowsId: function setRedHallowsId(id) {
    var old_id = this.red_hallows_id;
    this.red_hallows_id = id;
 
    if (old_id != this.red_hallows_id) {
      gcore.GlobalEvent.fire(HallowsEvent.HallowsRedStatus);
    }
  },
  getRedHallowsId: function getRedHallowsId() {
    return this.red_hallows_id;
  },
  //返回圣器数据
  getHallowsById: function getHallowsById(id) {
    return this.hallows_list[id];
  },
  //当前总结束
  curTotalStep: function curTotalStep() {
    var step = 0;
 
    for (var i in this.hallows_list) {
      step = step + this.hallows_list[i].step;
    }
 
    return step;
  },
  //获取圣器列表
  getHallowsList: function getHallowsList() {
    var list = [];
 
    for (var i in this.hallows_list) {
      list.push(this.hallows_list[i]);
    }
 
    return list;
  },
  //圣器共鸣等级
  getResonateLev: function getResonateLev() {
    return 0; //return self.resonate_lev 
  },
  //获取上阵伙伴数据
  getFormInfo: function getFormInfo() {
    if (Utils.next(this.attr_ratio_list) == null) {
      for (var i in Config.hallows_data.data_attr_radio) {
        var info = Config.hallows_data.data_attr_radio[i];
 
        for (var j in info.ratio) {
          var attr_key = info.ratio[i][0];
          var ratio = info.ratio[i][1];
          this.attr_ratio_list[Utils.getNorKey(info.type, attr_key)] = ratio;
        }
      }
    }
 
    var type_list = {};
    var partner_model = HeroController.getInstance().getModel();
 
    if (partner_model) {
      var form_pos_list = partner_model.getMyPosList();
 
      for (var k in form_pos_list) {
        var vo = partner_model.getHeroById(form_pos_list[k].id);
 
        if (vo) {
          if (type_list[vo.type] == null) {
            type_list[vo.type] = 0;
          }
 
          type_list[vo.type] = type_list[vo.type] + 1;
        }
      }
    }
 
    return type_list;
  },
  getRatio: function getRatio(type, attr_key) {
    return this.attr_ratio_list[Utils.getNorKey(type, attr_key)];
  },
  // 圣器任务列表
  updateHallowsTask: function updateHallowsTask(list) {
    if (list == null || Utils.next(list) == null) return;
 
    if (this.hallows_task_list == null) {
      this.hallows_task_list = {};
    }
 
    for (var i in list) {
      this.hallows_task_list[list[i].id] = list[i];
    }
 
    this.updateRedPoint();
    gcore.GlobalEvent.fire(HallowsEvent.UpdateHallowsTaskEvent);
  },
  // 获取指定圣器的任务列表, 这个id是圣器的id,
  getHallowsTaskList: function getHallowsTaskList(id) {
    var task_list = [];
    var hallows_task_config = Config.hallows_data.data_task;
 
    if (this.hallows_task_list) {
      for (var i in this.hallows_task_list) {
        var config = hallows_task_config[this.hallows_task_list[i].id];
 
        if (config.hid == id) {
          this.hallows_task_list[i].sort = config.sort;
          task_list.push(this.hallows_task_list[i]);
        }
      }
    }
 
    if (Utils.next(task_list)) {
      task_list.sort(function (a, b) {
        return a.id - b.id;
      });
    }
 
    return task_list;
  },
  // 获取指定任务数据
  getHallowsTaks: function getHallowsTaks(id) {
    if (this.hallows_task_list) {
      return this.hallows_task_list[id];
    }
  },
  // 获取当前待激活的圣器id
  getCurActivityHallowsId: function getCurActivityHallowsId() {
    if (this.hallows_list == null || Utils.next(this.hallows_list) == null) {
      //-- 第一个圣器
      return 1;
    }
 
    var next_id = 0;
 
    for (var i in this.hallows_list) {
      if (next_id < this.hallows_list[i].id) {
        next_id = this.hallows_list[i].id;
      }
    }
 
    return next_id + 1; // 取出当前待激活的圣器的id
  },
  // 当前待激活的神器是否有可领取的任务奖励
  checkHallowsAwardTips: function checkHallowsAwardTips() {
    if (this.hallows_task_list == null || Utils.next(this.hallows_task_list) == null) {
      return false;
    }
 
    var cur_hallows_id = this.getCurActivityHallowsId();
    var task_list = this.getHallowsTaskList(cur_hallows_id);
 
    if (task_list == null || Utils.next(task_list) == null) {
      return false;
    }
 
    for (var i in task_list) {
      if (task_list[i].finish == 1) {
        return true;
      }
    }
 
    return false;
  },
  // 获取当前是否已经激活所有神器
  checkIsHaveAllHallows: function checkIsHaveAllHallows() {
    var max_count = Config.hallows_data.data_base_length;
    var cur_count = 0;
 
    for (var i in this.hallows_list) {
      cur_count = cur_count + 1;
    }
 
    return cur_count >= max_count;
  },
  // 设置是否打开过神器界面的标记
  setOpenHallowsFlag: function setOpenHallowsFlag(flag) {
    this.open_flag = flag;
  },
  //1 为打开过,2为没打开过
  getHallowsOpenFlag: function getHallowsOpenFlag() {
    return this.open_flag;
  },
  // 根据神器id,从配置表数据中获取该神器最高属性数据
  makeHighestHallowVo: function makeHighestHallowVo(hallows_id) {
    if (hallows_id) {
      var hallows_vo = new HallowsVo();
      var max_lv = Config.hallows_data.data_max_lev[hallows_id];
      var max_skill_lv = Config.hallows_data.data_skill_max_lev[hallows_id];
      var config_info = gdata("hallows_data", "data_info", Utils.getNorKey(hallows_id, max_lv));
      var config_skill = gdata("hallows_data", "data_skill_up", Utils.getNorKey(hallows_id, max_skill_lv));
      ;
      var attr_data = [];
 
      for (var i in config_info.attr) {
        var attr_str = config_info.attr[i][0];
        var attr_temp = {};
        attr_temp.attr_id = Config.attr_data.data_key_to_id[attr_str];
        attr_temp.attr_val = config_info.attr[i][1];
        attr_data.push(attr_temp);
      }
 
      hallows_vo.id = hallows_id;
      hallows_vo.step = max_lv;
      hallows_vo.add_attr = attr_data;
      hallows_vo.skill_bid = config_skill.skill_bid;
      hallows_vo.skill_lev = max_skill_lv;
      return hallows_vo;
    }
  },
  __delete: function __delete() {}
});
 
cc._RF.pop();