Beispiel #1
0
        public static string getPlaylistText(FilteredPlaylist playlist, IndexMode indexMode, string levelFormat)
        {
            string          pageString = getPlaylistPageText(playlist);
            CalculateResult levels     = playlist.Calculate();
            string          levelList  = "";

            for (int i = 0; i < Math.Min(levels.allowedList.Count, FilteredPlaylist.pageSize); i++)
            {
                var levelIndex = indexMode == IndexMode.Initial ? levels.allowedList[i].index : i;
                levelList += GeneralUtilities.formatLevelInfoText(levels.allowedList[i].level, levelIndex, levelFormat) + "\n";
            }
            if (pageString != null)
            {
                levelList += $"[FFFFFF]Page {pageString}[-]";
            }
            else if (levels.allowedList.Count > FilteredPlaylist.pageSize)
            {
                levelList += $"[FFFFFF]and {levels.allowedList.Count - FilteredPlaylist.pageSize} more[-]";
            }
            else
            {
                levelList = levelList.Substring(0, levelList.Length - 1);
            }
            return(levelList);
        }
Beispiel #2
0
        public static string getPlaylistPageText(FilteredPlaylist playlist)
        {
            List <int> removeIndexes = new List <int>();
            List <int> pages         = new List <int>();

            for (int i = playlist.filters.Count - 1; i >= 0; i--)
            {
                if (playlist.filters[i] is LevelFilterPage)
                {
                    var filter = (LevelFilterPage)playlist.filters[i];
                    if (filter.comparison.comparison == IntComparison.Comparison.Equal)
                    {
                        if (filter.mode == LevelFilter.Mode.And)
                        {
                            pages.Clear();
                            pages.Add(filter.comparison.number);
                            removeIndexes.Add(i);
                            break;
                        }
                        else if (filter.mode == LevelFilter.Mode.Or)
                        {
                            pages.Insert(0, filter.comparison.number);
                            removeIndexes.Add(i);
                        }
                        else
                        {
                            break; // using `Not` will make things too unpredictable
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (playlist.filters[i] is LevelSortFilter)
                {
                    break; // anything before a sort filter is not guaranteed to be in the same place now
                }
            }
            if (pages.Count == 0)
            {
                pages.Add(1);
            }
            var newFilters = new List <LevelFilter>(playlist.filters);
            foreach (int index in removeIndexes)
            {
                newFilters.RemoveAt(index);
            }
            var newPlaylist          = new FilteredPlaylist(playlist.CopyModeAndLevelInfos(), newFilters);
            var unpagedList          = newPlaylist.Calculate();
            var totalPages           = Math.Ceiling((double)unpagedList.levelList.Count / (double)FilteredPlaylist.pageSize);
            string currentPageString = "";
            foreach (var page in pages)
            {
                currentPageString += page + ",";
            }
            currentPageString = currentPageString.Substring(0, currentPageString.Length - 1);
            return(currentPageString + "/" + totalPages);
        }
Beispiel #3
0
        public static List <LevelPlaylist.ModeAndLevelInfo> getFilteredLevels(ClientPlayerInfo p, string input)
        {
            var playlist = new FilteredPlaylist(getAllLevelsAndModes());
            var failures = addFiltersToPlaylist(playlist, p, input, true);

            sendFailures(failures, 4);
            return(playlist.Calculate().levelList);
        }
Beispiel #4
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (message == "")
            {
                help(p);
                return;
            }

            FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());

            if (!p.IsLocal_)
            {
                PlayCmd playCmd = Cmd.all.getCommand <PlayCmd>("play");
                filterer.AddFiltersFromString(playCmd.playFilter);
            }

            MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
            GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, message, true), 4);
            MessageUtilities.popMessageOptions();

            var levels = filterer.Calculate();

            if (levels.levelList.Count == 0)
            {
                MessageUtilities.sendMessage(p, "No levels found.");
                return;
            }
            var level = levels.allowedList[0];

            MessageUtilities.sendMessage(p, GeneralUtilities.formatLevelInfoText(level.level, level.index, infoFormat));

            if (levels.levelList.Count > 1)
            {
                MessageUtilities.sendMessage(p, $"Found {levels.levelList.Count - 1} more levels.");
            }
        }
