public static void Ingame()
        {
            int[]     messageStamps = new int[] { 300, 240, 180, 120, 60, 30, 15 };
            int[]     timeStamps    = new int[] { 30, 60, 60, 60, 60, 30, 15 };
            int       ti            = 0;
            Stopwatch game          = new Stopwatch();

            game.Start();

            while (true)
            {
                Thread.Sleep(10);

                if (Join == JoinType.Abyxa)
                {
                    a.Update();
                }

                // Swap killed survivors to red
                List <int> playersDead = cg.PlayerInfo.PlayersDead();
                for (int i = 0; i < playersDead.Count(); i++)
                {
                    if (playersDead[i] < 6)
                    {
                        cg.Interact.SwapToRed(playersDead[i]);
                    }
                }

                // end game if winning condition is met
                bool endgame = false;
                if (game.ElapsedMilliseconds >= 330 * 1000) // if time runs out, survivors win
                {
                    cg.Chat.Chat("The survivors defend long enough for help to arrive. Survivors win.");
                    endgame = true;
                    Thread.Sleep(2000);
                }
                if (cg.BlueCount == 0) // blue is empty, zombies win
                {
                    cg.Chat.Chat("The infection makes its way to the last human. Zombies win.");
                    endgame = true;
                    Thread.Sleep(2000);
                }
                if (endgame == true)
                {
                    cg.Chat.Chat("Resetting, please wait...");

                    game.Reset();

                    // ti will equal 0 if the game ends before mccree bots are removed, so remove the bots.
                    if (ti == 0)
                    {
                        cg.AI.RemoveAllBotsAuto();
                    }
                    Thread.Sleep(500);

                    ti = 0;

                    cg.RestartGame();

                    if (cg.TotalPlayerCount < 7 && Join == JoinType.ServerBrowser)
                    {
                        MatchIsPublic = true;
                        cg.GameSettings.SetJoinSetting(Deltin.CustomGameAutomation.Join.Everyone);
                    }
                    else
                    {
                        MatchIsPublic = false;
                    }

                    Thread.Sleep(1000);
                    return;
                }

                /*
                 * ti is short for time index
                 * the ti variable determines which time remaining message to use from the timeStamps variable.
                 */
                if (ti < timeStamps.Length)
                {
                    if (game.ElapsedMilliseconds >= Extra.SquashArray(timeStamps, ti) * 1000)
                    {
                        if (messageStamps[ti] > 60)
                        {
                            cg.Chat.Chat((messageStamps[ti] / 60) + " minutes remaining.");
                        }
                        if (messageStamps[ti] == 60)
                        {
                            cg.Chat.Chat("1 minute remaining.");
                        }
                        if (messageStamps[ti] < 60)
                        {
                            cg.Chat.Chat(messageStamps[ti] + " seconds remaining.");
                        }
                        ti++;
                        if (ti == 1)
                        {
                            // remove bots
                            cg.AI.RemoveAllBotsAuto();
                            cg.Chat.Chat("Zombies have been released. Good luck.");

                            // Swap blue players who didn't choose a hero to red if the version is TDM.
                            if (version == 1)
                            {
                                var blueslots = cg.BlueSlots;
                                for (int i = 0; i < blueslots.Count; i++)
                                {
                                    if (cg.PlayerInfo.IsHeroChosen(blueslots[i]) == false)
                                    {
                                        cg.Interact.SwapToRed(blueslots[i]);
                                    }
                                }
                            }
                        }
                        Thread.Sleep(500);
                    }
                }

                if (Join == JoinType.Abyxa)
                {
                    a.SetSurvivorCount(cg.BlueCount.ToString());
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string header = "Zombiebot v1.2";

            Console.Title = header;
            Console.WriteLine(header);

            string            name             = "Zombies - Infection"; // Default name for the Abyxa server.
            string            region           = "us";                  // Default region for the Abyxa server.
            bool              local            = false;                 // Determines if the Abyxa website is on the local server.
            Event?            owevent          = null;                  // The current overwatch event
            ScreenshotMethods screenshotMethod = ScreenshotMethods.BitBlt;

            // Parse config file
            string[] config    = null;
            string   filecheck = Extra.GetExecutingDirectory() + "config.txt"; // File location of config file.

            try
            {
                config = System.IO.File.ReadAllLines(filecheck);
            }
            catch (Exception ex)
            {
                if (ex is System.IO.DirectoryNotFoundException || ex is System.IO.FileNotFoundException)
                {
                    Console.WriteLine("Could not find configuration file at '{0}', using default settings.", filecheck);
                }
                else
                {
                    Console.WriteLine("Error getting configuration file at '{0}', using default settings.", filecheck);
                }
            }
            if (config != null)
            {
                for (int i = 0; i < config.Length; i++) // For each line in the config file
                {
                    string line = config[i].Trim(' ');
                    if (line.Length >= 2)
                    {
                        if (line[0] == '/' && line[1] == '/')
                        {
                            continue;
                        }
                    }

                    // Remove any text after "//"
                    int index = line.IndexOf("//");
                    if (index > 0)
                    {
                        line = line.Substring(0, index);
                    }
                    // Split line at "="
                    string[] lineSplit = line.Split(new string[] { "=" }, 2, StringSplitOptions.RemoveEmptyEntries);
                    // Trim whitespace
                    for (int lsi = 0; lsi < lineSplit.Length; lsi++)
                    {
                        lineSplit[lsi] = lineSplit[lsi].Trim(' ');
                    }

                    if (lineSplit.Length > 1)
                    {
                        switch (lineSplit[0])
                        {
                        case "local":
                        {
                            if (bool.TryParse(lineSplit[1], out bool set))
                            {
                                local = set;
                            }
                        }
                        break;

                        case "minimumPlayers":
                        {
                            if (int.TryParse(lineSplit[1], out int set) && set >= 0 && set <= 7)
                            {
                                minimumPlayers = set;
                            }
                        }
                        break;

                        case "name":
                        {
                            name = lineSplit[1];
                        }
                        break;

                        case "region":
                        {
                            if (lineSplit[0] == "region" && ValidRegions.Contains(lineSplit[1]))
                            {
                                region = lineSplit[1];
                            }
                        }
                        break;

                        case "DefaultMode":
                        {
                            if (Enum.TryParse(lineSplit[1], out JoinType jointype))
                            {
                                Join = jointype;
                            }
                        }
                        break;

                        case "Event":
                        {
                            if (Enum.TryParse(lineSplit[1], out Event setowevent))
                            {
                                owevent = setowevent;
                            }
                        }
                        break;

                        case "ScreenshotMethod":
                        {
                            if (Enum.TryParse(lineSplit[1], out ScreenshotMethods set))
                            {
                                screenshotMethod = set;
                            }
                        }
                        break;

                        case "version":
                        {
                            if (Int32.TryParse(lineSplit[1], out int set))
                            {
                                if (set == 0 || set == 1)
                                {
                                    version = set;
                                }
                            }
                        }
                        break;
                        }
                    }
                }
            }

            if (Join == null)
            {
                string joinmode = Extra.ConsoleInput("Abyxa or server browser (\"abyxa\"/\"sb\"/\"private\"): ", "abyxa", "sb", "private");
                if (joinmode == "abyxa")
                {
                    Join = JoinType.Abyxa;
                }
                else if (joinmode == "sb")
                {
                    Join = JoinType.ServerBrowser;
                }
                else if (joinmode == "private")
                {
                    Join = JoinType.Private;
                }
            }

            IntPtr useHwnd = new IntPtr();

            while (true)
            {
                Process[] overwatchProcesses = Process.GetProcessesByName("Overwatch");

                if (overwatchProcesses.Length == 0)
                {
                    Console.WriteLine("No Overwatch processes found, press enter to recheck.");
                    Console.ReadLine();
                    continue;
                }

                else if (overwatchProcesses.Length == 1)
                {
                    useHwnd = overwatchProcesses[0].MainWindowHandle;
                    break;
                }

                else if (overwatchProcesses.Length > 1)
                {
                    Console.Write("Click on the Overwatch window to use... ");
                    bool lookingForWindow = true;
                    while (lookingForWindow)
                    {
                        IntPtr hwnd = Extra.GetForegroundWindow();
                        overwatchProcesses = Process.GetProcessesByName("Overwatch");
                        for (int i = 0; i < overwatchProcesses.Length; i++)
                        {
                            if (overwatchProcesses[i].MainWindowHandle == hwnd)
                            {
                                Console.WriteLine("Overwatch window found.");
                                useHwnd          = hwnd;
                                lookingForWindow = false;
                                break;
                            }
                        }
                        System.Threading.Thread.Sleep(500);
                    }
                    break;
                }
            }

            Console.WriteLine("Press return to start.");
            Console.ReadLine();
            Console.WriteLine("Starting...");

            cg = new CustomGame(useHwnd, screenshotMethod);

            // Set the mode enabled
            if (version == 0)
            {
                cg.ModesEnabled = new ModesEnabled()
                {
                    Elimination = true
                };
                maps     = ElimMaps;
                mapsSend = ElimMapsSend;
            }
            else if (version == 1)
            {
                cg.ModesEnabled = new ModesEnabled()
                {
                    TeamDeathmatch = true
                };
                maps     = DmMaps;
                mapsSend = DmMapsSend;
            }

            // Set event
            if (owevent == null)
            {
                cg.CurrentOverwatchEvent = cg.GetCurrentOverwatchEvent();
            }
            else
            {
                cg.CurrentOverwatchEvent = (Event)owevent;
            }

            cg.Command.ListenTo.Add("$VOTE", true);
            cg.Command.SameExecutorCommandUpdate = true;
            cg.Chat.BlockGeneralChat             = true;

            a = null;
            if (Join == JoinType.Abyxa)
            {
                a = new Abyxa(name, region, local);
                a.SetMinimumPlayerCount(minimumPlayers);
                cg.GameSettings.SetJoinSetting(Deltin.CustomGameAutomation.Join.InviteOnly);
            }

            Setup();

            while (true)
            {
                bool pregame = Pregame();
                if (pregame)
                {
                    Ingame();
                }
                else
                {
                    Setup();
                }
            }
        }
示例#3
0
        public static OperationResult Ingame(Abyxa abyxa, bool serverBrowser, CustomGame cg, int version, CancellationToken cs)
        {
            if (abyxa != null)
            {
                abyxa.ZombieServer.GameStarted = DateTime.UtcNow.AddMinutes(5.5);
                abyxa.ZombieServer.Mode        = Abyxa.Ingame;
                abyxa.ZombieServer.PlayerCount = cg.GetCount(SlotFlags.Blue | SlotFlags.Queue);
                abyxa.Update();
            }

            cg.Chat.SendChatMessage("Zombies will be released in 30 seconds.");

            int[]     messageStamps = new int[] { 300, 240, 180, 120, 60, 30, 15 };
            int[]     timeStamps    = new int[] { 30, 60, 60, 60, 60, 30, 15 };
            int       ti            = 0;
            Stopwatch game          = new Stopwatch();

            game.Start();

            new Task(() =>
            {
                cg.Chat.SendChatMessage("If you can't move, you are a zombie. You will be able to move when the preperation phase is over.");
                Thread.Sleep(5000);
                cg.Chat.SendChatMessage("Survivors win when time runs out. Survivors are converted to zombies when they die. Zombies win when all survivors are converted.");
                Thread.Sleep(5000);
                cg.Chat.SendChatMessage("Zombies will be released when preperation phase is over.");
            }).Start();

            while (true)
            {
                if (cs.IsCancellationRequested)
                {
                    return(OperationResult.Canceled);
                }

                if (cg.IsDisconnected())
                {
                    return(OperationResult.Disconnected);
                }

                // Swap killed survivors to red
                List <int> survivorsDead = cg.GetSlots(SlotFlags.Blue | SlotFlags.DeadOnly);
                for (int i = 0; i < survivorsDead.Count(); i++)
                {
                    cg.Interact.SwapToRed(survivorsDead[i]);
                }

                // end game if winning condition is met
                bool endgame = false;
                if (game.ElapsedMilliseconds >= 330 * 1000) // if time runs out, survivors win
                {
                    Log("Game Over: Survivors win.");
                    cg.Chat.SendChatMessage("The survivors defend long enough for help to arrive. Survivors win.");
                    endgame = true;
                    Thread.Sleep(2000);
                }
                if (cg.BlueCount == 0) // blue is empty, zombies win
                {
                    Log("Game Over: Zombies win.");
                    cg.Chat.SendChatMessage("The infection makes its way to the last human. Zombies win.");
                    endgame = true;
                    Thread.Sleep(2000);
                }
                if (endgame == true)
                {
                    cg.Chat.SendChatMessage("Resetting, please wait...");

                    // ti will equal 0 if the game ends before mccree bots are removed, so remove the bots.
                    if (ti == 0)
                    {
                        cg.AI.RemoveAllBotsAuto();
                    }
                    Thread.Sleep(500);

                    cg.ToggleMap(ToggleAction.EnableAll);

                    cg.RestartGame();

                    UpdateMap(abyxa, cg);

                    return(OperationResult.Success);
                }

                /*
                 * ti is short for time index
                 * the ti variable determines which time remaining message to use from the timeStamps variable.
                 */
                if (ti < timeStamps.Length)
                {
                    if (game.ElapsedMilliseconds >= Extra.SquashArray(timeStamps, ti) * 1000)
                    {
                        if (messageStamps[ti] > 60)
                        {
                            cg.Chat.SendChatMessage((messageStamps[ti] / 60) + " minutes remaining.");
                        }
                        if (messageStamps[ti] == 60)
                        {
                            cg.Chat.SendChatMessage("1 minute remaining.");
                        }
                        if (messageStamps[ti] < 60)
                        {
                            cg.Chat.SendChatMessage(messageStamps[ti] + " seconds remaining.");
                        }
                        ti++;
                        if (ti == 1)
                        {
                            // remove bots
                            cg.AI.RemoveAllBotsAuto();
                            cg.Chat.SendChatMessage("Zombies have been released.");

                            // Swap blue players who didn't choose a hero to red if the version is TDM.
                            if (version == 1)
                            {
                                var blueslots = cg.BlueSlots;
                                for (int i = 0; i < blueslots.Count; i++)
                                {
                                    if (!cg.PlayerInfo.IsHeroChosen(blueslots[i]))
                                    {
                                        cg.Interact.SwapToRed(blueslots[i]);
                                    }
                                }
                            }
                        }
                        Thread.Sleep(500);
                    }
                }

                if (abyxa != null)
                {
                    abyxa.ZombieServer.Survivors = cg.BlueCount;
                    abyxa.Update();
                }

                Thread.Sleep(10);
            }
        }