/******************************************************************************* * * 活动:阵营招募 * * ******************************************************************************/ const ActBase = require( "act.base" ); const BackPackController = require( "backpack_controller" ); const RoleController = require( "role_controller" ); const SummonMod = require( "summon.mod" ); const ActTeamSummonMod3 = cc.Class( { extends: ActBase, // 初始化配置数据 initConfig: function() { // 视图附着 nx.plugin.add( this, ["view"] ); this.vattach( "Acts" ); }, // 注册监听事件 registerEvents: function() { if( !!this.bagEvent1 ) { gcore.GlobalEvent.unbind( this.bagEvent1 ); gcore.GlobalEvent.unbind( this.bagEvent2 ); gcore.GlobalEvent.unbind( this.bagEvent3 ); this.bagEvent1 = null; this.bagEvent2 = null; this.bagEvent3 = null; } this.bagEvent1 = gcore.GlobalEvent.bind( EventId.ADD_GOODS, this.onBagItemUpdate.bind( this ) ); this.bagEvent2 = gcore.GlobalEvent.bind( EventId.DELETE_GOODS, this.onBagItemUpdate.bind( this ) ); this.bagEvent3 = gcore.GlobalEvent.bind( EventId.MODIFY_GOODS_NUM, this.onBagItemUpdate.bind( this ) ); }, // 注册协议接受事件 registerProtocals: function() { this.RegisterProtocal( 23263, this.handle23263.bind( this ) ); }, // 从服务器初始化数据 reqBaseFromServer: function( _cb ) { nx.dt.fnInvoke( _cb, true ); this.configs = this.queryConfigs(); setTimeout( () => { this.freshTips(); }, 50 ) }, // ============================================================ // 基本操作 // ============================================================ // 点击抽奖 reqSummon: function( _once, _cb ) { SummonMod.getInstance().reqSummonTeamItem( this.configs.group_id, _once ? 1 : 10, _cb ); }, // 抽积分 reqScore: function( _cb ) { SummonMod.getInstance().reqSummonTeamScore( _cb ); }, // 召唤状态 reqState: function( _cb ) { this.SendProtocal( 23263, { camp_id: this.data.camp_id, }, _cb ); }, // 召唤状态 handle23263: function( _data ) { if( !this.isGoodData( _data, false ) || _data.camp_id != this.data.camp_id ) { return; } }, // ============================================================ // 道具相关 // ============================================================ // 道具更新 onBagItemUpdate: function( _bagCode, _itemList ) { let id1 = this.configs ? this.configs.item_id : -1; for( let k in _itemList ) { let tm = _itemList[k]; if( tm.base_id == id1 ) { this.freshTips(); break; } } }, // 获取道具数量 itemHave: function() { if( nx.dt.objEmpty( this.configs ) || !nx.dt.numPositive( this.configs.item_id, false ) ) { nx.error( `$SummonLimit:获取道具数量失败! ${this.data.camp_id}` ); return 0; } const BC = BackPackController.getInstance(); return BC.getModel().getBackPackItemNumByBid( this.configs.item_id ); }, // ============================================================ // 活动红点提示 // ============================================================ // 活动用到的提示KEY tipKeys: function() { return ["once", "ten", "score"]; }, // 红点提示更新 freshTips: function() { this.openTip( "reward", false ); if( !this.configs ) { this.openTip( "once", false ); this.openTip( "ten", false ); return; } // 抽取提示 let count = this.itemHave(); this.openTip( "once", count >= this.configs.item_once[0][1] ); this.openTip( "ten", count >= this.configs.item_ten[0][1] ); // VIP积分 let role = RoleController.getInstance().getRoleVo(); let key = game.configs.item_data.data_assets_id2label[ this.configs.score_id ]; let score = role[key]; if( role.vip_lev >= this.configs.score_vip && score >= this.configs.score_limit ) { this.openTip( "score", true ); } else { this.openTip( "score", false ); } }, // ============================================================ // 配置相关 // ============================================================ // 获取配置 queryConfigs: function() { const DATA = game.configs.recruit_gather_data; if( !DATA ) { nx.error( `$TeamSummon:配置表缺失!` ); return null; } let cfgs = DATA.data_partnersummon_const; let info = DATA.data_partnersummon_data[this.data.camp_id]; if( !cfgs || !info ) { nx.error( `$TeamSummon:配置缺失! ${this.data.camp_id}` ); return null; } let ret = nx.dt.objClone( info ); ret.item_id = cfgs.common_s.val; ret.score_id = cfgs.gpoints.val; ret.score_limit = cfgs.gpoints_per.val; ret.score_vip = cfgs.gather_vip.val; ret.rule = cfgs.rules.desc; return ret; }, } ); // 模块导出 module.exports = ActTeamSummonMod3;