public async Task ProgressAchievementAsync(AchievementID id, IUserMessage msg, int progression, string key) { if (!_achievements.ContainsKey(id)) { _achievements.Add(id, new UserAchievement(AchievementList.GetAchievement(id), 0, new List <string>())); } var achievement = _achievements[id]; int oldLevel = achievement.GetLevel(); achievement.AddProgression(progression, key); int newLevel = achievement.GetLevel(); if (newLevel > oldLevel) { IEmote emote; if (newLevel == 3) { emote = new Emoji("🥇"); // Gold } else if (newLevel == 2) { emote = new Emoji("🥈"); // Silver } else { emote = new Emoji("🥉"); // Copper } await msg?.AddReactionAsync(emote); Program.p.db.UpdateProfile(this); } }
public List <(System.Drawing.Image, int)> GetAchievements() { List <(System.Drawing.Image, int)> all = new List <(System.Drawing.Image, int)>(); foreach (var a in _achievements.OrderBy(x => x.Key)) { if (a.Value.GetLevel() > 0) { all.Add((System.Drawing.Image.FromStream(AchievementList.GetAchievementStream(a.Value.GetFilePath())), a.Value.GetLevel())); } } return(all); }
/// <summary> /// Create profile from db /// </summary> /// <param name="json"></param> public Profile(ulong id, JObject token) { _id = id; _visibility = (Visibility)token["Visibility"].Value <int>(); _username = token["Username"].Value <string>(); _discriminator = token["Discriminator"].Value <string>(); _friends = token["Friends"].Value <string>().Length > 0 ? token["Friends"].Value <string>().Split(',').Select(x => ulong.Parse(x)).ToList() : new List <ulong>(); _description = token["Description"].Value <string>(); _achievements = token["Achievements"].Value <string>().Length > 0 ? token["Achievements"].Value <string>().Split('|').Select((x) => { var split = x.Split(','); var a_id = (AchievementID)int.Parse(split[0]); return(new KeyValuePair <AchievementID, UserAchievement>(a_id, new UserAchievement(AchievementList.GetAchievement(a_id), int.Parse(split[1]), split.Skip(2).ToList()))); }).ToDictionary(x => x.Key, x => x.Value) : new Dictionary <AchievementID, UserAchievement>(); _creationDate = DateTime.ParseExact(token["CreationDate"].Value <string>(), "yyMMddHHmmss", CultureInfo.InvariantCulture); var colorString = token["BackgroundColor"].Value <string>().Split(','); _backgroundColor = System.Drawing.Color.FromArgb(int.Parse(colorString[0]), int.Parse(colorString[1]), int.Parse(colorString[2])); }