Beispiel #5
0
        public override void use(ClientPlayerInfo p, string message)
        {
            if (message == "")
            {
                help(p);
                return;
            }

            if (useVote && !p.IsLocal_)  // host can always force play, never uses vote.
            {
                Cmd.all.getCommand <VoteHandler.VoteCMD>("vote").forceNextUse();
                Cmd.all.getCommand <VoteHandler.VoteCMD>("vote").use(p, "y play " + message);
                return;
            }

            if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify)
            {
                MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify.");
                return;
            }

            FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());

            if (!p.IsLocal_)
            {
                filterer.AddFiltersFromString(playFilter);
            }

            MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
            GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, message, true), 4);
            MessageUtilities.popMessageOptions();

            var list = filterer.Calculate().levelList;

            if (list.Count == 0)
            {
                MessageUtilities.sendMessage(p, "Can't find a level with the filter '" + message + "'.");
                return;
            }

            LevelPlaylist playlist = new LevelPlaylist();

            playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_);

            var     currentPlaylist = playlist.Playlist_;
            AutoCmd autoCmd         = Cmd.all.getCommand <AutoCmd>("auto");
            int     origIndex       = G.Sys.GameManager_.LevelPlaylist_.Index_;
            int     index           = autoCmd.getInsertIndex();

            var maxPerRoundLocal = 0;

            if (p.IsLocal_ || maxPerRound <= 0)
            {
                maxPerRoundLocal = int.MaxValue;
            }
            else
            {
                maxPerRoundLocal = maxPerRound;
            }

            var maxPerCmdLocal = 0;

            if (p.IsLocal_ || maxPerCmd <= 0)
            {
                maxPerCmdLocal = int.MaxValue;
            }
            else
            {
                maxPerCmdLocal = maxPerCmd;
            }

            var countCmd = 0;

            var countRound = 0;

            playerVotesThisRound.TryGetValue(GeneralUtilities.getUniquePlayerString(p), out countRound);

            string lvlsStr = "";

            foreach (var lvl in list)
            {
                if (countRound + 1 > maxPerRoundLocal)
                {
                    MessageUtilities.sendMessage(p, $"You have reached the maximum amount of maps you can add per round ({maxPerRound})");
                    break;
                }
                if (countCmd + 1 > maxPerCmdLocal)
                {
                    MessageUtilities.sendMessage(p, "You have reached the maximum amount of maps you can add per " + GeneralUtilities.formatCmd("!play") + $" ({maxPerCmd})");
                    break;
                }
                countRound++;
                countCmd++;
                if (countCmd <= 10)
                {
                    lvlsStr += lvl.levelNameAndPath_.levelName_ + ", ";
                }
                currentPlaylist.Insert(index + countCmd - 1, lvl);
            }
            playerVotesThisRound[GeneralUtilities.getUniquePlayerString(p)] = countRound;

            if (countCmd > 0)
            {
                G.Sys.GameManager_.LevelPlaylist_.Clear();

                foreach (var lvl in currentPlaylist)
                {
                    G.Sys.GameManager_.LevelPlaylist_.Add(lvl);
                }
                G.Sys.GameManager_.LevelPlaylist_.SetIndex(origIndex);

                lvlsStr = lvlsStr.Substring(0, lvlsStr.Count() - 2);
                if (countCmd > 10)
                {
                    lvlsStr = lvlsStr + $" and {countCmd - 10} more";
                }

                if (p.IsLocal_)
                {
                    MessageUtilities.sendMessage(p, "Level(s) " + lvlsStr + " added to the playlist !");
                }
                else
                {
                    MessageUtilities.sendMessage("Level(s) " + lvlsStr + " added to the playlist by " + p.GetChatName() + "!");
                }
            }
        }
