const BridgeWindow = require( "bridge.window" ); const NxSpine = require( "nx.fx.spine" ); const Mod = require( "act.starskyprayer.mod" ); const ItemBase = require( "cmp.item.base" ); const themeMod = require( "acts.mod" ); const BackPackController = require( "backpack_controller" ); const FID = require( "bridge.function.ids" ); const TipsController = require( "tips_controller" ); const ActPopup = require( "act.popup.base" ); const NormalLen = 56; const TotalLen = 156; cc.Class({ extends: ActPopup, properties: { spRole: { default: null, type: NxSpine }, nodRewards : { default: null, type: cc.Node }, nodShows : { default: null, type: cc.Node }, nodRewardsR : { default: null, type: cc.Node }, nodRight : { default: null, type: cc.Node }, nodShop: { default: null, type: NxSpine }, nodTimes : { default: null, type: cc.Node }, nodEndTimes : { default: null, type: cc.Node }, nodJump : { default: null, type: cc.Toggle }, // E90901 }, // 初始化 onOpenConfigs: function( _params ) { this._super( _params ); this.mod = Mod.getInstance(); // 无效 if( !this.mod ) { this.delayClose(); return; } this.spRole.load( "resDB/models/H30102/H30102", ( _e ) => { if( !_e ) { this.spRole.action( "stand2", true ); } else { this.spRole.stop(); } } ); this.nodShop.load( "resDB/effects/E90901/action", ( _e ) => { if( !_e ) { this.nodShop.action( "action", true ); } else { this.nodShop.stop(); } } ); let rewards = gdata( this.mod.data.config, "data_reach_reward" ) ; this.periods_num = gdata( this.mod.data.config, "data_const" ).periods_num ; this.diamond_times = gdata( this.mod.data.config, "data_const" ).diamond_times.val; this.cfg = gdata( this.mod.data.config, "data_base_info" )[this.periods_num.val] ; let reachs = []; for (let i in rewards ) { let reward = rewards[i]; reachs.push( reward ); } this.reaches = reachs; let time = new Date(); let showtime = this.mod.data.end_time - ( time / 1000 ); nx.gui.setCdTxt( this.nodEndTimes, "left/time", showtime ); this.showRewards = reachs; let chd = this.nodRewards.children; for (let r = 0; r < reachs.length; r++) { let reach = reachs[r]; let nod = chd[r]; let cmp = nx.gui.getComponent( nod, "box", "cmp.common.itemlayout" ); if( cmp ){ cmp.rebuild( reach.reward ); } nx.gui.find( nod, "can/get" ).zIndex = reach.id; nx.gui.setString( nod, "point", reach.num ); nx.gui.setActive( nod, "boxopen", false ); } this.onShowRewards(); // 活动监听 this.mod.vbind( this, [ [ "starPrayData", this.freshInfo.bind( this ) ], ] ); nx.gui.hideAllChildren( this.nodShows, "", false ); // this.setProg(); this.mod.reqBaseData(); }, onEnable: function(){ }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } delete this.mod; this._super(); }, /** {"free_end_time":0,"draw_times":0,"gold_times":20,"luck_num":0,"ids":[],"log_info":[]}*/ freshInfo: function( _data ){ if( _data ){ let luck_num = _data.luck_num; let free_time = _data.free_end_time; let left = this.diamond_times - _data.gold_times; this.leftDia = left ; // this.records = _data.log_info; nx.gui.setString( this.nodTimes, "txt", _data.draw_times ); nx.gui.setString( this.nodEndTimes, "times/num", left ); nx.gui.setString( this.nodEndTimes, "times/all", this.diamond_times ); this.nodJump.isChecked = _data.is_skip == 1; this.skip = _data.is_skip == 1; this.setProg( luck_num ); let time = new Date(); let showtime = free_time - ( time / 1000 ); let nodd = nx.gui.find( this.nodRight, "ops/once/time" ); nx.gui.setCdTxt( nodd, "ttime", showtime ); this.dealOp( free_time ); this.dealReachRewards( _data.ids ); this.index = -1; //当前光环在哪个奖品上 // this.nodFocus.position = this.nodReward.children[this.index].position; //初始化光环位置 this.delayTime = 0.3; //开始的时候延迟调用的时间(最小时间间隔) this.delayTime_max = 1.5; //最大时间间隔 // this.addOrSub = false; //增加还是减少的bool值 this.loopCount = 0; //循环次数 this.circleCount = 2; //前面循环的圈数(效果圈,只为效果,和奖品无关) } }, onShowRewards: function(){ let rewards = gdata( this.mod.data.config, "data_reward_info" )[this.periods_num.val] ; let chd = this.nodRewardsR.children; for (let i in rewards ) { let reward = rewards[i]; let id = reward.point; let nod = chd[id - 1]; // { bid, num } let shows = { bid : reward.item_id, num : reward.num, info : reward.id, } let cmp = nx.gui.getComponent( nod, "item", ItemBase ); if( cmp ){ cmp.setData( shows ); } let level = 0; switch( reward.level_name ){ case "A" : { level = 2 };break; case "B" : { level = 3 };break; case "S" : { level = 4 };break; } let ico = "prefab/acts/starskyprayer/ui/starskyprayer_0" + level; nx.gui.setSpriteFrame( nod, "icor", ico ); nx.gui.setActive( nod, "focus", false ); } }, setProg: function( _num ){ // 右上角 幸運值 相關顯示 let nod = nx.gui.find( this.nodRight, "luck/mask" ); if( nod ){ nod.height = NormalLen + parseInt( ( TotalLen - NormalLen ) * _num * 0.012 ) ; } let lucknod = nx.gui.find( this.nodRight, "luck/score/txt" ); nx.gui.setString( lucknod, "", _num ); }, dealReachRewards : function( _reds ){ // ids":[{"id":7,"status":0},{"id":6,"status":0},{"id":5,"status":0},{"id":4,"status":0},{"id":3,"status":0},{"id":2,"status":0},{"id":1,"status":2}] let ids = _reds; let chd = this.nodRewards.children; for ( let i = 0; i < ids.length; i++ ) { let dataa = ids[i]; let nod = chd[ dataa.id - 1 ]; nx.gui.setActive( nod, "can", dataa.status == 1 ); nx.gui.setActive( nod, "boxopen", dataa.status == 2 ); // nx.gui.setActive( nod, "box", dataa.status == 1 || dataa.status == 0 ); nx.gui.setActive( nod, "box", true ); } }, // 處理 操作以及材料顯示 dealOp: function( _time ){ if( !this.cfg ){ return; } this.useFree = false; this.useItemF = false; this.useItemT = false; this.useDiaT = false; this.useDiaF = false; let free = _time == 0; let mat = this.cfg.loss_item_once[0][0]; let other = this.cfg.loss_goal_once[0][0]; let needmatf = this.cfg.loss_item_once[0][1]; let needmatt = this.cfg.loss_item_ten[0][1]; let needmatdf = this.cfg.loss_goal_once[0][1]; let needmatdt = this.cfg.loss_goal_ten[0][1]; let model = BackPackController.getInstance().getModel(); let have = model.getItemNumByBid( mat ); this.havemat = have; this.needMatT = needmatt; this.needMatF = needmatf; this.name = gitemdata( mat ); let haveDia = model.getItemNumByBid( other ); this.haveDia = haveDia; this.needMatDT = needmatdt; this.needMatDF = needmatdf; nx.gui.setString( this.nodRight, "have/num", have ); nx.bridge.setIconS( this.nodRight, "have/icon", mat ); let once = nx.gui.find( this.nodRight, "ops/once" ); let ten = nx.gui.find( this.nodRight, "ops/ten" ); nx.gui.setActive( once, "free", free ); nx.gui.setActive( once, "mat", !free ); nx.gui.setActive( once, "time", !free ); this.useFree = free; let self = this; let dealUseDia = function(){ if( haveDia >= needmatdt ){ if( self.useItemT ){ self.useDiaT = false; self.useItemF = true; self.useDiaF = false; }else{ if( self.useItemF ){ self.useDiaF = false; self.useDiaT = true; }else{ self.useDiaF = true; self.useDiaT = true; } } }else{ if( haveDia >= needmatdf ){ if( self.useItemF ){ self.useDiaF = false; self.useDiaT = false; }else{ self.useDiaF = true; self.useDiaT = false; } }else{ self.useDiaF = false; self.useDiaT = false; } } } // 当拥有的材料数量不小于10个时 if( have >= needmatt ){ nx.bridge.setIconS( once, "mat/icon", mat ); nx.bridge.setIconS( ten, "mat/icon", mat ); nx.gui.setString( once, "mat/neednum", "X" + needmatf ); nx.gui.setString( ten, "mat/neednum", "X" + needmatt ); this.useItemF = true; this.useItemT = true; this.useDiaF = false; this.useDiaT = false; // dealUseDia(); }else{ // 当材料可以 1抽 if( have >= needmatf ){ nx.bridge.setIconS( once, "mat/icon", mat ); nx.bridge.setIconS( ten, "mat/icon", this.leftDia == this.diamond_times ? mat : other ); nx.gui.setString( once, "mat/neednum", "X" + needmatf ); nx.gui.setString( ten, "mat/neednum", "X" + ( this.leftDia == this.diamond_times ? needmatt : needmatdt ) ); this.useItemF = true; this.useItemT = false; dealUseDia(); this.useDiaF = false; }else{ if( this.leftDia == this.diamond_times ){ nx.bridge.setIconS( once, "mat/icon", mat ); nx.bridge.setIconS( ten, "mat/icon", mat ); nx.gui.setString( once, "mat/neednum", "X" + needmatf ); nx.gui.setString( ten, "mat/neednum", "X" + needmatt ); }else{ nx.bridge.setIconS( once, "mat/icon", other ); nx.bridge.setIconS( ten, "mat/icon", other ); nx.gui.setString( once, "mat/neednum", "X" + needmatdf ); nx.gui.setString( ten, "mat/neednum", "X" + needmatdt ); } dealUseDia(); } } }, // 顯示 達成獎勵相關 onTouchShow: function( _idx ){ let id = parseInt( _idx ); for (let i = 0; i < this.nodShows.children.length; i++) { let nod = this.nodShows.children[i]; if( i != ( id - 1 ) ){ nx.gui.setActive( nod, "", false ); } } // nx.gui.hideAllChildren( this.nodShows, "", false ); let snod = this.nodShows.children[ id - 1 ]; let cmp = nx.gui.getComponent( snod, "bg/award", "cmp.common.itemlayout" ); let rewards = this.showRewards[ id - 1 ]; if( cmp ){ cmp.rebuild( rewards.reward ); } let show = snod.active; nx.gui.setActive( snod, "", !show ); }, // 打開 記錄 onTouchRecord: function(){ this.mod.reqStarPrayRecord( ( _ret, _data )=>{ if( !_ret ){ return; } nx.bridge.createPanel( "WndActStarSkyPrayRecords", _data ); } ) }, // onTouchShop: function(){ let shopInfo = gdata( this.mod.data.config, "data_shop_info" ) ; nx.bridge.createPanel( "WndActStarSkyPrayShop", shopInfo ); }, // 播放輪轉動畫 onDoAni: function( _time, _result, _loop, _usetype ){ let result = _result[0]; if( this.tween ){ this.tween.stop(); } this.loopCount = _loop >= 0 ? _loop : this.loopCount; this.usetype = _usetype; // this.nodFocus.opacity = 156; let num = 0; for (let i = 0; i < this.nodRewardsR.children.length; i++) { let nod = this.nodRewardsR.children[i]; let cmp = nx.gui.getComponent( nod, "item", ItemBase ); if( cmp ){ if( cmp.mdata.info == result.id ){ // nx.gui.setActive( nod, "focus", true ); num = i; } } } let all = num + 3 * this.nodRewardsR.children.length; this.unscheduleAllCallbacks(); let self = this; this.scheduleOnce(() => { this.index++; //循环到最后一个值之后从0开始 if ( this.index >= this.nodRewardsR.children.length ) { this.index = 0; } if( this.loopCount > 0 ){ this.delayTime = 0.05; this.onDoing = true; } //当前运行次数++ if ( this.loopCount >= this.nodRewardsR.children.length * this.circleCount && _result > 0 ) { //加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果) this.delayTime = 0.20; } this.loopCount++; if( this.loopCount > all ){ this.loopCount = all ; } //总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果 this.count = this.nodRewardsR.children.length * ( this.circleCount + 1 ) + _time; //判断是不是运行完了 if ( this.loopCount >= all && result.id > 0 ) { for (let i = 0; i < this.nodRewardsR.children.length; i++) { let nod = this.nodRewardsR.children[i]; let cmp = nx.gui.getComponent( nod, "item", ItemBase ); if( cmp ){ if( cmp.mdata.info == result.id ){ nx.gui.setActive( nod, "focus", true ); nod = nod; }else{ nx.gui.setActive( nod, "focus", false ); } } // nx.gui.setActive( nod, "focus", false ); } //隐藏遮罩 this.tween = cc.tween( this.node ) // .delay( 0.3 ) // .call( ()=>{ // } ) .delay( 0.5 ) .call( ()=>{ let nowresult = _result.shift(); if( !nowresult || nx.dt.arrEmpty( _result ) ){ let dataa = { group_id : self.periods_num.val, type : self.usetype, id : 0 } self.mod.reqGetStarPrayRewardData( dataa ); self.onDoing = false; for (let i = 0; i < this.nodRewardsR.children.length; i++) { let nod = this.nodRewardsR.children[i]; let cmp = nx.gui.getComponent( nod, "item", ItemBase ); if( cmp ){ nx.gui.setActive( nod, "focus", false ); } } return; } for (let i = 0; i < this.nodRewardsR.children.length; i++) { let nod = this.nodRewardsR.children[i]; let cmp = nx.gui.getComponent( nod, "item", ItemBase ); if( cmp ){ nx.gui.setActive( nod, "focus", false ); } } this.onDoAni( _time, _result, 0, self.usetype ); this.onDoing = false; } ) .start(); return; } else { //切换光环位置 for (let i = 0; i < this.nodRewardsR.children.length; i++) { let nod = this.nodRewardsR.children[i]; nx.gui.setActive( nod, "focus", false ); } nx.gui.setActive( this.nodRewardsR.children[this.index], "focus", true ); //重新调用本方法(因为schedule不能动态修改运行间隔时间) this.onDoAni( _time, _result, this.loopCount, self.usetype ); } }, this.delayTime, 0 ); //执行次数为0,实际执行次数为1 }, onTouchPray: function( _idx ){ let self = this; let times = parseInt( _idx ); // if( this.havemat > ) // if( this.useFree ) if( times == 1 ) { if( !this.useFree ){ if( this.havemat < this.needMatF ){ if( this.haveDia >= this.needMatDF ){ if( this.leftDia + times > this.diamond_times ){ let name = this.name ? this.name.name : ""; let str = nx.text.format( "ActStarPrayBuyTip", name ); nx.mbox( str, [ 'cancel', 'Buy' ], ( _key, _box ) => { _box.close(); if( _key == "Buy" ) { // this.reqSummon( _args.type, _times, _args ); // self.close(); nx.bridge.createPanel( "WndActStarSkyPrayShop" ); } } ); // nx.tbox( "PrayDiaTimesLimit" ); return; } } }else{ } } }else{ if( this.havemat < this.needMatT ){ if( this.haveDia >= this.needMatDT ){ if( this.leftDia + times > this.diamond_times ){ let name = this.name ? this.name.name : ""; let str = nx.text.format( "ActStarPrayBuyTip", name ); nx.mbox( str, [ 'cancel', 'Buy' ], ( _key, _box ) => { _box.close(); if( _key == "Buy" ) { // this.reqSummon( _args.type, _times, _args ); // self.close(); nx.bridge.createPanel( "WndActStarSkyPrayShop" ); } } ); // nx.tbox( "PrayDiaTimesLimit" ); return; } } } } let str = nx.text.format( "elfin_hatch_unlock_6", nx.text.getKey( "Dia" ) ); let usetype = 0; // 正在播動畫 if( this.onDoing ){ nx.tbox( "PrayDiaDoing" ); return; } this.unscheduleAllCallbacks(); if( times == 1 ){ // 1 free 3 钻石 4 道具 if( this.useFree ){ usetype = 1; }else{ if( this.useItemF ){ usetype = 4; }else{ if( this.useDiaF ){ usetype = 3; }else{ nx.mbox( str, [ 'cancel', 'GotoCharge' ], ( _key, _box ) => { _box.close(); if( _key == "GotoCharge" ) { // this.reqSummon( _args.type, _times, _args ); self.close(); nx.bridge.jumper.jump2Window( FID.Charge ); } } ); return; } } } }else{ if( this.useItemT ){ usetype = 4; }else{ if( this.useDiaT ){ usetype = 3; }else{ nx.mbox( str, [ 'cancel', 'GotoCharge' ], ( _key, _box ) => { _box.close(); if( _key == "GotoCharge" ) { // this.reqSummon( _args.type, _times, _args ); self.close(); nx.bridge.jumper.jump2Window( FID.Charge ); } } ); return; } } } let dataa = { group_id : this.periods_num.val, times : times, } this.mod.reqGetStarPray( dataa, ( _ret, _data ) => { // console.log( "當前的返回相關" + JSON.stringify( _data ) ); if( !_ret ) { nx.tbox( _data ); return; } // {"flag":1,"msg":"","item_id":[{"id":102}]} // 本地道具-1 // nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( this.have - 1 ) ); // 过程模拟 let num = -( this.nodRewardsR.children.length ); // nx.tween.fadeIn( this.nodFocus,"", 0.1 ); let self = this; this.finalResult = _data.item_id; if( this.skip || times == 10 ){ let dataa = { group_id : self.periods_num.val, type : usetype, id : 0 } self.onDoing = false; self.mod.reqGetStarPrayRewardData( dataa ); return; } // this.schedule( dealPlay, _data.item_id.length, cc.macro.REPEAT_FOREVER ); this.onDoAni( num/3, _data.item_id, 0, usetype ); // dealPlay(); } ); }, onTouchGetReach: function( _btn ){ this.mod.reqGetStarReachReward( _btn.zIndex ); }, onTouchJump: function(){ let jump = this.nodJump.isChecked; // this.mod.reqGetStarReachReward( _btn.zIndex ); this.mod.reqSetStatus( jump ); }, onTouchHelp: function(){ let explain = gdata( this.mod.data.config, "data_explain" )[1]; let prob = gdata( this.mod.data.config, "data_prob_info" ); let probs = []; for (let i in prob ) { let pro = prob[i]; probs.push( pro ); } let ruleinfo = { desc : explain.desc, prob : probs, mod : this.mod } nx.bridge.createPanel( "WndActStarSkyPrayRule", ruleinfo ); }, });