/****************************************************************** * * 战斗义肢洗炼 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const BackPackConst = require( "backpack_const" ); const HeroController = require( "hero_controller" ); const BackpackController = require( "backpack_controller" ); const HeroEvent = require( "hero_event" ); const HeroCalculate = require("hero_calculate"); cc.Class( { extends: BridgeWindow, properties: { nodholy : { default: null, type : cc.Node, displayName: "战斗义肢显示", }, nodProps : { default: null, type : cc.Node, displayName: "战斗义肢当前属性", }, nodCProps : { default: null, type : cc.Node, displayName: "战斗义肢洗炼属性", }, nodBottom: { default: null, type : cc.Node, displayName: "操作", }, nodScore: { default: null, type : cc.Node, displayName: "评分", }, }, onLoad:function(){ this.bindGEvent( HeroEvent.Holy_Equipment_Update_Event, this.freshByMsg.bind( this ) ); this.bindGEvent( EventId.MODIFY_GOODS_NUM, this.freshAttrInbag.bind( this ) ); }, // 重载:参数打开 onOpenConfigs: function( _params ) { // 传入战斗义肢的数据 // console.log( "傳入的戰鬥義肢數據" + JSON.stringify( _params ) ); this.holyData = _params.eqm; this.partner = _params.partner; // 固定属性相关 let cmp = nx.gui.getComponent( this.nodholy, "holy", "cmp.item.base" ); if( cmp ){ cmp.setData( this.holyData ); } this.freshHolyEqm(); }, freshAttrInbag : function( _bagcode, _list ){ if( _bagcode == BackPackConst.Bag_Code.EQUIPS ){ let attrs = []; for (let i in _list ) { let show = nx.dt.objClone( _list[i] ) ; if( i == this.holyData.id ){ show.partner_id = 0; show.holy_eqm = [ show ]; this.freshByMsg( show ); break; } } // this.freshByMsg( ) } }, freshByMsg: function( _data ){ this.partner = _data; let holy = _data.holy_eqm; let change = {}; let time = 0; for (let i = 0; i < holy.length; i++) { let holy_item = holy[i]; if( holy_item.id == this.holyData.id ){ let times = holy_item.extra; for (let i = 0; i < times.length; i++) { let item = times[i]; if( item.extra_k == 10 ){ time = item.extra_v; } } let holylst = holy_item.holy_eqm_attr; holylst.forEach( _item =>{ if( _item.pos > 100 ){ change = holy_item; }else{ this.holyData.holy_eqm_attr = holylst; } } ) } } if( !nx.dt.objEmpty( change ) ){ this.freshMat(); this.freshRandomAfter( change ); }else{ this.freshHolyEqm(); } nx.gui.setString( this.nodBottom, "times_tip",nx.text.format( "The equipment has been refined", time ) ); }, freshHolyEqm: function(){ this.freshMat(); let main_attr = this.holyData.main_attr; let title = game.configs.attr_data.data_id_to_name[main_attr[0].attr_id]; let icon_name = game.configs.attr_data.data_id_to_key[main_attr[0].attr_id]; let cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[icon_name]; this.base_score = cfg.score * 0.001 * main_attr[0].attr_val; let path = cc.path.join( "coms/images/" + "ico_"+ icon_name ); nx.gui.setSpriteFrame( this.nodholy, "prop/ico", path ); nx.gui.setString( this.nodholy, "prop/title", title ); nx.gui.setString( this.nodholy, "prop/txt", main_attr[0].attr_val ); this.freshRandom(); }, freshRandomAfter: function( _change ){ let holy_eqm_attr = _change.holy_eqm_attr; holy_eqm_attr.sort( Utils.tableUpperSorter(["pos"]) ); let new_holy_eqm_attr = []; let model = HeroController.getInstance().getModel(); let chd = nx.gui.find( this.nodCProps, "props" ).children; nx.gui.hideAllChildren( this.nodCProps, "props" ); let score1 = []; for (let i = 0; i < holy_eqm_attr.length; i++) { let attr = holy_eqm_attr[i]; let attr_node = chd[i]; if( attr && attr.pos > 100 ){ nx.gui.setActive( attr_node, "", true ); let title = game.configs.attr_data.data_id_to_key[attr.attr_id]; nx.bridge.attrs.setAttribute( nx.gui.find( attr_node, "prop" ) , [ title, attr.attr_val ] ); let cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[title]; score1.push( cfg.score * 0.001 * attr.attr_val ); new_holy_eqm_attr.push({ attr_key: title, attr_val: attr.attr_val }) let prog = nx.gui.getComponent( attr_node, "prop/prog", cc.ProgressBar ); let max_count = model.getHolyEquipmentMaxAttrByItemIdAttrKey( this.holyData.config.id, title ); let per = attr.attr_val / max_count; nx.gui.setActive( attr_node, "prop/val", per != 1 ); nx.gui.setActive( attr_node, "prop/prog/max", per == 1 ); if( prog ){ prog.progress = per; } } } nx.gui.setActive( this.nodBottom, "ops/save", true ); if (holy_eqm_attr && holy_eqm_attr.length > 0) { let new_score = HeroCalculate.getInstance().holyEquipMentPower(new_holy_eqm_attr) || 0; let num = 0; num = parseInt( this.holyData.score ) ; let sum_score = new_score + num + Math.ceil( this.base_score ) ; let add_score = sum_score - ( this.old_score + num + Math.ceil( this.base_score ) ); if (add_score > 0) { add_score = "+" + add_score; } else { add_score = + add_score; } nx.gui.setString( this.nodScore, "txt", sum_score ); nx.gui.setString( this.nodScore, "add", add_score ); } else { nx.gui.setString( this.nodScore, "txt", "???" ); nx.gui.setString( this.nodScore, "add", "???" ); } }, freshRandom: function(){ let holy_eqm_attr = this.holyData.holy_eqm_attr; holy_eqm_attr.sort( (a,b) => { return a.pos - b.pos; } ); let model = HeroController.getInstance().getModel(); let before_data = []; let old_holy_eqm_attr = []; let chd = nx.gui.find( this.nodProps, "props" ).children; nx.gui.hideAllChildren( this.nodProps, "props" ); let score0 = []; for (let i = 0; i < holy_eqm_attr.length; i++) { let attr = holy_eqm_attr[i]; let attr_node = chd[i]; if( attr && attr.pos < 100 ){ nx.gui.setActive( attr_node, "", true ); let title = game.configs.attr_data.data_id_to_key[attr.attr_id]; nx.bridge.attrs.setAttribute( nx.gui.find( attr_node, "prop" ) , [ title, attr.attr_val ] ); let cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[title]; score0.push( cfg.score * 0.001 * attr.attr_val ); let prog = nx.gui.getComponent( attr_node, "prop/prog", cc.ProgressBar ); let max_count = model.getHolyEquipmentMaxAttrByItemIdAttrKey( this.holyData.config.id, title ); let per = attr.attr_val / max_count; nx.gui.setActive( attr_node, "prop/val", per != 1 ); nx.gui.setActive( attr_node, "prop/prog/max", per == 1 ); if( prog ){ prog.progress = per; } } if( attr.pos > 100 ){ before_data.push( attr ); }else{ old_holy_eqm_attr.push({ attr_key: game.configs.attr_data.data_id_to_key[attr.attr_id], attr_val: attr.attr_val }); } } this.old_score = HeroCalculate.getInstance().holyEquipMentPower( old_holy_eqm_attr ) ; if( !nx.dt.arrEmpty( before_data ) ){ this.freshRandomAfter( { holy_eqm_attr: before_data } ); } nx.gui.setActive( this.nodBottom, "ops/save", !nx.dt.arrEmpty( before_data ) ); let times = this.holyData.extra; let time = 0; for (let i = 0; i < times.length; i++) { let item = times[i]; if( item.extra_k == 10 ){ time = item.extra_v; } } nx.gui.setString( this.nodBottom, "times_tip",nx.text.format( "The equipment has been refined", time ) ); nx.gui.setActive( this.nodProps, "desc", false ); // this.freshLockCost(); }, freshLockCost: function(){ // 花费取得 let pfg = game.configs.partner_holy_eqm_data.data_const.lock_pay_diamon; // 根据当前的选择锁定属性进行取值 this.selects = []; let chd = nx.gui.find( this.nodProps, "props" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; let toggle = nx.gui.getComponent( nod, "lock", cc.Toggle ); if( toggle.isChecked ){ this.selects.push( { pos: i + 1 } ); } } let cost = this.selects.length-1 >= 0 ? pfg.val[this.selects.length-1][1]:0; nx.bridge.setIconS( this.nodProps, "desc/icon", 3 ); nx.gui.setString( this.nodProps, "desc/txt",cost ); nx.gui.setActive( this.nodProps, "desc", !nx.dt.arrEmpty( this.selects ) ); }, onTouchSelecton: function(){ this.freshLockCost(); }, freshMat: function(){ let mfg = gdata( "partner_holy_eqm_data", "data_base_info", this.holyData.config.id ); let chd = nx.gui.find( this.nodBottom, "matInfo/mats" ).children; let mats = mfg.reset_price; for (let i = 0; i < mats.length; i++) { let mat = mats[i]; let nod = chd[i]; if( !mat ){ nx.gui.setActive( nod, "", false ); continue; } let count = BackpackController.getInstance().getModel().getItemNumByBid( mat[0] ); nx.bridge.setIconS( nod, "icon", mat[0] ); nx.gui.setString( nod, "txt",nx.dt.shortCount( mat[1] ) + "/" + nx.dt.shortCount( count ) ); } }, onTouchRefine: function(){ let HC = HeroController.getInstance(); if( HC ){ HC.sender11094( this.partner.partner_id, this.holyData.id, this.selects || [] ); } }, onTouchSave: function(){ let HC = HeroController.getInstance(); if( HC ){ HC.sender11090( this.partner.partner_id, this.holyData.id, 1 ); } }, } );