Beispiel #1
0
        protected UserMedal GetUserMedal(User user)
        {
            UserMedal userMedal = null;

            foreach (UserMedal medal in user.UserMedals)
            {
                if (medal.MedalID == Medal.ID)
                {
                    userMedal = medal;
                }
            }
            if (userMedal == null)
            {
                MedalLevel level = Medal.GetMedalLevel(user, true);
                if (level != null)
                {
                    userMedal             = new UserMedal();
                    userMedal.MedalID     = Medal.ID;
                    userMedal.MedalLeveID = level.ID;
                    userMedal.Url         = level.IconSrc;
                    userMedal.UserID      = user.UserID;
                }
            }

            return(userMedal);
        }
Beispiel #2
0
        /// <summary>
        /// 是否是自动获取的
        /// </summary>
        /// <param name="userMedal"></param>
        /// <returns></returns>
        protected bool IsAutoGet(UserMedal userMedal)
        {
            Medal medal = GetMedal(userMedal.MedalID);
            if (medal.IsCustom)
                return false;

            bool isAuto;

            if (isAutoGets.TryGetValue(userMedal.MedalID, out isAuto))
                return isAuto;

            MedalLevel level = medal.GetMedalLevel(user, true);

            if (level == null)
                isAuto = false;
            else
            {
                if (medal.GetMedalLevel(user, false).Value > level.Value)
                    isAuto = false;
                else
                    isAuto = true;
            }

            isAutoGets.Add(userMedal.MedalID, isAuto);

            return isAuto;
        }
Beispiel #3
0
        public async Task <IActionResult> NewMedal([FromBody] Medal medals)
        {
            var userId = Convert.ToInt32(userManager.GetUserId(User));

            if (userId == 0)
            {
                throw new UserNotExistsException(localizerAccount["UserNotFound"]);
            }

            var newMadel = new UserMedal()
            {
                ApplicationUserId = userId,
                Madel             = medals,
            };

            await unitOfWork.GetRepository <UserMedal>().InsertAsync(newMadel);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Ok"));
        }
Beispiel #4
0
        /// <summary>
        /// 是否是自动获取的
        /// </summary>
        /// <param name="userMedal"></param>
        /// <returns></returns>
        protected bool IsAutoGet(UserMedal userMedal)
        {
            Medal medal = GetMedal(userMedal.MedalID);

            if (medal.IsCustom)
            {
                return(false);
            }

            bool isAuto;

            if (isAutoGets.TryGetValue(userMedal.MedalID, out isAuto))
            {
                return(isAuto);
            }

            MedalLevel level = medal.GetMedalLevel(user, true);

            if (level == null)
            {
                isAuto = false;
            }
            else
            {
                if (medal.GetMedalLevel(user, false).Value > level.Value)
                {
                    isAuto = false;
                }
                else
                {
                    isAuto = true;
                }
            }

            isAutoGets.Add(userMedal.MedalID, isAuto);

            return(isAuto);
        }
Beispiel #5
0
        protected string GetMedalName(UserMedal userMedal)
        {
            Medal      medal      = GetMedal(userMedal.MedalID);
            MedalLevel medalLevel = null;

            foreach (MedalLevel level in medal.Levels)
            {
                if (level.ID == userMedal.MedalLeveID)
                {
                    medalLevel = level;
                    break;
                }
            }

            if (medalLevel != null && string.IsNullOrEmpty(medalLevel.Name) == false)
            {
                return(string.Concat(medal.Name, " - ", medalLevel.Name));
            }
            else
            {
                return(medal.Name);
            }
        }
