Esempio n. 1
0
        /// <summary>
        /// 下发任务
        /// </summary>
        /// <param name="user"></param>
        /// <param name="taskID"></param>
        public static List<UserTask> SendAllowTask(GameUser user, int taskID)
        {
            List<UserTask> userTaskList = new List<UserTask>();
            var cacheSet = new GameDataCacheSet<UserTask>();
            UserTask preTask = cacheSet.FindKey(user.UserID, taskID);
            if (taskID > 0 && preTask != null && (preTask.TaskState != TaskState.Close || preTask.TaskType == TaskType.Offset))
            {
                return userTaskList;
            }
            if (taskID == 0 && cacheSet.FindAll(user.UserID, m => m.TaskType < TaskType.Daily).Count > 0)
            {
                return userTaskList;
            }

            IList<StoryTaskInfo> taskList = StoryTaskInfo.GetNextTask(taskID);
            bool isSend = true;
            foreach (StoryTaskInfo taskInfo in taskList)
            {
                if (taskInfo.CountryID != CountryType.None && user.CountryID != taskInfo.CountryID)
                {
                    continue;
                }
                UserTask userTask = cacheSet.FindKey(user.UserID, taskInfo.TaskID);
                if (userTask == null)
                {
                    userTask = new UserTask
                    {
                        TaskID = taskInfo.TaskID,
                        UserID = user.UserID,
                        TaskType = taskInfo.TaskType,
                        TaskState = taskInfo.TaskLv <= user.UserLv ? TaskState.AllowTake : TaskState.NoTake,
                        CompleteNum = 0,
                        CreateDate = DateTime.Now
                    };
                    cacheSet.Add(userTask);
                    userTask = cacheSet.FindKey(user.UserID, taskInfo.TaskID);
                    userTaskList.Add(userTask);
                }
                else
                {
                    //判断是否已下发过
                    isSend = false;
                    break;
                }
            }
            if (isSend)
            {
                return userTaskList;
            }
            return new List<UserTask>();
        }
Esempio n. 2
0
        protected override void ProcessCmd(string[] args)
        {
            int taskID = args.Length > 0 ? args[0].Trim().ToInt() : 0;
            GameUser user = new GameDataCacheSet<GameUser>().FindKey(UserID);
            if (user == null)
            {
                UserCacheGlobal.Load(UserID);
                user = new GameDataCacheSet<GameUser>().FindKey(UserID);
            }
            var taskList = StoryTaskInfo.GetNextTask(taskID);
            foreach (StoryTaskInfo taskInfo in taskList)
            {
                if (taskInfo.CountryID != CountryType.None && user.CountryID != taskInfo.CountryID)
                {
                    continue;
                }
                var cacheSet = new GameDataCacheSet<UserTask>();
                UserTask userTask = cacheSet.FindKey(UserID, taskInfo.TaskID);
                if (userTask == null)
                {
                    userTask = new UserTask
                    {
                        TaskID = taskInfo.TaskID,
                        UserID = UserID,
                        TaskType = taskInfo.TaskType,
                        TaskState = TaskState.AllowTake,
                        CreateDate = DateTime.Now
                    };
                    cacheSet.Add(userTask);
                }
                else
                {
                    userTask.TaskState = TaskState.AllowTake;
                }
            }

        }
Esempio n. 3
0
        public override bool TakeAction()
        {
            StoryTaskInfo storyTask = new ShareCacheStruct<StoryTaskInfo>().FindKey(taskID);
            if (storyTask != null && storyTask.TaskLv <= ContextUser.UserLv)
            {
                UserTask userTask = new PersonalCacheStruct<UserTask>().FindKey(ContextUser.UserID, taskID);
                if (userTask != null && userTask.TaskState == TaskState.Close)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1433_RewardAlreadyReceive;
                    return false;
                }
                int collectNum = TrumpHelper.GetUserItemNum(ContextUser.UserID, storyTask.TargetItemID);
                if (collectNum < storyTask.TargetItemNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1462_ItemNumNotEnough;
                    return false;
                }
                ItemUseHelper itemuse = new ItemUseHelper();

                if (!itemuse.GeneralPrize(ContextUser, storyTask.Reward.ToList()))
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1433_StoryTaskGridNotEnough;
                    return false;
                }
                if (itemuse.DoPrize(ContextUser, storyTask.Reward.ToList()))
                {
                    UserItemHelper.UseUserItem(ContextUser.UserID, storyTask.TargetItemID, storyTask.TargetItemNum);
                    if (userTask != null && userTask.TaskState != TaskState.Close)
                    {
                        userTask.TaskState = TaskState.Close;
                    }

                    if (userTask == null)
                    {
                        userTask = new UserTask
                        {
                            UserID = ContextUser.UserID,
                            TaskID = taskID,
                            TaskType = storyTask.TaskType,
                            TaskStar = TaskStar.Star5,
                            TaskState = TaskState.Close,
                            TaskTargetNum = "0",
                            CompleteNum = 0,
                            CreateDate = DateTime.Now
                        };
                        new PersonalCacheStruct<UserTask>().Add(userTask);
                    }

                    ErrorCode = 0;
                    ErrorInfo = itemuse.content.Trim(',');
                }
            }
            return true;
        }
