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
"use strict";
cc._RF.push(module, '8f945muht9P9q6gp3WKcUDC', 'backpack_model');
// Scripts/mod/backpack/backpack_model.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2018-12-24 16:50:14
// --------------------------------------------------------------------
var BackPackConst = require("backpack_const");
 
var BackpackModel = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {},
  properties: {},
  initConfig: function initConfig() {
    this.item_list = {}; // 物品列表,背包类型座位key
 
    this.hallows_comp_list = {}; //神器合成
 
    this.equip_score_list = {};
  },
 
  /**
   * 初始化背包和装备背包数据
   * @param {*} data 
   */
  initItemList: function initItemList(data) {
    var GoodsVo = require("goods_vo");
 
    var bag_list = {};
 
    for (var index = 0; index < data.item_list.length; index++) {
      var element = data.item_list[index];
      var item_vo = new GoodsVo();
      item_vo.initAttrData(element);
      bag_list[element.id] = item_vo; // 装备背包备份多个最高评分列表的4件装备
 
      this.updateEquipScoreList(data.bag_code, item_vo);
    } // 储存空间物品
 
 
    var bag_code = data.bag_code;
    this.item_list[bag_code] = bag_list; // -- 是装备背包
 
    if (bag_code == BackPackConst.Bag_Code.EQUIPS) {// self.cur_equip_volume = #data.item_list 
      // -- MainuiController:getInstance():setBtnRedPoint(MainuiConst.btn_index.backpack, (self.cur_equip_volume >= data.volume))
    } else {
      if (!this.is_init_hero_chip_redpoint) {
        this.is_init_hero_chip_redpoint = true;
        this.getHeroChipRedPoint();
      }
    }
 
    this.setHallowsCompData();
    gcore.GlobalEvent.fire(EventId.GET_ALL_DATA, bag_code);
  },
  getHeroChipRedPoint: function getHeroChipRedPoint() {
    var hero_list = this.getAllBackPackArray(BackPackConst.item_tab_type.HERO);
    var status = false;
 
    for (var i = 0; i < hero_list.length; ++i) {
      var v = hero_list[i];
      status = this.checkHeroChipRedPoint(v);
 
      if (status) {
        break;
      }
    }
 
    var MainuiController = require("mainui_controller");
 
    var MainuiConst = require("mainui_const");
 
    MainuiController.getInstance().setBtnRedPoint(MainuiConst.btn_index.backpack, status);
  },
  // --检查英雄碎片是否能合/成
  checkHeroChipRedPoint: function checkHeroChipRedPoint(v) {
    if (v.quality != -1 && v.base_id) {
      // --碎片
      var partner_config = Config.partner_data.data_get_compound_info;
 
      if (partner_config[v.base_id]) {
        if (v.quantity >= partner_config[v.base_id].num) {
          return true;
        }
      } // --符文
 
 
      if (this.hallows_comp_list && this.hallows_comp_list[v.base_id]) {
        if (v.quantity >= this.hallows_comp_list[v.base_id].num) {
          return true;
        }
      }
    }
 
    return false;
  },
  // 增加或者更新一个物品
  updateBagItemsNum: function updateBagItemsNum(data, is_update) {
    var GoodsVo = require("goods_vo");
 
    var add_list = {};
    var bag_code = null;
 
    for (var index = 0; index < data.item_list.length; index++) {
      var element = data.item_list[index];
 
      if (this.item_list[element.storage] == null) {
        this.item_list[element.storage] = {};
      }
 
      var item_vo = this.item_list[element.storage][element.id];
 
      if (item_vo == null) {
        item_vo = new GoodsVo();
        this.item_list[element.storage][element.id] = item_vo;
      } //背包英雄符文碎片红点逻辑 (先算是否有红点) -zys
 
 
      var status = null;
      var config = Utils.getItemConfig(element.base_id);
 
      if (config.sub_type == BackPackConst.item_tab_type.HERO) {
        status = this.checkHeroChipRedPoint(item_vo);
      }
 
      item_vo.initAttrData(element); // 储存一下存储空间
 
      if (bag_code == null) {
        bag_code = element.storage;
      } // 备份新增物品
 
 
      add_list[element.id] = item_vo; // 装备背包备份多个最高评分列表的4件装备
 
      if (bag_code == BackPackConst.Bag_Code.EQUIPS) {
        if (item_vo && item_vo.config) {
          var type = item_vo.config.type || 1;
          if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
          this.equip_score_list[type][item_vo.id] = item_vo;
        }
      } //背包英雄符文碎片红点逻辑 (如果没有红点才判断)-zys
 
 
      if (!status && config.sub_type == BackPackConst.item_tab_type.HERO) {
        if (this.checkHeroChipRedPoint(item_vo)) {
          var MainuiController = require("mainui_controller");
 
          var MainuiConst = require("mainui_const");
 
          MainuiController.getInstance().setBtnRedPoint(MainuiConst.btn_index.backpack, true);
        }
      }
    }
 
    bag_code = bag_code || BackPackConst.Bag_Code.BACKPACK;
 
    if (is_update) {
      gcore.GlobalEvent.fire(EventId.MODIFY_GOODS_NUM, bag_code, add_list);
    } else {
      gcore.GlobalEvent.fire(EventId.ADD_GOODS, bag_code, add_list);
    }
  },
  // 删除一个物品
  deleteBagItems: function deleteBagItems(data) {
    var del_list = {};
    var bag_code = null;
 
    for (var index = 0; index < data.item_list.length; index++) {
      var element = data.item_list[index];
 
      if (this.item_list[element.storage]) {
        var item_vo = this.item_list[element.storage][element.id];
 
        if (bag_code == null) {
          bag_code = element.storage;
        } // bag_code = item_vo.storage || BackPackConst.Bag_Code.BACKPACK
 
 
        if (bag_code == BackPackConst.Bag_Code.EQUIPS) {
          if (item_vo && item_vo.config) {
            var type = item_vo.config.type || 1;
            if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
            this.equip_score_list[type][item_vo.id] = null;
          }
        } else if (bag_code == BackPackConst.Bag_Code.BACKPACK) {
          //背包里面的符文(以前神器)
          if (item_vo && item_vo.config) {
            var type = item_vo.config.type || 1;
 
            if (type == BackPackConst.item_type.ARTIFACTCHIPS) {
              if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
              this.equip_score_list[type][item_vo.id] = null;
            }
          }
        }
 
        if (item_vo) {
          del_list[element.id] = item_vo;
          this.item_list[element.storage][element.id] = null;
        }
      } // 储存一下存储空间
      // if (bag_code == null) {
      //     bag_code = element.storage
      // }
 
    }
 
    bag_code = bag_code || BackPackConst.Bag_Code.BACKPACK;
    gcore.GlobalEvent.fire(EventId.DELETE_GOODS, bag_code, del_list);
  },
  // 根据背包标签页类型返回当前的物品列表
  getAllBackPackArray: function getAllBackPackArray(type) {
    type = type || BackPackConst.item_tab_type.EQUIPS;
    var bag_code = BackPackConst.Bag_Code.BACKPACK;
 
    if (type == BackPackConst.item_tab_type.EQUIPS) {
      bag_code = BackPackConst.Bag_Code.EQUIPS;
    }
 
    var bag_list = this.item_list[bag_code];
    var temp_list = [];
 
    for (var key in bag_list) {
      var item_vo = bag_list[key];
 
      if (item_vo && item_vo.config && item_vo.config.sub_type == type) {
        temp_list.push(item_vo);
      }
    }
 
    if (temp_list.length > 0) {
      temp_list.sort(Utils.tableUpperSorter(["quality", "sort", "base_id"]));
    } // 排序
 
 
    return temp_list;
  },
  // 获取对应背包类型的物品列表 
  getBagItemList: function getBagItemList(bag_code) {
    return this.item_list[bag_code] || {};
  },
  // 根据bid获得道具物品的数量(包括资产道具)
  getItemNumByBid: function getItemNumByBid(bid) {
    var asset_key = gdata("item_data", "data_assets_id2label", bid);
 
    if (asset_key) {
      var RoleController = require("role_controller");
 
      var role_vo = RoleController.getInstance().getRoleVo();
 
      if (role_vo[asset_key]) {
        return role_vo[asset_key];
      } else {
        return 0;
      }
    } else {
      return this.getBackPackItemNumByBid(bid);
    }
  },
  // 根据bid获取背包物品的数量 
  getPackItemNumByBid: function getPackItemNumByBid(bag_code, bid) {
    if (bag_code == null) {
      bag_code = BackPackConst.Bag_Code.BACKPACK;
    }
 
    var len = 0;
    var bag_list = this.getBagItemList(bag_code);
 
    for (var k in bag_list) {
      var item = bag_list[k];
 
      if (item && item.config && item.config.id == bid) {
        len += item.quantity;
      }
    }
 
    return len;
  },
  // 根据bid获取背包物品数量
  getBackPackItemNumByBid: function getBackPackItemNumByBid(bid) {
    return this.getPackItemNumByBid(BackPackConst.Bag_Code.BACKPACK, bid);
  },
  getItemListForShare: function getItemListForShare(bag_type) {
    var bag_code = bag_type || BackPackConst.Bag_Code.BACKPACK;
    var list = this.item_list[bag_code];
    var target_list = [];
 
    if (list) {
      for (var item_i in list) {
        if (list[item_i] && list[item_i].config && list[item_i].config.can_share === 1) {
          target_list.push(list[item_i]);
        }
      }
    }
 
    return target_list;
  },
  //根据id获取背包的物品数据
  getBackPackItemById: function getBackPackItemById(id) {
    return this.getBagItemById(BackPackConst.Bag_Code.BACKPACK, id);
  },
  //根据bag_code,id获得物品数据
  getBagItemById: function getBagItemById(bag_code, id) {
    var temp_list = this.getBagItemList(bag_code);
 
    if (temp_list != null && temp_list[id] != null) {
      return temp_list[id];
    }
  },
  //根据类型获得背包中该类型物品的列表
  getBackPackItemListByType: function getBackPackItemListByType(type) {
    var list = [];
    var bag_list = this.getBagItemList(BackPackConst.Bag_Code.BACKPACK);
 
    for (var k in bag_list) {
      var item = bag_list[k];
 
      if (item && item.config && item.config.type == type) {
        list.push(item);
      }
    }
 
    return list;
  },
  //根据bid获取物品的id列表
  getBackPackItemIdListByBid: function getBackPackItemIdListByBid(bid) {
    var id_list = [];
    var bag_list = this.getBagItemList(BackPackConst.Bag_Code.BACKPACK);
 
    for (var k in bag_list) {
      var item = bag_list[k];
 
      if (item && item.config && item.config.id == bid) {
        id_list.push(item.id);
      }
    }
 
    return id_list;
  },
  //神器合成
  setHallowsCompData: function setHallowsCompData() {
    if (Utils.next(this.hallows_comp_list) != null) return;
    var data_list = Config.item_product_data.data_product_data;
 
    for (var i in data_list) {
      var v = data_list[i];
      this.hallows_comp_list[v.need_items[0][0]] = {
        bid: v.bid,
        num: v.need_items[0][1]
      };
    }
  },
  getHallowsCompData: function getHallowsCompData(id) {
    if (!this.hallows_comp_list && Utils.next(this.hallows_comp_list) == null) {
      return this.hallows_comp_list[id] || {};
    }
  },
  getAllEquipListByType: function getAllEquipListByType(type) {
    return this.equip_score_list[type] || [];
  },
  updateEquipScoreList: function updateEquipScoreList(bag_code, temp_item) {
    if (temp_item && temp_item.config) {
      var type = temp_item.config.type || 1; // 装备背包备份一个序号列表
 
      if (bag_code == BackPackConst.Bag_Code.EQUIPS) {
        if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
        this.equip_score_list[type][temp_item.id] = temp_item;
      } else if (bag_code == BackPackConst.Bag_Code.BACKPACK) {
        // 背包里面的符文(以前神器)
        if (type == BackPackConst.item_type.ARTIFACTCHIPS) {
          if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
          this.equip_score_list[type][temp_item.id] = temp_item;
        }
      }
    }
  }
});
module.exports = BackpackModel;
 
cc._RF.pop();