"use strict"; cc._RF.push(module, 'd15c65OUhxKWYqPTgemeBAc', 'task.mod'); // Scripts/mod/task/task.mod.js "use strict"; /****************************************************************** * * 任務相關控制 * ******************************************************************/ var BC = require("bridge.controller"); var TaskConst = require("task_const"); var TaskEvent = require("task_event"); // 任务状态 var TST = TaskConst.task_status; var TaskMod = cc.Class({ "extends": BC, // 初始化配置数据 initConfig: function initConfig() { var TaskModel = require("task_model"); this.model = new TaskModel(this); this.model.initConfig(); }, // 返回当前的model getModel: function getModel() { return this.model; }, // 注册监听事件 registerEvents: function registerEvents() {}, // 注册协议接受事件 registerProtocals: function registerProtocals() { 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 reqBaseFromServer(_cb) { var _this = this; // 配置加载 var cfgs = ["feat_data", "quest_data"]; this.loadConfigs(cfgs, function (_ret, _data) { _this.requestBaseQuestData(_cb); }); }, requestBaseQuestData: function requestBaseQuestData(_cb) { this.SendProtocal(16400, {}); //请求当前所有的成就列表 this.SendProtocal(25810, {}); //请求当前成就列表 this.SendProtocal(10410, {}, _cb); //请求当前成就列表 this.SendProtocal(10411, {}); }, ///---------------------------任务相关 start on10400: function on10400(data) { this.model.addTaskList(data.quest_list, false, true); }, on10403: function on10403(data) { this.model.addTaskList(data.quest_list, true); }, // on10408: function on10408(data) { // data.quest_list.forEach( _task =>{ // this.model.setTaskCompleted( _task ); // } ) }, on10411: function on10411(data) { this.main_panel_quest_list = data.quest_list; }, on10409: function on10409(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 getMainPanelQuestByID(id) { if (this.main_panel_quest_list) { for (var 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 on10410(data) { nx.mTip.openTip("tipTask.show", true); this.model.setMainTaskData(data); }, on10406: function on10406(data) { // nx.tbox( data.msg ); if (data.flag == 1) this.model.setTaskCompleted(data.id); }, requestSubmitTask: function requestSubmitTask(id) { var protocal = {}; protocal.id = id; this.SendProtocal(10406, protocal); }, requestSubmitTaskChange: function requestSubmitTaskChange() { this.SendProtocal(10412, {}); }, //------------------------任务相关 end // 历练 // 已接成就列表 on25810: function on25810(data) { this.model.updateTaskExpList(data); }, // 推送成就列表 on25811: function on25811(data) { this.model.updateTaskExpList(data, true); gcore.GlobalEvent.fire(TaskEvent.UpdateExpTask); }, // 领取成就奖励 send25812: function send25812(id) { var proto = {}; proto.id = id; this.SendProtocal(25812, proto); }, // 领取成就奖励 on25812: function on25812(data) { var 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 handle16400(data) { this.model.setAchievementScore(data.ach_point, data.next_ach_point); this.model.addAchievements(data.feat_list, false, true); // 成就提示更新 this.updateAchievementTips(); }, // 更新成就进度,也可能是新增成就 handle16401: function handle16401(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 reqAchievementReward(_id, _cb) { this.CB16402 = _cb; this.SendProtocal(16402, { id: _id }); }, // 提交成就返回 handle16402: function handle16402(_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 reqOverviewReward(_cb) { this.CB16403 = _cb; this.SendProtocal(16403, { is_all: 0 }); }, // 获取总览奖励返回 handle16403: function handle16403(_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; } var 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 updateAchievementTips() { // 有任务完成 var dot = false; var tasks = this.model.getAchievements(); for (var i = 0; i < tasks.length; ++i) { var tk = tasks[i]; if (tk && tk.finish == TST.finish) { dot = true; break; } } nx.mTip.openTip("home.achievement.other", dot); // 总览奖励 var cur = this.model.achievement_score; var tar = this.model.achievement_score_tar; nx.mTip.openTip("home.achievement.overview", cur >= tar); } }); module.exports = TaskMod; cc._RF.pop();