"use strict"; cc._RF.push(module, '0d1f9uA+4tE1Lnc2ojkdGfl', 'cmp.partner.reform.upstar'); // Scripts/mod/partner/cmps/reform/cmp/cmp.partner.reform.upstar.js "use strict"; /****************************************************************** * * 伙伴改造页: 升星 * ******************************************************************/ var FxTogs = require("nx.fx.togs"); var FxSVC = require("nx.fx.sv.expand"); var BridgeComponent = require("bridge.component"); var NxSpine = require("nx.fx.spine"); var BackpackController = require("backpack_controller"); var HeroConst = require("hero_const"); var HeroEvent = require("hero_event"); var HeroControl = require("hero_controller"); var TipsController = require("tips_controller"); var BackPackConst = require("backpack_const"); var HCT = HeroConst.CampType; cc.Class({ "extends": BridgeComponent, properties: { togCamp: { "default": null, type: FxTogs }, svcList: { "default": null, type: FxSVC }, lstNeed: { "default": null, type: cc.Node }, props: { "default": null, type: cc.Node }, role: { "default": null, type: NxSpine }, star: { "default": null, type: cc.Node } }, // 载入 onLoad: function onLoad() { var _this = this; // // 事件监听 this.bindGEvent(HeroEvent.Del_Hero_Event, this.onADHeros.bind(this)); this.bindGEvent(HeroEvent.Hero_Data_Update, this.onHeroInfoFresh.bind(this)); this.togCamp.posTog = this.onTogCamp.bind(this); this.togCamp.togTo(0); this.scheduleOnce(function () { _this.onTogCamp(HCT.eNone); }, 0.01); this.onFreshUpStar(); }, // 重载:关闭前 onPreClosed: function onPreClosed() { // this.svcList.rebuild( [] ); }, onEnable: function onEnable() { this.autouse = []; this.svcList.cleanFocus(); this.select = 0; this.svcList.addFocus(0); this.freshList(); }, // 购买伙伴上限返回 onBuyMaxHeroCount: function onBuyMaxHeroCount() {}, // 优化加载速度,在加载的时候就去取相关的等量替代伙伴的材料数据 onFreshUpStar: function onFreshUpStar() { var _this2 = this; var HC = HeroControl.getInstance(); var mod = HC.getModel(); // 根据阵营获取伙伴列表 this.partners = mod.getHeroReformListByCamp(this.curCamp); var count = 0; this.partners.forEach(function (_item) { if (_item.result.is_redpoint) { count++; } }); this.partners.sort(Utils.tableUpperSorter(["red"])); nx.mTip.openTip("tipReform.show", count > 0); nx.gui.setActive(this.svcList, "empty", nx.dt.arrEmpty(this.partners)); this.svcList.rebuild(this.partners); this.materialFive = []; // 五星同阵营材料 this.partnerHun = []; // 英魂材料 // 获取背包中的可以替代伙伴的材料 var items = BackpackController.getInstance().getModel().getAllBackPackArray(2); var add = function add(arr, items) { if (items.quantity > 0) { for (var i = 0; i < items.quantity; ++i) { items.partner_id = items.bid; arr.push(items); } } return arr; }; // 处理英魂材料 items.forEach(function (_item) { if (_item.type == BackPackConst.item_type.HERO_HUN) { add(_this2.partnerHun, _item); } }); }, // 伙伴增删 onADHeros: function onADHeros(_lst) { var upd = false; for (var i in _lst) { var ho = _lst[i]; if (ho && ho.camp_type == this.curCamp) { upd = true; break; } } if (upd) { this; this.onHeroInfoFresh(); } }, // 所有英雄基础信息获取事件 onHeroInfoFresh: function onHeroInfoFresh() { var _this3 = this; this.scheduleOnce(function () { _this3.onFreshUpStar(); _this3.freshList(); }, 0.3); }, // 此处刷新的是将要升星成的伙伴卡牌,与玩家自身的伙伴信息无关 freshList: function freshList() { var _this4 = this; if (nx.dt.arrEmpty(this.partners)) { return; } this.selects = []; this.arr0 = []; this.arr1 = []; this.arr2 = []; this.arr3 = []; if (this.select >= this.partners.length) { this.select = 0; } this.scheduleOnce(function () { _this4.svcList.addFocus(_this4.select); var partner = _this4.partners[_this4.select]; _this4.freshPartner(partner, _this4.select); }, 0.3); }, // 阵营切换 onTogCamp: function onTogCamp(_index) { var idx = parseInt(_index) || 0; if (this.curCamp == idx) { return; } nx.debug("[Hero]\u9635\u8425\u5207\u6362:" + this.curCamp + " -> " + idx); this.curCamp = idx; this.onFreshUpStar(); // 整体刷新 this.freshList(); }, // 选中切换 onFocusChanged: function onFocusChanged(_item) { this.partnerinfo = _item.info; // 空 if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) { return; } nx.audio.playSFX("audios/effects/touchitem"); // 聚焦 this.svcList.cleanFocus(); this.svcList.addFocus(_item.index); this.freshPartner(_item.mdata, _item.index); }, freshPartner: function freshPartner(_partner, _index) { var _this5 = this; this.select = _index; this.partner = _partner; // 判空 if (nx.dt.objEmpty(this.partner)) { this.role.stop(); return; } // 配置获取 var ckey = this.partner.bid + "_" + (this.partner.stars - 1); var nkey = this.partner.bid + "_" + this.partner.stars; this.ccfgs = gdata("partner_data", "data_partner_star", ckey); this.ncfgs = gdata("partner_data", "data_partner_star", nkey); if (nx.dt.objEmpty(this.ccfgs)) { nx.error("无效伙伴升星配置:", ckey); this.role.stop(); return; } nx.gui.setSpriteFrame(this.star, "", "coms/images/star" + this.partner.stars); // 战斗迷你 var path = PathTool.getSpinePath(this.ncfgs.res_id, this.ncfgs.res_id, false); this.role.load(path, function (_e) { if (!_e) { _this5.role.action("stand2", true); nx.gui.setActive(_this5.role.node, "", true); } else { _this5.role.stop(); nx.gui.setActive(_this5.role.node, "", false); } }); this.autouse = []; this.use = {}; this.scheduleOnce(function () { // 升星刷新 _this5.computeNeeds(); _this5.freshNeeds(); }, 0.1); }, // 统计材料 computeNeeds: function computeNeeds() { var _this6 = this; // expend1本体卡,expend2指定卡,expend3阵营卡,other_expend额外需要 // 随机的{1,4,2} : 1 表示阵营 4: 表示星级 2表示数量 // 指定的{10402,4,1} : 10402: 表示bid, 4: 表示星级 1:表示数量 var HC = HeroControl.getInstance(); var HM = HC.getModel(); // 需求重置 this.ptneeds = []; // 卡需求 this.mtneeds = []; // 道具需求 // 统计expend1指定卡 var lst = this.ncfgs.expend1 || []; lst.forEach(function (t) { var pcfgs = game.configs.partner_data.data_partner_base[t[0]]; var tcfgs = pcfgs ? Utils.getItemConfig(pcfgs.item_id) : null; if (!pcfgs || !tcfgs) { nx.error("升星材料配置缺失:", t[0]); return; } _this6.ptneeds.push({ bid: t[0], camp: pcfgs.camp_type || tcfgs.camp_type, name: pcfgs.name || tcfgs.name, qa: pcfgs.quality || tcfgs.quality, icon: tcfgs.icon, need_stars: t[1], need_count: t[2], selects: [], tip: false }); }); // 统计expend2指定卡 lst = this.ncfgs.expend2 || []; lst.forEach(function (t) { var pcfgs = game.configs.partner_data.data_partner_base[t[0]]; var tcfgs = pcfgs ? Utils.getItemConfig(pcfgs.item_id) : null; if (!pcfgs || !tcfgs) { nx.error("升星材料配置缺失:", t[0]); return; } _this6.ptneeds.push({ bid: t[0], camp: pcfgs.camp_type || tcfgs.camp_type, name: pcfgs.name || tcfgs.name, qa: pcfgs.quality || tcfgs.quality, icon: tcfgs.icon, need_stars: t[1], need_count: t[2], selects: [], tip: false }); }); // 统计expend3阵营卡 lst = this.ncfgs.expend3 || []; lst.forEach(function (t) { _this6.ptneeds.push({ bid: 0, camp: t[0], name: "AnyNameCamp" + t[0], qa: t[1] - 1, icon: 29982, need_stars: t[1], need_count: t[2], selects: [], tip: false }); }); // other_expend扩展道具需求 lst = this.ncfgs.other_expend || []; lst.forEach(function (t) { var tcfgs = Utils.getItemConfig(t[0]); if (!tcfgs) { nx.error("升星材料配置缺失:", t[0]); return; } _this6.mtneeds.push({ bid: t[0], icon: tcfgs.icon, need_count: t[1] }); }); // 提示检测 this.freshRedTips(); }, // 提示检测 freshRedTips: function freshRedTips() { // 卡片充足检测 if (nx.dt.arrNEmpty(this.ptneeds)) { var HC = HeroControl.getInstance(); var HM = HC.getModel(); var ARR = HM.getAllHeroArray(); this.selects = this.arr0.concat(this.arr1.concat(this.arr2.concat(this.args3))); for (var i = 0; i < this.ptneeds.length; ++i) { // 充足不提示 var need = this.ptneeds[i]; if (need.need_count <= need.selects.length) { need.tip = false; continue; } // 指定 if (need.bid != 0) { var cnt = 0; for (var k in ARR) { var p = ARR[k]; if (p.trial_end_time > 0 && nx.dt.objEmpty(this.use)) { if (this.ptneeds[0].bid == p.bid) { this.use = p; var show = []; show.push(p); this.ptneeds[0].selects = show; this.freshRedTips(); } } else { if (p.partner_id != this.partner_id && p.bid == need.bid && p.trial_end_time == 0 && p.star == need.need_stars && !nx.dt.arrMember(this.selects, p)) { cnt++; } if (cnt >= need.need_count) { break; } } } need.tip = cnt >= need.need_count; continue; } // 同系 else { var _cnt = 0; for (var _k in ARR) { var _p2 = ARR[_k]; // ( p && !nx.dt.arrMember( this.selects, p ) && p.config.camp_type == 0 && p.config.eqm_jie == need.need_stars ) if (nx.dt.arrNEmpty(this.partnerHun)) { var _p3 = this.partnerHun[_k]; if (_p3 && !nx.dt.arrMember(this.selects, _p3) && _p3.config.eqm_jie == need.need_stars) { _cnt++; } // continue; } if (_p2.partner_id != this.partner_id && _p2.camp_type == need.camp && _p2.star == need.need_stars && _p2.is_in_form == 0 && !nx.dt.arrMember(this.selects, _p2)) { _cnt++; } if (_cnt >= need.need_count) { break; } } need.tip = _cnt >= need.need_count; continue; } } } }, freshNeeds: function freshNeeds(_init) { if (_init === void 0) { _init = true; } // 卡片需求 var cards = nx.gui.setActive(this.lstNeed, "partners", nx.dt.arrNEmpty(this.ptneeds)); if (cards && cards.active) { var chds = cards.children; var show = 0; for (var i = 0; i < chds.length; ++i) { var node = chds[i]; var need = this.ptneeds[i]; if (nx.dt.objEmpty(need)) { node.active = false; show++; continue; } node.active = true; var icon = node.getComponent("cmp.item.base"); if (icon) { if (_init) { icon.setEmpty(); icon.setQuality(need.qa); icon.setIcon(need.icon); icon.setName(need.name); icon.setStars(need.need_stars); icon.setIcon(need.icon); icon.setCamp(need.camp); } nx.gui.setString(icon, "count", nx.text.format("UpStarsNeed", need.selects.length, need.need_count)); nx.gui.setActive(icon, 'bg/tip', need.tip); } } nx.gui.setActive(this, "panel/target/needs/adds/add", show != 2); nx.gui.setActive(this, "panel/target/needs/adds/addf", show != 2); nx.gui.setActive(this, "panel/target/needs/adds", show == 0 || show == 2); nx.gui.setActive(this, "panel/target/needs/add3", show == 1); } // 材料需求 var model = BackpackController.getInstance().getModel(); var mats = nx.gui.setActive(this.lstNeed, "mats", nx.dt.arrNEmpty(this.mtneeds)); if (mats && mats.active) { var _chds = mats.children; for (var _i = 0; _i < _chds.length; ++_i) { var _node = _chds[_i]; var _need = this.mtneeds[_i]; if (nx.dt.objEmpty(_need)) { _node.active = false; continue; } _node.active = true; nx.bridge.setIcon(_node, "icon", _need.icon); var have = model.getItemNumByBid(_need.bid); var str = cc.js.formatStr("%s/%s", Utils.getMoneyString(_need.need_count), Utils.getMoneyString(have)); nx.gui.setString(_node, "txt", str); this.mtneeds.have = have; } } }, // 点击材料 onTouchPartnerIcon: function onTouchPartnerIcon(_index) { var _this7 = this; var index = parseInt(_index); if (!nx.dt.numGood(index)) { return; } var HC = HeroControl.getInstance(); var pts = []; var need = this.ptneeds[_index]; var excluds = [this.partner]; for (var i = 0; i < this.ptneeds.length; ++i) { if (i == _index) continue; var _pts = this.ptneeds[i]; excluds = excluds.concat(_pts.selects); } // 伙伴筛选 var all = HC.getModel().getAllHeroArray(); all.forEach(function (_p) { // 非指定英雄 if (need.bid > 0 && (_p.bid != need.bid || _p.star != need.need_stars)) { return; } // 非派系英雄 if (need.bid <= 0 && (_p.camp_type != need.camp || _p.star != need.need_stars)) { return; } // // 非锁定英雄 // if( _p.is_in_form || _p.is_lock != 0 ) { // return; // } // 非排除英雄 if (nx.dt.arrMember(excluds, null, function (_m) { return _m.partner_id == _p.partner_id; })) { return; } ; pts.push(_p); }); // 排序 var sort_func = Utils.tableLowerSorter(["camp_type", "star", "bid"]); pts.sort(sort_func); if (nx.dt.arrNEmpty(this.partnerHun) && need.bid == 0) { if (need.camp == 0) { this.partnerHun.forEach(function (_item) { if (_item.config.eqm_jie == need.need_stars) { pts.push(_item); } }); } else { //||( _item.config.eqm_jie == need.need_stars && _item.config.camp_type == 0 ) this.partnerHun.forEach(function (_item) { if (_item.config.eqm_jie == need.need_stars && need.camp == _item.config.camp_type) { pts.push(_item); } }); } } var args = { partners: pts, count: need.need_count, selects: need.selects, flag: { type: need.name, star: need.need_stars } }; // console.log( "当前排除的伙伴" + JSON.stringify( excluds ) ); // 弹窗 HC.openPartnerSelector(true, args, function (_selects) { _this7.dealTip(index, _selects); _this7.ptneeds[_index].selects = _selects || []; _this7.saveNowSelects(index, _selects); _this7.freshRedTips(); _this7.freshNeeds(false); if (index != 0 && index != 1) { HC.openPartnerSelector(false); } }); }, dealTip: function dealTip(_idx, _selects) { var HC = HeroControl.getInstance(); var inteam = 0; var id = parseInt(_idx); var selects = _selects; var desc = ""; for (var i = 0; i < selects.length; i++) { var select = selects[i]; if (select.is_in_form > 0 && (id == 0 || id == 1)) { inteam = 1; desc = id == 0 ? nx.text.getKey("UpStarsTip") : nx.text.getKey("UpStarsTipN"); break; } } if (inteam > 0) { nx.mbox(desc, ['confirm'], function (_key, _box) { _box.close(); if (_key == "confirm") { HC.openPartnerSelector(false); } }); } else { HC.openPartnerSelector(false); } }, saveNowSelects: function saveNowSelects(_index, _count) { var dealData = function dealData(_arr) { if (_count.length > 0) { if (nx.dt.arrNEmpty(_arr)) { _arr = []; } _count.forEach(function (_item) { _arr.push(_item); }); } else { _arr = []; } return _arr; }; if (_index == 0) { this.arr0 = dealData(this.arr0); } if (_index == 1) { this.arr1 = dealData(this.arr1); } if (_index == 2) { this.arr2 = dealData(this.arr2); } if (_index == 3) { this.arr3 = dealData(this.arr3); } }, // 点击升星 onTouchUpStar: function onTouchUpStar() { // 卡片材料检查 var enough = true; var tiptxt = ""; for (var i in this.ptneeds) { var pt = this.ptneeds[i]; if (pt.need_count > pt.selects.length) { enough = false; tiptxt = "tip_noEnoughMaterial"; break; } } ; // 额外耗材 if (enough && nx.dt.arrNEmpty(this.mtneeds)) { for (var _i2 in this.mtneeds) { var mt = this.mtneeds; if (mt.have < mt.need_count) { enough = false; tiptxt = "tip_noEnoughMaterial"; break; } } } // 不足 if (!enough) { nx.tbox(tiptxt); return; } // 参数归纳 var args1 = []; var args2 = []; var args3 = []; this.willUpstar = []; for (var _i3 = 0; _i3 < this.ptneeds.length; ++_i3) { var _pt = this.ptneeds[_i3]; for (var k = 0; k < _pt.selects.length; ++k) { if (k == 0) { this.willUpstar.push(_pt.selects[0]); } var tm = _pt.selects[k]; if (_pt.bid > 0) { if (this.willUpstar[0].partner_id != tm.partner_id) { args1.push({ "partner_id": tm.partner_id }); } } else { if (tm.base_id) { args3.push({ "item_id": tm.base_id, "num": 1 }); } else { args2.push({ "partner_id": tm.partner_id }); } } } } var HC = HeroControl.getInstance(); HC.sender11005(this.willUpstar[0].partner_id, args1, args2, args3); }, showPartnerInfo: function showPartnerInfo() { var key = this.partner.bid + "_" + this.partner.stars; this.propsData = gdata("partner_data", "data_partner_show", key); this.propsData.star = this.partner.stars; this.propsData.break_lev = 0; TipsController.getInstance().showPartnerTips(this.propsData); } }); cc._RF.pop();