private static void InviteQueueToGame(Abyxa abyxa, CustomGame cg, int minimumPlayers) { var spectatorslots = cg.SpectatorSlots; // If players are in spectator and slots are available, switch them to blue/red for (int i = 1; i < spectatorslots.Count && PlayingCount < 7; i++) { if (!cg.Interact.SwapToBlue(spectatorslots[i])) { cg.Interact.SwapToRed(spectatorslots[i]); } } if (abyxa != null) { List <QueueUser> queue = abyxa.GetQueue(); for (int i = 0; i < queue.Count && PlayingCount < 7; i++) { if (!queue[i].IsWaiting || (queue[i].IsWaiting && cg.AllCount + queue.Count >= minimumPlayers)) { Log("Inviting the player " + queue[i].BattleTag + "..."); // invite player to game cg.InvitePlayer(queue[i].BattleTag, Team.BlueAndRed); // invite player to game cg.WaitForSlotUpdate(); // Wait for the slots to update abyxa.RemoveFromQueue(queue[i].BattleTag); // remove player from queue } } } }
private static string UpdateMap(Abyxa abyxa, CustomGame cg) { string currentMap = cg.GetCurrentMap()?.FirstOrDefault()?.ShortName; if (currentMap != null) { if (abyxa != null) { abyxa.ZombieServer.Map = currentMap; abyxa.Update(); } } else { Log("Could not detect current map."); } return(currentMap); }
public static void Setup(Abyxa abyxa, bool serverBrowser, CustomGame cg, Map[] maps, string preset, string name) { cg.AI.RemoveAllBotsAuto(); if (abyxa != null) { cg.Settings.JoinSetting = Join.InviteOnly; } if (preset != "") { cg.Settings.LoadPreset(preset); } int moderatorSlot = cg.PlayerInfo.ModeratorSlot(); if (moderatorSlot != -1) { if (moderatorSlot != 12) { cg.Interact.Move(moderatorSlot, 12); } } else { var allSlots = cg.AllSlots; if (allSlots.Count == 1 && allSlots[0] != 12) { cg.Interact.Move(allSlots[0], 12); } } cg.ToggleMap(ToggleAction.EnableAll); Thread.Sleep(500); cg.StartGame(); }
private static void SetupGame(Abyxa abyxa, bool serverBrowser, CustomGame cg, Map[] maps) { Log("Starting game with " + PlayingCount + " players."); if (abyxa != null) { abyxa.ZombieServer.Mode = Abyxa.SettingUpNextGame; abyxa.Update(); } if (serverBrowser) { cg.Settings.JoinSetting = Join.InviteOnly; } cg.SendServerToLobby(); // If there is too many players, swap some to spectators. If they can't be swapped to spectators, remove them from the game. var playingSlots = PlayingSlots; Random rnd = new Random(); for (int pc = playingSlots.Count; pc > 7; pc--) { int slotChosen = playingSlots[rnd.Next(playingSlots.Count - 1)]; // Swap the extra player to spectator. If they cannot be switched, remove them from the game. if (!cg.Interact.SwapToSpectators(slotChosen)) { cg.Interact.RemoveFromGame(slotChosen); } } if (abyxa != null) { abyxa.ZombieServer.PlayerCount = PlayingCount; abyxa.ZombieServer.InvitedCount = 0; abyxa.Update(); } Map chosenMap = MapVoting.VoteForMap(cg, maps); // Update map on website if (abyxa != null) { abyxa.ZombieServer.Map = chosenMap.ShortName.ToLower(); abyxa.Update(); } // Swap everyone in red to blue. var redslots = cg.RedSlots; while (redslots.Count > 0) { cg.Interact.SwapToBlue(redslots[0]); cg.WaitForSlotUpdate(); redslots = cg.RedSlots; } cg.AI.AddAI(AIHero.McCree, Difficulty.Easy, Team.Red, 6); // fill team 2 with mccree bots cg.WaitForSlotUpdate(); const int zombies = 2; for (int i = 0; i < zombies; i++) { var blueSlots = cg.BlueSlots; int choose = rnd.Next(0, blueSlots.Count); cg.Interact.SwapToRed(choose); } string zombie1Name = cg.GetPlayerName(18), zombie2Name = cg.GetPlayerName(19); cg.Chat.SendChatMessage($"{zombie1Name} and {zombie2Name} are the starting zombies."); // Start game cg.Chat.SendChatMessage("Starting game..."); cg.StartGame(); }
public static OperationResult Pregame(Abyxa abyxa, bool serverBrowser, CustomGame cg, Map[] maps, int minimumPlayers, CancellationToken cs) { int prevPlayerCount = 0; Stopwatch pregame = new Stopwatch(); Stopwatch skirmish = new Stopwatch(); skirmish.Start(); // Create the PlayerTracker PlayerTracker playerTracker = new PlayerTracker(); // Add the $SWAPME command ListenTo swapMeCommand = new ListenTo(command: "$SWAPME", listen: true, getNameAndProfile: true, checkIfFriend: false, callback: (commandData) => OnSwapMe(commandData, cg, playerTracker)); cg.Commands.ListenTo.Add(swapMeCommand); if (abyxa != null) { abyxa.ZombieServer.Mode = Abyxa.Pregame; UpdateMap(abyxa, cg); abyxa.Update(); } cg.Chat.SwapChannel(Channel.Match); // Make game publc if there is less than 7 players. if (serverBrowser) { if (cg.AllCount < 7) { cg.Settings.JoinSetting = Join.Everyone; } else { cg.Settings.JoinSetting = Join.InviteOnly; } } try { while (true) { if (cs.IsCancellationRequested) { return(OperationResult.Canceled); } if (cg.IsDisconnected()) { return(OperationResult.Disconnected); } if (abyxa != null) { abyxa.Update(); } cg.TrackPlayers(playerTracker, SlotFlags.BlueAndRed | SlotFlags.IngameOnly); if (skirmish.ElapsedMilliseconds >= 300 * 1000) { cg.RestartGame(); prevPlayerCount = 0; skirmish.Restart(); cg.Chat.SwapChannel(Channel.Match); string currentMap = UpdateMap(abyxa, cg) ?? "Unknown"; Log("Restarting the game. New map: " + currentMap); } InviteQueueToGame(abyxa, cg, minimumPlayers); var invitedSlots = cg.GetInvitedSlots(); int playerCount = PlayingCount - invitedSlots.Count; // update server if (abyxa != null) { abyxa.ZombieServer.PlayerCount = playerCount; abyxa.ZombieServer.InvitedCount = invitedSlots.Count; abyxa.Update(); } // Send a message when someone joins if (playerCount > prevPlayerCount) { int wait = minimumPlayers - playerCount; if (wait > 1) { cg.Chat.SendChatMessage("Welcome to Zombies! Waiting for " + wait + " more players. I am a bot, source is at the github repository ItsDeltin/Overwatch-Custom-Game-Automation"); } if (wait == 1) { cg.Chat.SendChatMessage("Welcome to Zombies! Waiting for " + wait + " more player. I am a bot, source is at the github repository ItsDeltin/Overwatch-Custom-Game-Automation"); } if (wait < 0) { cg.Chat.SendChatMessage("Welcome to Zombies! Game will be starting soon. I am a bot, source is at the github repository ItsDeltin/Overwatch-Custom-Game-Automation"); } } prevPlayerCount = playerCount; if (!pregame.IsRunning && playerCount >= minimumPlayers) { cg.Chat.SendChatMessage("Enough players have joined, starting game in 15 seconds."); pregame.Start(); } // if too many players leave, cancel the countdown. if (pregame.IsRunning == true && playerCount < minimumPlayers) { cg.Chat.SendChatMessage("Players left, waiting for " + (minimumPlayers - playerCount) + " more players, please wait."); pregame.Reset(); } if (serverBrowser && cg.Settings.JoinSetting == Join.Everyone && PlayingCount >= 7) { cg.Settings.JoinSetting = Join.InviteOnly; } else if (serverBrowser && cg.Settings.JoinSetting == Join.InviteOnly && PlayingCount < 7) { cg.Settings.JoinSetting = Join.Everyone; } // if the amount of players equals 7 or the queue list is empty and there is enough players, // and the pregame timer elapsed 15 seconds, // and there is no one invited and loading, // start the game. if (pregame.ElapsedMilliseconds >= 15 * 1000) { SetupGame(abyxa, serverBrowser, cg, maps); return(OperationResult.Success); } } } finally { playerTracker.Dispose(); cg.Commands.ListenTo.Remove(swapMeCommand); } } // Pregame
private static void Start(Config config, bool skipSetup, bool debug, CancellationToken cs) { Initialized = true; Abyxa abyxa = null; if (config.DefaultMode == "abyxa") { abyxa = new Abyxa(config.Name, config.Region, config.Local); abyxa.ZombieServer.MinimumPlayerCount = config.MinimumPlayers; } bool serverBrowser = config.DefaultMode == "serverbrowser"; ZombieBotTask = Task.Run(() => { OperationResult operationResult = OperationResult.Success; try { cg = new CustomGame(new CustomGameBuilder() { OverwatchProcess = CustomGame.GetOverwatchProcess() ?? CustomGame.StartOverwatch(new OverwatchInfoAuto() { BattlenetExecutableFilePath = config.BattlenetExecutable, OverwatchSettingsFilePath = config.OverwatchSettingsFile, ScreenshotMethod = config.ScreenshotMethod }), ScreenshotMethod = config.ScreenshotMethod }); cg.Commands.Listen = true; cg.ModesEnabled = config.Version == 0 ? Gamemode.Elimination : Gamemode.TeamDeathmatch; cg.CurrentEvent = config.OverwatchEvent; Map[] maps = config.Version == 0 ? ElimMaps : TdmMaps; if (cs.IsCancellationRequested) { operationResult = OperationResult.Canceled; } else { if (!skipSetup) { Setup(abyxa, serverBrowser, cg, maps, config.Preset, config.Name); } if (cs.IsCancellationRequested) { operationResult = OperationResult.Canceled; } else { while (!cs.IsCancellationRequested) { if ((operationResult = Pregame(abyxa, serverBrowser, cg, maps, config.MinimumPlayers, cs)) != OperationResult.Success) { break; } if ((operationResult = Ingame(abyxa, serverBrowser, cg, config.Version, cs)) != OperationResult.Success) { break; } } } } } catch (OverwatchClosedException) { operationResult = OperationResult.Exited; } catch (OverwatchStartFailedException) { operationResult = OperationResult.StartFailed; } cg.Dispose(); cg = null; if (abyxa != null) { abyxa.Kill(); } if (operationResult == OperationResult.Canceled) { Log("Bot stopped."); } else if (operationResult == OperationResult.Disconnected) { Log("Overwatch disconnected, bot stopped."); } else if (operationResult == OperationResult.Exited) { Log("Overwatch exited, bot stopped."); } else if (operationResult == OperationResult.StartFailed) { Log("Could not start Overwatch, bot stopped."); } Initialized = false; }); }
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(); } } }
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); } }