Example #1
0
        //-------------------------------------------------------------------------
        public void c2sTaskGiveUp(int task_id)
        {
            if (IsClient)
            {
                return;
            }

            TaskBase task = null;

            MapTask.TryGetValue(task_id, out task);
            if (task != null)
            {
                task.c2sTaskGiveUp();
            }
        }
Example #2
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 #3
0
        //-------------------------------------------------------------------------
        public void _serverAddDirtyTask(TaskBase task)
        {
            mMapDirtyTask[task.TbDataTask.Id] = task.TaskData;

            if (task.TaskData.task_state == TaskState.Release)
            {
                // 发放本任务的任务奖励
                if (OnServerTaskAward != null)
                {
                    OnServerTaskAward(task);
                }

                // 添加到完成队列,同步给客户端后即删除已完成的任务
                QueTaskDone.Enqueue(task.TbDataTask.Id);
            }
        }
Example #4
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 #5
0
        //-------------------------------------------------------------------------
        // 任务奖励发放
        void _onTaskAward(TaskBase task)
        {
            // 经验奖励
            int award_exp = task.TbDataTask.AwardExp;
            int cur_exp   = CoPlayer.CoActor.Def.mPropExperience.get();

            cur_exp += award_exp;
            CoPlayer.CoActor.Def.mPropExperience.set(cur_exp);

            // 道具奖励
            List <Item> award_list_item = task.getListAwardItem();

            foreach (var i in award_list_item)
            {
                CoPlayer.CoBag.addItem(i);
            }
        }
Example #6
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 #7
0
        //-------------------------------------------------------------------------
        public void _serverAddDirtyTask(TaskBase task)
        {
            mMapDirtyTask[task.TbDataTask.Id] = task.TaskData;

            if (task.TaskData.task_state == TaskState.Release)
            {
                // 发放本任务的任务奖励
                if (OnServerTaskAward != null)
                {
                    OnServerTaskAward(task);
                }

                // 添加到完成队列,同步给客户端后即删除已完成的任务
                QueTaskDone.Enqueue(task.TbDataTask.Id);
            }
        }