public static async Task OnTitle(SocketGuildUser user, int titleId) { if (titleId == 0) { return; } // Kamtro God bool god = false; foreach (int i in NodeMap.Keys) { if (i == 0) { continue; } if (!UserDataManager.GetUserData(user).Titles.Contains(i)) { god = true; } } if (god) { await AddTitle(user, TitleIDs.KAMTRO_GOD); } }
public static async Task OnScore(SocketGuildUser user) { int s = UserDataManager.GetUserData(user).Score; // for titles if (s >= 1) { await AddTitle(user, TitleIDs.KAMTRO_SQUIRE); } if (s >= 10_000) { await AddTitle(user, TitleIDs.TALKATIVE); } if (s >= 50_000) { await AddTitle(user, TitleIDs.CHATTERBOX); } if (s >= 100_000) { await AddTitle(user, TitleIDs.REGULAR); } if (s >= 500_000) { await AddTitle(user, TitleIDs.KAMTRO_VETERAN); } }
public static async Task OnBuy(SocketGuildUser customer) { int spent = UserDataManager.GetUserData(customer).KamtrokensSpent; if (spent > 1) { await AddTitle(customer, TitleIDs.FIRST_BUY); } else if (spent > 50) { await AddTitle(customer, TitleIDs.SHOPPER); } else if (spent > 200) { await AddTitle(customer, TitleIDs.FRIDAY_EXPERT); } else if (spent > 1000) { await AddTitle(customer, TitleIDs.SHOPMASTER); } else { return; } UserDataManager.SaveUserData(); }
public static void LoadInventories() { string data = FileManager.ReadFullFile(DataFileNames.UserInventoriesFile); Dictionary <ulong, UserInventoryNode> UserInventories = JsonConvert.DeserializeObject <Dictionary <ulong, UserInventoryNode> >(data) ?? new Dictionary <ulong, UserInventoryNode>(); foreach (ulong id in UserInventories.Keys) { if (BotUtils.GetGUser(id) == null) { continue; } if (UserDataManager.UserData.ContainsKey(id)) { // User has a data file, things are all good UserDataManager.GetUserData(BotUtils.GetGUser(id)).Inventory = UserInventories[id]; } else { // wacky things are going on, create a user profile and then load inventory UserDataManager.AddUser(BotUtils.GetGUser(id)); UserDataManager.GetUserData(BotUtils.GetGUser(id)).Inventory = UserInventories[id]; } } KLog.Info("Loaded Inventories."); }
/// <summary> /// Method that checks for titles related to rep. Called whenever a user reps another user. /// </summary> /// <remarks> /// This method has a lot of checks, they are all there without return statements for a reason. /// It will make sure to fill in any missing titles the user should have gotten. /// </remarks> /// <param name="from">The user doing the repping</param> /// <param name="to">The user who has been repped</param> /// <returns></returns> public static async Task OnRep(SocketGuildUser from, SocketGuildUser to) { UserDataNode f = UserDataManager.GetUserData(from); UserDataNode t = UserDataManager.GetUserData(to); // rep given if (f.RepGiven >= 1) { await AddTitle(from, TitleIDs.WARM_WELCOMER); } if (f.RepGiven >= 10) { await AddTitle(from, TitleIDs.DECAREPPER); } if (f.RepGiven >= 50) { await AddTitle(from, TitleIDs.CHARITABLE); } if (f.RepGiven >= 100) { await AddTitle(from, TitleIDs.HUNDRED_REP_GIVEN); } if (f.RepGiven >= 500) { await AddTitle(from, TitleIDs.REPPER_OF_D); } // rep recieved if (t.Reputation >= 1) { await AddTitle(to, TitleIDs.WARMLY_WELCOMED); } if (t.Reputation >= 10) { await AddTitle(to, TitleIDs.TEN_REP); } if (t.Reputation >= 30) { await AddTitle(to, TitleIDs.COOL_KID); } if (t.Reputation >= 100) { await AddTitle(to, TitleIDs.POPULAR); } if (t.Reputation >= 1000) { await AddTitle(to, TitleIDs.MILLENIAL_MEMBER); } }
public static UserInventoryNode GetInventory(ulong userId) { UserDataManager.AddUserIfNotExists(BotUtils.GetGUser(userId)); if (UserDataManager.GetUserData(BotUtils.GetGUser(userId)).Inventory == null) { UserDataManager.GetUserData(BotUtils.GetGUser(userId)).Inventory = new UserInventoryNode(); SaveInventories(); } return(UserDataManager.GetUserData(BotUtils.GetGUser(userId)).Inventory); }
public static void SaveInventories() { Dictionary <ulong, UserInventoryNode> UserInventories = new Dictionary <ulong, UserInventoryNode>(); foreach (ulong i in UserDataManager.UserData.Keys) { if (BotUtils.GetGUser(i) == null) { continue; // null checking. } UserInventories.Add(i, UserDataManager.GetUserData(BotUtils.GetGUser(i)).Inventory ?? new UserInventoryNode()); } BotUtils.WriteToJson(UserInventories, DataFileNames.UserInventoriesFile); KLog.Info("Saved Inventories."); }
public static async Task AddTitle(SocketGuildUser user, int titleid) { if (!NodeMap.ContainsKey(titleid)) { KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} invalid title ID #{titleid}"); return; } TitleNode node = NodeMap[titleid]; if (node == null) { KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} null title with ID #{titleid}"); return; } UserDataNode u = UserDataManager.GetUserData(user); if (u.Titles == null) { u.Titles = new List <int>(); } if (u.Titles.Contains(titleid)) { return; // Don't give duplicate titles } u.Titles.Add(titleid); node.OnComplete(user); KLog.Important($"User {BotUtils.GetFullUsername(user)} has earned title {node.Name}"); UserDataManager.SaveUserData(); await AnnounceAchievement(user, node); }
public static bool HasTitleUnlocked(SocketGuildUser user, int title) { return(UserDataManager.GetUserData(user).Titles.Contains(title)); }