Files
fc/dev/project/assets/Scripts/mod/acts/taskDaily/act.task.daily.mod.js
T

152 lines
4.0 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/*******************************************************************************
*
* 活动: 日常任务模版
*
*
******************************************************************************/
const ActBase = require( "act.base" );
const ActModTaskDaily = cc.Class( {
extends: ActBase,
// 初始化配置数据
initConfig: function() {
// 视图附着
nx.plugin.add( this, ["view"] );
this.vattach( "Acts" );
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 31160, this.handle31160.bind( this ) ); // 任务信息
this.RegisterProtocal( 31161, this.handle31161.bind( this ) ); // 任务信息
this.RegisterProtocal( 31162, this.handle31162.bind( this ) ); // 提交任务
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
let cfgs = [
"happy_daytask_data",
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
nx.dt.fnInvoke( _cb, true );
this.reqBaseData();
} );
},
// ============================================================
// 操作
// ============================================================
// 任务信息
reqBaseData: function( _cb ) {
this.SendProtocal( 31160, {}, _cb );
},
// 任务信息
handle31160: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
this.handle31161( _data );
},
// 任务更新
handle31161: function( _data ) {
if( !this.isGoodData( _data ) ||
nx.dt.arrEmpty( _data.list ) ) {
return;
}
let list = this.vget( "dailyTasks", [] );
if( nx.dt.arrEmpty( list ) ) {
this.vset( "dailyTasks", _data.list || [] );
} else {
for( let i = 0; i < _data.list.length; ++i ) {
let old = false;
let info = _data.list[i];
for( let k = 0; k < list.length; ++k ) {
let temp = list[k];
if( temp.id == info.id ) {
list[k] = info;
old = true;
break;
}
}
if( !old ) {
list.push( info );
}
}
this.vset( "dailyTasks", list || [] );
}
this.freshTips();
},
// 提交任务
reqFinish: function( _tid, _cb ) {
this.SendProtocal( 31162, {
id: _tid
}, _cb );
},
// 提交任务
handle31162: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
},
// 获取任务配置表
queryTaskCfgs: function() {
let data = game.configs.happy_daytask_data.data_day_task_list;
let list = data ? data[this.data.camp_id] : null;
if( nx.dt.objEmpty( list ) ) {
nx.error( `日常任务配置缺失!${this.data.camp_id}` );
}
return list;
},
// 获取规则
queryRule: function() {
let data = game.configs.happy_daytask_data.data_const;
return data ? data.rules.desc : "";
},
// 获取道具信息
queryItemsConfig: function() {
let data = game.configs.happy_daytask_data.data_camp_item;
return data ? data[this.data.camp_id] : null;
},
// ============================================================
// 活动红点提示
// ============================================================
// 红点提示更新
freshTips: function() {
let can = false;
let list = this.vget( "dailyTasks" ) || [];
for( let i = 0; i < list.length; ++i ) {
// 0:未完成 1:已完成 2:已提交
let task = list[i];
if( task && task.status == 1 ) {
can = true;
break;
}
}
this.openTip( "reward", can );
},
} );
// 模块导出
module.exports = ActModTaskDaily;