/****************************************************************** * * 活动: StepUP * ******************************************************************/ const ActBase = require( "act.base" ); const SummonDefine = require( "summon.define" ); const HeroController = require( "hero_controller" ); const FID = require( "bridge.function.ids" ); // 桥接替换的界面 const STStage = SummonDefine.StepUpStage; const ActStepUp = cc.Class( { extends: ActBase, // 初始化配置数据 initConfig: function() { // 视图附着 nx.plugin.add( this, ["view"] ); this.vattach( "Acts" ); }, // 注册协议接受事件 registerProtocals: function() { this.RegisterProtocal( 23236, this.handle23236.bind( this ) ); this.RegisterProtocal( 23237, this.handle23237.bind( this ) ); this.RegisterProtocal( 23240, this.handle23240.bind( this ) ); this.RegisterProtocal( 23238, this.handle23238.bind( this ) ); this.RegisterProtocal( 23239, this.handle23239.bind( this ) ); this.RegisterProtocal( 23241, this.handle23241.bind( this ) ); this.RegisterProtocal( 23243, this.handle23243.bind( this ) ); }, // 从服务器初始化数据 reqBaseFromServer: function( _cb ) { // 配置加载 let cfgs = [ "step_up_recruit_data", // step——up 召唤 ]; this.loadConfigs( cfgs, ( _ret, _data ) => { this.fetchData( _cb ); } ); }, // 原始数据 getData: function() { return this.stepData || { state: STStage.Empty, // 开启状态 gold_times: 0, // 钻石次数 camp_id: 0, // 活动ID turns: 0, // 轮次信息 step: 0, // 当前步骤 debris_num: 0, // 碎片数量 integral: 0, // 积分 reward_status: 0, // 最终奖励是否领取 get_reward: [], // 达成奖励领取情况 }; }, // 当前配置 getConfig: function() { // 已经存在 if( nx.dt.objNEmpty( this.stepConfigs ) ) { return this.stepConfigs; } // 活动无效 if( nx.dt.objEmpty( this.stepData ) || !nx.dt.numPositive( this.stepData.camp_id, false ) ) { this.stepConfigs = null; nx.error( "STEP-UP 当前配置无效!" ); return null; } // 配置无效 let DATA = game.configs.step_up_recruit_data; let campId = this.stepData.camp_id; if( nx.dt.objEmpty( DATA.data_action[campId] ) ) { this.stepConfigs = null; nx.error( "STEP-UP 当前配置无效:", campId ); return null; } let data = { diamond_times: DATA.data_const.diamond_times, turns: DATA.data_const.turns, cfgs: nx.dt.objClone( DATA.data_action[campId] ), rewards: DATA.data_reward_items[campId], steps: [], }; let SINFO = DATA.data_interface; let groups = data.cfgs.group_id; for( let i = 0; i < groups.length; ++i ) { let gid = groups[i]; let tmp = SINFO[gid]; if( nx.dt.objEmpty( tmp ) ) { nx.error( "STEP-UP 无效的group配置:", gid ); continue; } data.steps.push( tmp ); } this.stepConfigs = data; return data; }, // 信息请求 fetchData: function( _cb ) { this.SendProtocal( 23237, {}, _cb ); }, // 信息请求返回 handle23237: function( _data ) { if( !this.isGoodData( _data ) ) { return; } let props = this.getData(); nx.dt.copyProperties( props, _data ); this.stepData = props; this.stepConfigs = null; this.freshTips(); }, // 信息更新推送 handle23240: function( _data ) { if( !this.isGoodData( _data ) ) { return; } let props = this.getData(); nx.dt.copyProperties( props, _data ); this.stepData = props; gcore.GlobalEvent.fire( SummonDefine.StepUpFresh ); this.freshTips(); }, // 召唤请求 reqSummon: function( _type, _cb ) { // 容量检查 if( !this.checkVolume( 10 ) ) { nx.tbox( "PartnerBagFull" ); nx.bridge.jumper.jump2Window( FID.Recycle ); return; } this.SendProtocal( 23236, { times: 10, recruit_type: _type }, _cb ); }, // 背包容量检查 checkVolume: function( _count ) { const HC = HeroController.getInstance(); const HM = HC.getModel(); // 背包容量判断 let bagInfo = HM.getHeroMaxCount(); let remains = bagInfo.max_count - bagInfo.have_coutn; return _count <= remains; }, // 召唤请求返回 handle23236: function( _data ) { }, // 角色奖励 reqReward: function( _cb ) { this.SendProtocal( 23238, {}, _cb ); }, // 角色奖励回复 handle23238: function( _data ) { if( !this.isGoodData( _data ) ) { return; } }, // 轮次奖励 reqTurnReward: function( _turn, _cb ) { this.SendProtocal( 23239, { turn: _turn }, _cb ); }, // 轮次奖励回复 handle23239: function( _data ) { if( !this.isGoodData( _data ) ) { return; } }, // 请求排行榜 reqRankList: function( _cb ) { this.SendProtocal( 23241, {}, _cb ); }, // 排行榜回复 handle23241: function( _data ) { if( !this.isGoodData( _data ) ) { return; } this.rankData = _data; }, // ============================================================ // 礼包相关 // ============================================================ // 礼包请求 reqGiftList: function( _cb ) { this.SendProtocal( 23243, {}, _cb ); }, // 礼包更新 handle23243: function( _data ) { if( !this.isGoodData( _data ) ) { return; } this.vset( "stepGifts", _data.gift_buy_info || [] ); }, // ============================================================ // 活动红点提示 // ============================================================ // 活动用到的提示KEY tipKeys: function() { return ["card", "rd2", "rd4", "rd6", "rd8", "rd10"]; }, // 红点提示更新 freshTips: function() { const keys = [2, 4, 6, 8, 10]; const data = this.getData(); if( data.state != STStage.Open && data.state != STStage.Complete ) { this.openTip( "card", false ); keys.forEach( _t => { this.openTip( "rd" + _t, false ); } ); return; } // 轮次奖励 keys.forEach( _t => { let got = nx.dt.arrMember( data.get_reward, null, ( _m ) => { return _m && _m.turn == _t; } ); this.openTip( "rd" + _t, !got && ( _t <= data.turns ) ); } ); // 收卡 let tip = ( data.debris_num >= 10 ) && ( data.reward_status == 0 ); this.openTip( "card", tip ); }, } ); module.exports = ActStepUp;