// -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 星命塔 //
Create: 2019-02-27 11:03:16 // -------------------------------------------------------------------- const BridgeController = require( "bridge.controller" ); const StartowerEvent = require( "startower.define" ); const BTC = require("battle_controller"); const StartowerController = cc.Class( { extends: BridgeController, ctor: function() { }, // 初始化配置数据 initConfig: function() { // 已通关的最大层数 this.max_tower = 0; //剩余挑战次数 this.less_count = 0; //已购买次数 this.buy_count = 0; this.reward_list = []; //通关奖励状态 }, // 注册协议接受事件 registerProtocals: function() { this.RegisterProtocal( 11320, this.handle11320 ) //星命塔信息 this.RegisterProtocal( 11321, this.handle11321 ) //购买挑战次数 this.RegisterProtocal( 11322, this.handle11322 ) //挑战星命塔 this.RegisterProtocal( 11323, this.handle11323 ) //推送星命塔结算 this.RegisterProtocal( 11324, this.handle11324 ) //扫荡星命塔 this.RegisterProtocal( 11325, this.handle11325 ) //请求星命塔通关录像 this.RegisterProtocal( 11326, this.handle11326 ) //推送星命塔有解锁 this.RegisterProtocal( 11333, this.handle11333 ) //分享通关录像 this.RegisterProtocal( 11334, this.handle11334 ) this.RegisterProtocal( 11335, this.handle11335 ) this.RegisterProtocal( 11327, this.handle11327 ) // 星命塔排行榜 this.RegisterProtocal( 11328, this.handle11328 ) //通关奖励 this.RegisterProtocal( 11329, this.handle11329 ) }, // 从服务器初始化数据 reqBaseFromServer: function( _cb ) { // 配置加载 let cfgs = [ "star_tower_data" ]; this.loadConfigs( cfgs, ( _ret, _data ) => { this.reqTowerInitData( _cb ); } ); }, reqTowerInitData( _cb ) { // 功能解锁检查 let is_open = this.checkIsOpen(); // 锁定中不请求数据 if( nx.dt.objNEmpty( is_open ) ) { nx.dt.fnInvoke( _cb, true ); return; } this.CB11320 = _cb; this.SendProtocal( 11320, {}, _cb ); }, checkIsOpen: function() { if(!game.configs.star_tower_data)return; var open_config = game.configs.star_tower_data.data_tower_const.open_floor; if( open_config == null ) return null; let ret = nx.bridge.checkConditions( open_config.val ); return ret; }, //打开主界面 openMainView: function( bool ) { nx.bridge.createPanel( "WndStartower", {} ); }, //打开挑战主界面 openStarTowerMainView: function( bool, data ) { nx.bridge.createPanel( "WndStartowerInfo", data ); }, //打开奖励总览 openAwardWindow: function( bool ) { if(bool){ nx.bridge.createPanel( "WndStartowerAward", {} ); }else{ nx.bridge.closePanel( "WndStartowerAward" ); } }, //星命塔结算 getResultWindow: function() { return this.result_window; }, //--打开tips界面 openTipsWindow: function( bool, data ) { if( bool == true ) { if( this.tips_window == null ) { this.tips_window = Utils.createClass( "star_tower_tips_window", this ); } this.tips_window.open( data ) } else { if( this.tips_window ) { this.tips_window.close() this.tips_window = null } } }, //请求星命塔数据 sender11320: function() { this.SendProtocal( 11320, {} ) }, handle11320: function( data ) { // 功能解锁检查 let is_open = this.checkIsOpen(); // 锁定中不请求数据 if( nx.dt.objNEmpty( is_open ) ) { // nx.dt.fnInvoke( _cb, true ); return; } // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setStarTowerData( data ); }, //购买挑战次数 sender11321: function() { var protocal = {}; this.SendProtocal( 11321, protocal ); }, handle11321: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } this.updateLessCount( data ); }, //挑战星命塔 sender11322: function( tower, isauto ) { var protocal = {}; protocal.tower = tower; protocal.isauto = isauto; this.SendProtocal( 11322, protocal ); }, handle11322: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } }, //推送星命塔结算 handle11323: function( data ) { nx.bridge.vset( "ResultInfo", data ); require( "battle_controller" ).getInstance().pushSpecialRetInfo(data.combat_type,data); }, refrreshNewTower: function( data ) { if(data.result == 1){ if (data.is_skip == 1) {//--是否跳过战斗打开怪物逃跑界面 // this.openTipsWindow(true,data) } this.updateMaxTower(data); this.updateLessCount(data); this.sender11334(); } }, //扫荡星命塔 sender11324: function( tower ) { var protocal = {}; protocal.tower = tower; this.SendProtocal( 11324, protocal ); }, handle11324: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } this.updateLessCount( data ); }, //请求星命塔通关录像 sender11325: function( tower ) { var protocal = {}; protocal.tower = tower; this.SendProtocal( 11325, protocal ); }, handle11325: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } gcore.GlobalEvent.fire( StartowerEvent.Video_Data_Event, data ) }, handle11326: function( data ) { this.show_data = data; this.is_show_lock = true; }, //分享通关录像 sender11333: function( replay_id, channel, tower ) { var protocal = {}; protocal.replay_id = replay_id; protocal.channel = channel; protocal.tower = tower; this.SendProtocal( 11333, protocal ); }, handle11333: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } if( data.result == 1 ) { this.openVideoWindow( false ); } }, sender11334: function() { this.SendProtocal( 11334, {} ); }, handle11334: function( data ) {//from_floor,target_floor // 失败判定 // if( !this.isGoodData( data ) ) { // return; // } if( data.result == 1 ) { gcore.GlobalEvent.fire( StartowerEvent.Update_Jump_Floor, data ); } }, sender11335: function() { this.SendProtocal( 11335, {} ); }, handle11335: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } if( data.result == 1 ) { //max_tower BTC.getInstance().openOtherFinish(7); // let result = nx.bridge.vget( "ResultInfo" ); // this.refrreshNewTower(result); } }, requestStarTowerRank: function() { this.SendProtocal( 11327, {} ); }, handle11327: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } gcore.GlobalEvent.fire( StartowerEvent.Update_Top3_rank, data.rank_lists ); }, //领取通关奖励 sender11328: function( id ) { var proto = {}; proto.id = id; this.SendProtocal( 11328, proto ); }, handle11328: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } if( data.result == 1 ) { gcore.GlobalEvent.fire( StartowerEvent.Update_Reward_Event ); } }, handle11329: function( data ) { // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setRewardData( data.award_list ); gcore.GlobalEvent.fire( StartowerEvent.Update_First_Reward_Msg ); }, //////////////////////////////////////// setStarTowerData: function( data ) { var tempsort = { 0: 2, // 0 未领取放中间 1: 1, // 1 可领取放前面 2: 3, // 2 已领取放最后 } this.max_tower = data.max_tower || 0; this.less_count = data.count || 0; this.buy_count = data.buy_count || 0; let is_reward = false; if( Utils.next( data.award_list ) != null ) { for( var i in data.award_list ) { var tab = {}; tab.id = data.award_list[ i ].id; tab.status = data.award_list[ i ].status; tab.sort = tempsort[ tab.status ]; this.reward_list[ data.award_list[ i ].id - 1 ] = tab; if(tab.status == 1){ is_reward = true; } } } this.reward_list.sort( Utils.tableLowerSorter( [ "sort", "id" ] ) ) //更新红点 nx.mTip.openTip("pve.tower.reward",is_reward); gcore.GlobalEvent.fire( StartowerEvent.Update_All_Data ); }, setRewardData: function( data ) { if( !this.reward_list || !data[ 0 ] ) return; var tempsort = { 0: 2, // 0 未领取放中间 1: 1, // 1 可领取放前面 2: 3, // 2 已领取放最后 } let is_reward = false; for( var i in this.reward_list ) { if( this.reward_list[ i ].id == data[ 0 ].id ) { this.reward_list[ i ].status = data[ 0 ].status; this.reward_list[ i ].sort = tempsort[ data[ 0 ].status ]; if(data[0].status == 1){ is_reward = true; } break; } } nx.mTip.openTip("pve.tower.reward",is_reward); this.reward_list.sort( Utils.tableLowerSorter( [ "sort", "id" ] ) ) }, sortFunc: function( data ) { data.sort( function( objA, objB ) { if( objA.sort != objB.sort ) { if( objA.sort && objB.sort ) { return objA.sort - objB.sort; } else { return false; } } else { return objA.id - objB.id; } } ) return data }, getRewardData: function( id ) { if( !this.reward_list ) return; if( id == null ) { return this.reward_list || {}; } else { return this.reward_list[ id ] || {}; } }, getRewardDataById(id){ if( !this.reward_list ) return; if(!id)return null; for(let i = 0;i < this.reward_list.length;i++){ if(this.reward_list[i].id == id){ return this.reward_list[i]; } } return null; }, checkRedPoint: function() { var is_open = this.checkIsOpen(); if( !is_open ) return; var status = false; for( var i in this.reward_list ) { if( this.reward_list[ i ].status == 1 ) { status = true; break; } } status = status || ( this.less_count > 0 ); }, updateMaxTower: function( data ) { if( data && data.max_tower && this.max_tower < data.max_tower ) { this.max_tower = data.max_tower; } gcore.GlobalEvent.fire( StartowerEvent.Fight_Success_Event ) }, updateLessCount: function( data ) { if( data.count != null ) { this.less_count = data.count || 0; //更新红点 } if( data.buy_count != null ) { this.buy_count = data.buy_count; } gcore.GlobalEvent.fire( StartowerEvent.Count_Change_Event ); }, getNowTowerId: function() { return this.max_tower || 0; }, getTowerLessCount: function() { return this.less_count; }, getBuyCount: function() { return this.buy_count; }, //////////////////////////////////////// } ); module.exports = StartowerController;