Esempio n. 4
0
 /// <summary>
 /// 是否最后一个主线任务的支线
 /// </summary>
 /// <param name="taskID"></param>
 /// <returns></returns>
 public static bool IsLastTask(UserTask taskInfo)
 {
     int currTaskID = ConfigEnvSet.GetInt("StoryTaskInfo.CurrMaxTaskID");
     StoryTaskInfo taskOffset = new ConfigCacheSet<StoryTaskInfo>().FindKey(taskInfo.TaskID);
     if (taskOffset != null && (taskOffset.TaskType == TaskType.Offset || taskOffset.TaskType == TaskType.Elite) && taskOffset.PreTaskID.Length > 0)
     {
         if (taskOffset.PreTaskID[0] == currTaskID)
         {
             taskInfo.TaskState = TaskState.Close;
             return true;
         }
     }
     return false;
 }
Esempio n. 5
0
        public static void ResetStar(UserTask userTask)
        {

        }
Esempio n. 6
0
        /// <summary>
        /// 刷新日常任务,当天的记录不清空
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userTask"></param>
        /// <returns></returns>
        public static List<UserTask> RefreshDailyTask(string userID, UserTask userTask)
        {
            List<UserTask> userTaskList = new GameDataCacheSet<UserTask>().FindAll(userID, m => !m.TaskState.Equals(TaskState.Disable) && m.TaskType.Equals(TaskType.Daily));
            foreach (UserTask userTaskTemp in userTaskList)
            {
                //关掉任务
                userTaskTemp.TaskState = TaskState.Disable;
                //userTaskTemp.Update();
            }

            TaskStar taskStar = TaskStar.Star1;
            if (userTask != null)
            {
                if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && userTask.CreateDate.Date < DateTime.Now.Date)
                {
                    taskStar = TaskStar.Star1;
                }
                else
                {
                    taskStar = GetTaskStar(userTask.TaskStar, userTask.TakeDate);
                }
            }

            DailyTaskInfo[] dtaskList = RandomUtils.GetRandomArray(new ConfigCacheSet<DailyTaskInfo>().FindAll().ToArray(), DailyMaxCount);
            foreach (DailyTaskInfo item in dtaskList)
            {
                UserTask tempTask = new GameDataCacheSet<UserTask>().FindKey(userID, item.TaskID);
                if (tempTask == null)
                {
                    tempTask = new UserTask
                    {
                        UserID = userID,
                        TaskID = item.TaskID,
                        TaskType = item.TaskType,
                        TaskStar = taskStar,
                        TaskState = TaskState.AllowTake,
                        TaskTargetNum = "0",
                        CompleteNum = 0,
                        CreateDate = DateTime.Now
                    };
                    new GameDataCacheSet<UserTask>().Add(tempTask);
                }
                else
                {
                    tempTask.TaskStar = taskStar;
                    tempTask.TaskState = TaskState.AllowTake;
                    tempTask.TaskTargetNum = "0";
                    if (!tempTask.CreateDate.Date.Equals(DateTime.Now.Date))
                    {
                        tempTask.CompleteNum = 0;
                    }
                    tempTask.CreateDate = DateTime.Now;
                }

            }

            return new GameDataCacheSet<UserTask>().FindAll(userID,
                m => m.TaskType.Equals(TaskType.Daily) &&
                    (m.TaskState.Equals(TaskState.Taked) || m.TaskState.Equals(TaskState.AllowTake) || m.TaskState.Equals(TaskState.Completed)) &&
                    m.CreateDate.Date.Equals(DateTime.Now.Date)
            );
        }
Esempio n. 7
0
        public override bool TakeAction()
        {
            UserTask usertask = new GameDataCacheSet<UserTask>().FindKey(ContextUser.UserID, TaskID);
            StoryTaskInfo taskInfo = new ConfigCacheSet<StoryTaskInfo>().FindKey(TaskID);
            if(taskInfo==null)
            {
                return false;
            }
            if(usertask==null)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                //ErrorInfo = LanguageManager.GetLang().St3002_NotFind;
                SaveLog(new Exception(string.Format("{0},User:{1},task:{2}", LanguageManager.GetLang().St3002_NotFind, ContextUser.UserID, TaskID)));
                return false;
            }
            ErrorCode = Ops;
            if (Ops == 1)
            {
                //领取
                if (usertask.TaskState != TaskState.AllowTake)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    //ErrorInfo = LanguageManager.GetLang().St3002_NoAllowTaked;
                    return false;
                }
                if (taskInfo.TaskLv > ContextUser.UserLv)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St3002_LvNotEnough;
                    return false;
                }

                TaskState taskState = TaskState.Taked;
                if (taskInfo.TermsType == PlotTermsType.Dialogue)
                {
                    //对话直接完成
                    taskState = TaskState.Completed;
                }
                if (new GameDataCacheSet<UserTask>().FindKey(usertask.UserID, usertask.TaskID) == null)
                {
                    usertask = new UserTask()
                    {
                        UserID = ContextUser.UserID,
                        TaskID = TaskID,
                        TaskType = taskInfo.TaskType,
                        TaskTargetNum = string.Empty,
                        TaskState = taskState,
                        TakeDate = DateTime.Now,
                        CompleteNum = 0,
                        CreateDate = DateTime.Now
                    };
                    new GameDataCacheSet<UserTask>().Add(usertask);
                }
                else
                {
                    usertask.TaskState = taskState;
                    usertask.TakeDate = DateTime.Now;
                    //usertask.Update();
                }
                PlotHelper.EnablePlot(Uid, taskInfo.PlotID);

            }
            else if (Ops == 2)
            {
                
                if (usertask.TaskState == TaskState.Completed)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St3002_Completed;
                    return false;
                }
                if (usertask.TaskState != TaskState.Taked)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    //ErrorInfo = LanguageManager.GetLang().St3002_NoTaked;
                    return false;

                }
                usertask.TaskTargetNum = string.Empty;
                usertask.TaskState = TaskState.AllowTake;
                //usertask.Update();
            }

            return true;
        }