private async Task _generateOpponentAsync() { // Pick a random species from the same zone as the player's gotchi. List <Species> species_list = new List <Species>(); foreach (SpeciesZone zone in await SpeciesUtils.GetZonesAsync(await SpeciesUtils.GetSpeciesAsync(player1.Gotchi.Gotchi.SpeciesId))) { species_list.AddRange((await ZoneUtils.GetSpeciesAsync(zone.Zone)).Where(x => !x.IsExtinct)); } player2 = new PlayerState(); if (species_list.Count() > 0) { player2.Gotchi = await GotchiUtils.GenerateGotchiAsync(new GotchiGenerationParameters { Base = player1.Gotchi.Gotchi, Species = species_list[BotUtils.RandomInteger(species_list.Count())], MinLevel = player1.Gotchi.Stats.Level - 3, MaxLevel = player1.Gotchi.Stats.Level + 3, GenerateMoveset = true, GenerateStats = true }); } // Set the opponent. if (player2.Gotchi != null) { player2.Gotchi.Gotchi.OwnerId = WildGotchiUserId; player2.Gotchi.Gotchi.Id = WildGotchiId; } }
private async Task DoAutoFeederAsync(ulong userId, IEnumerable <Gotchi> userGotchis) { // Auto-feeder if ((await GotchiUtils.GetItemFromInventoryAsync(userId, GotchiItemId.AutoFeeder)).Count > 0) { GotchiUserInfo userInfo = await GotchiUtils.GetUserInfoAsync(userId); const int costPerFeeding = 5; if (userInfo != null && userInfo.G >= costPerFeeding) { int gotchisFed = userGotchis.Where(g => g.IsHungry).Count(); if (gotchisFed > 0) { await GotchiUtils.FeedGotchisAsync(userId); userInfo.G = Math.Max(0, userInfo.G - (costPerFeeding * gotchisFed)); await GotchiUtils.UpdateUserInfoAsync(userInfo); } } } }
public static async Task ShowBattleStateAsync(ICommandContext context, GotchiBattleState state) { // Get an image of the battle. string gif_url = ""; GotchiGifCreatorParams p1 = new GotchiGifCreatorParams { gotchi = state.player1.Gotchi.Gotchi, x = 50, y = 150, state = state.player1.Gotchi.Stats.Hp > 0 ? (state.player2.Gotchi.Stats.Hp <= 0 ? GotchiState.Happy : GotchiState.Energetic) : GotchiState.Dead, auto = false }; GotchiGifCreatorParams p2 = new GotchiGifCreatorParams { gotchi = state.player2.Gotchi.Gotchi, x = 250, y = 150, state = state.player2.Gotchi.Stats.Hp > 0 ? (state.player1.Gotchi.Stats.Hp <= 0 ? GotchiState.Happy : GotchiState.Energetic) : GotchiState.Dead, auto = false }; gif_url = await GotchiUtils.GenerateAndUploadGotchiGifAndReplyAsync(context, new GotchiGifCreatorParams[] { p1, p2 }, new GotchiGifCreatorExtraParams { backgroundFileName = await GotchiUtils.GetGotchiBackgroundFileNameAsync(state.player2.Gotchi.Gotchi, "home_battle.png"), overlay = (Graphics gfx) => { // Draw health bars. _drawHealthBar(gfx, p1.x, 180, (double)state.player1.Gotchi.Stats.Hp / state.player1.Gotchi.Stats.MaxHp); _drawHealthBar(gfx, p2.x, 180, (double)state.player2.Gotchi.Stats.Hp / state.player2.Gotchi.Stats.MaxHp); } }); EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle(string.Format("**{0}** vs. **{1}** (Turn {2})", state.player1.Gotchi.Gotchi.Name, state.player2.Gotchi.Gotchi.Name, state.turnCount)); embed.WithImageUrl(gif_url); embed.WithDescription(state.battleText); if (state.BattleIsOver) { embed.WithFooter("The battle has ended!"); } else if (state.turnCount == 0) { embed.WithFooter("The battle has begun. Pick your move!"); } else { embed.WithFooter(string.Format("Beginning Turn {0}. Pick your move!", state.turnCount + 1)); } await context.Channel.SendMessageAsync("", false, embed.Build()); }
private async Task DoEvolveAsync(ulong userId, IEnumerable <Gotchi> userGotchis) { // Gotchi evolution (time-based) foreach (Gotchi gotchi in userGotchis) { if (gotchi.CanEvolve) { await GotchiUtils.EvolveAndUpdateGotchiAsync(gotchi); } } }
private async Task DoBackgroundLoopAsync() { // If gotchis are not enabled, don't do anything. if (Bot.OurFoodChainBot.Instance.Config.GotchisEnabled) { foreach (IGrouping <ulong, Gotchi> userGotchis in (await GotchiUtils.GetGotchisAsync()).GroupBy(g => g.OwnerId)) { await DoAutoFeederAsync(userGotchis.Key, userGotchis); await DoEvolveAsync(userGotchis.Key, userGotchis); } } }
private async Task _endBattle(ICommandContext context) { PlayerState winner = player1.Gotchi.Stats.Hp <= 0.0 ? player2 : player1; PlayerState loser = player1.Gotchi.Stats.Hp <= 0.0 ? player1 : player2; // Calculate the amount of EXP awarded to the winner. // The loser will get 50% of the winner's EXP. double exp = _getExpEarned(winner.Gotchi.Gotchi, loser.Gotchi.Gotchi, won: true); double exp1 = player2.Gotchi.Stats.Hp <= 0.0 ? exp : exp * .5; double exp2 = player1.Gotchi.Stats.Hp <= 0.0 ? exp : exp * .5; long levels1 = player1.Gotchi.Stats.AddExperience((int)exp1); long levels2 = player2.Gotchi.Stats.AddExperience((int)exp2); StringBuilder sb = new StringBuilder(); sb.AppendLine(battleText); // Show the winner's accomplishments, then the loser's. if (!IsCpuGotchi(winner.Gotchi.Gotchi)) { double winner_exp = winner.Gotchi.Gotchi.Id == player1.Gotchi.Gotchi.Id ? exp1 : exp2; long winner_levels = winner.Gotchi.Gotchi.Id == player1.Gotchi.Gotchi.Id ? levels1 : levels2; long winner_g = (long)Math.Round(loser.Gotchi.Stats.Level * (BotUtils.RandomInteger(150, 200) / 100.0)); sb.AppendLine(string.Format("🏆 **{0}** won the battle! Earned **{1} EXP** and **{2}G**.", winner.Gotchi.Gotchi.Name, winner_exp, winner_g)); if (winner_levels > 0) { sb.AppendLine(string.Format("🆙 **{0}** leveled up to level **{1}**!", winner.Gotchi.Gotchi.Name, winner.Gotchi.Stats.Level)); } if (((winner.Gotchi.Stats.Level - winner_levels) / 10) < (winner.Gotchi.Stats.Level / 10)) { if (await GotchiUtils.EvolveAndUpdateGotchiAsync(winner.Gotchi.Gotchi)) { Species sp = await BotUtils.GetSpeciesFromDb(winner.Gotchi.Gotchi.SpeciesId); sb.AppendLine(string.Format("🚩 Congratulations, **{0}** evolved into **{1}**!", winner.Gotchi.Gotchi.Name, sp.ShortName)); } } // Update the winner's G. GotchiUserInfo user_data = await GotchiUtils.GetUserInfoAsync(winner.Gotchi.Gotchi.OwnerId); user_data.G += winner_g; await GotchiUtils.UpdateUserInfoAsync(user_data); sb.AppendLine(); } if (!IsCpuGotchi(loser.Gotchi.Gotchi)) { double loser_exp = loser.Gotchi.Gotchi.Id == player1.Gotchi.Gotchi.Id ? exp1 : exp2; long loser_levels = loser.Gotchi.Gotchi.Id == player1.Gotchi.Gotchi.Id ? levels1 : levels2; sb.AppendLine(string.Format("💀 **{0}** lost the battle... Earned **{1} EXP**.", loser.Gotchi.Gotchi.Name, loser_exp)); if (loser_levels > 0) { sb.AppendLine(string.Format("🆙 **{0}** leveled up to level **{1}**!", loser.Gotchi.Gotchi.Name, loser.Gotchi.Stats.Level)); } if (((loser.Gotchi.Stats.Level - loser_levels) / 10) < (loser.Gotchi.Stats.Level / 10)) { if (await GotchiUtils.EvolveAndUpdateGotchiAsync(loser.Gotchi.Gotchi)) { Species sp = await BotUtils.GetSpeciesFromDb(loser.Gotchi.Gotchi.SpeciesId); sb.AppendLine(string.Format("🚩 Congratulations, **{0}** evolved into **{1}**!", loser.Gotchi.Gotchi.Name, sp.ShortName)); } } } // Update exp in the database. using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Gotchi SET level=$level, exp=$exp WHERE id=$id;")) { cmd.Parameters.AddWithValue("$id", player1.Gotchi.Gotchi.Id); cmd.Parameters.AddWithValue("$level", DBNull.Value); cmd.Parameters.AddWithValue("$exp", player1.Gotchi.Stats.Experience); await Database.ExecuteNonQuery(cmd); } if (!IsCpuGotchi(player2.Gotchi.Gotchi)) { using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Gotchi SET level=$level, exp=$exp WHERE id=$id;")) { cmd.Parameters.AddWithValue("$id", player2.Gotchi.Gotchi.Id); cmd.Parameters.AddWithValue("$level", DBNull.Value); cmd.Parameters.AddWithValue("$exp", player2.Gotchi.Stats.Experience); await Database.ExecuteNonQuery(cmd); } } // Deregister the battle state. DeregisterBattle(context.User.Id); battleText = sb.ToString(); }