/****************************************************************** * * 家园模块 * ******************************************************************/ const HomeDefine = require( "home.define" ); const BridgeController = require( "bridge.controller" ); const RoleController = require( "role_controller" ); const HomeModel = cc.Class( { extends: BridgeController, // 初始化配置数据 initConfig: function() { }, // 注册监听事件 registerEvents: function() { }, // 注册协议接受事件 registerProtocals: function() { // 家园 this.RegisterProtocal( 26031, this.handle26031.bind( this ) ); // 家园信息 this.RegisterProtocal( 26032, this.handle26032.bind( this ) ); // 访客信息 this.RegisterProtocal( 26033, this.handle26033.bind( this ) ); // 更新推送 this.RegisterProtocal( 26034, this.handle26034.bind( this ) ); // 奖励领取 this.RegisterProtocal( 26035, this.handle26035.bind( this ) ); // 家园改名 this.RegisterProtocal( 26036, this.handle26036.bind( this ) ); // 家园拜访 this.RegisterProtocal( 26037, this.handle26037.bind( this ) ); // 修改主题 this.RegisterProtocal( 26038, this.handle26038.bind( this ) ); // 访客提示 // 亲密度 this.RegisterProtocal( 29300, this.handle29300.bind( this ) ); // 亲密度信息 this.RegisterProtocal( 29301, this.handle29301.bind( this ) ); // 亲密度推送 this.RegisterProtocal( 29306, this.handle29306.bind( this ) ); // 密谈信息 this.RegisterProtocal( 29302, this.handle29302.bind( this ) ); // 密谈信息 this.RegisterProtocal( 29303, this.handle29303.bind( this ) ); // 领取奖励 this.RegisterProtocal( 29304, this.handle29304.bind( this ) ); // 使用道具 this.RegisterProtocal( 29305, this.handle29305.bind( this ) ); // 档案信息 this.RegisterProtocal( 29307, this.handle29307.bind( this ) ); // 档案信息 }, // 从服务器初始化数据 reqBaseFromServer: function( _cb ) { // 配置加载 let cfgs = [ "homeland_data", // 家园 "favor_data", // 亲密度 "halidom_data", // 基础核心 ]; this.loadConfigs( cfgs, ( _ret, _data ) => { this.reqIntimacyData(); this.reqHomeData( _cb ); } ); }, // 更新当前家园信息 updateHomeData: function( _data ) { // 判空 if( nx.dt.objEmpty( _data ) ) { return; } // 是不是自己家 const RC = RoleController.getInstance(); const Ro = RC.getRoleVo(); if( Ro && Ro.rid == _data.rid && Ro.srv_id == _data.srv_id ) { nx.bridge.vset( "HomeMine", true ); } else { nx.bridge.vset( "HomeMine", false ); } // 基础信息 nx.bridge.vset( "HomeName", _data.name || "" ); nx.bridge.vset( "HomeOwnerRid", _data.rid || 0 ); nx.bridge.vset( "HomeOwnerSrv", _data.srv_id || "" ); nx.bridge.vset( "HomeOwnerName", _data.role_name || "" ); nx.bridge.vset( "HomeVisitors", _data.visitor_num || 0 ); nx.bridge.vset( "HomeThemeList", _data.look_list || [] ); nx.bridge.vset( "HomeTheme", _data.look_id || 1 ); nx.bridge.vset( "HomeRewards", _data.rewards || [] ); nx.bridge.vset( "HomePartners", _data.partner_bids || [] ); nx.bridge.vset( "HomeEditing", false ); // 提示信息刷新 this.updateTipView(); }, // 获取家园信息 reqHomeData: function( _cb ) { // 锁定中不请求数据 let lkifo = nx.bridge.vget( "HomeLocked" ); if( nx.dt.objNEmpty( lkifo ) ) { nx.dt.fnInvoke( _cb, true ); return; } this.CB26031 = _cb; this.SendProtocal( 26031, {}, _cb ); }, // 家园信息返回 handle26031: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } this.updateHomeData( _data ); }, // 获取访客信息 reqVisitorList: function( _cb ) { this.SendProtocal( 26032, {}, _cb ); }, // 访客信息返回 handle26032: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, handle26038: function( _data ) { nx.mTip.openTip( "home.footmark.new", _data && _data.code == 1 ); }, // 更新推送 handle26033: function( _data ) { if( nx.dt.objEmpty( _data ) ) { return; } nx.bridge.vset( "HomeThemeList", _data.look_list ); nx.bridge.vset( "HomeTheme", _data.look_id ); nx.bridge.vset( "HomeRewards", _data.rewards ); nx.bridge.vset( "HomePartners", _data.partner_bids ); }, // 奖励领取 reqGetReward: function( _id, _cb ) { let args = { rid: nx.bridge.vget( "HomeOwnerRid" ), srv_id: nx.bridge.vget( "HomeOwnerSrv" ), reward_id: _id, }; this.SendProtocal( 26034, args, _cb ); }, // 奖励领取 handle26034: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 改名 reqChangeName: function( _txt, _cb ) { this.SendProtocal( 26035, { name: _txt, }, _cb ); }, // 改名回复 handle26035: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } nx.bridge.vset( "HomeName", _data.name ); }, // 拜访家园 reqVisitHome: function( _srvId, _rid, _cb ) { this.SendProtocal( 26036, { rid: _rid, srv_id: _srvId, }, _cb ); }, // 家园拜访 handle26036: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } // 成功 this.updateHomeData( _data ); }, // 改主题 reqChangeTheme: function( _id, _cb ) { this.SendProtocal( 26037, { look_id: _id, }, _cb ); }, // 改主题回复 handle26037: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } nx.bridge.vset( "HomeTheme", _data.look_id ); }, // 主题编辑切换 togHomeEdit: function() { let open = nx.bridge.vget( "HomeEditing" ); nx.bridge.vset( "HomeEditing", !open ); }, // 提示信息刷新 updateTipView: function() { }, // ======================================================== // 闺房 / 亲密度 // ======================================================== // 闺蜜更新 setGirls: function( _list, _reset ) { // 重置 if( _reset ) { nx.bridge.vset( "HomeGirls", _list || [] ); return; } // 部分更新 let ids = []; let arr = nx.bridge.vget( "HomeGirls" ); for( let i = 0; i < _list.length; ++i ) { let tm = _list[ i ]; ids.push( tm.partner_id ); for( let k = 0; k < arr.length; ++k ) { let girl = arr[ k ]; if( tm.partner_id == girl.partner_id ) { arr[ k ] = tm; break; } } } nx.bridge.vset( "HomeGirls", arr, false ); // 当前通告 let cur = nx.bridge.vget( "HomeGirlShow" ); if( nx.dt.arrMember( ids, cur ) ) { nx.bridge.vnotify( "HomeGirlShow" ); } }, // 当前闺蜜设定 setCurrentGirl: function( _pid ) { let pid = nx.bridge.vget( "HomeGirlShow" ); if( pid != _pid ) { nx.bridge.vset( "HomeGirlShow", _pid ); } }, // 获取当前闺蜜 queryGirl: function( _pid ) { let arr = nx.bridge.vget( "HomeGirls" ); for( let i in arr ) { let gr = arr[ i ]; if( gr && gr.partner_id == _pid ) { return gr; } } return null; }, // 亲密度信息 reqIntimacyData: function( _cb ) { this.SendProtocal( 29300, {}, _cb ); }, // 亲密度信息 handle29300: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } // 成功 this.setGirls( _data.intimacy_list, true ); }, // 亲密度推送 handle29301: function( _data ) { if( nx.dt.objEmpty( _data ) || nx.dt.arrEmpty( _data.intimacy_list ) ) { return; } this.setGirls( _data.intimacy_list, false ); }, // 使用道具 reqUseIntimacyItem: function( _bid, _num, _cb ) { this.SendProtocal( 29304, { partner_id: nx.bridge.vget( "HomeGirlShow" ), item_id: _bid, num: _num }, _cb ); }, // 使用道具 handle29304: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 领取奖励 reqGetIntimacyReward: function( _pid, _tid, _cb ) { this.SendProtocal( 29303, { partner_id: nx.bridge.vget( "HomeGirlShow" ), profile_id: _pid, talk_id: _tid, }, _cb ); }, // 领取奖励 handle29303: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 密谈 reqStoryData: function( _pid, _cb ) { this.SendProtocal( 29306, { partner_id: nx.bridge.vget( "HomeGirlShow" ), profile_id: _pid, }, _cb ); }, // 密谈返回 handle29306: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 密谈 commitStoryOp: function( _pid, _tid, _cb ) { this.SendProtocal( 29302, { partner_id: nx.bridge.vget( "HomeGirlShow" ), profile_id: _pid, talk_id: _tid, }, _cb ); }, // 密谈返回 handle29302: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 档案信息 reqArchiveInfo: function( _pid, _cb ) { this.SendProtocal( 29305, { partner_id: nx.bridge.vget( "HomeGirlShow" ), profile_id: _pid, }, _cb ); }, // 档案信息返回 handle29305: function( _data ) { // 失败判定 if( !this.isGoodData( _data ) ) { return; } }, // 档案信息返回 handle29307: function( _data ) { if (!nx.frame.vget("hMode")) { nx.bridge.vset("HOpened", false); return; } // 失败判定 if (!this.isGoodData(_data)) { return; } // // 未开启 this.partners = _data.mood_list || []; if (nx.dt.arrEmpty(this.partners)) { nx.bridge.vset("HOpened", false); return; } // // 重置 nx.bridge.vset("HOpened", true); }, } ); module.exports = HomeModel;