public MedalSettings() { Medals = new MedalCollection(); MaxMedalID = 3; Medal medal = new Medal(); medal.ID = 1; medal.IsCustom = false; medal.IsHidden = false; medal.Enable = true; medal.Condition = "point_1"; medal.Name = "大富翁"; medal.MaxLevelID = 5; MedalLevel level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/gold1.gif"; level.ID = 1; level.Name = "万元户"; level.Value = 10000; medal.Levels.Add(level); level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/gold2.gif"; level.ID = 2; level.Name = "暴发户"; level.Value = 100000; medal.Levels.Add(level); level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/gold3.gif"; level.ID = 3; level.Name = "百万富翁"; level.Value = 1000000; medal.Levels.Add(level); level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/gold4.gif"; level.ID = 4; level.Name = "千万富翁"; level.Value = 10000000; medal.Levels.Add(level); level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/gold5.gif"; level.ID = 5; level.Name = "亿万富翁"; level.Value = 100000000; medal.Levels.Add(level); Medals.Add(medal); medal = new Medal(); medal.ID = 2; medal.IsCustom = true; medal.IsHidden = false; medal.Enable = true; medal.Condition = ""; medal.Name = "忠实用户"; medal.MaxLevelID = 1; level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/medal15.gif"; level.ID = 1; level.Name = "一级"; level.Condition = "参与“领取每日积分大礼包”任务可获得此图标"; medal.Levels.Add(level); Medals.Add(medal); medal = new Medal(); medal.ID = 3; medal.IsCustom = true; medal.IsHidden = true; medal.Enable = true; medal.Condition = ""; medal.Name = "开国元老"; medal.MaxLevelID = 1; level = new MedalLevel(); level.IconSrc = "~/max-assets/icon-medal/medal11.gif"; level.ID = 1; level.Name = "一级"; level.Condition = "需要管理员点亮"; medal.Levels.Add(level); Medals.Add(medal); }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="onlyGetAuto">为true 则不包括管理员手动颁发的</param> /// <returns></returns> public MedalLevel GetMedalLevel(User user, bool onlyGetAuto) { MedalLevel tempMedalLevel = null; if (onlyGetAuto == false) { foreach (UserMedal userMedal in user.UserMedals) { if (userMedal.MedalID == ID) { int i = 0; foreach (MedalLevel level in Levels) { if (level.ID == userMedal.MedalLeveID) { tempMedalLevel = level; if (i == Levels.Count - 1)//是最大等级的勋章 直接返回 { return(tempMedalLevel); } break; } i++; } } } } if (IsCustom) { return(tempMedalLevel); } int value = 0; switch (Condition.ToLower()) { case "point_0": value = user.Points; break; case "point_1": value = user.ExtendedPoints[0]; break; case "point_2": value = user.ExtendedPoints[1]; break; case "point_3": value = user.ExtendedPoints[2]; break; case "point_4": value = user.ExtendedPoints[3]; break; case "point_5": value = user.ExtendedPoints[4]; break; case "point_6": value = user.ExtendedPoints[5]; break; case "point_7": value = user.ExtendedPoints[6]; break; case "point_8": value = user.ExtendedPoints[7]; break; #if !Passport case "totalonlinetime": value = user.TotalOnlineTime; break; #endif case "totaltopics": value = user.TotalTopics; break; case "totalposts": value = user.TotalPosts; break; case "deletedtopics": value = user.DeletedTopics; break; case "deletedreplies": value = user.DeletedReplies; break; case "valuedtopics": value = user.ValuedTopics; break; default: break; } for (int i = Levels.Count - 1; i > -1; i--) { MedalLevel medalLevel = Levels[i]; if (value >= medalLevel.Value) { if (tempMedalLevel == null) { return(medalLevel); } else if (medalLevel.Value > tempMedalLevel.Value)//与管理员颁发的 比较 返回等级大的 { return(medalLevel); } else { return(tempMedalLevel); } } } return(tempMedalLevel); }