Files
fc/dev/project/library/imports/8f/8f9459ae-86df-4ff6-aea0-a7758a7140c2.js
T

401 lines
14 KiB
JavaScript
Raw Normal View History

2026-05-24 10:21:26 +08:00
"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 BridgeClass = require("bridge.class");
var BackPackConst = require("backpack_const");
var HeroController = require("hero_controller");
var FID = require("bridge.function.ids");
var BackpackModel = cc.Class({
"extends": BridgeClass,
ctor: function ctor() {},
properties: {},
initConfig: function initConfig() {
this.item_list = {}; // 物品列表,背包类型座位key
this.hallows_comp_list = {}; //神器合成
this.equip_score_list = {};
// --英魂的列表..因為英雄計算紅點消耗巨大..這裡保存多一份.減少負擔
this.hero_hun_list = {};
},
/**
* 初始化背包和装备背包数据
* @param {*} data
*/
initItemList: function initItemList(data) {
// cc.error(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
} else {
if (!this.is_init_hero_chip_redpoint) {
this.is_init_hero_chip_redpoint = true;
}
}
this.setHallowsCompData();
gcore.GlobalEvent.fire(EventId.GET_ALL_DATA, bag_code);
},
getHeroChipRedPoint: function getHeroChipRedPoint() {
var hero_list = this.getAllBackPackArray(BackPackConst.item_sub_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;
}
}
return status;
},
// --检查英雄碎片是否能合/成
checkHeroChipRedPoint: function checkHeroChipRedPoint(v) {
if (v.quality != -1 && v.base_id) {
// --碎片
var partner_config = game.configs.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;
var RedPoint = false;
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 && config.sub_type == BackPackConst.item_sub_type.HERO) {
status = this.checkHeroChipRedPoint(item_vo);
}
if (config && config.sub_type == BackPackConst.item_sub_type.SPECIAL) {
RedPoint = true;
}
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) {
RedPoint = true;
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;
}
} 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.HERO_HUN) {
this.hero_hun_list[item_vo.id] = item_vo;
}
}
}
//背包英雄符文碎片红点逻辑 (如果没有红点才判断)-zys
if (!status && config && config.sub_type == BackPackConst.item_sub_type.HERO) {
if (this.checkHeroChipRedPoint(item_vo)) {}
}
}
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);
}
if (RedPoint) {
var _sfg = game.configs.source_data.data_source_data[FID.Equips];
var eqm = nx.bridge.checkConditions(_sfg.lev_limit);
if (nx.dt.objEmpty(eqm)) {
HeroController.getInstance().getModel().dealReformEqm();
}
}
var sfg = game.configs.source_data.data_source_data[FID.Mono];
var mono = nx.bridge.checkConditions(sfg.lev_limit);
if (nx.dt.objEmpty(mono)) {
if (game.configs.monopoly_data) {
var DATA = game.configs.monopoly_data.data_const.item_bid;
var count = this.getBackPackItemNumByBid(DATA.val);
nx.mTip.openTip("bar.monopoly", count > 0);
}
}
},
// 删除一个物品
deleteBagItems: function deleteBagItems(data) {
var del_list = {};
var bag_code = null;
var RedPoint = false;
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) {
RedPoint = true;
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) {
RedPoint = true;
if (!this.equip_score_list[type]) this.equip_score_list[type] = {};
this.equip_score_list[type][item_vo.id] = null;
} else if (type == BackPackConst.item_type.HERO_HUN) {
this.hero_hun_list[item_vo.id] = null;
}
}
}
if (item_vo) {
del_list[element.id] = item_vo;
this.item_list[element.storage][element.id] = null;
delete this.item_list[element.storage][element.id];
}
}
// 储存一下存储空间
// if (bag_code == null) {
// bag_code = element.storage
// }
}
var sfg = game.configs.source_data.data_source_data[FID.Mono];
var mono = nx.bridge.checkConditions(sfg.lev_limit);
if (nx.dt.objEmpty(mono)) {
var DATA = game.configs.monopoly_data.data_const.item_bid;
var count = this.getBackPackItemNumByBid(DATA.val);
nx.mTip.openTip("bar.monopoly", count > 0);
}
bag_code = bag_code || BackPackConst.Bag_Code.BACKPACK;
gcore.GlobalEvent.fire(EventId.DELETE_GOODS, bag_code, del_list);
if (RedPoint) {
var _sfg2 = game.configs.source_data.data_source_data[FID.Equips];
var eqm = nx.bridge.checkConditions(_sfg2.lev_limit);
if (nx.dt.objEmpty(eqm)) {
HeroController.getInstance().getModel().dealReformEqm();
}
}
},
// 根据背包标签页类型返回当前的物品列表
getAllBackPackArray: function getAllBackPackArray(type) {
type = type || BackPackConst.item_sub_type.EQUIPS;
var bag_code = BackPackConst.Bag_Code.BACKPACK;
if (type == BackPackConst.item_sub_type.EQUIPS || type == BackPackConst.item_sub_type.HOLYEQUIPMENT) {
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] || {};
},
// --獲取英雄武魂
getHeroHunList: function getHeroHunList() {
return this.hero_hun_list || {};
},
// 根据bid获得道具物品的数量(包括资产道具)
getItemNumByBid: function getItemNumByBid(bid) {
var asset_key = game.configs.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_codeid获得物品数据
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;
},
//根据bid物品的id
getBackPackItemIDByBid: function getBackPackItemIDByBid(bid) {
return this.getPackItemIDByBid(BackPackConst.Bag_Code.BACKPACK, bid);
},
//根据bid获得bag_code物品的id
getPackItemIDByBid: function getPackItemIDByBid(bag_code, bid) {
var bag_list = this.getBagItemList(bag_code);
var id = 0;
for (var k in bag_list) {
var item = bag_list[k];
if (item && item.config && item.config.id == bid) {
id = item.id;
break;
}
}
return id;
},
//神器合成
setHallowsCompData: function setHallowsCompData() {
// if (Utils.next(this.hallows_comp_list) != null) return;
// var data_list = game.configs.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;
} else if (type == BackPackConst.item_type.HERO_HUN) {
this.hero_hun_list[temp_item.id] = temp_item;
}
}
}
}
});
module.exports = BackpackModel;
cc._RF.pop();