"use strict"; cc._RF.push(module, 'cbaefStWFJBmJI1Ps8JScv/', 'task_model'); // Scripts/mod/task/task_model.js "use strict"; // -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 这里填写详细说明,主要填写该模块的功能简要 //
Create: 2019-01-09 11:26:10 // -------------------------------------------------------------------- var BridgeClass = require("bridge.class"); var TaskConst = require("task_const"); var RoleController = require("role_controller"); var TaskEvent = require("task_event"); var TaskVo = require("task_vo"); var FID = require("bridge.function.ids"); var TaskModel = cc.Class({ "extends": BridgeClass, ctor: function ctor() { this.ctrl = arguments[0]; }, properties: {}, initConfig: function initConfig() { this.task_list = []; //当前所有任务数据 this.task_status_list = []; //任务icon的红点状态 this.update_feat_status_list = []; //待更新成就状态,延迟更新的 this.dic_task_exp_data = {}; this.showDaily = 0; this.main_task_data = []; // 類型 1 的成就任務 this.achieve_task_data = []; // 類型 11 的成長引導任務 this.battle_task_data = []; // 類型 10 的其他副本戰鬥任務 this.branch_task_data = []; // 類型 2 的親密度培養任務 this.tasks = []; // 成就相关 this.achievement_score = 0; this.achievement_score_tar = 0; this.achievement_dicts = []; this.achievement_list = {}; this.finish_achievement_list = []; }, // @desc:需要检测的红点状态,分活跃度,任务或者成就3中 // author:{author} // time:2018-05-22 15:50:49 // --@type: // return checkQuestAndFeatStatus: function checkQuestAndFeatStatus(type) { var red_status = false; if (type == TaskConst.update_type.activity) { var role_vo = RoleController.getInstance().getRoleVo(); if (role_vo != null && this.activity_data != null) { for (var i in game.configs.activity_data.data_get) { var v = game.configs.activity_data.data_get[i]; if (role_vo.activity >= v.activity && !this.activity_data[v.activity]) { red_status = true; break; } } } } else if (type == TaskConst.update_type.quest) { if (this.task_list != null) { for (var k in this.task_list) { var v = this.task_list[k]; if (v.finish == TaskConst.task_status.finish) { red_status = true; break; } } } } else if (type == TaskConst.update_type.feat) { if (this.achievement_list != null) { for (var k in this.achievement_list) { var v = this.achievement_list[k]; if (v.finish == TaskConst.task_status.finish) { red_status = true; break; } } } } // if( this.red_status_list == null ) { // this.red_status_list = []; // } // if( this.red_status_list[ type ] == null || ( this.red_status_list[ type ] != null && this.red_status_list[ type ] != red_status ) ) { // this.red_status_list[ type ] = red_status; // //抛出事件更新红点 // gcore.GlobalEvent.fire( TaskEvent.UpdateUIRedStatus, type, red_status ); // } // //红点状态 // var num = 0; // if( red_status == true ) // num = 1; }, // @desc:用于日常面板上的红点接口判断 // author:{author} // time:2018-05-28 14:41:18 // --@type: // return getRedStatus: function getRedStatus(type) { if (this.red_status_list == null) return false; return this.red_status_list[type]; }, // @desc:更新整个活跃度数据,只有在上线或者断线重连的时候更新 // author:{author} // time:2018-05-22 16:14:11 // --@data: // return updateActivityData: function updateActivityData(data_list) { this.activity_data = {}; for (var k in data_list) { var v = data_list[k]; this.activity_data[v.activity] = true; } this.checkQuestAndFeatStatus(TaskConst.update_type.activity); gcore.GlobalEvent.fire(TaskEvent.UpdateActivityInfo, this.activity_data); }, // @desc:领取某个活跃度宝箱之后的更新,更新单个的 // author:{author} // time:2018-05-22 16:14:40 // --@activity: // return updateSingleActivityData: function updateSingleActivityData(activity) { if (this.activity_data == null) return; this.activity_data[activity] = true; this.checkQuestAndFeatStatus(TaskConst.update_type.activity); gcore.GlobalEvent.fire(TaskEvent.UpdateActivityInfo, this.activity_data); }, getActivityData: function getActivityData() { return this.activity_data; }, //desc:增加或者更新任务 //time:2018-07-19 05:58:51 //@task_list: //@is_update: //@return addTaskList: function addTaskList(task_list, is_update, is_init) { // this.setMainTaskData( { quest_list :task_list } ); if (!game.configs.quest_data) { return; } var showDaily = 0; this.new_task = task_list; var taskVo, config = null; var is_new = false; var finish_list = []; if (nx.dt.objNEmpty(this.allTask_data)) { for (var o in this.allTask_data) { var task = this.allTask_data[o]; var _loop = function _loop() { var taskl = task[p]; var tc = []; taskl.forEach(function (_task) { tc.push(tc); }); for (var _i = 0; _i < taskl.length; _i++) { var taskc = taskl[_i]; for (var c = 0; c < task_list.length; c++) { var taskn = task_list[c]; if (taskn.id == taskc.id) { taskc.finish = taskn.finish; taskc.canshow = true; taskc.show = 1; } if (taskn.type == TaskConst.task_type.daily) { showDaily++; } // if( taskn.type == taskc.type ){ // if( !nx.dt.arrMember( tc, taskn.id ) ){ // taskl.push( taskn ); // // break; // }else{ // if( taskn.id == taskc.id ){ // taskc.finish = taskn.finish; // taskc.canshow = true; // taskc.show = 1; // } // } // } } } }; for (var p in task) { _loop(); } } } else { for (var c = 0; c < task_list.length; c++) { var taskn = task_list[c]; if (taskn.type == TaskConst.task_type.daily) { showDaily++; } } } if (showDaily > 0) { var count = 0; if (is_init == true) this.task_list = []; this.showDaily = 0; for (var i in task_list) { var v = task_list[i]; config = game.configs.quest_data.data_get[v.id]; if (config != null) { if (config.type == TaskConst.task_type.daily) { if (this.task_list[v.id] == null) { this.task_list[v.id] = new TaskVo(v.id, TaskConst.type.quest); is_new = true; } else { if (v.finish == 1 && is_update == true) finish_list.push(v.id); } taskVo = this.task_list[v.id]; taskVo.updateData(v); if (v.finish == 1) { count++; this.showDaily = count; } } } } nx.mTip.openTip("daily.tip", this.showDaily > 0); } this.checkQuestAndFeatStatus(TaskConst.update_type.quest); gcore.GlobalEvent.fire(TaskEvent.UpdateTaskList, { "new": is_new, task: task_list }); }, // @desc:设置一个任务为提交完成状态 // author:{author} // time:2018-05-22 16:27:46 // --@id: // return setTaskCompleted: function setTaskCompleted(id) { var taskVo = this.task_list[id]; [{ "type": "1", "deep": 1, "elements": [{ "type": "第1章", "deep": 2, "elements": [{ "id": 10001, "name": "指挥官在梦境中遇到了神秘女子,增长了见闻", "lev": 1, "type": 1, "group": 0, "group_desc": "第1章", "desc": "角色升到10级", "progress": [{ "cli_label": "evt_levup", "target": 0, "target_val": 10, "param": [], "value": 10, "finish": 1 }], "extra": [], "commit_rewards": [], "res": "", "finish": 1, "show": 1 }] }, { "type": "第2章", "deep": 2, "elements": [{ "id": 10002, "name": "指挥官教训了小喽喽", "lev": 1, "type": 1, "group": 0, "group_desc": "第2章", "desc": "角色升到20级", "progress": [{ "cli_label": "evt_levup", "target": 0, "target_val": 20, "param": [], "value": 0, "finish": 0 }], "extra": [], "commit_rewards": [], "res": "", "finish": 0, "show": 0 }] }] }]; if (this.allTask_data) { for (var o in this.allTask_data) { var task = this.allTask_data[o]; for (var p in task) { var taskl = task[p]; for (var i = 0; i < taskl.length; i++) { var item = taskl[i]; if (item.id == id) { item.finish = 2; if (item.type != 2) { item.canshow = false; taskl.splice(item, 1); } else { item.canshow = true; } } } } } } for (var _i2 = 0; _i2 < this.main_task_data.length; _i2++) { var _item = this.main_task_data[_i2]; if (_item.type == TaskConst.task_type.main) { var moreInfo = _item.elements; for (var j = 0; j < moreInfo.length; j++) { var qitems = moreInfo[j]; var qs = qitems.elements; for (var _o = 0; _o < qs.length; _o++) { var litem = qs[_o]; if (litem.id == id) { litem.finish = 2; qs.splice(_item, 1); } } } } } // console.log( "当前的主线任务的相关数据model3333333" + JSON.stringify( this.allTask_data ) ); gcore.GlobalEvent.fire(TaskEvent.UpdateTaskList, false); if (taskVo != null) { taskVo.setCompletedStatus(TaskConst.task_status.completed); this.checkQuestAndFeatStatus(TaskConst.update_type.quest); gcore.GlobalEvent.fire(TaskEvent.UpdateTaskList, false); } var count = 0; for (var d in this.task_list) { var daily = this.task_list[d]; if (daily.finish == 1) { count++; } // if( daily.id == id ){ // } } nx.mTip.openTip("daily.tip", count > 0); }, // @desc:获取全部任务列表,这个根据 finish_sort 做了排序的 // author:{author} // time:2018-05-22 19:23:23 // return getTaskList: function getTaskList() { var task_list = []; for (var k in this.task_list) { task_list.push(this.task_list[k]); } if (Utils.next(task_list)) { task_list.sort(Utils.tableLowerSorter(["finish_sort", "id"])); } return task_list; }, getTaskById: function getTaskById(id) { return this.task_list[id]; }, //存贮主线任务数据 11 10 setMainTaskData: function setMainTaskData(_data) { var _msgData = _data.quest_list; // 任务的类型, 具体的类型下所包含的任务信息 var tfg = nx.dt.objClone(game.configs.quest_data.data_get); // let tfgl = game.configs.quest_data.data_get_length; // 返回缓存 // if( !this.allTask_data ){ // this.allTask_data = {}; // }else{ // return this.allTask_data; // } // // [ // {"id":10001,"type":1,"finish":0,"accept_time":0,"progress":[{"id":0,"finish":0,"target":10060,"target_val":1,"value":0,"ext_data":[]}]}, // {"id":10002,"type":1,"finish":0,"accept_time":0,"progress":[{"id":0,"finish":0,"target":10080,"target_val":1,"value":0,"ext_data":[]}]}, // {"id":10003,"type":1,"finish":0,"accept_time":0,"progress":[{"id":0,"finish":0,"target":10100,"target_val":1,"value":0,"ext_data":[]}]} // ]} var data = {}; for (var id in tfg) { var temp = nx.dt.objClone(tfg[id]); temp.value = 0; // nx.dt.arrNEmpty( temp.progress ) ? temp.progress[0].value = 0 : temp.progress.value = 0 ; // nx.dt.arrNEmpty( temp.progress ) ? temp.progress[0].finish = 0 : temp.progress.finish = 0 ; temp.finish = 0; temp.show = 0; // temp.progress[0].finish = 0; temp.canshow = false; var key1 = temp.type; if (this.new_task) { if (!nx.dt.arrEmpty(this.new_task)) { for (var l = 0; l < this.new_task.length; l++) { var _msg = this.new_task[l]; if (_msg) { if (temp.id == _msg.id) { temp.finish = _msg.finish; temp.show = temp.finish && temp.finish != 2 ? 1 : 0; // if( !nx.dt.arrEmpty( _msg.progress ) && !nx.dt.arrEmpty( temp.progress ) ){ // temp.progress[0].finish = _msg.progress[0].finish || 0; // temp.progress[0].value = _msg.progress[0].value || 0; // }else{ // // temp.value = 0; // } temp.canshow = temp.finish != 2; } } } } else {} } for (var i = 0; i < _msgData.length; i++) { var msg = _msgData[i]; if (msg) { if (temp.id == msg.id) { temp.finish = msg.finish; temp.show = temp.finish != 2 ? 1 : 0; // if( !nx.dt.arrEmpty( msg.progress ) && !nx.dt.arrEmpty( temp.progress ) ){ // temp.progress[0].finish = msg.progress[0].finish || 0; // temp.progress[0].value = msg.progress[0].value || 0; // }else{ // // temp.value = 0; // } if (temp.type != 2) { temp.canshow = temp.finish != 2; } else { temp.canshow = true; } } } } // console.log( "当前的任务刷新ssss" + JSON.stringify( temp ) ); if (temp.type != 3 && temp.finish != 2) { var key2 = temp.group_desc; data[key1] = data[key1] || {}; data[key1][key2] = data[key1][key2] || []; data[key1][key2].push(nx.dt.objClone(temp)); } } // console.log( "所有的任務信息" + JSON.stringify( data ) ); this.allTask_data = nx.dt.objClone(data); // // { type: 1/2/3, stype: "类型", lst: [] } if (!nx.dt.arrNEmpty(this.main_task_data) || !nx.dt.arrNEmpty(this.branch_task_data)) { for (var k1 in data) { // k1任务类型 var tree = { type: k1, deep: 1, elements: [] }; var _temp = data[k1]; // console.log( "当前的数据格式任务相关" + JSON.stringify( temp ) ); if (k1 == 1) { for (var k2 in _temp) { tree.elements.push({ type: k2, deep: 2, elements: _temp[k2] }); } this.main_task_data.push(tree); } if (k1 == 2) { for (var _k in _temp) { tree.elements.push({ type: _k, deep: 2, elements: _temp[_k] }); } this.branch_task_data.push(tree); } if (k1 == 10) { for (var _k2 in _temp) { tree.elements.push({ type: _k2, deep: 2, elements: _temp[_k2] }); } this.branch_task_data.push(tree); } } } // this.main_task_data = data; gcore.GlobalEvent.fire(TaskEvent.UpdateTaskList, data); // return this.achievement_dicts; }, getMainTaskData: function getMainTaskData() { return this.main_task_data; }, getAllTaskInfo: function getAllTaskInfo() { return this.allTask_data; }, getBranchTaskInfo: function getBranchTaskInfo() { return this.branch_task_data; }, updateTaskExpList: function updateTaskExpList(scdata, is_check_notice) { if (!scdata) { return; } var role_vo = RoleController.getInstance().getRoleVo(); if (!role_vo) { return; } if (!is_check_notice) { this.dic_task_exp_data = {}; } if (scdata.achievement_list) { var finish_id_list = []; var hide_finish_id_list = []; for (var i in scdata.achievement_list) { var v = scdata.achievement_list[i]; if (this.dic_task_exp_data[v.id]) { for (var k in v) { this.dic_task_exp_data[v.id][k] = v[k]; } } // else { // let config = game.configs.room_feat_data.data_exp_info[ v.id ]; // if( config ) { // this.dic_task_exp_data[ v.id ] = new TaskVo( v.id, TaskConst.type.exp ); // for( let k in v ) { // this.dic_task_exp_data[ v.id ][ k ] = v[ k ]; // } // } // } if (is_check_notice && this.dic_task_exp_data[v.id] && v.finish == TaskConst.task_status.finish && this.dic_task_exp_data[v.id].config) { var lev = this.dic_task_exp_data[v.id].config.lev || 0; if (role_vo.lev >= lev) { if (this.dic_task_exp_data[v.id].config.hide == 1) { hide_finish_id_list.push(v.id); } else { finish_id_list.push(v.id); } } } } // 提示相关处理 if (is_check_notice) { // let config_limit = game.configs.room_feat_data.data_const.experience_open_limit; // if( config_limit ) { if (role_vo.lev >= 55) { // 任务完成 if (finish_id_list.length == 0) { gcore.GlobalEvent.fire(TaskEvent.UpdateExpTaskFinishTips, finish_id_list); } } else { // 任务完成 if (finish_id_list.length == 0) { gcore.GlobalEvent.fire(TaskEvent.UpdateExpTaskFinishTips, finish_id_list); } } } } if (scdata.finish_list) { for (var _i3 in scdata.finish_list) { var _v = scdata.finish_list[_i3]; this.dic_task_exp_data[_v.id].finish = TaskConst.task_status.completed; for (var _k3 in _v) { this.dic_task_exp_data[_v.id][_k3] = _v[_k3]; } // let config = game.configs.room_feat_data.data_exp_info[ v.id ]; // if( config ) { // this.dic_task_exp_data[ v.id ] = new TaskVo( v.id, TaskConst.type.exp ); // } } } this.checkQuestAndFeatStatus(TaskConst.update_type.exp); }, updateTaskExpDataByID: function updateTaskExpDataByID(id, time) { if (this.dic_task_exp_data[id]) { this.dic_task_exp_data[id].finish_time = time; this.dic_task_exp_data[id].finish = TaskConst.task_status.completed; this.checkQuestAndFeatStatus(TaskConst.update_type.exp); } }, getTaskExpList: function getTaskExpList() { return this.dic_task_exp_data || {}; }, getTaskExpListById: function getTaskExpListById(id) { if (this.dic_task_exp_data) { return this.dic_task_exp_data[id]; } }, // ================================================================= // 成就相关 // ================================================================= // 获取成就字典 getAchievementDict: function getAchievementDict() { // 返回缓存 if (nx.dt.arrNEmpty(this.achievement_dicts)) { return this.achievement_dicts; } var data = {}; var DATA = game.configs.feat_data.data_get; for (var id in DATA) { var temp = DATA[id]; var key1 = temp.first_label; var key2 = temp.name; data[key1] = data[key1] || {}; data[key1][key2] = data[key1][key2] || []; data[key1][key2].push(nx.dt.objClone(temp)); } this.achievement_dicts = []; for (var k1 in data) { var tree = { name: k1, deep: 1, elements: [] }; var _temp2 = data[k1]; for (var k2 in _temp2) { tree.elements.push({ name: k2, deep: 2, elements: _temp2[k2] }); } this.achievement_dicts.push(tree); } return this.achievement_dicts; }, // 获取成就任务项 getAchievementById: function getAchievementById(id) { return this.achievement_list[id]; }, // 设置成就积分 setAchievementScore: function setAchievementScore(_cur, _tar) { this.achievement_score = _cur; this.achievement_score_tar = _tar; }, //desc:增加或者更新任务 //time:2018-07-19 05:59:30 //@achievement_list: //@is_update: //@return addAchievements: function addAchievements(achievement_list, is_update, is_init) { // 初始化重置 if (is_init == true) { this.achievement_list = {}; } var is_new = false; var finish_list = []; var taskVo, config = null; if (game.configs.feat_data) { for (var i in achievement_list) { var v = achievement_list[i]; config = gdata("feat_data", "data_get", [v.id]); if (!config) { continue; } if (this.achievement_list[v.id] == null) { this.achievement_list[v.id] = new TaskVo(v.id, TaskConst.type.feat); is_new = true; } else { if (v.finish == 1 && is_update == true) { finish_list.push(v.id); } if (v.finish == 2) { this.setAchievementComplete(v.id); } } taskVo = this.achievement_list[v.id]; taskVo.updateData(v); } this.checkQuestAndFeatStatus(TaskConst.update_type.feat); this.notifyUpdateAchievements(is_new, finish_list); } }, setAchievementComplete: function setAchievementComplete(id) { var taskVo = this.achievement_list[id]; if (taskVo != null) { taskVo.setCompletedStatus(TaskConst.task_status.completed); this.checkQuestAndFeatStatus(TaskConst.update_type.feat); this.notifyUpdateAchievements(false); } }, // @desc:是否需要抛出更新成就的事件,因为提交一个成就可能触发新增成就,所以如果都抛事件的话,会触发多次更新,做延迟抛出更新,避免次更新 // author:{author} // time:2018-05-23 11:56:08 // --@status: // return notifyUpdateAchievements: function notifyUpdateAchievements(status, finish_list) { gcore.GlobalEvent.fire(TaskEvent.UpdateFeatList, finish_list); }, getAchievements: function getAchievements() { var achievement_list = []; for (var k in this.achievement_list) { var v = this.achievement_list[k]; if (v.finish != TaskConst.task_status.completed) achievement_list.push(v); } if (Utils.next(achievement_list)) { achievement_list.sort(Utils.tableLowerSorter(["finish_sort", "id"])); } return achievement_list; } }); cc._RF.pop();