/****************************************************************** * * 伙伴信息页 --- 升星 * ******************************************************************/ const BridgeComponent = require( "bridge.component" ); const HeroEvent = require( "hero_event" ); const HeroControl = require( "hero_controller" ); const BackpackController = require( "backpack_controller" ); const BackPackConst = require("backpack_const"); const RoleController = require( "role_controller" ); cc.Class( { extends: BridgeComponent, properties: { lstInfo: { default: null, type: cc.Node }, lstNeed: { default: null, type: cc.Node }, nodSpecial: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, }, // 显示 onEnable: function() { // 变量 this.ptneeds = []; this.selects = []; // 视图监听 this.vbind( [ [ "ShowPartner", this.onPartnerChanged.bind( this ) ] ] ); // 事件监听 this.bindGEvent( HeroEvent.Hero_Data_Update, this.onPartnerUpdate.bind( this ) ); }, // 隐藏 onDisable: function() { // 视图监听解除 this.vunbind(); // 事件监听解除 this.unbindGEvents(); }, // 有伙伴数据更新 onPartnerUpdate: function( _vo ) { if( _vo && this.partner && _vo.partner_id == this.partner.partner_id ) { this.onPartnerChanged( _vo ); nx.bridge.vset( "ShowPartner", _vo ); } }, // 伙伴更新 onPartnerChanged: function( _partner ) { this.partner = _partner; this.selects = []; this.arr0 = []; this.arr1 = []; this.arr2 = []; // 判空 if( nx.dt.objEmpty( this.partner ) ) { this.setEmpty(); return; } // 配置获取 let ckey = this.partner.bid + "_" + this.partner.star; let nkey = this.partner.bid + "_" + ( this.partner.star + 1 ); this.ccfgs = gdata( "partner_data", "data_partner_star", ckey ); this.ncfgs = gdata( "partner_data", "data_partner_star", nkey ); let mfg = game.configs.partner_data.data_partner_star[ nkey ] ; if( nx.dt.objEmpty( this.ccfgs ) ) { nx.error( "无效伙伴升星配置:", ckey ); this.setEmpty(); return; } // 是否满级 if( !mfg ) { nx.gui.setActive( this, "max", true ); nx.gui.setActive( this, "nor", false ); return; } // 升星刷新 nx.gui.setActive( this, "max", false ); nx.gui.setActive( this, "nor", true ); this.freshUpStar(); }, // 置空 setEmpty: function() { nx.gui.setActive( this, "max", false ); nx.gui.setActive( this, "nor", true ); nx.gui.setActive( this.lstInfo, "", false ); nx.gui.setActive( this.lstNeed, "", false ); nx.gui.setActive( this.nodOps, "", false ); nx.gui.setActive( this.nodSpecial, "", false ); }, // 升星刷新 freshUpStar: function() { // 星级 nx.gui.setActive( this.lstInfo, "", true ); let cico = cc.path.join( "coms/images", "star" + this.ccfgs.star ); let nico = cc.path.join( "coms/images", "star" + this.ncfgs.star ); nx.gui.setSpriteFrame( this.lstInfo, "stars/from", cico ); nx.gui.setSpriteFrame( this.lstInfo, "stars/to", nico ); // 三条提升 let atts = this.ncfgs.attr_show || []; for( let i = 0; i < 3; ++i ) { let node = nx.gui.find( this.lstInfo, "t" + ( i + 1 ) ); let attr = atts[ i ]; if( nx.dt.arrEmpty( attr ) ) { node.active = false; continue; } node.active = true; // 三元素:描述/老值/新值 if( attr.length == 3 ) { nx.gui.setString( node, "from/tip", nx.text.getKey( attr[ 0 ] ) ); nx.gui.setString( node, "from/txt", nx.text.getKey( attr[ 1 ] ) ); nx.gui.setString( node, "to", nx.text.getKey( attr[ 2 ] ) ); nx.gui.setActive( node, "arrow", true ); } // 单元素:描述 else { nx.gui.setString( node, "from/tip", nx.text.getKey( attr[ 0 ] ) ); nx.gui.setString( node, "from/txt", "" ); nx.gui.setString( node, "to", "" ); nx.gui.setActive( node, "arrow", false ); } } // 单技能提升 nx.gui.setActive( this.lstInfo, "skill", false ); let csks = this.ccfgs.skills; let nsks = this.ncfgs.skills; if( nx.dt.arrNEmpty( csks ) && nx.dt.arrNEmpty( nsks ) ) { let ids = []; for( let i = 0; i < nsks.length; ++i ) { if( csks[ i ][ 1 ] != nsks[ i ][ 1 ] ) { ids.push( [ csks[ i ][ 1 ], nsks[ i ][ 1 ] ] ); } } // 只有一个技能提升时需要展示 if( ids.length == 1 ) { let ifo = ids[ 0 ]; let node = nx.gui.find( this.lstInfo, "skill" ); let from = nx.gui.getComponent( node, "from", "cmp.skill.base" ); let to = nx.gui.getComponent( node, "to", "cmp.skill.base" ); if( from && to ) { node.active = true; from.setData( ifo[ 0 ] ); to.setData( ifo[ 1 ] ); } } } let showUpstar = true; if( this.partner.star == 10 || this.partner.star == 11 || this.partner.star == 12 ){ let cfg = game.configs.partner_data.data_partner_const; let can = HeroControl.getInstance().getModel().checkHighStarCondition( this.partner.star ) ; let descs = HeroControl.getInstance().getModel().getDescs(); nx.gui.setSpriteFrame( this.nodSpecial, "needs/conditions/star", cc.path.join( "coms/images/star" + ( this.partner.star + 1 ) ) ); nx.gui.gocChildren( this.nodSpecial, "needs/desc/view/content", descs.length ); let chd = nx.gui.find( this.nodSpecial, "needs/desc/view/content" ).children; for (let d = 0; d < descs.length; d++) { let desc = descs[d]; nx.gui.setString( chd[d], "desc", desc ); } let show = 0; can.forEach( _c =>{ if( _c == true ){ show++; } } ) nx.gui.setActive( this.nodSpecial, "", show == 0 ); nx.gui.setActive( this.lstNeed.parent, "", show != 0 ); }else{ nx.gui.setActive( this.nodSpecial, "", false ); // 材料刷新 nx.gui.setActive( this.lstNeed, "", true ); } this.computeNeeds(); this.freshNeeds(); // 刷新操作 nx.gui.setActive( this.nodOps, "", true ); }, // 统计材料 computeNeeds: function() { // expend1本体卡,expend2指定卡,expend3阵营卡,other_expend额外需要 // 随机的{1,4,2} : 1 表示阵营 4: 表示星级 2表示数量 // 指定的{10402,4,1} : 10402: 表示bid, 4: 表示星级 1:表示数量 const HC = HeroControl.getInstance(); const HM = HC.getModel(); // 需求重置 this.ptneeds = []; // 卡需求 this.mtneeds = []; // 道具需求 this.partnerHun = []; // 英魂材料 let items = BackpackController.getInstance().getModel().getAllBackPackArray( 2 ); let add = function( arr, items ){ if( items.quantity > 0 ){ for (let i = 0; i < items.quantity; ++i) { items.partner_id = items.bid; arr.push( items ); } } return arr; } items.forEach( _item => { if( _item.type == BackPackConst.item_type.HERO_HUN ){ _item.sortid = 0; add( this.partnerHun, _item ); } } ) // 统计expend2指定卡 let lst = this.ncfgs.expend2 || []; lst.forEach( t => { let pcfgs = game.configs.partner_data.data_partner_base[ t[ 0 ] ]; let tcfgs = pcfgs ? Utils.getItemConfig( pcfgs.item_id ) : null; if( !pcfgs || !tcfgs ) { nx.error( "升星材料配置缺失:", t[ 0 ] ); return; } this.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( t => { this.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( t => { let tcfgs = Utils.getItemConfig( t[ 0 ] ); if( !tcfgs ) { nx.error( "升星材料配置缺失:", t[ 0 ] ); return; } this.mtneeds.push( { bid: t[ 0 ], icon: tcfgs.icon, need_count: t[ 1 ], } ) } ); // 提示检测 this.freshRedTips(); }, // 提示检测 freshRedTips: function() { // 卡片充足检测 if( nx.dt.arrNEmpty( this.ptneeds ) ) { const HC = HeroControl.getInstance(); const HM = HC.getModel(); const ARR = HM.getAllHeroArray(); this.selects = this.arr0.concat( this.arr1.concat( this.arr2 ) ); for( let i = 0; i < this.ptneeds.length; ++i ) { // 充足不提示 let need = this.ptneeds[ i ]; if( need.need_count <= need.selects.length ) { need.tip = false; continue; } // 指定 if( need.bid != 0 ) { let cnt = 0; for( let k in ARR ) { let p = ARR[ k ]; if( p.partner_id != this.partner.partner_id && p.bid == need.bid && // 非锁定英雄 nx.dt.objEmpty( p.dic_locks ) && p.is_lock == 0 && p.star == need.need_stars && p.is_in_form == 0 && !nx.dt.arrMember( this.selects, p ) ) { cnt++; } if( cnt >= need.need_count ) { break; } } need.tip = ( cnt >= need.need_count ); continue; } // 同系 else { let cnt = 0; for( let k in ARR ) { let p = ARR[ k ]; // 任意阵营的高星材料 if( need.camp == 0 ){ if( nx.dt.arrNEmpty( this.partnerHun ) ){ let p = this.partnerHun[k]; if( p && !nx.dt.arrMember( this.selects, p ) && p.config.eqm_jie == need.need_stars ){ cnt++; } continue; } if( p.partner_id != this.partner.partner_id && p.star == need.need_stars && p.is_in_form == 0 && !nx.dt.arrMember( this.selects, p ) ) { cnt++; } }else{ //|| ( 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 ) ){ let p = this.partnerHun[k]; if( ( p && !nx.dt.arrMember( this.selects, p ) && p.config.camp_type == need.camp && p.config.eqm_jie == need.need_stars ) ){ cnt++; } // continue; } if( p.partner_id != this.partner.partner_id && p.camp_type == need.camp && p.star == need.need_stars && p.is_in_form == 0 && !nx.dt.arrMember( this.selects, p ) ) { cnt++; } } if( cnt >= need.need_count ) { break; } } need.tip = ( cnt >= need.need_count ); continue; } } } }, // 刷新材料 freshNeeds: function( _init = true ) { // 卡片需求 let cards = nx.gui.setActive( this.lstNeed, "partners", nx.dt.arrNEmpty( this.ptneeds ) ); if( cards && cards.active ) { const chds = cards.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[ i ]; let need = this.ptneeds[ i ]; if( nx.dt.objEmpty( need ) ) { node.active = false; continue; } node.active = true; let 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/txt", need.selects.length + '/' + need.need_count ); nx.gui.setActive( icon, 'bg/tip', need.tip ); } } // 微调间距 let len = this.ptneeds.length; if( len >= 2 && len <= 4 ) { let space = [40,40,5]; let layout = nx.gui.getComponent( this.lstNeed, "partners", cc.Layout); layout.spacingX = space[len-2]; } } // 材料需求 let model = BackpackController.getInstance().getModel(); let mats = nx.gui.setActive( this.lstNeed, "mats", nx.dt.arrNEmpty( this.mtneeds ) ); if( mats && mats.active ) { const chds = mats.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[ i ]; let need = this.mtneeds[ i ]; if( nx.dt.objEmpty( need ) ) { node.active = false; continue; } node.active = true; nx.bridge.setIconS( node, "icon", need.icon ); let have = model.getItemNumByBid( need.bid ); let str = cc.js.formatStr( "%s/%s", Utils.getMoneyString( have ), Utils.getMoneyString( need.need_count ) ); nx.gui.setString( node, "txt", str ); this.mtneeds.have = have; } } }, // 点击材料 onTouchPartnerIcon: function( _index ) { let index = parseInt( _index ); if( !nx.dt.numGood( index ) ) { return; } let HC = HeroControl.getInstance(); let pts = []; let need = this.ptneeds[ _index ]; let excluds = [ this.partner ]; for( let i = 0; i < this.ptneeds.length; ++i ) { if( i == _index ) continue; let pts = this.ptneeds[ i ]; excluds = excluds.concat( pts.selects ); } // 伙伴筛选 const all = HC.getModel().getAllHeroArray(); // 获取道具 特殊道具 90900 可以替代任意的九星伙伴材料 all.forEach( _p => { // 非指定英雄 if( need.bid > 0 && ( _p.bid != need.bid || _p.star != need.need_stars ) ) { return; } if( need.camp != 0 ){ // 非派系英雄 if( need.bid <= 0 && ( _p.camp_type != need.camp || _p.star != need.need_stars ) ) { return; } } if( need.camp == 0 ){ // 非派系英雄 if( _p.star != need.need_stars ) { return; } } // 非锁定英雄 if( _p.is_in_form != 0 || nx.dt.objNEmpty( _p.dic_locks ) || _p.is_lock != 0 ) { return; } // 非排除英雄 if( nx.dt.arrMember( excluds, null, ( _m ) => { return _m.partner_id == _p.partner_id; } ) ) { return; }; _p.sortid = _p.bid; pts.push( _p ); } ); // 排序 let 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( _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( _item => { if( ( _item.config.eqm_jie == need.need_stars && need.camp == _item.config.camp_type ) ){ pts.push( _item ); } } ) } } pts.sort( Utils.tableLowerSorter( [ "sortid" ] ) ); let args = { partners: pts, count : need.need_count, selects : need.selects, flag: { type: need.name, star: need.need_stars, } } // console.log( "所有的伙伴相关" + JSON.stringify( pts ) ); // 弹窗 HC.openPartnerSelector( true, args, ( _selects => { this.ptneeds[ _index ].selects = _selects || []; this.saveNowSelects( index, _selects ); this.freshRedTips(); this.freshNeeds( false ); HC.openPartnerSelector( false ); } ) ); }, saveNowSelects: function( _index, _count ){ const dealData = function( _arr ){ if( _count.length > 0 ){ if( nx.dt.arrNEmpty( _arr ) ){ _arr = []; } _count.forEach( _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 ); } }, // 点击升星 onTouchUpStar: function() { // 卡片材料检查 let enough = true; let tiptxt = ""; for( let i in this.ptneeds ) { let 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( let i in this.mtneeds ) { let mt = this.mtneeds; if( mt.have < mt.need_count ) { enough = false; tiptxt = "tip_noEnoughMaterial"; break; } } } // 不足 if( !enough ) { nx.tbox( tiptxt ); return; } // 参数归纳 let args1 = []; let args2 = []; let args3 = []; for( let i = 0; i < this.ptneeds.length; ++i ) { let pt = this.ptneeds[ i ]; for( let k = 0; k < pt.selects.length; ++k ) { let tm = pt.selects[ k ]; // console.log("伙伴需求数据" + JSON.stringify( tm ) ); if( pt.bid > 0 ) { 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} ); } } } } let HC = HeroControl.getInstance(); HC.sender11005( this.partner.partner_id, args1, args2, args3 ); }, // 点击改造室 onTouchTransformRoom: function() { let HC = HeroControl.getInstance(); HC.openHeroReformWindow( true, this.partner ); this.scheduleOnce( () => { HC.openHeroMainInfoWindow( false ); HC.openHeroBagWindow( false ); }, 0.1 ); }, onTouchTip: function(){ nx.tbox( "UpStarsNotEnoughTip" ); }, } );