public static void SaveLocationToDisk(ISession session, double lat, double lng, double speed) { if (session.Stats.IsSnipping) { return; } // Make sure new location is valid. if (!LocationUtils.IsValidLocation(lat, lng)) { return; } // If last location is valid, make sure distance between last location and new location is less than 1000m. if ((lastLat != 0 || lastLng != 0) && LocationUtils.CalculateDistanceInMeters(lat, lng, lastLat, lastLng) > 1000) { return; } // Don't save new position if it is outside of our max travel distance. if (LocationUtils.CalculateDistanceInMeters(lat, lng, session.Settings.DefaultLatitude, session.Settings.DefaultLongitude) > session.LogicSettings.MaxTravelDistanceInMeters) { return; } lastLat = lat; lastLng = lng; var coordsPath = Path.Combine(session.LogicSettings.ProfileConfigPath, "LastPos.ini"); File.WriteAllText(coordsPath, $"{lat}:{lng}"); }
private static async Task PostProcessDataFetched(IEnumerable <SnipePokemonInfo> pokemons, bool displayList = true) { // Filter out pokemon with invalid locations. pokemons = pokemons.Where(p => LocationUtils.IsValidLocation(p.Latitude, p.Longitude)).ToList(); var rw = new Random(); var speedInMetersPerSecond = _setting.WalkingSpeedInKilometerPerHour / 3.6; int count = 0; await Task.Run(() => { foreach (var item in pokemons) { #region ITEM PROCESSING //the pokemon data already in the list if (rarePokemons.Any(x => x.Value.UniqueId == item.UniqueId || (LocationUtils.CalculateDistanceInMeters(x.Value.Latitude, x.Value.Longitude, item.Latitude, item.Longitude) < 10 && item.Id == x.Value.Id))) { continue; } //check if pokemon in the snip list if (!pokemonToBeCaughtLocallyIds.ContainsKey(item.PokemonId)) { continue; } count++; var snipeSetting = _setting.HumanWalkSnipeFilters.FirstOrDefault(x => x.Key == item.PokemonId); HumanWalkSnipeFilter config = new HumanWalkSnipeFilter(_setting.HumanWalkingSnipeMaxDistance, _setting.HumanWalkingSnipeMaxEstimateTime, 3, //default priority _setting.HumanWalkingSnipeTryCatchEmAll, _setting.HumanWalkingSnipeSpinWhileWalking, _setting.HumanWalkingSnipeAllowSpeedUp, _setting.HumanWalkingSnipeMaxSpeedUpSpeed, _setting.HumanWalkingSnipeDelayTimeAtDestination, _setting.HumanWalkingSnipeAllowTransferWhileWalking); if (_setting.HumanWalkSnipeFilters.Any(x => x.Key == item.PokemonId)) { config = _setting.HumanWalkSnipeFilters.First(x => x.Key == item.PokemonId).Value; } item.Setting = Clone <HumanWalkSnipeFilter>(config); CalculateDistanceAndEstTime(item); if (item.Distance < 10000 && item.Distance != 0) //only add if distance <10km { rarePokemons[item.GetHashCode()] = item; } #endregion } }); if (count > 0) { var orderedRares = rarePokemons.OrderBy(p => p.Value.Setting.Priority).ThenBy(p => p.Value.Distance); _session.EventDispatcher.Send(new HumanWalkSnipeEvent() { Type = HumanWalkSnipeEventTypes.PokemonScanned, Pokemons = ApplyFilter(orderedRares.ToList()), DisplayMessage = displayList }); if (_setting.HumanWalkingSnipeDisplayList) { var ordered = rarePokemons.OrderBy(p => p.Value.Setting.Priority).ThenBy(p => p.Value.Distance) .Where(p => p.Value.ExpiredTime > DateTime.Now.AddSeconds(p.Value.EstimatedTime) && !p.Value.IsVisited) .ToList(); if (ordered.Count > 0 && displayList) { Logger.Write( string.Format( " Source | Name | Distance | Expires | Travel times | Catchable" ) ); foreach (var pokemon in ordered) { string name = _session.Translation.GetPokemonTranslation(pokemon.Value.PokemonId); name += "".PadLeft(30 - name.Length, ' '); string source = pokemon.Value.Source; source += "".PadLeft(30 - source.Length, ' '); Logger.Write( string.Format( " {0} | {1} | {2:0.00}m \t| {3:mm} min {3:ss} sec | {4:00} min {5:00} sec | {6}", source, name, pokemon.Value.Distance, pokemon.Value.ExpiredTime - DateTime.Now, pokemon.Value.EstimatedTime / 60, pokemon.Value.EstimatedTime % 60, pokemon.Value.ExpiredTime > DateTime.Now.AddSeconds(pokemon.Value.EstimatedTime) ? "Possible" : "Missied" ) ); } } } } }