Ejemplo n.º 1
0
        IEnumerator waitUtilEnd()
        {
            if (advanceMessage != "")
            {
                MessageUtilities.sendMessage(advanceMessage);
            }
            didFinish = false;
            int currentIndex = index;

            if (maxRunTime > 60)
            {
                yield return(new WaitForSeconds(maxRunTime - 60));

                CountdownCmd countdownCommand = list.getCommand <CountdownCmd>("countdown");
                if (currentIndex == index && autoMode && !countdownCommand.countdownStarted)
                {
                    MessageUtilities.sendMessage("This map has run for the maximum time.");

                    // start countdown for 60 seconds. Everyone is marked DNF at 60 seconds.
                    countdownCommand.startCountdown(60);
                }
            }
            else
            {
                CountdownCmd countdownCommand = list.getCommand <CountdownCmd>("countdown");
                countdownCommand.startCountdown(maxRunTime);
            }
            yield return(null);
        }
Ejemplo n.º 2
0
        public AutoCmd(CmdList list)
        {
            this.list = list;

            Events.Network.ConnectedToServer.Subscribe(data =>
            {
                autoMode = false;
            });

            Events.Network.ServerInitialized.Subscribe(data =>
            {
                autoMode = false;
            });

            Events.ServerToClient.ModeFinished.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    onModeFinish();
                });
            });

            Events.GameMode.ModeStarted.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    onModeStart();
                });
            });

            Events.GameMode.Go.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    onGo();
                });
            });

            Events.ClientToAllClients.ChatMessage.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    onChatEvent(data.message_);
                });
            });

            Events.RaceMode.FinalCountdownActivate.Subscribe(data =>
            {
                try {
                    AutoSpecCmd autoSpecCommand   = list.getCommand <AutoSpecCmd>("autospec");
                    CountdownCmd countdownCommand = list.getCommand <CountdownCmd>("countdown");
                    if (G.Sys.PlayerManager_.PlayerList_.Count == 2 && autoSpecCommand.autoSpecMode)
                    {
                        countdownCommand.stopCountdown();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed to stop countdown: {e}");
                }
            });
        }
Ejemplo n.º 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.");
                        }
                    }
                }
            }