Skip to content

Commit

Permalink
Better pokestop grabbing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyTrent authored Aug 3, 2016
1 parent 761ac8a commit f4e600a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions PoGo.PokeMobBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,34 @@ private static async Task<List<FortData>> GetPokeStops(ISession session)
session.EventDispatcher.Send(new PokeStopListEvent { Forts = pokeStops.ToList() });

// Wasn't sure how to make this pretty. Edit as needed.
pokeStops = pokeStops
.Where(
i =>
i.Type == FortType.Checkpoint &&
i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime() &&
( // Make sure PokeStop is within max travel distance, unless it's set to 0.
LocationUtils.CalculateDistanceInMeters(
session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
i.Latitude, i.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters) ||
session.LogicSettings.MaxTravelDistanceInMeters == 0
);
if (session.LogicSettings.Teleport)
{
pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts)
.Where(
i =>
i.Type == FortType.Checkpoint &&
i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime() &&
( // Make sure PokeStop is within max travel distance, unless it's set to 0.
LocationUtils.CalculateDistanceInMeters(
session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
i.Latitude, i.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters) ||
session.LogicSettings.MaxTravelDistanceInMeters == 0
);
}
else
{
pokeStops = mapObjects.MapCells.SelectMany(i => i.Forts)
.Where(
i =>
i.Type == FortType.Checkpoint &&
i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime() &&
( // Make sure PokeStop is within max travel distance, unless it's set to 0.
LocationUtils.CalculateDistanceInMeters(
session.Client.CurrentLatitude, session.Client.CurrentLongitude,
i.Latitude, i.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters) ||
session.LogicSettings.MaxTravelDistanceInMeters == 0
);
}

return pokeStops.ToList();
}
Expand All @@ -460,4 +477,4 @@ private static async Task DownloadProfile(ISession session)
session.Profile = await session.Client.Player.GetPlayer();
}
}
}
}

0 comments on commit f4e600a

Please sign in to comment.