/****************************************************************** * * 限定僚机 * ******************************************************************/ const ActPage = require( "act.page.base" ); const ItemLayout = require( "cmp.item.layout" ); const BridgeItemBinder = require( "bridge.binder.item.icon.count" ); const TipsController = require( "tips_controller" ); const FID = require( "bridge.function.ids" ); cc.Class( { extends: ActPage, properties: { nodLogo: {default: null, type: cc.Node}, nodDate: {default: null, type: cc.Node}, tipTimes: {default: null, type: cc.Node}, nodCoin: {default: null, type: BridgeItemBinder}, nodScore: {default: null, type: BridgeItemBinder}, nodOps: {default: null, type: cc.Node}, nodReward: {default: null, type: cc.Node}, nodTotal: {default: null, type: cc.Node}, tipCover: {default: null, type: cc.Node}, tipReward: {default: null, type: ItemLayout}, }, // 初始化 build: function( _data ) { this._super( _data ); // 置空 if( !this.mod || nx.dt.objEmpty( this.data ) ) { this.setEmpty(); return; } // 配置查询 this.configs = this.mod.queryConfigs(); if( !this.configs ) { this.setEmpty(); return; } // 活动监听 this.mod.vbind( this, [ ["LimitWingsFreshed", this.onFreshData.bind( this )], ] ); // 基本信息 this.freshBasic(); }, // 显示 onEnable: function() { this.tipCover.active = false; this.tipTimes.active = false; // 刷新 if( this.mod ) { this.mod.reqBaseData(); } }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } this._super(); }, // 置空 setEmpty: function() { nx.gui.setActive( this, "right", false ); }, // 基本信息 freshBasic: function() { // 置空 if( !this.mod || !this.configs || nx.dt.objEmpty( this.data ) ) { this.setEmpty(); return; } // Logo刷新 let tags = cc.path.join( "locals/{lang}/images/spriteparty", this.configs.bg ); nx.gui.setSpriteFrame( this.nodLogo, "img", nx.res.fmtPath( tags ) ); // 道具绑定 this.nodCoin.setID( this.configs.prop_id, () => { this.freshOps(); } ); // 积分绑定 this.nodScore.setID( this.configs.point_id ); // 红点绑定 let tip1 = nx.gui.getComponent( this.nodOps, "once/tip", "nx.vb.visible" ); if( tip1 ) { tip1.setTarget( nx.mTip, this.mod.getTipKey( "once" ) ); } let tip2 = nx.gui.getComponent( this.nodOps, "ten/tip", "nx.vb.visible" ); if( tip2 ) { tip2.setTarget( nx.mTip, this.mod.getTipKey( "ten" ) ); } // 自选提示 let txt = nx.text.format( "僚机自选提示", this.configs.min_num ); nx.gui.setString( this.nodTotal, "txt", txt ); // 剩余时间 let secs = this.mod.data.end_time - client.socket.getTime(); this.freshDate( secs ); }, // 刷新活动日期 freshDate: function( _secs ) { let time = nx.bridge.time.toNeedSeconds( _secs ); nx.gui.setString( this.nodDate, "txt", time ); }, // 信息刷新 onFreshData: function() { // 累计 let times = this.mod.vget( "LimitWingsTimes" ); nx.gui.setString( this.nodTotal, "num", times ); // 自选剩余 if( times >= this.configs.max_num ) { this.tipTimes.active = false; } else { this.tipTimes.active = true; let loop = this.configs.min_num || 40; let remains = loop - ( times % loop ); let txt = nx.text.format( "僚机自选", remains ); nx.gui.setString( this.tipTimes, "txt", txt ); } // 一轮结束的特殊判断 let prog = Math.floor( times % this.configs.min_num ) / this.configs.min_num; if( times > 0 && ( times % this.configs.min_num ) == 0 ) { if( this.mod.canReward() ) { times -= 1; prog = 1; } } // 特殊:次数超过一轮并且有奖品 if( times >= this.configs.min_num && this.mod.canReward() ) { prog = 1; } // 奖励统计 let items = this.mod.vget( "LimitWingsRewards" ); let limit1 = Math.floor( this.configs.max_num / this.configs.min_num ) - 1; let limit2 = Math.floor( Math.max( 0, times ) / this.configs.min_num ); let limit = Math.min( limit1, limit2 ); let range = [limit * this.configs.min_num, ( limit + 1 ) * this.configs.min_num]; // let arr = []; // items.forEach( _t => { // if( _t.id > range[0] && _t.id <= range[1] ) { // arr.push( _t ); // } // } ); // arr.sort( ( _a, _b ) => { // return _a.id - _b.id; // } ); items.sort( ( _a, _b ) => { return _a.id - _b.id; } ); this.freshRewards( Math.min( 1, prog ), items ); }, // 刷新奖励 freshRewards: function( _progress, _list ) { // 进度 let prog = nx.gui.getComponent( this.nodReward, "progress", cc.ProgressBar ); if( prog ) { prog.progress = _progress; } let rewards = _list || []; if( rewards.length != 5 ) { nx.error( `僚机祈愿奖励有误:${rewards.length}` ); return; } // 状态转动作 // status: 0-未完成,1-可领取,2-已领取 // action1 普通状态 // action2 可开启状态 // action3 开启过程,reword事件出获得道具 // action4 开完状态 let st2act = function( _st ) { switch( _st ) { case 0: return 'action1'; case 1: return 'action2'; case 2: return 'action4'; default: return 'action1'; } }; // 单设 let self = this; let single = function( _box, _time, _data ) { // 次数 nx.gui.setString( _time, "num", _data.id ); // 宝箱 let cfgs = self.mod.queryReward( _data.id ); if( !cfgs ) { return; } let act = st2act( _data.status ); let res = PathTool.getSpinePath( cfgs.res_id, "action", false ); let cmp = nx.gui.getComponent( _box, "", "nx.fx.spine" ); cmp.play( res, act, null, true ); _box.prayData = _data; nx.gui.setActive( _box, "tip", _data.status == 1 ); } for( let i = 0; i < rewards.length; ++i ) { single( nx.gui.find( this.nodReward, `boxes/b${i + 1}` ), nx.gui.find( this.nodReward, `times/t${i + 1}` ), rewards[i] ); } }, // 变化信息 freshOps: function() { // 置空 if( !this.mod || !this.configs || nx.dt.objEmpty( this.data ) ) { return; } // 按钮设置 let autoOp = function( _node, _draw, _pt ) { let tinfo = gitemdata( _draw[0] ); if( tinfo ) { nx.bridge.setIcon( _node, "btn/list/icon", tinfo.icon ); nx.gui.setString( _node, "btn/list/num", _draw[1] ); } let pinfo = gitemdata( _pt[0] ); if( pinfo ) { nx.bridge.setIcon( _node, "score/infos/icon", pinfo.icon ); nx.gui.setString( _node, "score/infos/num", "x" + _pt[1] ); } } // 操作刷新 autoOp( nx.gui.find( this.nodOps, "once" ), this.configs.draw_one[0], this.configs.one_point_num[0] ); autoOp( nx.gui.find( this.nodOps, "ten" ), this.configs.draw_ten[0], this.configs.ten_point_num[0] ); }, // 点击单抽 onTouchOnce: function() { if( !this.configs || !this.mod ) { return; } this.mod.reqSummon( true, ( _ret, _msg, _code ) => { // 道具不足 if( !_ret && _code == 101 ) { nx.tbox( _msg ); this.onTouchCoin(); } } ); }, // 点击十抽 onTouchTen: function() { if( !this.configs || !this.mod ) { return; } this.mod.reqSummon( false, ( _ret, _msg, _code ) => { // 道具不足 if( !_ret && _code == 101 ) { nx.tbox( _msg ); this.onTouchCoin(); } } ); }, // 点击规则 onTouchRule: function() { let rule = this.mod ? this.mod.queryRule() : ""; if( nx.dt.strNEmpty( rule ) ) { const TC = TipsController.getInstance(); TC.showTextPanel( "tip", rule ); } }, // 点击道具 onTouchCoin: function() { if( this.actRoot && this.configs ) { this.actRoot.jumpToMenu( this.configs.jump ); } }, // 点击奖池 onTouchChi: function() { let data = this.configs.award; if( nx.dt.arrEmpty( data ) ) { return; } let args = { title: "奖池详情", group:[], }; let ids = []; for( let i = 0; i < data[0].length; ++i ) { ids.push( data[0][i][0] ); } args.group.push( { name:"限定奖池", partners: ids } ); let ids2 = []; for( let i = 0; i < data[1].length; ++i ) { ids2.push( data[1][i][0] ); } args.group.push( { name:"基础奖池", partners: ids2 } ); nx.bridge.createPanel( "WndPartnerPool", args ); }, // 点击兑换 onTouchShop: function() { nx.bridge.jumper.jump2Window( FID.PartnerWingsShops ); }, // 点击头像 onTouchAvatar: function( _btn ) { let pdata = _btn ? _btn.pdata : null; if( !pdata ) { return; } let key = pdata.bid + "_" + pdata.init_star; let propsData = gdata( "partner_data", "data_partner_show", key ); propsData.star = pdata.init_star; propsData.break_lev = 0; TipsController.getInstance().showPartnerTips( propsData ); }, // 点击宝箱 onTouchBox: function( _box ) { let info = _box ? _box.prayData : null; if( !info ) { return; } // 详情 if( info.status != 1 ) { let cfgs = this.mod.queryReward( info.id ); if( cfgs && nx.dt.arrNEmpty( cfgs.rewards ) ) { this.tipCover.active = true; this.tipReward.rebuild( cfgs.rewards ); let pos = _box.convertToWorldSpaceAR( cc.Vec2.ZERO ); pos = this.tipCover.convertToNodeSpaceAR( pos ); this.tipReward.node.y = pos.y; } return; } // 拆盒 // action3 开启过程,reword事件出获得道具 let cmp = nx.gui.getComponent( _box, "", "nx.fx.spine" ); if( cmp ) { cmp.action( "action3", false, ( _event ) => { // 音效 if( _event == 'reword' ) { nx.audio.playSFX( "audios/effects/del", false ); } // 完成 if( _event == 'complete' ) { this.mod.reqReward(); } } ); } }, // 点击提示覆盖层 onTouchTipCover: function() { this.tipCover.active = false; }, } );