Beispiel #1
0
 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);
 }
Beispiel #2
0
        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();
        }
Beispiel #3
0
 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;
     }
 }
Beispiel #4
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);
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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());
        }