Example #1
0
        //-------------------------------------------------------------------------
        public void loadAllTask(List <TaskData> list_taskdata)
        {
            foreach (var i in list_taskdata)
            {
                TbDataTask  tbdata_task  = EbDataMgr.Instance.getData <TbDataTask>(i.task_id);
                TaskFactory task_factory = null;
                MapTaskFactory.TryGetValue(tbdata_task.TaskType, out task_factory);

                if (task_factory != null)
                {
                    TaskBase task_base = task_factory.createTask(i);
                    MapTask[task_base.TaskData.task_id] = task_base;
                }
            }
        }
Example #2
0
        //-------------------------------------------------------------------------
        public void serverUpdate(float elapsed_tm)
        {
            if (QueTaskDone.Count > 0)
            {
                foreach (var i in QueTaskDone)
                {
                    TaskBase task = null;
                    MapTask.TryGetValue(i, out task);
                    if (task == null)
                    {
                        continue;
                    }

                    if (task.TaskData.task_state == TaskState.Release)
                    {
                        // 查询下一个任务
                        int next_task_id = task.TbDataTask.NextId;

                        // 创建下一个任务
                        TbDataTask next_tbdata_task = EbDataMgr.Instance.getData <TbDataTask>(next_task_id);

                        if (next_tbdata_task == null)
                        {
                            continue;
                        }

                        TaskFactory next_task_factory = null;
                        MapTaskFactory.TryGetValue(next_tbdata_task.TaskType, out next_task_factory);

                        if (next_task_factory != null)
                        {
                            TaskBase next_task = next_task_factory.createTask(next_task_id);
                            MapTask[next_task.TaskData.task_id] = next_task;

                            mMapDirtyTask[next_task_id] = next_task.TaskData;
                        }
                    }
                }
            }

            while (QueTaskDone.Count > 0)
            {
                int task_id = QueTaskDone.Dequeue();
                MapTask.Remove(task_id);
            }
        }
Example #3
0
        //-------------------------------------------------------------------------
        public void clientUpdateTask(Dictionary <int, TaskData> map_taskdata)
        {
            foreach (var i in map_taskdata)
            {
                TaskBase task = null;
                MapTask.TryGetValue(i.Key, out task);
                if (task != null)
                {
                    TaskState old_state = task.TaskData.task_state;
                    task.clientUpdateTask(i.Value);
                    TaskState new_state = task.TaskData.task_state;

                    if (OnClientTaskStateChange != null && old_state != new_state)
                    {
                        OnClientTaskStateChange(task);
                    }

                    // 客户端移除已完成的任务
                    if (task.TaskData.task_state == TaskState.Release)
                    {
                        MapTask.Remove(task.TbDataTask.Id);
                    }
                }
                else
                {
                    TbDataTask  tbdata_task  = EbDataMgr.Instance.getData <TbDataTask>(i.Key);
                    TaskFactory task_factory = null;
                    MapTaskFactory.TryGetValue(tbdata_task.TaskType, out task_factory);

                    if (task_factory != null)
                    {
                        TaskBase task_base = task_factory.createTask(i.Value);
                        MapTask[task_base.TaskData.task_id] = task_base;

                        if (OnClientTaskStateChange != null)
                        {
                            OnClientTaskStateChange(task);
                        }
                    }
                }
            }
        }
Example #4
0
        //-------------------------------------------------------------------------
        void _init(TaskMgr task_mgr, Entity et, TaskData task_data)
        {
            TaskMgr = task_mgr;
            Entity = et;

            TaskData = task_data;
            if (TaskData.task_data == null) TaskData.task_data = new Dictionary<byte, string>();

            TbDataTask = EbDataMgr.Instance.getData<TbDataTask>(TaskData.task_id);

            onInit();
        }