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); }
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
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); } }