public override async Task <OnGameConfigureResponse> OnRemoteBotGameConfigure() { // Only called on remote bots, not for hosted bots. // // Hosted bots are passed their information, like user name, and what game to join. // But remote bots just act like external players. So when they start, you have to either join a game that's already // been created, or create a new game. // // This function simply gives you a nice interface to create or join a game. It's also possible to use the // `KokkaKoroService` object directly to call the service directly. // Note! All KokkaKoroService throw exceptions if there is an unexpected failure. Logger.Log(Log.Info, $"OnRemoteBotGameConfigure"); // Example: List all games on the service // List<KokkaKoroGame> games = await KokkaKoroService.ListGames(); // Example: Using the service SDK, you can call list bots: List <ServiceProtocol.Common.KokkaKoroBot> bots = await KokkaKoroService.ListBots(); // But we know we want to beat the TestBot. List <string> botNames = new List <string>(); botNames.Add("RandomBot"); // We want to make a new game that auto starts and has the test bot to play against. return(OnGameConfigureResponse.CreateNewGame("MyTestBotGame", botNames, true)); // Or if we used the service to create a game, we could join it like this. // return OnGameConfigureResponse.JoinGame(gameId); }
private async Task <(Guid, string, bool, bool)> ConfigureGame(Service kokkaKoroService) { // If this is a hosted bot, we already know what game we want. if (IsHostedBot()) { return(m_hostedArgs.GameId, m_hostedArgs.Passcode, false, true); } // If this is a remote bot, ask the client what they want. OnGameConfigureResponse gameConfig = null; // Now based on the state, call the bot setup. try { gameConfig = await OnRemoteBotGameConfigure(); if (gameConfig == null) { throw new Exception("No game config returned"); } } catch (Exception e) { await FireOnUnhandledException("OnRemovteBotGameConfigure", e); return(Guid.Empty, null, false, false); } Guid gameId; if (gameConfig.ConfigType == GameConfigureType.CreateNewGame) { // If we need to create a game, do it now. KokkaKoroGame newGame = null; try { newGame = await kokkaKoroService.CreateGame(new CreateGameOptions() { GameName = gameConfig.GameName, Password = gameConfig.GamePassword }); } catch (Exception e) { await FireDisconnect("Failed create game.", false, e); return(Guid.Empty, null, false, false); } // Add any bots requested. foreach (string botName in gameConfig.NewGameBotNames) { try { newGame = await kokkaKoroService.AddBotToGame(new AddHostedBotOptions() { BotName = botName, InGameName = botName, GameId = newGame.Id, Password = gameConfig.GamePassword }); } catch (Exception e) { await FireDisconnect("Failed to add bot.", false, e); return(Guid.Empty, null, false, false); } } gameId = newGame.Id; } else { gameId = gameConfig.JoinGameId; } return(gameId, gameConfig.GamePassword, gameConfig.ShouldAutoStartGame, true); }