188 lines
5.2 KiB
JavaScript
188 lines
5.2 KiB
JavaScript
|
|
/*******************************************************************************
|
||
|
|
*
|
||
|
|
* 活动: 月卡
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************************/
|
||
|
|
|
||
|
|
const ActBase = require( "act.base" );
|
||
|
|
|
||
|
|
const ActMonth = cc.Class( {
|
||
|
|
|
||
|
|
extends: ActBase,
|
||
|
|
|
||
|
|
// 初始化配置数据
|
||
|
|
initConfig: function() {
|
||
|
|
|
||
|
|
// 视图附着
|
||
|
|
nx.plugin.add( this, [ "view" ] );
|
||
|
|
this.vattach( "Acts" );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 注册协议接受事件
|
||
|
|
registerProtocals: function() {
|
||
|
|
|
||
|
|
this.RegisterProtocal( 16705, this.handle16705.bind( this ) ); // 月卡信息
|
||
|
|
this.RegisterProtocal( 16706, this.handle16706.bind( this ) ); // 领取月卡
|
||
|
|
this.RegisterProtocal( 16707, this.handle16707.bind( this ) ); // 月卡额外奖励情况
|
||
|
|
this.RegisterProtocal( 16708, this.handle16708.bind( this ) ); // 领取月卡额外奖励
|
||
|
|
this.RegisterProtocal( 16701, this.handle16701.bind( this ) ); // 月卡激活
|
||
|
|
},
|
||
|
|
|
||
|
|
// 从服务器初始化数据
|
||
|
|
reqBaseFromServer: function( _cb ) {
|
||
|
|
|
||
|
|
nx.dt.fnInvoke( _cb, true );
|
||
|
|
this.reqBaseData();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 请求剧情信息
|
||
|
|
reqBaseData: function( _cb ) {
|
||
|
|
this.reqMonthData();
|
||
|
|
this.reqExtraData( _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 月卡操作
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 请求月卡信息
|
||
|
|
reqMonthData: function( _cb ) {
|
||
|
|
this.SendProtocal( 16705, {}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 请求月卡信息返回
|
||
|
|
handle16705: function( _data ) {
|
||
|
|
|
||
|
|
|
||
|
|
if( !this.isGoodData( _data ) ) {
|
||
|
|
this.vset( "monthCard1", null );
|
||
|
|
this.vset( "monthCard2", null );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.vset( "monthCard1", {
|
||
|
|
is_reward: _data.card1_is_reward, // 状态 0:未激活 1:可领取 2:已领取 3:可激活
|
||
|
|
start_time: _data.card1_start_time, // 开始时间(unixtime)
|
||
|
|
end_time: _data.card1_end_time, // 到期时间(unixtime)
|
||
|
|
days: _data.card1_days, // 累计天数
|
||
|
|
acc: _data.card1_acc, // 累计进度
|
||
|
|
} );
|
||
|
|
|
||
|
|
this.vset( "monthCard2", {
|
||
|
|
is_reward: _data.card2_is_reward, // 状态 0:未激活 1:可领取 2:已领取 3:可激活
|
||
|
|
start_time: _data.card2_start_time, // 开始时间(unixtime)
|
||
|
|
end_time: _data.card2_end_time, // 到期时间(unixtime)
|
||
|
|
days: _data.card2_days, // 累计天数
|
||
|
|
acc: _data.card2_acc, // 累计进度
|
||
|
|
} );
|
||
|
|
|
||
|
|
if( this.data ){
|
||
|
|
// 提示刷新
|
||
|
|
this.freshTips();
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取月卡奖励
|
||
|
|
reqMonthReward: function( _type, _cb ) {
|
||
|
|
this.SendProtocal( 16706, {
|
||
|
|
card_type: _type,
|
||
|
|
}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取月卡奖励返回
|
||
|
|
handle16706: function( _data ) {
|
||
|
|
|
||
|
|
if( !this.isGoodData( _data ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let key = "monthCard" + _data.card_type;
|
||
|
|
let ifo = this.vget( key );
|
||
|
|
if( ifo ) {
|
||
|
|
ifo.is_reward = 2;
|
||
|
|
ifo.days += 1;
|
||
|
|
this.vset( key, ifo );
|
||
|
|
}
|
||
|
|
|
||
|
|
// 提示刷新
|
||
|
|
this.freshTips();
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 额外操作
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 请求月卡激活
|
||
|
|
reqActiveCard: function( _type, _cb ) {
|
||
|
|
this.SendProtocal( 16701, {
|
||
|
|
card_type: _type
|
||
|
|
}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 激活月卡返回
|
||
|
|
handle16701: function( _data ) {
|
||
|
|
|
||
|
|
if( !this.isGoodData( _data ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 请求月卡额外奖励信息
|
||
|
|
reqExtraData: function( _cb ) {
|
||
|
|
this.SendProtocal( 16707, {}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 请求月卡额外奖励信息返回
|
||
|
|
handle16707: function( _data ) {
|
||
|
|
|
||
|
|
let stat = _data ? _data.status : 0;
|
||
|
|
this.vset( "monthExtraStatus", stat || 0 );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取月卡额外奖励
|
||
|
|
reqExtraReward: function( _type, _cb ) {
|
||
|
|
this.SendProtocal( 16708, {}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取月卡额外奖励返回
|
||
|
|
handle16708: function( _data ) {
|
||
|
|
|
||
|
|
if( !this.isGoodData( _data ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.vset( "monthExtraStatus", 2 );
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 活动红点提示
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 活动用到的提示KEY
|
||
|
|
tipKeys: function() {
|
||
|
|
return [ "active1", "active2", "reward1", "reward2" ];
|
||
|
|
},
|
||
|
|
|
||
|
|
// 红点提示更新
|
||
|
|
freshTips: function() {
|
||
|
|
|
||
|
|
this.openTip( "reward", false );
|
||
|
|
|
||
|
|
let c1 = this.vget( "monthCard1" );
|
||
|
|
if( c1 ) {
|
||
|
|
this.openTip( "reward1", c1.is_reward == 1 );
|
||
|
|
this.openTip( "active1", c1.is_reward == 3 );
|
||
|
|
}
|
||
|
|
|
||
|
|
let c2 = this.vget( "monthCard2" );
|
||
|
|
if( c2 ) {
|
||
|
|
this.openTip( "reward2", c2.is_reward == 1 );
|
||
|
|
this.openTip( "active2", c2.is_reward == 3 );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 模块导出
|
||
|
|
module.exports = ActMonth;
|