Exemplo n.º 1
0
        private async void OnTaskMessageAdded(object sender, TaskEventArgs <TaskMessage> e)
        {
            SqlTask sqlTask = e.SqlTask;

            if (sqlTask != null)
            {
                TaskProgressInfo progressInfo = new TaskProgressInfo
                {
                    TaskId  = sqlTask.TaskId.ToString(),
                    Message = e.TaskData.Description,
                    Status  = sqlTask.TaskStatus
                };
                await serviceHost.SendEvent(TaskStatusChangedNotification.Type, progressInfo);
            }
        }
Exemplo n.º 2
0
        private async void OnTaskStatusChanged(object sender, TaskEventArgs <SqlTaskStatus> e)
        {
            SqlTask sqlTask = e.SqlTask;

            if (sqlTask != null)
            {
                TaskProgressInfo progressInfo = new TaskProgressInfo
                {
                    TaskId = sqlTask.TaskId.ToString(),
                    Status = e.TaskData
                };

                if (sqlTask.IsCompleted)
                {
                    progressInfo.Duration = sqlTask.Duration;
                }
                await serviceHost.SendEvent(TaskStatusChangedNotification.Type, progressInfo);
            }
        }
Exemplo n.º 3
0
        protected override async void Run(Session session, C2G_Task message, Action <G2C_Task> reply)
        {
            G2C_Task response = new G2C_Task();

            try
            {
                List <TaskInfo>         taskInfoList         = new List <TaskInfo>();
                DBProxyComponent        proxyComponent       = Game.Scene.GetComponent <DBProxyComponent>();
                ConfigComponent         configCom            = Game.Scene.GetComponent <ConfigComponent>();
                List <TaskProgressInfo> taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");

                if (taskProgressInfoList.Count <= 0)
                {
                    for (int j = 0; j < TaskData.getInstance().getDataList().Count; ++j)
                    {
                        TaskProgressInfo info = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                        info.UId         = message.uid;
                        info.Name        = TaskData.getInstance().getDataList()[j].Name;
                        info.TaskId      = (int)TaskData.getInstance().getDataList()[j].Id;
                        info.Target      = TaskData.getInstance().getDataList()[j].Target;
                        info.Reward      = TaskData.getInstance().getDataList()[j].Reward;
                        info.Desc        = TaskData.getInstance().getDataList()[j].Desc;
                        info.CurProgress = 0;
                        await proxyComponent.Save(info);
                    }
                    taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");
                }
                else if (taskProgressInfoList.Count < TaskData.getInstance().getDataList().Count)
                {
                    for (int i = 0; i < TaskData.getInstance().getDataList().Count; ++i)
                    {
                        List <TaskProgressInfo> infos = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid},TaskId:{ TaskData.getInstance().getDataList()[i].Id}}}");

                        if (infos.Count <= 0)
                        {
                            TaskConfig       config = TaskData.getInstance().GetDataByTaskId(TaskData.getInstance().getDataList()[i].Id);
                            TaskProgressInfo info   = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                            info.UId         = message.uid;
                            info.Name        = config.Name;
                            info.TaskId      = (int)config.Id;
                            info.Target      = config.Target;
                            info.Reward      = config.Reward;
                            info.Desc        = config.Desc;
                            info.CurProgress = 0;
                            await proxyComponent.Save(info);
                        }
                    }
                    taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");
                }

                for (int i = 0; i < taskProgressInfoList.Count; ++i)
                {
                    TaskInfo         taskInfo     = new TaskInfo();
                    TaskProgressInfo taskProgress = taskProgressInfoList[i];
                    taskInfo.Id         = taskProgress.TaskId;
                    taskInfo.TaskName   = taskProgress.Name;
                    taskInfo.Desc       = taskProgress.Desc;
                    taskInfo.Reward     = taskProgress.Reward;
                    taskInfo.IsComplete = taskProgress.IsComplete;
                    taskInfo.IsGet      = taskProgress.IsGet;
                    taskInfo.Progress   = taskProgress.CurProgress;
                    taskInfo.Target     = taskProgress.Target;
                    taskInfoList.Add(taskInfo);
                }

                response.TaskProgressList = taskInfoList;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新任务
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="taskId"></param>
        /// <param name="progress"></param>
        public static async Task UpdateTask(long uid, int taskId, int progress)
        {
            DBProxyComponent        proxyComponent       = Game.Scene.GetComponent <DBProxyComponent>();
            TaskInfo                taskInfo             = new TaskInfo();
            List <TaskProgressInfo> taskProgressInfoList =
                await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid},TaskId:{taskId}}}");

            if (taskProgressInfoList.Count <= 0)
            {
                TaskProgressInfo info   = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                TaskConfig       config = ConfigHelp.Get <TaskConfig>(taskId);
//                TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskId);
                info.IsGet       = false;
                info.UId         = uid;
                info.Name        = config.Name;
                info.TaskId      = (int)config.Id;
                info.IsComplete  = false;
                info.Target      = config.Target;
                info.Reward      = config.Reward;
                info.Desc        = config.Desc;
                info.CurProgress = 0;

                await proxyComponent.Save(info);

                taskProgressInfoList =
                    await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid},TaskId:{taskId}}}");
            }

            if (taskProgressInfoList.Count > 0)
            {
                /*
                 * progress = -1  代表输
                 * progress = 1  代表赢
                 */
                if (taskId == 104)
                {
                    if (!taskProgressInfoList[0].IsComplete)
                    {
                        if (progress == -1)
                        {
                            taskProgressInfoList[0].CurProgress = 0;
                            await proxyComponent.Save(taskProgressInfoList[0]);
                        }
                        else if (progress == 1)
                        {
                            taskProgressInfoList[0].CurProgress += progress;
                            if (taskProgressInfoList[0].CurProgress == taskProgressInfoList[0].Target)
                            {
                                taskProgressInfoList[0].IsComplete = true;
                            }

                            await proxyComponent.Save(taskProgressInfoList[0]);
                        }
                    }
                }
                else
                {
                    taskProgressInfoList[0].CurProgress += progress;
                    if (taskProgressInfoList[0].CurProgress >= taskProgressInfoList[0].Target)
                    {
                        taskProgressInfoList[0].IsComplete = true;
                    }

                    await proxyComponent.Save(taskProgressInfoList[0]);
                }
            }

            // 增加转盘次数
            if (taskId == 101)
            {
                if (taskProgressInfoList[0].CurProgress < 4)
                {
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(uid);

                    ++playerBaseInfo.ZhuanPanCount;
                    await proxyComponent.Save(playerBaseInfo);
                }
            }

//            Log.Debug("UpdateTask111111111111");
        }