Beispiel #6
0
        public override void use(ClientPlayerInfo p, string message)
        {
            Match playlistCmdMatch = Regex.Match(message, @"^(\w+) ?(.*)$");

            if (!playlistCmdMatch.Success)
            {
                help(p);
                return;
            }
            string uniquePlayerString = GeneralUtilities.getUniquePlayerString(p);
            string filterCmd          = playlistCmdMatch.Groups[1].Value.ToLower();
            string filterCmdData      = playlistCmdMatch.Groups[2].Value;

            switch (filterCmd)
            {
            default:
                MessageUtilities.sendMessage(p, $"[A00000]Invalid sub-command `{filterCmd}`[-]");
                help(p);
                break;

            case "list":
            {
                var searchRegex = GeneralUtilities.getSearchRegex(filterCmdData);
                var results     = "";
                foreach (KeyValuePair <string, string> pair in savedFilters)
                {
                    if (Regex.IsMatch(pair.Key, searchRegex, RegexOptions.IgnoreCase))
                    {
                        results += "\n" + pair.Key;
                    }
                }
                if (results.Length == 0)
                {
                    results = " None";
                }
                MessageUtilities.sendMessage(p, "[FFFFFF]Found:[-]" + results);
                break;
            }

            case "save":
            {
                Match nameFilterMatch = Regex.Match(filterCmdData, @"^(.+?)\s+(.*)$");
                if (!playlistCmdMatch.Success)
                {
                    MessageUtilities.sendMessage(p, "[A00000]Bad format for save[-]");
                    help(p);
                    return;
                }
                var saveAt     = nameFilterMatch.Groups[1].Value;
                var saveFilter = nameFilterMatch.Groups[2].Value;
                if (saveAt == "")
                {
                    MessageUtilities.sendMessage(p, "[A00000]Name required[-]");
                    help(p);
                    return;
                }
                else if (saveFilter == "")
                {
                    MessageUtilities.sendMessage(p, "[A00000]Filter required[-]");
                    help(p);
                    return;
                }
                savedFilters[saveAt] = saveFilter;
                Entry.save();
                PlaylistTools.LevelFilters.LevelFilterLast.SetActivePlayer(p);
                var result = FilteredPlaylist.ParseFiltersFromString(saveFilter);
                if (!result.value.Any(filter => filter is PlaylistTools.LevelFilters.LevelFilterLast))
                {
                    PlaylistTools.LevelFilters.LevelFilterLast.SaveFilter(p, saveFilter);
                }
                else
                {
                    MessageUtilities.sendMessage(p, "[FFA000]The filter -last will always pull from your last-used filter "
                                                 + "and does not have a consistent value. If you want to save your last used filter, "
                                                 + "you will need to re-type it.");
                }
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
                GeneralUtilities.sendFailures(result.failures, 4);
                MessageUtilities.popMessageOptions();
                MessageUtilities.sendMessage(p, $"Saved filter to [FFFFFF]{saveAt}[-]:\n[FFFFFF]{saveFilter}[-]");
                break;
            }

            case "del":
            {
                if (filterCmdData == "")
                {
                    MessageUtilities.sendMessage(p, "[A00000]You must enter a name[-]");
                    break;
                }
                List <string> toDelete;
                var           count = 0;
                if (deleteConfirmation.TryGetValue(uniquePlayerString, out toDelete))
                {
                    if (filterCmdData.ToLower() == "yes")
                    {
                        foreach (string filterName in toDelete)
                        {
                            savedFilters.Remove(filterName);
                            count++;
                        }
                        MessageUtilities.sendMessage(p, $"Deleted {count} filters.");
                        deleteConfirmation.Remove(uniquePlayerString);
                        Entry.save();
                        break;
                    }
                    else if (filterCmdData.ToLower() == "no")
                    {
                        deleteConfirmation.Remove(uniquePlayerString);
                        MessageUtilities.sendMessage(p, "Cancelled deletion.");
                        break;
                    }
                }
                var searchRegex = GeneralUtilities.getSearchRegex(filterCmdData);
                toDelete = new List <string>();
                var results = "";
                foreach (KeyValuePair <string, string> pair in savedFilters)
                {
                    if (Regex.IsMatch(pair.Key, searchRegex, RegexOptions.IgnoreCase))
                    {
                        toDelete.Add(pair.Key);
                        results += "\n" + pair.Key;
                        count++;
                    }
                }
                if (count > 0)
                {
                    deleteConfirmation[uniquePlayerString] = toDelete;
                    MessageUtilities.sendMessage(p, $"[FFFFFF]Use [A05000]!filter del yes[-] to delete {count} filters:[-] {results}");
                }
                else
                {
                    MessageUtilities.sendMessage(p, "[A00000]No filters found[-]");
                }
            }
            break;

            case "show":
            {
                var searchRegex = GeneralUtilities.getSearchRegex(filterCmdData);
                var results     = "";
                foreach (KeyValuePair <string, string> pair in savedFilters)
                {
                    if (Regex.IsMatch(pair.Key, searchRegex, RegexOptions.IgnoreCase))
                    {
                        results += $"\n{pair.Key}[FFFFFF]:[-] {pair.Value}";
                    }
                }
                if (results.Length == 0)
                {
                    results = " None";
                }
                MessageUtilities.sendMessage(p, "[FFFFFF]Found:[-]" + results);
                break;
            }

            case "current":
            {
                PlaylistCmd playlistCmd = Cmd.all.getCommand <PlaylistCmd>("playlist");
                if (!playlistCmd.canUseCurrentPlaylist)
                {
                    MessageUtilities.sendMessage(p, "Cannot modify current playlist right now.");
                    break;
                }
                Console.WriteLine($"Filter txt: {filterCmdData}");
                // 1. load current playlist into filter
                LevelPlaylist    currentList = G.Sys.GameManager_.LevelPlaylist_;
                FilteredPlaylist preFilterer = new FilteredPlaylist(currentList.Playlist_);
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
                GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(preFilterer, p, filterCmdData, false), 4);
                MessageUtilities.popMessageOptions();
                // 2. add filter that always allows the current level and helps us find it after calculation.
                var indexFilter = new ForceCurrentIndexFilter(currentList.Index_);
                preFilterer.AddFilter(indexFilter);
                // 3. Calculate filter results.
                CalculateResult levels = preFilterer.Calculate();
                // 4. Update current playlist
                currentList.Playlist_.Clear();
                currentList.Playlist_.AddRange(levels.levelList);
                // 4. Get current level index, set playlist index to current level index
                if (indexFilter.level != null)
                {
                    int index = levels.levelList.IndexOf(indexFilter.level);
                    if (index >= 0)
                    {
                        currentList.SetIndex(index);
                    }
                    else
                    {
                        currentList.SetIndex(0);
                        MessageUtilities.sendMessage(p, "[A05000]Warning: could not find current level in new playlist (2). Reset to beginning.[-]");
                    }
                }
                else
                {
                    currentList.SetIndex(0);
                    MessageUtilities.sendMessage(p, "[A05000]Warning: could not find current level in new playlist. Reset to beginning.[-]");
                }
                MessageUtilities.sendMessage(p, "Filtered current playlist. Upcoming:");
                FilteredPlaylist filterer = new FilteredPlaylist(currentList.Playlist_, -currentList.Index_ - 1);
                filterer.AddFilter(new LevelFilterAll());
                filterer.AddFilter(new LevelFilterIndex(new IntComparison(currentList.Index_, IntComparison.Comparison.Greater)));
                MessageUtilities.sendMessage(p, GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Initial, playlistCmd.levelFormat));
                break;
            }

            case "upcoming":
            {
                PlaylistCmd playlistCmd = Cmd.all.getCommand <PlaylistCmd>("playlist");
                if (!playlistCmd.canUseCurrentPlaylist)
                {
                    MessageUtilities.sendMessage(p, "Cannot modify current playlist right now.");
                    break;
                }
                // 1. load current playlist into filter
                LevelPlaylist currentList = G.Sys.GameManager_.LevelPlaylist_;
                if (currentList.Index_ == currentList.Count_ - 1)
                {
                    MessageUtilities.sendMessage(p, "Cannot filter upcoming because you are on the last item of the list.");
                    break;
                }
                var levelsUpcoming           = currentList.Playlist_.GetRange(currentList.Index_ + 1, currentList.Count_ - currentList.Index_ - 1);
                FilteredPlaylist preFilterer = new FilteredPlaylist(levelsUpcoming);
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
                GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(preFilterer, p, filterCmdData, false), 4);
                MessageUtilities.popMessageOptions();
                // 2. Calculate filter results.
                List <LevelPlaylist.ModeAndLevelInfo> levels = preFilterer.Calculate().levelList;
                // 3. Update current playlist
                currentList.Playlist_.RemoveRange(currentList.Index_ + 1, currentList.Count_ - currentList.Index_ - 1);
                currentList.Playlist_.AddRange(levels);
                // 4. Print results
                MessageUtilities.sendMessage(p, "Filtered current playlist. Upcoming:");
                FilteredPlaylist filterer = new FilteredPlaylist(currentList.Playlist_, -currentList.Index_ - 1);
                filterer.AddFilter(new LevelFilterAll());
                filterer.AddFilter(new LevelFilterIndex(new IntComparison(currentList.Index_, IntComparison.Comparison.Greater)));
                MessageUtilities.sendMessage(p, GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Initial, playlistCmd.levelFormat));
                break;
            }
            }
        }
