/// <summary> /// Translates Sequence contents into human readable formats and Decimal representations. Contains game ID, but not sequence. /// </summary> /// <returns></returns> public Dictionary <string, string> MakeHumanReadable(bool getUsername = false) { if (this.status == Status.Uninitialized) { return(null); } Dictionary <string, string> x = new Dictionary <string, string>(); x.Add("Game", gameName[0].ToString().ToUpper() + gameName.Substring(1)); //x.Add("Iteration", gameIteration.ToString()); x.Add("Game ID", gameID); x.Add("Time", playedTime.AddHours(-Defs.EST_OFFSET).ToString("yyyy MMMM dd") + ", " + playedTime.AddHours(-Defs.EST_OFFSET).ToString("HH:mm") + " EST"); int i = 1; foreach (var player in Players) { if (getUsername) { x.Add("Player " + i, GuildCache.GetUsername(player.Item1) + " (" + player.Item1.ToString() + ")"); } else { x.Add("Player " + i + " ID", player.Item1.ToString()); } x.Add("Player " + i + " Points", player.Item2.ToString()); i++; } return(x); }
public static bool NewDay(SocketTextChannel channel) { channel.SendMessageAsync("`Resetting user daily limits...`"); List <string> PLAYSTODAY_TYPES = new List <string>(); foreach (var keyValue in UnoSaveFields) { if (keyValue.Key.StartsWith("PLAYSTODAY")) { PLAYSTODAY_TYPES.Add(keyValue.Key); } } var directories = Directory.EnumerateDirectories(USER_SAVE_DIRECTORY); foreach (var user in directories) { foreach (var playsToday in PLAYSTODAY_TYPES) { try { SaveFiles_Mapped.ModifyFieldValue(playsToday, user + "\\" + UNO_SAVE_FILE_NAME, "0"); }catch { /*file did not exist, move on*/ } } } channel.SendMessageAsync("`Storing metadata statistics...`"); GuildCache.LogCMD(); channel.SendMessageAsync("`Complete.`"); return(true); }
public static bool CreateUnoSaveFiles(SocketGuildUser user, string directory) { CreateMappedSaveFileFields(directory + "\\" + UNO_SAVE_FILE_NAME, UnoSaveFields); CreateMappedSaveFileFields(directory + "\\FN" + FORTNIGHT_NUMBER + "_" + UNO_SAVE_FILE_NAME, UnoSaveFields); ModifyFieldValue("LIT-TEAM", directory + "\\" + UNO_SAVE_FILE_NAME, GuildCache.GetTeam(user)); ModifyFieldValue("LIT-TEAM", directory + "\\FN" + FORTNIGHT_NUMBER + "_" + UNO_SAVE_FILE_NAME, GuildCache.GetTeam(user)); return(true); }
public SavedLeaderboard(string key, string[] leaderboardFile, Scoring type = Scoring.Points, short fortnightNo = -1, ulong teamspecific = 0) { this.scoringType = type; this.KEY = key; string[] temp; string team, username; team = ""; username = ""; int score = 0; this.FORTNIGHT_NO = fortnightNo; RESULTS = new List <LBUser>(); this.teamspecific = teamspecific; try { foreach (string str in leaderboardFile) { temp = str.Split(':'); if (temp.Count() != 2) { throw new Exception(); } ulong ID = 0; ID = UInt64.Parse(temp[0]); if (ID == 447487261760552982) { //dummy account which defaults to null, shouldn't appear on lb continue; } team = GuildCache.GetTeam(ID) ?? "?"; if (team == "?") { team = SaveFiles_Mapped.SearchCachedTeam(ID) ?? "?"; } if (teamspecific != 0) { if (team != teamspecific.ToString()) { continue; } } username = GuildCache.GetUsername(ID) ?? "?"; score = Int32.Parse(temp[1]); RESULTS.Add(new LBUser(ID, username, team, score)); } } catch (Exception e) { throw e; } CalculateTeamScores(); if (key == "POINTS-SERVER" && fortnightNo == FORTNIGHT_NUMBER && teamspecific == 0) { GuildCache.SetTeamScore(RED_TEAM_SCORE, 1); GuildCache.SetTeamScore(YELLOW_TEAM_SCORE, 2); GuildCache.SetTeamScore(GREEN_TEAM_SCORE, 3); GuildCache.SetTeamScore(BLUE_TEAM_SCORE, 4); } SortLeaderboard(); }
public Player(string ID, string username, string discrim, bool won, byte ranking, int cardsPlayed = 0, string team = "") { this.ID = ID; this.name = username + "#" + discrim; this.won = won; this.ranking = ranking; this.noOfCardsPlayed = cardsPlayed; if (team == "") { team = GuildCache.GetTeam(GuildCache.GetUserByID(UInt64.Parse(ID))) ?? "?"; } else { this.team = team; } }
public static void LogCMD() { string date = ""; if (DateTime.Now.TimeOfDay.TotalMinutes > 180) { date = SaveFiles_Sequences.GenerateDateHex().Substring(0, 3); } else { date = (Int32.Parse(SaveFiles_Sequences.GenerateDateHex().Substring(0, 3), NumberStyles.HexNumber) - 0x1).ToString(); } SaveFiles_Mapped.AddLine(COMMANDS_BY_DATE_DIRECTORY, date, cmdEx.ToString()); cmdEx = 0; GuildCache.IncrementCMD(0); }
private static List <Player> DeterminePlayerTeams(List <Player> o) { foreach (Player player in o) { ulong ID; try { ID = UInt64.Parse(player.ID); } catch { continue; } string rolesubs = GuildCache.GetTeam(ID) ?? null; if (rolesubs == null) { player.team = "none"; continue; } player.team = rolesubs; } return(o); }
public static string InterpretScoreInputAndGetPlacementInfo(string args, ulong requesterID = 0) { args.ToLower(); string GAME_TYPE = ""; short FORTNIGHT = FORTNIGHT_NUMBER; try { if (args.Contains("overall")) { FORTNIGHT = -1; args = args.Replace("overall", ""); } else if (Regex.IsMatch(args, @"(fn|fortnight)\s?(\d{1,2})(\D|$)", RegexOptions.IgnoreCase)) { string fnNo = Regex.Match(args, @"(fn|fortnight)\s?(\d{1,2})(\D|$)").Groups[2].ToString(); FORTNIGHT = Int16.Parse(fnNo); if (FORTNIGHT >= 0 && FORTNIGHT < 13) { return("Individual tracking before Fortnight 13 is not available. Reference <#490300319729713172>."); } if (FORTNIGHT > FORTNIGHT_NUMBER) { return("The server is on Fortnight " + FORTNIGHT_NUMBER + ", and does not have tracking for future fortnights yet, silly goose."); } args = args.Replace("fn" + fnNo, ""); args = args.Replace("fn " + fnNo, ""); } string[] gameTypes = { "cah", "uno", "ms", "tetris", "bumps", "idlerpg", "pokeduel", "bingo", "chess", "tourney", "tournament", "casino", "minesweeper", "idle", "poke", "knight", "knights", "trivia" }; foreach (string gameType in gameTypes) { if (args.Contains(gameType)) { GAME_TYPE = gameType; args = args.Replace(gameType, ""); break; } } if (GAME_TYPE == "") { GAME_TYPE = "server"; } List <SocketGuildUser> x = new List <SocketGuildUser>(); bool local = false; if (args != "") { x = GuildCache.InterpretUserInput(args); } else if (requesterID != 0) { x = GuildCache.InterpretUserInput(requesterID.ToString()); local = true; } else { throw new Exception(); } if (x == null) { return("User not found."); } if (x.Count() == 0) { return("User not found."); } ulong userID = x[0].Id; string res; try { switch (GAME_TYPE) { case "server": res = GetUserScore("SERVER", userID, "POINTS", "Server", FORTNIGHT, local); break; case "uno": res = GetUserScore("UNO", userID, "FIRST", "First-place Uno!", FORTNIGHT, local); break; case "cah": res = GetUserScore("CAH", userID, "FIRST", "CAH", FORTNIGHT, local); break; case "bingo": res = GetUserScore("BINGO", userID, "HIGH", "Bingo", FORTNIGHT, local); break; case "ms": case "minesweeper": res = GetUserScore("MS", userID, "ITER", "Minesweeper", FORTNIGHT, local); break; case "tetris": res = GetUserScore("TETRIS", userID, "HIGH", "Tetris", FORTNIGHT, local); break; case "pokeduel": case "poke": res = GetUserScore("POKEDUEL", userID, "ITER", "Pokeduels", FORTNIGHT, local); break; case "idlerpg": case "idle": res = GetUserScore("IDLERPG", userID, "ITER", "IdleRPG duels", FORTNIGHT, local); break; case "chess": res = GetUserScore("CHESS", userID, "ITER", "Chess", FORTNIGHT, local); break; case "bumps": res = GetUserScore("BUMPS", userID, "ITER", "Bumps", FORTNIGHT, local); break; case "casino": res = GetUserScore("CASINO", userID, "POINTS", "Casino points", FORTNIGHT, local); break; case "tourney": case "tournament": res = GetUserScore("TOURNEY", userID, "POINTS", "Tourney points", FORTNIGHT, local); break; case "knight": case "knights": res = GetUserScore("KNIGHTS", userID, "ITER", "Knights", FORTNIGHT, local); break; case "trivia": res = GetUserScore("KNIGHTS", userID, "ITER", "Knights", FORTNIGHT, local); break; default: throw new Exception("Game not found"); } if (res == null) { throw new Exception("Leaderboard not found"); } } catch (Exception e) { return(e.Message + "\n" + e.StackTrace); } return(res); } catch (Exception e) { return(e.Message + "\n" + e.StackTrace); } }
public static Task CAHLog(string message, bool force = false) { byte noOfPlayers = 0; if (Byte.TryParse(message.Trim().Substring(0, message.IndexOf(" ")), out byte ignore)) { noOfPlayers = Byte.Parse(message.Trim().Substring(0, message.IndexOf(" "))); } else if (message.IndexOf("\n") != -1) { if (Byte.TryParse(message.Trim().Substring(0, message.IndexOf("\n")), out byte ignore2)) { noOfPlayers = Byte.Parse(message.Trim().Substring(0, message.IndexOf("\n"))); } } List <Tuple <SocketGuildUser, bool> > users; try { users = GuildCache.InterpretUserInputWithTies(message); } catch (Exception e) { throw e; } if (users.Where(x => x.Item1 == null).Count() >= 1) { string list = "`"; foreach (var user in users) { list += (user.Item1?.Username ?? "NULL") + ", "; } list += "`"; throw new Exception(":exclamation: At least one user was invalid.\n " + list); } if (noOfPlayers == 0) { noOfPlayers = (byte)users.Count(); } if (!force) { string lastTeam = GuildCache.GetTeam(users[0].Item1); bool qualifiable = false; foreach (var keyvalue in users) { var player = keyvalue.Item1; if (GuildCache.GetTeam(player) != lastTeam) { qualifiable = true; break; } } if (!qualifiable) { throw new Exception("Game is not qualifiable for logging (one team)."); } } List <Tuple <ulong, byte> > orderedPairs = new List <Tuple <ulong, byte> >(); byte maxReward = (byte)(noOfPlayers * 5); byte lastReward = maxReward; for (int currIndex = 0; currIndex < users.Count(); currIndex++) { var pair = users[currIndex]; if (pair.Item2 == false) { //not a tie, return to normal if (maxReward - (currIndex * 5) <= 0) { lastReward = 5; } else { lastReward = (byte)(maxReward - (currIndex * 5)); } orderedPairs.Add(new Tuple <ulong, byte>(pair.Item1.Id, (byte)(lastReward))); } else { //tie, use last reward orderedPairs.Add(new Tuple <ulong, byte>(pair.Item1.Id, (byte)(lastReward))); } } Bridge.LogGame("cah", orderedPairs); int q = 0; foreach (var orderedPair in orderedPairs) { SaveFileUpdate(orderedPair, "cah"); if (q == 0) { string saveDir = USER_SAVE_DIRECTORY + "\\" + orderedPair.Item1.ToString() + "\\" + UNO_SAVE_FILE_NAME; string FNsaveDir = USER_SAVE_DIRECTORY + "\\" + orderedPair.Item1.ToString() + "\\" + "FN" + FORTNIGHT_NUMBER + "_" + UNO_SAVE_FILE_NAME; AddFieldValue("FIRST-CAH", saveDir, "1"); AddFieldValue("FIRST-CAH", FNsaveDir, "1"); } q++; } return(Task.CompletedTask); }
public static Task ManualUnoLog(string message, bool force = false, bool manual = false, byte manualnoofplayers = 3) { string playerStrArr = message; byte noOfPlayers = manualnoofplayers; if (!manual) { playerStrArr = ""; noOfPlayers = 0; if (Byte.TryParse(message.Trim().Substring(0, message.IndexOf(" ")), out byte ignore)) { noOfPlayers = Byte.Parse(message.Trim().Substring(0, message.IndexOf(" "))); } else if (message.IndexOf("\n") != -1) { if (Byte.TryParse(message.Trim().Substring(0, message.IndexOf("\n")), out byte ignore2)) { noOfPlayers = Byte.Parse(message.Trim().Substring(0, message.IndexOf("\n"))); } } for (int i = 1; i <= 100; i++) { if (message.IndexOf(i + ". ") != -1 && message.IndexOf((i + 1) + ". ") != -1) { int start = message.IndexOf((i) + ". ") + ((i + 1) + ". ").Length; int end = message.IndexOf(i + 1 + ". "); var captureArea = message.Substring(start, end - start); playerStrArr += captureArea + ","; message = message.Substring(message.IndexOf(i + 1 + ". ")); } else if (message.IndexOf(i + ". ") != -1) { int start = message.IndexOf((i) + ". ") + ((i + 1) + ". ").Length; if (message.Contains("\n")) { if (start < message.IndexOf("\n")) { var captureArea = message.Substring(start, message.IndexOf("\n") - start); playerStrArr += captureArea; } break; } else if (message.Contains("This game lasted")) { var captureArea = message.Substring(start, message.IndexOf("This game lasted") - start); playerStrArr += captureArea; break; } else { var captureArea = message.Substring(start); playerStrArr += captureArea; break; } } } playerStrArr = playerStrArr.Replace("\n", ""); if (playerStrArr == "" || ((playerStrArr.Count(x => x == ',') < MIN_NO_OF_PLAYERS - 1) && noOfPlayers == 0)) { //throw new Exception("Minimum number of players was not met for logging."); } } var users = GuildCache.InterpretUserInput(playerStrArr); if (GuildCache.IsWellFormattedListOfUsers(users) != "") { string list = "`"; foreach (var user in users) { list += (user?.Username ?? "NULL") + ", "; } list += "`"; throw new Exception("Malformatted set of users: " + list); } List <Player> players = new List <Player>(); foreach (var user in users) { players.Add(new Player(user.Id.ToString(), user.Username, user.Discriminator, true, 1, 0, GuildCache.GetTeam(user) ?? "")); } if (noOfPlayers == 0) { noOfPlayers = (byte)players.Count(); } players = DeterminePointDistribution(players, noOfPlayers); if (!force) { if (!IsGameQualifable(players)) { throw new Exception("Each player was of the same team, rendering the game unqualifiable."); } } if (noOfPlayers == 2) { try { Games_1v1.Uno1v1Log(players.Select(x => UInt64.Parse(x.ID)).ToList()); return(Task.CompletedTask); }catch (Exception e) { throw e; } } List <Tuple <ulong, byte> > orderedPairs = new List <Tuple <ulong, byte> >(); foreach (Player p in players) { orderedPairs.Add(new Tuple <ulong, byte>(UInt64.Parse(p.ID), (byte)p.pointsEarned)); } Bridge.LogGame("uno", orderedPairs); int q = 0; foreach (var orderedPair in orderedPairs) { SaveFileUpdate(orderedPair, "uno"); if (q == 0) { string saveDir = USER_SAVE_DIRECTORY + "\\" + players[0].ID.ToString() + "\\" + UNO_SAVE_FILE_NAME; string FNsaveDir = USER_SAVE_DIRECTORY + "\\" + players[0].ID.ToString() + "\\" + "FN" + FORTNIGHT_NUMBER + "_" + UNO_SAVE_FILE_NAME; AddFieldValue("FIRST-UNO", saveDir, "1"); AddFieldValue("FIRST-UNO", FNsaveDir, "1"); if (Int32.Parse(SearchValue(saveDir, "HIGH-UNO")) < players[0].pointsEarned) { SetFieldValue("HIGH-UNO", saveDir, players[0].pointsEarned.ToString()); } if (Int32.Parse(SearchValue(FNsaveDir, "HIGH-UNO")) < players[0].pointsEarned) { SetFieldValue("HIGH-UNO", FNsaveDir, players[0].pointsEarned.ToString()); } } q++; } return(Task.CompletedTask); }
public static Task ONWLog(string message, bool force = false) { /* Yet to be tested on main release */ List <Tuple <SocketGuildUser, bool> > users; try { users = GuildCache.InterpretUserInputWithTies(message); } catch (Exception e) { throw e; } if (users.Where(x => x.Item1 == null).Count() >= 1) { string list = "`"; foreach (var user in users) { list += (user.Item1?.Username ?? "NULL") + ", "; } list += "`"; throw new Exception(":exclamation: At least one user was invalid.\n " + list); } byte noOfPlayers = (byte)users.Count(); if (!force) { string lastTeam = GuildCache.GetTeam(users[0].Item1); bool qualifiable = false; foreach (var keyvalue in users) { var player = keyvalue.Item1; if (GuildCache.GetTeam(player) != lastTeam) { qualifiable = true; break; } } if (!qualifiable) { throw new Exception("Game is not qualifiable for logging (one team)."); } } List <Tuple <ulong, byte> > orderedPairs = new List <Tuple <ulong, byte> >(); byte lastReward = noOfPlayers; //initially set to highReward value byte lowReward = (byte)(noOfPlayers / 2); for (int currIndex = 0; currIndex < users.Count(); currIndex++) { var pair = users[currIndex]; if (pair.Item2 == false) { //not a tie, swap to low reward lastReward = lowReward; orderedPairs.Add(new Tuple <ulong, byte>(pair.Item1.Id, (byte)(lastReward))); } else { //tie, use last reward orderedPairs.Add(new Tuple <ulong, byte>(pair.Item1.Id, (byte)(lastReward))); } } // Bridge.LogGame("onw", orderedPairs); int q = 0; foreach (var orderedPair in orderedPairs) { SaveFileUpdate(orderedPair, "onw"); if (users[q].Item2 == true) { string saveDir = USER_SAVE_DIRECTORY + "\\" + orderedPair.Item1.ToString() + "\\" + UNO_SAVE_FILE_NAME; string FNsaveDir = USER_SAVE_DIRECTORY + "\\" + orderedPair.Item1.ToString() + "\\" + "FN" + FORTNIGHT_NUMBER + "_" + UNO_SAVE_FILE_NAME; AddFieldValue("FIRST-ONW", saveDir, "1"); AddFieldValue("FIRST-ONW", FNsaveDir, "1"); } q++; } return(Task.CompletedTask); }
public Embed GetEmbed(bool includeBadges = false) { EmbedBuilder emb = new EmbedBuilder(); GetPlacements(); if (stats.ContainsKey("LIT-TEAM")) { if (stats["LIT-TEAM"] == TEAM_ONE_ID.ToString()) { emb.WithColor(255, 179, 186); } else if (stats["LIT-TEAM"] == TEAM_TWO_ID.ToString()) { emb.WithColor(8, 255, 0); } else if (stats["LIT-TEAM"] == WILD_ID.ToString()) { emb.WithColor(0, 0, 0); } else { var team = GuildCache.GetTeam(USER_ID); if (team == TEAM_ONE_ID.ToString()) { emb.WithColor(255, 179, 186); } else if (team == TEAM_TWO_ID.ToString()) { emb.WithColor(8, 255, 0); } else if (team == WILD_ID.ToString()) { emb.WithColor(0, 0, 0); } else { emb.WithColor(178, 178, 178); } } } if (stats.ContainsKey("LIT-CUSTOMCOLOR")) { var hexColor = stats["LIT-CUSTOMCOLOR"]; if (hexColor != "-" && Int32.TryParse(hexColor, System.Globalization.NumberStyles.HexNumber, null, out int ignore)) { if (Int32.Parse(hexColor, System.Globalization.NumberStyles.HexNumber) < 0xFFFFFF) { emb.WithColor(Byte.Parse(hexColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), Byte.Parse(hexColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), Byte.Parse(hexColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)); } } } var url = GuildCache.GetUserByID(USER_ID)?.GetAvatarUrl(); emb.WithThumbnailUrl(url); StringBuilder toBeEarned = new StringBuilder(); foreach (var stat in stats) { if (!stat.Key.StartsWith("LIT")) { if (placement.ContainsKey(stat.Key)) { if (stat.Value == "0") { string add = RemoveEmojis(desiredFields[stat.Key]); toBeEarned.Append(", " + add); continue; } //emb.AddField(desiredFields[stat.Key], stat.Value + "(" + (placement[stat.Key] + 1) + "th)",true); emb.AddField(desiredFields[stat.Key], stat.Value, true); } else { if (stat.Value == "0") { string add = RemoveEmojis(desiredFields[stat.Key]); toBeEarned.Append(", " + add); continue; } emb.AddField(desiredFields[stat.Key], stat.Value, true); } } } string tBE = toBeEarned.ToString(); if (tBE.Length > 1) { emb.WithFooter("Still to be earned: " + tBE.Substring(1)); } return(emb.Build()); }