Example #1
0
        public override bool TakeAction()
        {
            bool result = true;
            taskInfo = new ConfigCacheSet<StoryTaskInfo>().FindKey(TaskID);
            if (taskInfo == null)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                //this.ErrorInfo = LanguageManager.GetLang().St3002_NotFind;
                SaveLog(new Exception(string.Format("{0},User:{1},task:{2}", LanguageManager.GetLang().St3002_NotFind, ContextUser.UserID, TaskID)));
                return false;
            }
            _userGeneral = UserGeneral.GetMainGeneral(Uid);
            //获得奖励
            UserTask userTask = new GameDataCacheSet<UserTask>().FindKey(ContextUser.UserID, TaskID);
            if (userTask == null || userTask.TaskState != TaskState.Completed)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St3007_NoCompleted;
                return false;
            }
            //交付物品任务扣除材料
            if (taskInfo.TermsType == PlotTermsType.Shouji || taskInfo.TermsType == PlotTermsType.Delivery)
            {
                UserItemHelper.UseUserItem(Uid, taskInfo.TargetItemID, taskInfo.TargetItemNum);
            }
            userTask.TaskState = TaskState.Close;
            UserTaskLog taskLog = new UserTaskLog()
            {
                LogID = Guid.NewGuid().ToString(),
                TaskID = userTask.TaskID,
                UserID = userTask.UserID,
                TaskType = userTask.TaskType,
                TaskState = userTask.TaskState,
                TaskPrize = string.Format("Experience:{0},GameCoin:{1};GameCoin:{2} ",
                    taskInfo.Experience,
                    taskInfo.GameCoin,
                    ContextUser.GameCoin
                ),
                CreateDate = DateTime.Now
            };
            var sender = DataSyncManager.GetDataSender();
            sender.Send(taskLog);

            ContextUser.GameCoin = MathUtils.Addition(ContextUser.GameCoin, taskInfo.GameCoin, int.MaxValue);
            if (taskInfo.TaskType == TaskType.Master && ContextUser.TaskProgress < TaskID)
            {
                ContextUser.TaskProgress = TaskID;
            }
            //ContextUser.Update();

            //任务加佣兵经验
            //var userEmbattles = new GameDataCacheSet<UserEmbattle>().FindAll(UserEmbattle.Index_UserID_MagicID, Uid, ContextUser.UseMagicID);
            //foreach (var userEmbattle in userEmbattles)
            //{
            //    UserGeneral userGeneral = new GameDataCacheSet<UserGeneral>().FindKey(ContextUser.UserID, userEmbattle.GeneralID);
            //    if (userGeneral == null) continue;
            //    userGeneral.CurrExperience = MathUtils.Addition(userGeneral.CurrExperience, taskInfo.Experience, int.MaxValue);
            //    //userGeneral.Update();
            //}
            UserHelper.UserGeneralExp(ContextUser.UserID,taskInfo.Experience);

            //开启功能
            TaskHelper.EnableFunction(ContextUser, taskInfo.FunctionEnum);

            //下发可接任务
            TaskHelper.SendAllowTask(ContextUser, TaskID);

            //开启副本
            PlotHelper.EnablePlot(Uid, taskInfo.EnablePlot);

            //保留主线任务
            var cacheSet = new GameDataCacheSet<UserTask>();
            if (userTask.TaskType == TaskType.Master)
            {
                //userTask.Update();
            }
            else
            {
                //原因:最后支线任务无限刷新BUG
                if (!TaskHelper.IsLastTask(userTask))
                {
                    cacheSet.Delete(userTask);
                }
            }
            return result;
        }
