Files

302 lines
8.7 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 任務相關控制
*
******************************************************************/
const BC = require( "bridge.controller" );
const TaskConst = require( "task_const" );
const TaskEvent = require( "task_event" );
// 任务状态
const TST = TaskConst.task_status;
const TaskMod = cc.Class( {
extends: BC,
// 初始化配置数据
initConfig: function() {
let TaskModel = require( "task_model" );
this.model = new TaskModel( this );
this.model.initConfig();
},
// 返回当前的model
getModel: function() {
return this.model;
},
// 注册监听事件
registerEvents: function() {
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 10400, this.on10400 ); //全部任务列表
this.RegisterProtocal( 10403, this.on10403 ); //增加已接任务
this.RegisterProtocal( 10406, this.on10406 ); //提交任务返回,客户端自己更新内存缓存数据
this.RegisterProtocal( 10409, this.on10409 ); //更新已接任务进度
this.RegisterProtocal( 10410, this.on10410 ); //全部主线支线任务列表
this.RegisterProtocal( 10408, this.on10408 ); //全部主线支线任务列表
this.RegisterProtocal( 10411, this.on10411 ); //主成长面板任务列表
this.RegisterProtocal( 16400, this.handle16400 ) //全部成就列表
this.RegisterProtocal( 16401, this.handle16401 ) //更新成就进度,也可能是新增成就
this.RegisterProtocal( 16402, this.handle16402 ) //提交成就返回
this.RegisterProtocal( 16403, this.handle16403 ) //总览奖励领取
// 历练协议
this.RegisterProtocal( 25810, this.on25810 ) //已接成就列表
this.RegisterProtocal( 25811, this.on25811 ) //推送成就列表
this.RegisterProtocal( 25812, this.on25812 ) //领取成就奖励
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"feat_data",
"quest_data",
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
this.requestBaseQuestData( _cb );
} );
},
requestBaseQuestData: function( _cb ) {
this.SendProtocal( 16400, {} ); //请求当前所有的成就列表
this.SendProtocal( 25810, {} ); //请求当前成就列表
this.SendProtocal( 10410, {}, _cb ); //请求当前成就列表
this.SendProtocal( 10411, {} );
},
///---------------------------任务相关 start
on10400: function( data ) {
this.model.addTaskList( data.quest_list, false, true );
},
on10403: function( data ) {
this.model.addTaskList( data.quest_list, true );
},
//
on10408: function( data ) {
// data.quest_list.forEach( _task =>{
// this.model.setTaskCompleted( _task );
// } )
},
on10411: function( data ) {
this.main_panel_quest_list = data.quest_list;
},
on10409: function( data ) {
this.model.addTaskList( data.quest_list, true );
// //刷新下
// if(this.main_panel_quest_list)
// {
// for( let k in this.main_panel_quest_list )
// {
// var mQuest = this.main_panel_quest_list[k]
// for( let k in data.quest_list )
// {
// var quest = data.quest_list[k];
// if(quest.id == mQuest.id)
// {
// this.main_panel_quest_list[k] = quest;
// }
// }
// }
// }
},
getMainPanelQuestByID:function (id)
{
if(this.main_panel_quest_list)
{
for( let k in this.main_panel_quest_list )
{
var mQuest = this.main_panel_quest_list[k]
if(id == mQuest.id)
return this.main_panel_quest_list[k];
}
}
},
on10410: function( data ) {
nx.mTip.openTip( "tipTask.show", true );
this.model.setMainTaskData( data );
},
on10406: function( data ) {
// nx.tbox( data.msg );
if( data.flag == 1 )
this.model.setTaskCompleted( data.id );
},
requestSubmitTask: function( id ) {
var protocal = {};
protocal.id = id;
this.SendProtocal( 10406, protocal );
},
requestSubmitTaskChange: function( ) {
this.SendProtocal( 10412, {} );
},
//------------------------任务相关 end
// 历练
// 已接成就列表
on25810: function( data ) {
this.model.updateTaskExpList( data );
},
// 推送成就列表
on25811: function( data ) {
this.model.updateTaskExpList( data, true );
gcore.GlobalEvent.fire( TaskEvent.UpdateExpTask );
},
// 领取成就奖励
send25812: function( id ) {
let proto = {};
proto.id = id;
this.SendProtocal( 25812, proto );
},
// 领取成就奖励
on25812: function( data ) {
let config = game.configs.room_feat_data.data_const.home_world_feat;
if( config && config.val == data.id ) {
HomeworldController.getInstance().openHomeworldFigureWindow( true )//废弃
}
this.model.updateTaskExpDataByID( data.id, data.finish_time );
gcore.GlobalEvent.fire( TaskEvent.UpdateExpTaskTime );
},
// ======================================================================
// 家园 --- 成就相关
// ======================================================================
// 全部成就列表
handle16400: function( data ) {
this.model.setAchievementScore( data.ach_point, data.next_ach_point );
this.model.addAchievements( data.feat_list, false, true );
// 成就提示更新
this.updateAchievementTips();
},
// 更新成就进度,也可能是新增成就
handle16401: function( data ) {
// [16401]:{"ach_point":0,"next_ach_point":250,"feat_list":[{"id":31010,"finish":0,"end_time":0,"finish_time":0,"progress":[{"id":0,"finish":0,"target":0,"target_val":50000,"value":25375}]}]}
this.model.setAchievementScore( data.ach_point, data.next_ach_point );
this.model.addAchievements( data.feat_list, true );
// 成就提示更新
this.updateAchievementTips();
},
// 提交成就
reqAchievementReward: function( _id, _cb ) {
this.CB16402 = _cb;
this.SendProtocal( 16402, { id: _id } );
},
// 提交成就返回
handle16402: function( _data ) {
// 失败
if( nx.dt.objEmpty( _data ) ||
nx.dt.strNEmpty( _data.msg ) ) {
nx.dt.fnInvoke( this.CB16402, false, _data ? _data.msg : "ErrFailed" );
this.CB16402 = null;
return;
}
this.model.setAchievementComplete( _data.id );
nx.dt.fnInvoke( this.CB16402, true, _data );
this.CB16402 = null;
// 成就提示更新
this.updateAchievementTips();
},
// 获取总览奖励
reqOverviewReward: function( _cb ) {
this.CB16403 = _cb;
this.SendProtocal( 16403, { is_all: 0 } );
},
// 获取总览奖励返回
handle16403: function( _data ) {
// 失败
if( nx.dt.objEmpty( _data ) ||
nx.dt.strNEmpty( _data.msg ) ) {
nx.dt.fnInvoke( this.CB16403, false, _data ? _data.msg : "ErrFailed" );
this.CB16403 = null;
return;
}
let cur = this.model.achievement_score;
this.model.setAchievementScore( cur, _data.next_ach_point );
nx.dt.fnInvoke( this.CB16403, true, _data );
this.CB16403 = null;
// 成就提示更新
this.updateAchievementTips();
},
// 成就提示更新
updateAchievementTips: function() {
// 有任务完成
let dot = false;
let tasks = this.model.getAchievements();
for( let i = 0; i < tasks.length; ++i ) {
let tk = tasks[ i ];
if( tk && tk.finish == TST.finish ) {
dot = true;
break;
}
}
nx.mTip.openTip( "home.achievement.other", dot );
// 总览奖励
let cur = this.model.achievement_score;
let tar = this.model.achievement_score_tar;
nx.mTip.openTip( "home.achievement.overview", cur >= tar );
},
} );
module.exports = TaskMod;