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()); }
public MethodResult <PokemonSettings> GetPokemonSetting(PokemonId pokemon) { if (PokeSettings == null) { return(new MethodResult <PokemonSettings> { Message = "Settings haven't been grabbed yet" }); } if (pokemon == PokemonId.Missingno) { return(new MethodResult <PokemonSettings> { Message = "No settings on Missingno" }); } //Shouldn't happen if (!PokeSettings.TryGetValue(pokemon, out PokemonSettings pokemonSettings)) { return(new MethodResult <PokemonSettings>() { Message = "Pokemon Id does not exist" }); } return(new MethodResult <PokemonSettings>() { Data = pokemonSettings, Message = "Success", Success = true }); }
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>()); } int pokemonCandy = 0; if (PokemonCandy.Any(x => x.FamilyId == setting.FamilyId)) { pokemonCandy = PokemonCandy.Where(x => x.FamilyId == setting.FamilyId).FirstOrDefault().Candy_; //int pokemonCandy = PokemonCandy.SingleOrDefault(x => x.FamilyId == setting.FamilyId).Candy_; } int candyToEvolve = setting.EvolutionBranch.Select(x => x.CandyCost).FirstOrDefault(); int totalPokemon = pokemon.Count(); if (candyToEvolve == 0) { //Not thinks good return(pokemon.OrderByDescending(x => x.Cp).ToList()); //return new List<PokemonData>(); } int maxPokemon = pokemonCandy / candyToEvolve; if (maxPokemon > limit) { maxPokemon = limit; } return(pokemon.OrderByDescending(x => x.Cp).Skip(maxPokemon).ToList()); }
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 }); }