Beispiel #7
0
        public override void use(ClientPlayerInfo p, string message)
        {
            Match playlistCmdMatch = Regex.Match(message, @"^(\w+) ?(.*)$");

            if (!playlistCmdMatch.Success)
            {
                help(p);
                return;
            }
            MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
            string uniquePlayerString = GeneralUtilities.getUniquePlayerString(p);
            string playlistCmd        = playlistCmdMatch.Groups[1].Value.ToLower();
            string playlistCmdData    = playlistCmdMatch.Groups[2].Value;

            switch (playlistCmd)
            {
            default:
                MessageUtilities.sendMessage($"[A00000]Invalid sub-command `{playlistCmd}`[-]");
                help(p);
                break;

            case "list":
            {
                List <string> playlists = getPlaylists(playlistCmdData);
                var           results   = "";
                foreach (string playlist in playlists)
                {
                    results += "\n" + (playlist == "current" ? playlist : Resource.GetFileNameWithoutExtension(playlist));
                }
                if (results == "")
                {
                    results = "None";
                }
                MessageUtilities.sendMessage("[FFFFFF]Playlists: [-]" + results);
                break;
            }

            case "new":
            {
                LevelPlaylist list = LevelPlaylist.Create(true);
                list.Name_ = "New Playlist";
                FilteredPlaylist levels = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());
                GeneralUtilities.addFiltersToPlaylist(levels, p, playlistCmdData, true);
                list.Playlist_.AddRange(levels.Calculate().levelList);
                selectedPlaylists[uniquePlayerString] = list;
                MessageUtilities.sendMessage("[FFFFFF]New playlist with...[-]");
                MessageUtilities.sendMessage(GeneralUtilities.getPlaylistText(levels, GeneralUtilities.IndexMode.Final, levelFormat));
                break;
            }

            case "load":
            {
                int           matchingCount    = 0;
                LevelPlaylist selectedPlaylist = getPlaylistLevels(playlistCmdData, out matchingCount, getActivePlaylist(p));
                if (matchingCount == 0)
                {
                    MessageUtilities.sendMessage("[A00000]Could not find any playlists with that search[-]");
                    break;
                }
                else if (matchingCount == 1)
                {
                    MessageUtilities.sendMessage($"{selectedPlaylist.Name_} is now active");
                }
                else
                {
                    MessageUtilities.sendMessage($"{selectedPlaylist.Name_} is now active, but {matchingCount - 1} others matched too");
                }

                selectedPlaylists[uniquePlayerString] = selectedPlaylist;
                break;
            }

            case "save":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                if (selectedPlaylist.Playlist_.Count == 0)
                {
                    MessageUtilities.sendMessage("[A00000]Your active playlist is empty[-]");
                    break;
                }
                if (playlistCmdData == "")
                {
                    MessageUtilities.sendMessage($"[A05000]No name given. Using existing name: {selectedPlaylist.Name_}");
                    playlistCmdData = selectedPlaylist.Name_;
                }
                bool result = savePlaylist(selectedPlaylist, playlistCmdData);
                switch (playlistCmdData)
                {
                case "current":
                    if (result)
                    {
                        MessageUtilities.sendMessage("Set current playlist to active playlist.");
                    }
                    else
                    {
                        MessageUtilities.sendMessage("You cannot save to the current playlist right now.");
                    }
                    break;

                case "upcoming":
                    if (result)
                    {
                        MessageUtilities.sendMessage("Set upcoming levels to active playlist.");
                    }
                    else
                    {
                        MessageUtilities.sendMessage("You cannot save to the current playlist right now.");
                    }
                    break;

                case "active":
                    MessageUtilities.sendMessage("No changes made.");
                    break;

                default:
                    selectedPlaylist.Name_ = playlistCmdData;
                    MessageUtilities.sendMessage($"Saved playlist as {playlistCmdData}.");
                    break;
                }
                break;
            }

            case "active":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                MessageUtilities.sendMessage(selectedPlaylist.Name_);
                break;
            }

            case "del":
            {
                if (playlistCmdData == "")
                {
                    MessageUtilities.sendMessage("[A00000]You must enter a name[-]");
                    break;
                }
                List <string> toDelete;
                var           count = 0;
                if (deleteConfirmation.TryGetValue(uniquePlayerString, out toDelete))
                {
                    if (playlistCmdData.ToLower() == "yes")
                    {
                        foreach (string playlist in toDelete)
                        {
                            FileEx.Delete(playlist);
                            count++;
                        }
                        MessageUtilities.sendMessage($"Deleted {count} playlists.");
                        deleteConfirmation.Remove(uniquePlayerString);
                        break;
                    }
                    else if (playlistCmdData.ToLower() == "no")
                    {
                        deleteConfirmation.Remove(uniquePlayerString);
                        MessageUtilities.sendMessage("Cancelled deletion.");
                        break;
                    }
                }
                var           searchRegex = GeneralUtilities.getSearchRegex(playlistCmdData);
                List <string> playlists   = GeneralUtilities.playlists();
                playlists.RemoveAll((string s) => !Resource.FileExist(s));
                toDelete = new List <string>();
                var results = "";
                foreach (string playlist in playlists)
                {
                    if (Regex.IsMatch(playlist == "current" ? playlist : Resource.GetFileNameWithoutExtension(playlist), searchRegex, RegexOptions.IgnoreCase))
                    {
                        toDelete.Add(playlist);
                        results += "\n" + (playlist == "current" ? playlist : Resource.GetFileNameWithoutExtension(playlist));
                        count++;
                    }
                }
                if (count > 0)
                {
                    deleteConfirmation[uniquePlayerString] = toDelete;
                    MessageUtilities.sendMessage($"[FFFFFF]Use [A05000]!playlist del yes[-] to delete {count} playlists:[-] {results}");
                }
                else
                {
                    MessageUtilities.sendMessage("[A00000]No playlists found[-]");
                }
            }
            break;

            case "show":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                FilteredPlaylist filterer = new FilteredPlaylist(selectedPlaylist.Playlist_);
                GeneralUtilities.addFiltersToPlaylist(filterer, p, playlistCmdData, false);
                MessageUtilities.sendMessage(GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Initial, levelFormat));
                break;
            }

            case "filter":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                FilteredPlaylist filterer = new FilteredPlaylist(selectedPlaylist.Playlist_);
                GeneralUtilities.addFiltersToPlaylist(filterer, p, playlistCmdData, false);
                selectedPlaylist.Playlist_.Clear();
                selectedPlaylist.Playlist_.AddRange(filterer.Calculate().levelList);
                MessageUtilities.sendMessage("[FFFFFF]Filtered:[-]");
                MessageUtilities.sendMessage(GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Final, levelFormat));
                break;
            }

            case "add":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());
                GeneralUtilities.addFiltersToPlaylist(filterer, p, playlistCmdData, true);
                selectedPlaylist.Playlist_.AddRange(filterer.Calculate().levelList);
                MessageUtilities.sendMessage("[FFFFFF]Added:[-]");
                MessageUtilities.sendMessage(GeneralUtilities.getPlaylistText(filterer, GeneralUtilities.IndexMode.Final, levelFormat));
                break;
            }

            case "clear":
            {
                LevelPlaylist selectedPlaylist;
                if (!selectedPlaylists.TryGetValue(uniquePlayerString, out selectedPlaylist))
                {
                    MessageUtilities.sendMessage("[A00000]You have no active playlist[-]");
                    break;
                }
                selectedPlaylist.Playlist_.Clear();
                MessageUtilities.sendMessage("[FFFFFF]Cleared[-]");
                break;
            }
            }
            MessageUtilities.popMessageOptions();
        }
