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