Пример #1
0
        void advanceLevel()
        {
            AutoCmd autoCommand = list.getCommand <AutoCmd>("auto");

            if (autoCommand.autoMode)
            {
                autoCommand.nextLevel();
            }
            else
            {
                G.Sys.GameManager_.StartCoroutine(waitAndGoNext());
            }
        }
Пример #2
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() + "!");
                }
            }
        }
Пример #3
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.");
                        }
                    }
                }
            }