public GotchiBattleState(IOfcBotConfiguration botConfiguration, DiscordSocketClient discordClient, SQLiteDatabase database, GotchiService gotchiService) { _botConfiguration = botConfiguration; _discordClient = discordClient; this.database = database; this.gotchiService = gotchiService; }
public static async Task RegisterBattleAsync(ICommandContext context, IOfcBotConfiguration botConfiguration, DiscordSocketClient discordClient, SQLiteDatabase database, GotchiService gotchiService, Gotchi gotchi1, Gotchi gotchi2) { // Initialize the battle state. GotchiBattleState state = new GotchiBattleState(botConfiguration, discordClient, database, gotchiService) { // Initialize Player 1 (which must be a human player). player1 = new PlayerState { Gotchi = new BattleGotchi { Gotchi = gotchi1, Moves = await Global.GotchiContext.MoveRegistry.GetMoveSetAsync(database, gotchi1), Stats = await new GotchiStatsCalculator(database, Global.GotchiContext).GetStatsAsync(gotchi1), Types = await Global.GotchiContext.TypeRegistry.GetTypesAsync(database, gotchi1) } } }; if (gotchi2 != null) { // Initialize Player 2 (which may be a human player, or a CPU). state.player2 = new PlayerState { Gotchi = new BattleGotchi { Gotchi = gotchi2, Moves = await Global.GotchiContext.MoveRegistry.GetMoveSetAsync(database, gotchi2), Stats = await new GotchiStatsCalculator(database, Global.GotchiContext).GetStatsAsync(gotchi2), Types = await Global.GotchiContext.TypeRegistry.GetTypesAsync(database, gotchi2) } }; } else { // Otherwise, generate an opponent for the user. await state._generateOpponentAsync(); // If the opponent is null (no species available as opponents), abort. if (state.player2.Gotchi.Gotchi is null) { await BotUtils.ReplyAsync_Info(context, "There are no opponents available."); return; } // Since the user is battling a CPU, accept the battle immediately. state.accepted = true; } state.player1.Gotchi.Context = Global.GotchiContext; state.player2.Gotchi.Context = Global.GotchiContext; // Register the battle state in the battle state collection. _battle_states[gotchi1.OwnerId] = state; if (state.player2.Gotchi.Gotchi.OwnerId != WildGotchiUserId) { _battle_states[state.player2.Gotchi.Gotchi.OwnerId] = state; } // Set the initial message displayed when the battle starts. StringBuilder sb = new StringBuilder(); sb.AppendLine("The battle has begun!"); sb.AppendLine(); sb.AppendLine(string.Format("Pick a move with `{0}gotchi move`.\nSee your gotchi's moveset with `{0}gotchi moveset`.", botConfiguration.Prefix)); state.battleText = sb.ToString(); // If the user is battling a CPU, show the battle state immediately. // Otherwise, it will be shown when the other user accepts the battle challenge. if (state.IsBattlingCpu()) { await ShowBattleStateAsync(context, state); } }