private async Task <MethodResult <List <MapCell> > > GetMapObjects() { try { //Only mapobject returns objects var checkAllReponse = await _client.Map.GetMapObjects(); GetMapObjectsResponse mapObjectResponse = checkAllReponse.Item1; return(new MethodResult <List <MapCell> > { Data = mapObjectResponse.MapCells.ToList(), Message = "Success", Success = true }); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Failed to get map objects", Models.LoggerTypes.Exception, ex)); return(new MethodResult <List <MapCell> > { Message = "Failed to get map objects" }); } }
public async Task <GetMapObjectsResponse> GetMapObjects() { if (DateTime.Now >= _LastScanTS.AddSeconds(30) || _LastScanTS == null) { _LastScanTS = DateTime.Now; _LastMOResponse = await _client.Map.GetMapObjects(); } return(_LastMOResponse); }
private static FortData[] GetNearbyGyms(GetMapObjectsResponse mapObjectsResponse = null) { if (mapObjectsResponse == null) { mapObjectsResponse = Logic.objClient.Map.GetMapObjects().Result.Item1; } var pokeGyms = Logic.Instance.navigation .pathByNearestNeighbour( mapObjectsResponse.MapCells.SelectMany(i => i.Forts) .Where(i => i.Type == FortType.Gym) .OrderBy(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude)) .ToArray(), GlobalVars.WalkingSpeedInKilometerPerHour); return(pokeGyms); }
private FortData[] GetNearbyPokeStops(bool updateMap = true, GetMapObjectsResponse mapObjectsResponse = null) { //Query nearby objects for mapData if (mapObjectsResponse == null) { mapObjectsResponse = objClient.Map.GetMapObjects().Result.Item1; } //narrow map data to pokestops within walking distance var unixNow = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds; var pokeStops = mapObjectsResponse.MapCells.SelectMany(i => i.Forts) .Where(i => i.Type == FortType.Checkpoint && i.CooldownCompleteTimestampMs < unixNow); var pokeGyms = mapObjectsResponse.MapCells.SelectMany(i => i.Forts) .Where(i => i.Type == FortType.Gym && i.CooldownCompleteTimestampMs < unixNow); if (!GlobalVars.Gyms.Farm) { pokeGyms = new List <FortData>(); } var both = pokeStops.Concat(pokeGyms) .OrderBy(i => LocationUtils.CalculateDistanceInMeters(objClient.CurrentLatitude, objClient.CurrentLongitude, i.Latitude, i.Longitude)); var forts = navigation.pathByNearestNeighbour(both.ToArray(), BotSettings.WalkingSpeedInKilometerPerHour); if (updateMap) { if (pokeStops.Any()) { Task.Factory.StartNew(() => infoObservable.PushAvailablePokeStopLocations(pokeStops.ToArray())); } if (pokeGyms.Any()) { Task.Factory.StartNew(() => infoObservable.PushAvailablePokeGymsLocations(pokeGyms.ToArray())); } } return(forts); }
private static FortData[] GetNearbyGyms(GetMapObjectsResponse mapObjectsResponse = null) { //Logic.objClient.Player.UpdatePlayerLocation(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, Logic.objClient.CurrentAltitude); LocationUtils.updatePlayerLocation(Logic.objClient, Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, Logic.objClient.CurrentAltitude); RandomHelper.RandomSleep(400); if (mapObjectsResponse == null) { mapObjectsResponse = Logic.objClient.Map.GetMapObjects().Result.Item1; } var pokeGyms = Logic.Instance.navigation .pathByNearestNeighbour( mapObjectsResponse.MapCells.SelectMany(i => i.Forts) .Where(i => i.Type == FortType.Gym) .OrderBy(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude)) .ToArray(), GlobalVars.WalkingSpeedInKilometerPerHour); Task.Factory.StartNew(() => RefreshGymsInMap(pokeGyms)); return(pokeGyms); }
private async Task <MethodResult <List <MapCell> > > GetMapObjects() { TimeSpan secondsSinceLastRequest = DateTime.Now - _lastMapRequest; if (secondsSinceLastRequest < TimeSpan.FromSeconds(6)) { return(new MethodResult <List <MapCell> > { Data = new List <MapCell>(), Success = true }); } try { //Only mapobject returns objects var checkAllReponse = await _client.Map.GetMapObjects(); GetMapObjectsResponse mapObjectResponse = checkAllReponse.Item1; _lastMapRequest = DateTime.Now; return(new MethodResult <List <MapCell> > { Data = mapObjectResponse.MapCells.ToList(), Message = "Success", Success = true }); } catch (Exception ex) { LogCaller(new LoggerEventArgs("Failed to get map objects", Models.LoggerTypes.Exception, ex)); return(new MethodResult <List <MapCell> > { Message = "Failed to get map objects" }); } }
<GetMapObjectsResponse> GetMapObjects(bool forceRequest = false) { // In case we did last _minSecondsBetweenMapCalls before, we return the cached response if (_lastGetMapRequest.AddSeconds(_minSecondsBetweenMapCalls).Ticks > DateTime.UtcNow.Ticks && !forceRequest && _cachedGetMapResponse != null ) { return(_cachedGetMapResponse); } var cellIds = S2Helper.GetNearbyCellIds(Client.CurrentLongitude, Client.CurrentLatitude).ToArray(); var sinceTimeMs = new long[cellIds.Length]; for (var index = 0; index < cellIds.Length; index++) { sinceTimeMs[index] = 0; } var getMapObjectsMessage = new GetMapObjectsMessage { CellId = { cellIds }, SinceTimestampMs = { sinceTimeMs }, Latitude = Client.CurrentLatitude, Longitude = Client.CurrentLongitude }; var request = new Request { RequestType = RequestType.GetMapObjects, RequestMessage = getMapObjectsMessage.ToByteString() }; _cachedGetMapResponse = await PostProtoPayloadCommonR <Request, GetMapObjectsResponse>(request).ConfigureAwait(false); _lastGetMapRequest = DateTime.UtcNow; return(_cachedGetMapResponse); }
private static void ParseMapObject(GetMapObjectsResponse response) { if (response.Status == MapObjectsStatus.Success) { foreach (var cell in response.MapCells) { foreach (var poke in cell.NearbyPokemons) { _nearbyPokemon[poke.EncounterId] = poke; } } } if (_nearbyPokemon.Count > 0) { Console.WriteLine("NEARBY POKEMON"); } foreach (var poke in _nearbyPokemon.Values) { Console.WriteLine($" Name: {poke.PokemonId}, Distance: {poke.DistanceInMeters}m (This value will always be 200m until Niantic fixes servers)"); } }
protected ByteString GetGlobalPacket(RequestType typ, object msg) { switch (typ) { //case RequestType.Encounter: // var pl = (EncounterMessage)msg; // EncounterResponse en = new EncounterResponse(); // return en.ToByteString(); //case RequestType.CatchPokemon: // CatchPokemonResponse cp = new CatchPokemonResponse(); // return cp.ToByteString(); //case RequestType.FortSearch: // FortSearchResponse fs = new FortSearchResponse(); // return fs.ToByteString(); //case RequestType.FortDetails: // FortDetailsResponse fd = new FortDetailsResponse(); // return fd.ToByteString(); //https://github.com/msx752/PoGoEmulator/issues/23 case RequestType.GetMapObjects: GetMapObjectsMessage mgmo = (GetMapObjectsMessage)msg; var lat = mgmo.Latitude; var lon = mgmo.Longitude; RepeatedField <MapCell> cells = Fort.GetFortsByCells(mgmo.CellId); GetMapObjectsResponse gmo = new GetMapObjectsResponse(); gmo.Status = POGOProtos.Map.MapObjectsStatus.Success; gmo.MapCells.AddRange(cells); return(gmo.ToByteString()); case RequestType.CheckChallenge: var c = new CheckChallengeResponse() { ChallengeUrl = " " }; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(CheckChallengeResponse)}"); return(c.ToByteString()); //case RequestType.GetDownloadUrls: // GetDownloadUrlsResponse gdu = new GetDownloadUrlsResponse(); // return gdu.ToByteString(); case RequestType.DownloadSettings: DownloadSettingsResponse ds = new DownloadSettingsResponse(); ds.Hash = "2788184af4004004d6ab0740f7632983332106f6"; ds.Settings = new POGOProtos.Settings.GlobalSettings() { FortSettings = new FortSettings() { InteractionRangeMeters = 40.25098039215686, MaxTotalDeployedPokemon = 10, MaxPlayerDeployedPokemon = 1, DeployStaminaMultiplier = 8.062745098039215, DeployAttackMultiplier = 0, FarInteractionRangeMeters = 1000.0156862745098 }, MapSettings = new MapSettings() { PokemonVisibleRange = 999.00196078431372, PokeNavRangeMeters = 751.0156862745098, EncounterRangeMeters = 999.25098039215686, GetMapObjectsMinRefreshSeconds = 16, GetMapObjectsMaxRefreshSeconds = 16, GetMapObjectsMinDistanceMeters = 10.007843017578125f, GoogleMapsApiKey = "AIzaSyDilRVKLXIdPBMsR41VCxx3FpoHpbSEPIc" //change it for you }, InventorySettings = new InventorySettings() { MaxPokemon = 1000, MaxBagItems = 1000, BasePokemon = 250, BaseBagItems = 350, BaseEggs = 9 }, MinimumClientVersion = "0.35.0", }; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(DownloadSettingsResponse)}"); return(ds.ToByteString()); case RequestType.DownloadRemoteConfigVersion: DownloadRemoteConfigVersionResponse drcv = new DownloadRemoteConfigVersionResponse(); drcv.Result = DownloadRemoteConfigVersionResponse.Types.Result.Success; drcv.ItemTemplatesTimestampMs = 1471650700946; drcv.AssetDigestTimestampMs = 1467338276561000; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(DownloadRemoteConfigVersionResponse)}"); return(drcv.ToByteString()); case RequestType.DownloadItemTemplates: var dit = GlobalSettings.GameMaster.Decode; //this.Log.Dbg($"TypeOfResponseMessage: {nameof(DownloadItemTemplatesResponse)}"); return(dit.ToByteString()); default: throw new Exception($"unknown (Global) Returns type: {typ}"); } }
public static bool Execute(GetMapObjectsResponse mapObjectsResponse) { client = Logic.objClient; infoObservable = Logic.Instance.infoObservable; //bypass catching pokemon if disabled if (GlobalVars.CatchPokemon && AllowCatchPokemon) { if (mapObjectsResponse == null) { mapObjectsResponse = client.Map.GetMapObjects().Result; } MapPokemon mapIncensePokemon = null; try { var duration = Setout.lastincenseuse - DateTime.Now; Logger.Debug("last incense use duration: " + duration); if (duration.TotalMilliseconds > 0) { var incensePokemon = client.Map.GetIncensePokemons(); Logger.Debug("incensePokemon: " + incensePokemon); if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable) { mapIncensePokemon = new MapPokemon(); mapIncensePokemon.EncounterId = incensePokemon.EncounterId; mapIncensePokemon.Longitude = incensePokemon.Longitude; mapIncensePokemon.Latitude = incensePokemon.Latitude; mapIncensePokemon.PokemonDisplay = incensePokemon.PokemonDisplay; mapIncensePokemon.PokemonId = incensePokemon.PokemonId; mapIncensePokemon.SpawnPointId = incensePokemon.EncounterLocation; mapIncensePokemon.ExpirationTimestampMs = incensePokemon.DisappearTimestampMs; Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Found incensed Pokemon: {mapIncensePokemon.PokemonId}"); if (GlobalVars.ShowPokemons) { infoObservable.PushNewPokemonLocation(mapIncensePokemon); } } else { Logger.Debug("incensePokemon.Result: " + incensePokemon.Result); } } } catch (Exception ex1) { Logger.ExceptionInfo(ex1.ToString()); } if (mapIncensePokemon != null) { if (!GlobalVars.catchPokemonSkipList.Contains(mapIncensePokemon.PokemonId)) { CatchIncensedPokemon(mapIncensePokemon.EncounterId, mapIncensePokemon.SpawnPointId, mapIncensePokemon.PokemonId, mapIncensePokemon.Longitude, mapIncensePokemon.Latitude); } } var pokemons = mapObjectsResponse.MapCells.SelectMany(i => i.CatchablePokemons).OrderBy(i => LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, i.Latitude, i.Longitude)); Logger.Debug($"Pokemons Catchable: {pokemons.Count()}"); var nearbyPokemons = mapObjectsResponse.MapCells.SelectMany(i => i.NearbyPokemons); Logger.Debug($"Pokemons Nearby: {nearbyPokemons.Count()}"); var wildPokemons = mapObjectsResponse.MapCells.SelectMany(i => i.WildPokemons).OrderBy(i => LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, i.Latitude, i.Longitude)); Logger.Debug($"Pokemons Wild: {wildPokemons.Count()}"); if (pokemons.Any()) { var strNames = pokemons.Aggregate("", (current, pokemon) => current + (pokemon.PokemonId + ", ")); strNames = strNames.Substring(0, strNames.Length - 2); Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Found {pokemons.Count()} catchable Pokemon(s): " + strNames); if (GlobalVars.ShowPokemons) { ShowNearbyPokemons(pokemons); } } else { zeroCachablePokemons++; if (zeroCachablePokemons > 10) { zeroCachablePokemons = 0; //client.Login.DoLogin().Wait(); //client.Login.Reauthenticate().Wait(); } return(false); } //catch them all! foreach (var pokemon in pokemons) { #region Stats Log //increment log stats counter and log stats Setout.count++; if (Setout.count >= 9) { Setout.Execute(); } #endregion #region Skip pokemon if in list if (GlobalVars.catchPokemonSkipList.Contains(pokemon.PokemonId)) { Logger.ColoredConsoleWrite(ConsoleColor.Green, "Skipped Pokemon: " + pokemon.PokemonId); continue; } #endregion //get distance to pokemon var distance = LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); RandomHelper.RandomSleep(distance > 100 ? 1000 : 100, distance > 100 ? 1100 : 110); // Do Catch here CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokemon.PokemonId, pokemon.Longitude, pokemon.Latitude); } client.Map.GetMapObjects(true).Wait(); //force Map Objects Update client.Inventory.GetHoloInventory(true); //force Inventory Update return(true); } return(false); }
public async Task<GetMapObjectsResponse> GetMapObjects() { if (DateTime.Now >= _LastScanTS.AddSeconds(30) || _LastScanTS == null) { _LastScanTS = DateTime.Now; _LastMOResponse = await _client.Map.GetMapObjects(); } return _LastMOResponse; }
private async Task ExecuteCatchAllNearbyPokemons(Client clien, GetMapObjectsResponse mapObjects) { var pokemons = mapObjects.MapCells.SelectMany(i => i.CatchablePokemons).ToList(); if (!(nbPokemons < 230)) await EvolveAndTransfert(clien); foreach (var pokemon in pokemons) { if (ForceUnbanning || Stopping) break; FarmingPokemons = true; // await locationManager.update(pokemon.Latitude, pokemon.Longitude); var encounterPokemonResponse = await client.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnpointId); var pokemonCP = encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp; var pokemonIV = Math.Round(Perfect(encounterPokemonResponse?.WildPokemon?.PokemonData)); CatchPokemonResponse caughtPokemonResponse; do { if (ClientSettings.RazzBerryMode == "cp") if (pokemonCP > ClientSettings.RazzBerrySetting) await client.UseRazzBerry(client, pokemon.EncounterId, pokemon.SpawnpointId); if (ClientSettings.RazzBerryMode == "probability") if (encounterPokemonResponse.CaptureProbability.CaptureProbability_.First() < ClientSettings.RazzBerrySetting) await client.UseRazzBerry(client, pokemon.EncounterId, pokemon.SpawnpointId); caughtPokemonResponse = await client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, MiscEnums.Item.ITEM_POKE_BALL, pokemonCP); ; //note: reverted from settings because this should not be part of settings but part of logic } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape); string pokemonName; if (language == "german") pokemonName = LanguageSetting.GermanName[(int)pokemon.PokemonId - 1]; else if (language == "french") pokemonName = LanguageSetting.frenchPokemons[(int)pokemon.PokemonId - 1]; else pokemonName = Convert.ToString(pokemon.PokemonId); if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { ColoredConsoleWrite(Color.Green, $"We caught a {pokemonName} with {pokemonCP} CP and {pokemonIV}% IV"); foreach (int xp in caughtPokemonResponse.Scores.Xp) TotalExperience += xp; TotalPokemon += 1; nbPokemons++; } else ColoredConsoleWrite(Color.Red, $"{pokemonName} with {pokemonCP} CP and {pokemonIV}% IV got away.."); FarmingPokemons = false; await Task.Delay(0); //3000 } }
/// <summary> /// Provides a safe way to invoke the <see cref="MapObjectsReceived" /> event. /// </summary> /// <param name="value"></param> public void RaiseMapObjectsReceived(GetMapObjectsResponse value) => MapObjectsReceived?.Invoke(this, value);
/// <summary> /// /// </summary> /// <param name="force">For thread wait until next api call available to use</param> /// <param name="updateCache">Allow update cache, in some case we don't want update cache, snipe pokemon is an example</param> /// <returns></returns> public async Task <GetMapObjectsResponse> GetMapObjects(bool force = false, bool updateCache = true) { if (force) { var t = GetMilisSecondUntilRefreshMapAvail(); //wait until get map available if (t > 0) { await Task.Delay(t).ConfigureAwait(false); } } if (!CanRefreshMap()) { return(force ? await GetMapObjects(force, updateCache).ConfigureAwait(false) : LastGetMapObjectResponse); // If we cannot refresh the map, return the cached response. } var lat = Client.CurrentLatitude; var lon = Client.CurrentLongitude; var getMapObjectsMessage = new GetMapObjectsMessage { CellId = { S2Helper.GetNearbyCellIds(lon, lat) }, SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, Latitude = lat, Longitude = lon }; var getMapObjectsRequest = new Request { RequestType = RequestType.GetMapObjects, RequestMessage = getMapObjectsMessage.ToByteString() }; var request = await GetRequestBuilder().GetRequestEnvelope(CommonRequest.FillRequest(getMapObjectsRequest, Client)).ConfigureAwait(false); Tuple <GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetHoloInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse, GetBuddyWalkedResponse> response = await PostProtoPayload <Request, GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetHoloInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse, GetBuddyWalkedResponse>(request).ConfigureAwait(false); GetHoloInventoryResponse getHoloInventoryResponse = response.Item4; CommonRequest.ProcessGetHoloInventoryResponse(Client, getHoloInventoryResponse); DownloadSettingsResponse downloadSettingsResponse = response.Item6; CommonRequest.ProcessDownloadSettingsResponse(Client, downloadSettingsResponse); CheckChallengeResponse checkChallengeResponse = response.Item2; CommonRequest.ProcessCheckChallengeResponse(Client, checkChallengeResponse); LastRpcMapObjectsRequestMs = Util.TimeUtil.GetCurrentTimestampInMilliseconds(); var numCells = response.Item1.MapCells.Count; var numCellsWithForts = response.Item1.MapCells.Count(x => x.Forts.Count > 0); var numCellsWithNearbyPokemon = response.Item1.MapCells.Count(x => x.NearbyPokemons.Count > 0); var numCellsWithWildPokemon = response.Item1.MapCells.Count(x => x.WildPokemons.Count > 0); // Only cache good responses if (updateCache && numCells > 0 && (numCellsWithForts > 0 || numCellsWithNearbyPokemon > 0 || numCellsWithWildPokemon > 0)) { // Good map response since we got at least a fort or pokemon in our cells. LastGetMapObjectResponse = response.Item1; LastGeoCoordinateMapObjectsRequest = new GeoCoordinate(lat, lon); } if (updateCache && LastGetMapObjectResponse == null) { LastGetMapObjectResponse = response.Item1; } return(response.Item1); }