Beispiel #6
0
        protected string GetMedals(string urlFormat, string imgFormat, bool isHave)
        {
            StringBuilder imgs = new StringBuilder();

            if (isHave)
            {
                foreach (Medal medal in AllSettings.Current.MedalSettings.Medals)
                {
                    MedalLevel medalLevel = medal.GetMedalLevel(My);
                    if (medalLevel != null)
                    {
                        MedalLevel nextLevel = null;
                        int        i         = 0;
                        foreach (MedalLevel level in medal.Levels)
                        {
                            if (level.ID == medalLevel.ID)
                            {
                                if (medal.Levels.Count > i + 1)
                                {
                                    nextLevel = medal.Levels[i + 1];
                                }
                            }
                            i++;
                        }

                        string title;
                        if (medalLevel.Name != string.Empty)
                        {
                            title = medal.Name + "(" + medalLevel.Name + ")";
                        }
                        else
                        {
                            title = medal.Name;
                        }

                        if (nextLevel != null)
                        {
                            if (medal.IsCustom)
                            {
                                title = title + ";点亮下一级图标条件:" + nextLevel.Condition;
                            }
                            else
                            {
                                title = title + ";点亮下一级图标条件:" + GetConditionName(medal.Condition) + "达到" + nextLevel.Value;
                            }
                        }


                        UserMedal userMedal = My.UserMedals.GetValue(medal.ID, medalLevel.ID);
                        if (userMedal != null && string.IsNullOrEmpty(userMedal.ShowUrl) == false)
                        {
                            string url = userMedal.ShowUrl;
                            if (string.IsNullOrEmpty(userMedal.UrlTitle) == false)
                            {
                                title = userMedal.UrlTitle;
                            }

                            imgs.Append(string.Format(urlFormat, url, string.Format(imgFormat, medalLevel.LogoUrl, title)));
                        }
                        else
                        {
                            imgs.Append(string.Format(imgFormat, medalLevel.LogoUrl, title));
                        }
                    }
                }
            }
            else
            {
                foreach (Medal medal in AllSettings.Current.MedalSettings.Medals)
                {
                    if (medal.IsHidden)
                    {
                        continue;
                    }

                    MedalLevel medalLevel = medal.GetMedalLevel(My);
                    if (medalLevel == null)
                    {
                        if (medal.Levels.Count == 0)
                        {
                            continue;
                        }
                        medalLevel = medal.Levels[0];

                        string title;

                        if (medalLevel.Name != string.Empty)
                        {
                            title = medal.Name + "(" + medalLevel.Name + ")";
                        }
                        else
                        {
                            title = medal.Name;
                        }

                        if (medal.IsCustom)
                        {
                            title = title + ";点亮该图标条件:" + medalLevel.Condition;
                        }
                        else
                        {
                            title = title + ";点亮该图标条件:" + GetConditionName(medal.Condition) + "达到" + medalLevel.Value;
                        }

                        imgs.Append(string.Format(imgFormat, medalLevel.LogoUrl, title));
                    }
                }
            }

            return(imgs.ToString());
        }
Beispiel #7
0
        protected string GetMedalName(UserMedal userMedal)
        {
            Medal medal = GetMedal(userMedal.MedalID);
            MedalLevel medalLevel = null;
            foreach (MedalLevel level in medal.Levels)
            {
                if (level.ID == userMedal.MedalLeveID)
                {
                    medalLevel = level;
                    break;
                }
            }

            if (medalLevel != null && string.IsNullOrEmpty(medalLevel.Name) == false)
                return string.Concat(medal.Name, " - ", medalLevel.Name);
            else
                return medal.Name;
        }
Beispiel #8
0
        protected UserMedal GetUserMedal(User user)
        {
            UserMedal userMedal = null;
            foreach (UserMedal medal in user.UserMedals)
            {
                if (medal.MedalID == Medal.ID)
                    userMedal = medal;
            }
            if (userMedal == null)
            {
                MedalLevel level = Medal.GetMedalLevel(user, true);
                if (level != null)
                {
                    userMedal = new UserMedal();
                    userMedal.MedalID = Medal.ID;
                    userMedal.MedalLeveID = level.ID;
                    userMedal.Url = level.IconSrc;
                    userMedal.UserID = user.UserID;
                }
            }

            return userMedal;
        }