示例#1
0
 public Resetter(CustomGame cg)
 {
     _cg = cg;
 }
示例#2
0
        public void Test_FindOriginDestination_CanMove()
        {
            //Init Game
            CustomGame customGame = InitGame(null);

            // Penguin in 0;0
            int x = 0;
            int y = 0;
            // Set cell with penguin
            Cell cell = (Cell)customGame.Board.Board[x, y];

            cell.FishCount      = 1;
            cell.CellType       = CellType.FishWithPenguin;
            cell.CurrentPenguin = new Penguin(customGame.CurrentPlayer);

            // Cell 1 fish in 1;0
            x = 1;
            y = 0;
            // Set cell with 1 fish
            cell           = (Cell)customGame.Board.Board[x, y];
            cell.FishCount = 1;

            // Cell 3 fish in 2;0
            x = 2;
            y = 0;
            // Set cell with 3 fish
            cell           = (Cell)customGame.Board.Board[x, y];
            cell.FishCount = 3;

            // Cell water in 3;0
            x = 3;
            y = 0;
            // Set cell water
            cell          = (Cell)customGame.Board.Board[x, y];
            cell.CellType = CellType.Water;

            // Cell 1 fish in 0;1
            x = 0;
            y = 1;
            // Set cell with 1 fish
            cell           = (Cell)customGame.Board.Board[x, y];
            cell.FishCount = 1;

            // Cell 2 fish in 1;2
            x = 1;
            y = 2;
            // Set cell with 2 fish
            cell           = (Cell)customGame.Board.Board[x, y];
            cell.FishCount = 2;

            // Cell water in 1;3
            x = 1;
            y = 3;
            // Set cell water
            cell          = (Cell)customGame.Board.Board[x, y];
            cell.CellType = CellType.Water;

            // Launch function
            AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer);
            Dictionary <string, Coordinates> coordinates = aiHard.FindOriginDestination();

            // Test
            Assert.IsTrue(coordinates["destination"].X == 2 && coordinates["destination"].Y == 0);
        }
示例#3
0
        public static Map VoteForMap(CustomGame cg, Map[] maps)
        {
            Random rnd = new Random();

            int[] votemap = new int[VoteCount]; // The index of maps that can be voted for. 3 is the amount of maps chosen that can be voted for.
            for (int i = 0; i < votemap.Length; i++)
            {
                int choose;
                while (true)
                {
                    // Make sure there are no duplicates when choosing the next map to be added to the votemap array
                    choose = rnd.Next(maps.Length);
                    if (votemap.Contains(choose))
                    {
                        continue;
                    }
                    break;
                }
                votemap[i] = choose;
            }

            // Send the maps to vote for to the chat.
            cg.Chat.SendChatMessage(FormatMessage(
                                        "Vote for map! (15 seconds)",
                                        maps[votemap[0]].ShortName + " - $VOTE 1",
                                        maps[votemap[1]].ShortName + " - $VOTE 2",
                                        maps[votemap[2]].ShortName + " - $VOTE 3"));

            // Listen to the "$VOTE" command for 15 seconds.
            cg.Commands.ListenTo.Add(VoteCommand);
            Thread.Sleep(15000);
            cg.Commands.ListenTo.Remove(VoteCommand);
            // Get results
            int[] results = new int[VoteCount]
            {
                VoteResults.Count(vr => vr.VotingFor == 1),
                VoteResults.Count(vr => vr.VotingFor == 2),
                VoteResults.Count(vr => vr.VotingFor == 3)
            };

            int winningmap = votemap[Array.IndexOf(results, results.Max())];

            // Dispose all chat identities.
            foreach (Vote voteResult in VoteResults)
            {
                voteResult.ChatIdentity.Dispose();
            }
            VoteResults = new List <Vote>();

            // Print the results to the chat
            string mapResults = String.Format("{0}: {1} votes, {2}: {3} votes, {4}: {5} votes",
                                              maps[votemap[0]].ShortName, results[0],
                                              maps[votemap[1]].ShortName, results[1],
                                              maps[votemap[2]].ShortName, results[2]);

            cg.Chat.SendChatMessage(mapResults);
            Program.Log(mapResults);
            cg.Chat.SendChatMessage("Next map: " + maps[winningmap].ShortName);
            cg.ToggleMap(ToggleAction.DisableAll, maps[winningmap]);

            return(maps[winningmap]);
        }
示例#4
0
    private bool IsOverwatchOpen()
    {
        bool isOverwatchOpen = CustomGame.GetOverwatchProcess() != null;

        return(isOverwatchOpen);
    }
示例#5
0
 public MainForm()
 {
     custom = CustomGame.Default;
     InitializeComponent();
 }
示例#6
0
 public DebugUtils(bool debug, CustomGame cg)
 {
     Debug = debug;
     Cg    = cg;
 }
示例#7
0
 private void CustomGameSetup(CustomGame cg)
 {
     SetupNames(cg);
     cg.AI.RemoveAllBotsAuto();
     cg.Chat.SwapChannel(Channel.Match);
 }
        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(new ListenTo("$VOTE", true, false));
            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(true);

            while (true)
            {
                bool pregame = Pregame();
                if (pregame)
                {
                    Ingame();
                }
                else
                {
                    Setup(false);
                }
            }
        }
示例#9
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);
            }
        }