Beispiel #8
0
            public override void use(ClientPlayerInfo p, string message)
            {
                if (!doForceNextUse)
                {
                    if (!votesAllowed)
                    {
                        MessageUtilities.sendMessage(p, "Votes are disabled.");
                        return;
                    }
                }
                else
                {
                    doForceNextUse = false;
                }

                bool voteValue;
                bool isInfo;

                string voteType;
                string parameter;

                var matchShortcut    = Regex.Match(message, parent.voteCmdShortcutPattern);
                var shortcutVoteType = matchShortcut.Groups[1].Value.ToLower();

                if (matchShortcut.Success && voteThresholds.ContainsKey(shortcutVoteType))
                {
                    voteValue = true;
                    isInfo    = false;
                    voteType  = shortcutVoteType;
                    parameter = matchShortcut.Groups[2].Value;
                }
                else
                {
                    var match = Regex.Match(message, parent.voteCmdPattern);

                    if (!match.Success)
                    {
                        help(p);
                        return;
                    }

                    string voteValueS = match.Groups[1].Value.ToLower();
                    voteValue = false;
                    isInfo    = false;
                    if (voteValueS == "yes" || voteValueS == "y" || voteValueS == "1" || voteValueS == "true" || voteValueS == "t")
                    {
                        voteValue = true;
                    }
                    else if (voteValueS == "no" || voteValueS == "n" || voteValueS == "0" || voteValueS == "false" || voteValueS == "f")
                    {
                        voteValue = false;
                    }
                    else if (voteValueS == "info" || voteValueS == "i")
                    {
                        isInfo = true;
                    }
                    else
                    {
                        MessageUtilities.sendMessage(p, "Invalid <voteType>, or invalid [yes/no] You can use yes/no, y/n, 1/0, true/false, and t/f.");
                        MessageUtilities.sendMessage(p, "You can use [info/i] to get info.");
                        MessageUtilities.sendMessage(p, "<voteType>s: skip, stop, play");
                        return;
                    }

                    voteType  = match.Groups[2].Value.ToLower();
                    parameter = match.Groups[3].Value;
                }


                if (!voteThresholds.ContainsKey(voteType))
                {
                    MessageUtilities.sendMessage(p, $"Invalid <voteType>. ({voteType})");
                    help(p);
                    return;
                }

                AutoCmd     autoCommand     = parent.list.getCommand <AutoCmd>("auto");
                AutoSpecCmd autoSpecCommand = parent.list.getCommand <AutoSpecCmd>("autospec");
                int         playerOffset    = (autoCommand.autoMode && autoSpecCommand.autoSpecMode) ? -1 : 0;

                int numPlayers = G.Sys.PlayerManager_.PlayerList_.Count + playerOffset;

                if (isInfo)
                {
                    MessageUtilities.sendMessage(p, $"Info for {voteType}:");
                    MessageUtilities.sendMessage(p, $"Pass threshold: {Convert.ToInt32(Math.Floor(voteThresholds[voteType]*100))}%");
                    int value = parent.votes[voteType].Count;
                    MessageUtilities.sendMessage(p, $"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}");
                    return;
                }


                if (voteType == "skip")
                {
                    if (GeneralUtilities.isOnLobby())
                    {
                        MessageUtilities.sendMessage(p, "You can't vote to skip in the lobby!");
                        return;
                    }

                    if (votedSkip)
                    {
                        MessageUtilities.sendMessage(p, "Vote skip already succeeded.");
                        return;
                    }

                    List <string> votes = parent.votes[voteType];

                    int value = votes.Count;


                    string playerVoteId = GeneralUtilities.getUniquePlayerString(p);
                    if (voteValue)
                    {
                        if (votes.Contains(playerVoteId))
                        {
                            MessageUtilities.sendMessage($"{p.Username_} has already voted to skip {G.Sys.GameManager_.LevelName_}.");
                            return;
                        }
                        votes.Add(playerVoteId);
                        value = votes.Count;
                        MessageUtilities.sendMessage($"{p.Username_} voted to skip {G.Sys.GameManager_.LevelName_}.");
                        if (Convert.ToDouble(value) / Convert.ToDouble(numPlayers) < voteThresholds[voteType])
                        {
                            MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}");
                        }
                        else
                        {
                            votedSkip = true;
                            MessageUtilities.sendMessage("Vote skip succeeded! Skipping map...");
                            parent.advanceLevel();
                        }
                    }
                    else
                    {
                        votes.Remove(playerVoteId);
                        value = votes.Count;
                        MessageUtilities.sendMessage($"{p.Username_} unvoted to skip {G.Sys.GameManager_.LevelName_}.");
                        MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}");
                        return;
                    }
                }
                else if (voteType == "stop")
                {
                    if (GeneralUtilities.isOnLobby())
                    {
                        MessageUtilities.sendMessage(p, "You can't vote to stop the countdown in the lobby!");
                        return;
                    }

                    List <string> votes = parent.votes[voteType];

                    int value = votes.Count;

                    string playerVoteId = GeneralUtilities.getUniquePlayerString(p);
                    if (voteValue)
                    {
                        if (votes.Contains(playerVoteId))
                        {
                            MessageUtilities.sendMessage($"{p.Username_} has already voted to stop the countdown.");
                            return;
                        }
                        votes.Add(playerVoteId);
                        value = votes.Count;
                        MessageUtilities.sendMessage($"{p.Username_} voted to stop the countdown.");
                        if (Convert.ToDouble(value) / Convert.ToDouble(numPlayers) < voteThresholds[voteType])
                        {
                            MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}");
                        }
                        else
                        {
                            parent.votes[voteType].Clear();
                            CountdownCmd command = parent.list.getCommand <CountdownCmd>("countdown");
                            command.stopCountdown();
                            MessageUtilities.sendMessage("Vote stop succeeded! Stopping countdown...");
                        }
                    }
                    else
                    {
                        votes.Remove(playerVoteId);
                        value = votes.Count;
                        MessageUtilities.sendMessage($"{p.Username_} unvoted to stop the countdown.");
                        MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}");
                        return;
                    }
                }
                else if (voteType == "play")
                {
                    if (GeneralUtilities.isOnLobby())
                    {
                        MessageUtilities.sendMessage(p, "You can't vote for the next level in the lobby.");
                        return;
                    }

                    if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify)
                    {
                        MessageUtilities.sendMessage(p, "You can't vote for levels in trackmogrify.");
                        return;
                    }

                    string levelName = parameter;

                    FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes());
                    if (!p.IsLocal_)
                    {
                        PlayCmd playCmd = Cmd.all.getCommand <PlayCmd>("play");
                        filterer.AddFiltersFromString(playCmd.playFilter);
                    }
                    MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p));
                    GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, levelName, true), 4);
                    MessageUtilities.popMessageOptions();

                    List <LevelPlaylist.ModeAndLevelInfo> lvls         = filterer.Calculate().levelList;
                    List <LevelResultsSortInfo>           levelResults = new List <LevelResultsSortInfo>();

                    double threshold = voteThresholds["play"];

                    LevelPlaylist playlist = new LevelPlaylist();
                    playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_);
                    var     currentPlaylist = playlist.Playlist_;
                    AutoCmd autoCmd         = Cmd.all.getCommand <AutoCmd>("auto");
                    int     origIndex       = G.Sys.GameManager_.LevelPlaylist_.Index_;
                    int     index           = autoCmd.getInsertIndex();

                    int addCount = 0;
                    foreach (LevelPlaylist.ModeAndLevelInfo lvl in lvls)
                    {
                        string        id = $"{lvl.mode_}:{lvl.levelNameAndPath_.levelName_}:{lvl.levelNameAndPath_.levelPath_}";
                        List <string> votes;
                        if (!parent.votes.TryGetValue(id, out votes))
                        {
                            if (voteValue)
                            {
                                votes            = new List <string>();
                                parent.votes[id] = votes;
                            }
                            else
                            {
                                //MessageUtilities.sendMessage($"{p.Username_} unvoted for these maps.");
                                levelResults.Add(new LevelResultsSortInfo(lvl, 0, numPlayers, threshold, -1));
                                continue;
                            }
                        }
                        string playerVoteId = GeneralUtilities.getUniquePlayerString(p);
                        if (!voteValue)
                        {
                            votes.Remove(playerVoteId);
                            if (votes.Count == 0)
                            {
                                parent.votes.Remove(id);
                            }
                            //MessageUtilities.sendMessage($"{p.Username_} unvoted for these maps.");
                            levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, -1));
                            continue;
                        }
                        else
                        {
                            if (votes.Contains(playerVoteId))
                            {
                                //MessageUtilities.sendMessage($"{p.Username_} has already voted for these maps.");
                                levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, 0));
                                //return;
                                continue;
                            }
                            else
                            {
                                votes.Add(playerVoteId);
                                levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, 1));
                                if (Convert.ToDouble(votes.Count) / Convert.ToDouble(numPlayers) >= threshold)
                                {
                                    currentPlaylist.Insert(index + addCount, lvl);
                                    parent.votes.Remove(id);
                                    addCount++;
                                }
                            }
                        }
                    }

                    G.Sys.GameManager_.LevelPlaylist_.Clear();
                    foreach (var lvl in currentPlaylist)
                    {
                        G.Sys.GameManager_.LevelPlaylist_.Add(lvl);
                    }
                    G.Sys.GameManager_.LevelPlaylist_.SetIndex(origIndex);

                    var playersThreshold = Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)));

                    if (lvls.Count == 0)
                    {
                        MessageUtilities.sendMessage(p, "Can't find any levels with the filter '" + levelName + "'.");
                    }

                    string newMessage;
                    int    count;

                    newMessage = "";
                    count      = 0;
                    foreach (LevelResultsSortInfo level in levelResults)
                    {
                        if (level.voteState == -1)
                        {
                            if (++count <= 10)
                            {
                                newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + $"({level.votes}/{playersThreshold}), ";
                            }
                        }
                    }
                    if (count != 0)
                    {
                        if (count > 10)
                        {
                            MessageUtilities.sendMessage($"{p.Username_} unvoted for {newMessage} and {count - 10} more.");
                        }
                        else
                        {
                            MessageUtilities.sendMessage($"{p.Username_} unvoted for {newMessage}.");
                        }
                    }

                    newMessage = "";
                    count      = 0;
                    foreach (LevelResultsSortInfo level in levelResults)
                    {
                        if (level.voteState >= 0)
                        {
                            if (++count <= 10)
                            {
                                newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + $"({level.votes}/{playersThreshold}), ";
                            }
                        }
                    }
                    if (count != 0)
                    {
                        if (count > 10)
                        {
                            MessageUtilities.sendMessage($"{p.Username_} voted for {newMessage} and {count - 10} more.");
                        }
                        else
                        {
                            MessageUtilities.sendMessage($"{p.Username_} voted for {newMessage}.");
                        }
                    }

                    newMessage = "";
                    count      = 0;
                    foreach (LevelResultsSortInfo level in levelResults)
                    {
                        if (level.success)
                        {
                            if (++count <= 10)
                            {
                                newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + ", ";
                            }
                        }
                    }
                    if (count != 0)
                    {
                        if (count > 10)
                        {
                            MessageUtilities.sendMessage(newMessage + $"and {count - 10} more added.");
                        }
                        else
                        {
                            MessageUtilities.sendMessage(newMessage + "added.");
                        }
                    }
                }
            }