private List <PokemonData> GetPokemonByPossibleEvolve(IGrouping <PokemonId, PokemonData> pokemon, int limit) { PokemonSettings setting = null; if (!PokeSettings.TryGetValue(pokemon.Key, out setting)) { LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", pokemon.Key), LoggerTypes.Info)); return(new List <PokemonData>()); } Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId); int candyToEvolve = setting.CandyToEvolve; int totalPokemon = pokemon.Count(); int totalCandy = pokemonCandy.Candy_; if (candyToEvolve == 0) { return(new List <PokemonData>()); } int maxPokemon = totalCandy / candyToEvolve; if (maxPokemon > limit) { maxPokemon = limit; } return(pokemon.OrderByDescending(x => x.Cp).Skip(maxPokemon).ToList()); }
private bool CanEvolvePokemon(PokemonData pokemon) { // Can't evolve pokemon in gyms. if (!string.IsNullOrEmpty(pokemon.DeployedFortId)) { return(false); } var settings = PokeSettings.SingleOrDefault(x => x.Value.PokemonId == pokemon.PokemonId); // Can't evolve pokemon that are not evolvable. if (settings.Value.EvolutionIds.Count == 0 && settings.Value.EvolutionBranch.Count == 0) { return(false); } int familyCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == settings.Value.FamilyId).Candy_; bool canEvolve = false; // Check requirements for all branches, if we meet the requirements for any of them then we return true. foreach (var branch in settings.Value.EvolutionBranch) { var itemCount = Items.Count(x => x.ItemId == branch.EvolutionItemRequirement); var Candies2Evolve = branch.CandyCost; // GetCandyToEvolve(settings); var Evolutions = familyCandy / Candies2Evolve; if (branch.EvolutionItemRequirement != ItemId.ItemUnknown) { if (itemCount == 0) { continue; // Cannot evolve so check next branch } } if (familyCandy < branch.CandyCost) { continue; // Cannot evolve so check next branch } // If we got here, then we can evolve so break out of loop. canEvolve = true; } return(canEvolve); }
public async Task <MethodResult> ExportStats() { MethodResult result = await UpdateDetails(); //Prevent API throttling await Task.Delay(500); if (!result.Success) { return(result); } //Possible some objects were empty. var builder = new StringBuilder(); builder.AppendLine("=== Trainer Stats ==="); if (Stats != null && PlayerData != null) { builder.AppendLine(String.Format("Group: {0}", UserSettings.GroupName)); builder.AppendLine(String.Format("Username: {0}", UserSettings.Username)); builder.AppendLine(String.Format("Password: {0}", UserSettings.Password)); builder.AppendLine(String.Format("Level: {0}", Stats.Level)); builder.AppendLine(String.Format("Current Trainer Name: {0}", PlayerData.Username)); builder.AppendLine(String.Format("Team: {0}", PlayerData.Team)); builder.AppendLine(String.Format("Stardust: {0:N0}", TotalStardust)); builder.AppendLine(String.Format("Unique Pokedex Entries: {0}", Stats.UniquePokedexEntries)); } else { builder.AppendLine("Failed to grab stats"); } builder.AppendLine(); builder.AppendLine("=== Pokemon ==="); if (Pokemon != null) { foreach (PokemonData pokemon in Pokemon.OrderByDescending(x => x.Cp)) { string candy = "Unknown"; MethodResult <PokemonSettings> pSettings = GetPokemonSetting(pokemon.PokemonId); if (pSettings.Success) { Candy pCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == pSettings.Data.FamilyId); if (pCandy != null) { candy = pCandy.Candy_.ToString("N0"); } } double perfectResult = CalculateIVPerfection(pokemon); string iv = "Unknown"; iv = Math.Round(perfectResult, 2).ToString() + "%"; builder.AppendLine(String.Format("Pokemon: {0,-10} CP: {1, -5} IV: {2,-7} Primary: {3, -14} Secondary: {4, -14} Candy: {5}", pokemon.PokemonId, pokemon.Cp, iv, pokemon.Move1.ToString().Replace("Fast", ""), pokemon.Move2, candy)); } } //Remove the hardcoded directory later try { string directoryName = "AccountStats"; if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } string fileName = UserSettings.Username.Split('@').First(); string filePath = Path.Combine(directoryName, fileName) + ".txt"; File.WriteAllText(filePath, builder.ToString()); LogCaller(new LoggerEventArgs(String.Format("Finished exporting stats to file {0}", filePath), LoggerTypes.Info)); return(new MethodResult { Message = "Success", Success = true }); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Failed to export stats due to exception", LoggerTypes.Warning, ex)); return(new MethodResult()); } }
private async Task <MethodResult <List <PokemonData> > > GetPokemonToEvolve() { if (!UserSettings.EvolvePokemon) { LogCaller(new LoggerEventArgs("Evolving disabled", LoggerTypes.Info)); return(new MethodResult <List <PokemonData> > { Data = new List <PokemonData>(), Message = "Evolving disabled", Success = true }); } await UpdatePokemon(false); await UpdatePokemonCandy(false); MethodResult result = await GetItemTemplates(); if (!result.Success) { LogCaller(new LoggerEventArgs("Failed to grab pokemon settings. Skipping evolution", LoggerTypes.Warning)); return(new MethodResult <List <PokemonData> > { Data = new List <PokemonData>(), Success = true }); } List <PokemonData> pokemonToEvolve = new List <PokemonData>(); IEnumerable <IGrouping <PokemonId, PokemonData> > groupedPokemon = Pokemon.OrderByDescending(x => x.PokemonId).GroupBy(x => x.PokemonId); foreach (IGrouping <PokemonId, PokemonData> group in groupedPokemon) { EvolveSetting evolveSetting = UserSettings.EvolveSettings.FirstOrDefault(x => x.Id == group.Key); if (evolveSetting == null) { LogCaller(new LoggerEventArgs(String.Format("Failed to find evolve settings for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } if (!evolveSetting.Evolve) { //Don't evolve continue; } PokemonSettings setting; if (!PokeSettings.TryGetValue(group.Key, out setting)) { LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } if (setting.EvolutionIds.Count == 0) { //Pokemon can't evolve continue; } Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId); List <PokemonData> pokemonGroupToEvolve = group.Where(x => x.Cp >= evolveSetting.MinCP).OrderByDescending(x => CalculateIVPerfection(x).Data).ToList(); if (pokemonCandy == null) { LogCaller(new LoggerEventArgs(String.Format("No candy found for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } int candyToEvolve = setting.CandyToEvolve; int totalPokemon = pokemonGroupToEvolve.Count; int totalCandy = pokemonCandy.Candy_; int maxPokemon = totalCandy / candyToEvolve; foreach (PokemonData pData in pokemonGroupToEvolve.Take(maxPokemon)) { pokemonToEvolve.Add(pData); } } return(new MethodResult <List <PokemonData> > { Data = pokemonToEvolve, Message = "Success", Success = true }); }
private MethodResult <List <PokemonData> > GetPokemonToEvolve() { if (!UserSettings.EvolvePokemon) { LogCaller(new LoggerEventArgs("Evolving disabled", LoggerTypes.Info)); return(new MethodResult <List <PokemonData> > { Data = new List <PokemonData>(), Message = "Evolving disabled", Success = true }); } var pokemonToEvolve = new List <PokemonData>(); IEnumerable <IGrouping <PokemonId, PokemonData> > groupedPokemon = Pokemon.OrderByDescending(x => x.PokemonId).GroupBy(x => x.PokemonId); foreach (IGrouping <PokemonId, PokemonData> group in groupedPokemon) { EvolveSetting evolveSetting = UserSettings.EvolveSettings.FirstOrDefault(x => x.Id == group.Key); if (evolveSetting == null) { LogCaller(new LoggerEventArgs(String.Format("Failed to find evolve settings for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } if (!evolveSetting.Evolve) { //Don't evolve continue; } PokemonSettings setting; if (!PokeSettings.TryGetValue(group.Key, out setting)) { LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId); List <PokemonData> pokemonGroupToEvolve = group.Where(x => x.Cp >= evolveSetting.MinCP).OrderByDescending(x => CalculateIVPerfection(x)).ToList(); if (pokemonCandy == null) { LogCaller(new LoggerEventArgs(String.Format("No candy found for pokemon {0}", group.Key), LoggerTypes.Info)); continue; } int candyToEvolve = setting.EvolutionBranch.Select(x => x.CandyCost).FirstOrDefault(); int totalPokemon = pokemonGroupToEvolve.Count; int totalCandy = pokemonCandy.Candy_; int maxPokemon = totalCandy / candyToEvolve; foreach (PokemonData pData in pokemonGroupToEvolve.Take(maxPokemon)) { if (!CanTransferOrEvolePokemon(pData, true)) { LogCaller(new LoggerEventArgs(String.Format("Skipped {0}, this pokemon cant not be transfered maybe is a favorit, is deployed or is a buddy pokemon.", pData.PokemonId), LoggerTypes.Info)); } else { pokemonToEvolve.Add(pData); } } } return(new MethodResult <List <PokemonData> > { Data = pokemonToEvolve, Message = "Success", Success = true }); }