Пример #1
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);
        }
Пример #2
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);
        }