Skip to content

Commit

Permalink
Deployment fix, Loop fix, ApiFailureStrategy rewrite, more exception …
Browse files Browse the repository at this point in the history
…handling.
  • Loading branch information
disdain13 committed Sep 8, 2016
1 parent 70276ed commit 4ee1067
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
74 changes: 48 additions & 26 deletions PokeRoadie/PokeRoadieLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ private bool RaiseSyncEvent(Delegate method, params object[] args)
private int locationAttemptCount = 0;
private List<TutorialState> tutorialAttempts = new List<TutorialState>();
private List<ulong> _recentEncounters = new List<ulong>();
public bool NeedsNewLogin { get; set; } = false;
public volatile bool NeedsNewLogin = false;
public volatile bool IsTravelingLongDistance;

#endregion
#region " Properties "
public Context Context { get; set; }
public bool IsTravelingLongDistance { get; set; }
public bool CanCatch { get { return Context.Settings.CatchPokemon && Context.Session.Current.CatchEnabled && !softBan && Context.Navigation.LastKnownSpeed <= Context.Settings.MaxCatchSpeed && noWorkTimer <= DateTime.Now; } }
public bool CanVisit { get { return Context.Settings.VisitPokestops && Context.Session.Current.VisitEnabled && !softBan; } }
public bool CanVisitGyms { get { return Context.Settings.VisitGyms && Context.Statistics.Currentlevel > 4 && !softBan; } }
Expand Down Expand Up @@ -996,7 +996,7 @@ private async Task ExecuteFarming()
{
IsTravelingLongDistance = true;
Logger.Write($"We have traveled outside the max distance of {Context.Settings.MaxDistance}, returning to center at {wayPointGeo}", LogLevel.Navigation, ConsoleColor.White);
await Context.Navigation.HumanLikeWalking(wayPointGeo, distanceFromStart > Context.Settings.MaxDistance / 2 ? Context.Settings.LongDistanceSpeed : Context.Settings.MinSpeed, distanceFromStart > Context.Settings.MaxDistance / 2 ? GetLongTask() : GetShortTask(), distanceFromStart > Context.Settings.MaxDistance / 2 ? false : true);
await Context.Navigation.HumanLikeWalking(wayPointGeo, distanceFromStart > Context.Settings.MaxDistance / 2 ? Context.Settings.LongDistanceSpeed : Context.Settings.MinSpeed, GetShortTask(), distanceFromStart > Context.Settings.MaxDistance / 2 ? false : true);
gymTries.Clear();
locationAttemptCount = 0;
Logger.Write($"Arrived at center point {Math.Round(wayPointGeo.Latitude, 5)}", LogLevel.Navigation);
Expand Down Expand Up @@ -1479,40 +1479,62 @@ private async Task ProcessGym(FortData pokeStop, GetMapObjectsResponse mapObject
fortString = $"{ fortDetails.Name} | { fortDetails.GymState.FortData.OwnedByTeam } | { pokeStop.GymPoints} | { fortDetails.GymState.Memberships.Count}";
if (_playerProfile.PlayerData.Team != TeamColor.Neutral && fortDetails.GymState.FortData.OwnedByTeam == _playerProfile.PlayerData.Team)
{
await PokeRoadieInventory.GetCachedInventory(Context.Client);

var pokemonList = await Context.Inventory.GetHighestsVNotDeployed(1);
var pokemon = pokemonList.FirstOrDefault();

if (pokemon != null)
var maxCount = 0;
var points = fortDetails.GymState.FortData.GymPoints;
if (points < 1600) maxCount = 1;
else if (points < 4000) maxCount = 2;
else if (points < 8000) maxCount = 3;
else if (points < 12000) maxCount = 4;
else if (points < 16000) maxCount = 5;
else if (points < 20000) maxCount = 6;
else if (points < 30000) maxCount = 7;
else if (points < 40000) maxCount = 8;
else if (points < 50000) maxCount = 9;
else maxCount = 10;

var availableSlots = maxCount - fortDetails.GymState.Memberships.Count();

if (availableSlots > 0)
{
var response = await Context.Client.Fort.FortDeployPokemon(fortInfo.FortId, pokemon.Id);
await PokeRoadieInventory.GetCachedInventory(Context.Client);
var pokemonList = await Context.Inventory.GetHighestsVNotDeployed(1);
var pokemon = pokemonList.FirstOrDefault();

if (response.Result == FortDeployPokemonResponse.Types.Result.Success)
if (pokemon != null)
{
PokeRoadieInventory.IsDirty = true;
Logger.Write($"(GYM) Deployed {Context.Utility.GetMinStats(pokemon)} to {fortDetails.Name}", LogLevel.None, ConsoleColor.Green);
var response = await Context.Client.Fort.FortDeployPokemon(fortInfo.FortId, pokemon.Id);

//raise event
if (OnDeployToGym != null)
if (response.Result == FortDeployPokemonResponse.Types.Result.Success)
{
if (!RaiseSyncEvent(OnDeployToGym, location, fortDetails, pokemon))
OnDeployToGym(location, fortDetails, pokemon);
PokeRoadieInventory.IsDirty = true;
Logger.Write($"(GYM) Deployed {Context.Utility.GetMinStats(pokemon)} to {fortDetails.Name}", LogLevel.None, ConsoleColor.Green);

//raise event
if (OnDeployToGym != null)
{
if (!RaiseSyncEvent(OnDeployToGym, location, fortDetails, pokemon))
OnDeployToGym(location, fortDetails, pokemon);
}
}
else
{
Logger.Write($"(GYM) Deployment Failed at {fortString} - {response.Result}", LogLevel.None, ConsoleColor.Red);
}
}
//else if (response.Result == FortDeployPokemonResponse.Types.Result.ErrorPokemonNotFullHp)
//{
// var figureThisShitOut = pokemon;
//}
//else
//{
// Logger.Write($"(GYM) Deployment Failed at {fortString} - {response.Result}", LogLevel.None, ConsoleColor.Green);
//}
else
{
Logger.Write($"(GYM) No available pokemon to deploy.", LogLevel.None, ConsoleColor.Cyan);
}
}
else
{
Logger.Write($"(GYM) {fortString} is full - {fortDetails.GymState.Memberships.Count()}/{maxCount}", LogLevel.None, ConsoleColor.Cyan);
}

}
else
{
Logger.Write($"(GYM) Wasted walk on {fortString}", LogLevel.None, ConsoleColor.Cyan);
Logger.Write($"(GYM) {fortString}", LogLevel.None, ConsoleColor.Cyan);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion PokeRoadie/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2016.9.6.1")]
[assembly: AssemblyVersion("2016.9.8.1")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 4ee1067

Please sign in to comment.