Example #2
0
        public override bool TakeAction()
        {
            TaskStar taskOpsStar = TaskStar.Star1;
            userLv = ContextUser.UserLv;
            this.ErrorCode = ops;
            if (ops == 1)
            {
                if (!VipHelper.GetVipOpenFun(ContextUser.VipLv, ExpandType.RefreashDailyTask))
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_VipNotEnoughNotFuntion;
                    return false;
                }
                List<UserTask> taskArray = new GameDataCacheSet<UserTask>().FindAll(ContextUser.UserID, u => u.TaskState == TaskState.AllowTake && u.TaskType == TaskType.Daily);
                if (taskArray.Count > 0)
                {
                    if (taskArray[0].TaskStar == TaskStar.Star5)
                    {
                        ErrorCode = LanguageManager.GetLang().ErrorCode;
                        ErrorInfo = LanguageManager.GetLang().St3005_RefreashStarFull;
                        return false;
                    }
                }
                ErrorInfo = string.Format(LanguageManager.GetLang().St3005_RefreashUseGold, useProGold);
                return false;
            }
            else if (ops == 2)
            {
                if (ContextUser.GoldNum < useProGold)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return false;
                }

                List<UserTask> taskArray = new GameDataCacheSet<UserTask>().FindAll(ContextUser.UserID, u => u.TaskState != TaskState.Disable && u.TaskType == TaskType.Daily);
                if (taskArray.Count > 0)
                {
                    taskOpsStar = TaskHelper.GetTaskStar(taskArray[0].TaskStar, taskArray[0].TakeDate);
                }
                foreach (UserTask taskInfo in taskArray)
                {
                    taskInfo.TaskStar = taskOpsStar;
                    //taskInfo.Update();
                }
                ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useProGold, int.MaxValue);
                //ContextUser.Update();
                if (taskArray.Count > 0)
                {
                    userTaskList = taskArray;
                    //UserTask userTask = taskArray[0];
                    //刷新任务
                    //userTaskList = TaskHelper.RefreshDailyTask(ContextUser.UserID, userTask);
                }
            }
            else if (ops == 3)
            {
                if (!VipHelper.GetVipOpenFun(ContextUser.VipLv, ExpandType.ShuanChuMaxXingJiRenWu))
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St_VipNotEnoughNotFuntion;
                    return false;
                }
                this.ErrorInfo = string.Format(LanguageManager.GetLang().St3005_RefreashUseGold, useFullGold);
                return false;
            }
            else if (ops == 4)
            {
                if (ContextUser.GoldNum < useFullGold)
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return false;
                }

                taskOpsStar = TaskStar.Star5;
                List<UserTask> taskArray = new GameDataCacheSet<UserTask>().FindAll(ContextUser.UserID, u => u.TaskState == TaskState.AllowTake && u.TaskType == TaskType.Daily);

                foreach (UserTask taskInfo in taskArray)
                {
                    taskInfo.TaskStar = taskOpsStar;
                    //taskInfo.Update();
                }
                if (taskArray.Count > 0)
                {
                    UserTask userTask = taskArray[0];
                    //刷新任务
                    userTaskList = TaskHelper.RefreshDailyTask(ContextUser.UserID, userTask);
                }

                ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useFullGold, int.MaxValue);
                //ContextUser.Update();

            }
            else if (ops == 5)
            {
                if (!VipHelper.GetVipOpenFun(ContextUser.VipLv, ExpandType.DailyRenWuZhiJieWanCheng))
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St_VipNotEnoughNotFuntion;
                    return false;
                }
                this.ErrorInfo = string.Format(LanguageManager.GetLang().St3005_CompletedUseGold, completedUseGold);
                return false;

            }
            else if (ops == 6)
            {
                if (ContextUser.GoldNum < completedUseGold)
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return false;
                }

                List<UserTask> taskArray = new GameDataCacheSet<UserTask>().FindAll(ContextUser.UserID, u => u.TaskState == TaskState.Taked && u.TaskType == TaskType.Daily);
                if (taskArray.Count > 0)
                {
                    UserTask userTask = taskArray[0];
                    DailyTaskInfo dtaskInfo = new ConfigCacheSet<DailyTaskInfo>().FindKey(taskArray[0].TaskID);
                    //交付任务

                    //奖励
                    int userExp = ContextUser.ExpNum;
                    int expNum = userTask.GetDailyExpNum(userLv);
                    ContextUser.ExpNum = MathUtils.Addition(ContextUser.ExpNum, expNum, int.MaxValue);
                    //ContextUser.Update();
                    var userItem = userTask.GetDailyItem(userLv);
                    if (userItem != null)
                    {
                        UserItemHelper.AddUserItem(ContextUser.UserID, userItem.ItemID, userItem.Num);

                    }
                    userTask.TaskState = TaskState.Close;
                    userTask.CompleteNum = MathUtils.Addition(userTask.CompleteNum, 1, int.MaxValue);
                    //userTask.Update();
                    //奖励日志
                    UserTaskLog taskLog = new UserTaskLog()
                    {
                        LogID = System.Guid.NewGuid().ToString(),
                        TaskID = userTask.TaskID,
                        UserID = userTask.UserID,
                        TaskType = userTask.TaskType,
                        TaskState = userTask.TaskState,
                        TaskPrize = string.Format("ExpNum:{0},item:{1}={2};User expnum:{3}", expNum,
                            userItem != null ? userItem.ItemID : 0,
                            userItem != null ? userItem.Num : 0,
                            userExp
                        ),
                        CreateDate = DateTime.Now
                    };
                    var sender = DataSyncManager.GetDataSender();
                    sender.Send(taskLog);
                    //刷新任务
                    userTaskList = TaskHelper.RefreshDailyTask(ContextUser.UserID, userTask);

                    ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, completedUseGold, int.MaxValue);
                    //ContextUser.Update();
                }
            }
            else if (ops == 0)
            {
                if (TaskID > 0)
                {
                    UserTask userTask = new GameDataCacheSet<UserTask>().FindKey(ContextUser.UserID, TaskID);
                    if (userTask == null || userTask.TaskState != TaskState.Completed)
                    {
                        this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                        this.ErrorInfo = LanguageManager.GetLang().St3007_NoCompleted;
                        return false;
                    }
                    if (TaskHelper.GetTaskCompleteNum(ContextUser.UserID) >= TaskHelper.DailyEveryMaxNum)
                    {
                        this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                        this.ErrorInfo = LanguageManager.GetLang().St3005_CompletedTimeout;
                        return false;
                    }
                    DailyTaskInfo dtaskInfo = new ConfigCacheSet<DailyTaskInfo>().FindKey(userTask.TaskID);
                    //交付任务

                    //奖励
                    int userExp = ContextUser.ExpNum;
                    int expNum = userTask.GetDailyExpNum(userLv);
                    ContextUser.ExpNum = MathUtils.Addition(ContextUser.ExpNum, expNum, int.MaxValue);
                    //ContextUser.Update();
                    var userItem = userTask.GetDailyItem(userLv);
                    if (userItem != null)
                    {
                        UserItemHelper.AddUserItem(ContextUser.UserID, userItem.ItemID, userItem.Num);
                    }
                    userTask.TaskState = TaskState.Close;
                    userTask.CompleteNum = MathUtils.Addition(userTask.CompleteNum, 1, int.MaxValue);
                    //userTask.Update();
                    //奖励日志
                    UserTaskLog taskLog = new UserTaskLog()
                    {
                        LogID = System.Guid.NewGuid().ToString(),
                        TaskID = userTask.TaskID,
                        UserID = userTask.UserID,
                        TaskType = userTask.TaskType,
                        TaskState = userTask.TaskState,
                        TaskPrize = string.Format("ExpNum:{0},item:{1}={2};User expnum:{3}", expNum,
                            userItem != null ? userItem.ItemID : 0,
                            userItem != null ? userItem.Num : 0,
                            userExp
                        ),
                        CreateDate = DateTime.Now
                    };

                    var sender = DataSyncManager.GetDataSender();
                    sender.Send(taskLog);
                    //刷新任务
                    userTaskList = TaskHelper.RefreshDailyTask(ContextUser.UserID, userTask);

                }
                else
                {
                    //刷新当天任务
                    if (!TaskHelper.CheckDailyTaskTimeout(ContextUser.UserID, out userTaskList))
                    {
                        userTaskList = new GameDataCacheSet<UserTask>().FindAll(ContextUser.UserID,
                            m => m.TaskType.Equals(TaskType.Daily) &&
                                !m.TaskState.Equals(TaskState.NoTake) &&
                                !m.TaskState.Equals(TaskState.Disable)
                        );
                    }

                    if (userTaskList.Count == 0)
                    {
                        //初始化时刷新任务
                        userTaskList = TaskHelper.RefreshDailyTask(ContextUser.UserID, null);
                    }

                    //刷新状态
                    foreach (UserTask userTask in userTaskList)
                    {
                        bool isModify = false;

                        if (userTask.TaskState == TaskState.Taked &&
                            userTask.TaskTargetNum.ToInt() >= (int)userTask.TaskStar)
                        {
                            isModify = true;
                            userTask.TaskState = TaskState.Completed;
                        }
                        if (isModify)
                        {
                            //userTask.Update();
                        }
                    }
                }
            }

            //计算当天完成次数
            currNum = TaskHelper.GetTaskCompleteNum(ContextUser.UserID);
            return true;
        }