Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Alpha-Build' into B…
Browse files Browse the repository at this point in the history
…eta-Build
  • Loading branch information
Brian committed Aug 21, 2016
2 parents eaad1bc + b5e0442 commit f7f23e3
Show file tree
Hide file tree
Showing 71 changed files with 2,081 additions and 1,696 deletions.
81 changes: 41 additions & 40 deletions PokemonGo.RocketBot.Logic/Common/ApiFailureStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

using System;
using System.Threading.Tasks;
using PokemonGo.RocketBot.Logic.Event;
using PokemonGo.RocketBot.Logic.State;
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.Exceptions;
using PokemonGo.RocketAPI.Extensions;
using PokemonGo.RocketBot.Logic.Event;
using PokemonGo.RocketBot.Logic.State;
using POGOProtos.Networking.Envelopes;

#endregion
Expand All @@ -23,6 +23,42 @@ public ApiFailureStrategy(ISession session)
_session = session;
}

public void HandleApiSuccess(RequestEnvelope request, ResponseEnvelope response)
{
_retryCount = 0;
}

public async Task<ApiOperation> HandleApiFailure(RequestEnvelope request, ResponseEnvelope response)
{
if (_retryCount == 11)
return ApiOperation.Abort;

await Task.Delay(500);
_retryCount++;

if (_retryCount%5 == 0)
{
try
{
DoLogin();
}
catch (PtcOfflineException)
{
await Task.Delay(20000);
}
catch (AccessTokenExpiredException)
{
await Task.Delay(2000);
}
catch (Exception ex) when (ex is InvalidResponseException || ex is TaskCanceledException)
{
await Task.Delay(1000);
}
}

return ApiOperation.Retry;
}

public async Task<ApiOperation> HandleApiFailure()
{
if (_retryCount == 11)
Expand All @@ -31,7 +67,7 @@ public async Task<ApiOperation> HandleApiFailure()
await Task.Delay(500);
_retryCount++;

if (_retryCount % 5 == 0)
if (_retryCount%5 == 0)
{
DoLogin();
}
Expand Down Expand Up @@ -120,7 +156,7 @@ private async void DoLogin()
}
catch (InvalidResponseException)
{
_session.EventDispatcher.Send(new ErrorEvent()
_session.EventDispatcher.Send(new ErrorEvent
{
Message = _session.Translation.GetTranslation(TranslationString.InvalidResponse)
});
Expand All @@ -139,40 +175,5 @@ private async void DoLogin()
});
}
}
public void HandleApiSuccess(RequestEnvelope request, ResponseEnvelope response)
{
_retryCount = 0;
}

public async Task<ApiOperation> HandleApiFailure(RequestEnvelope request, ResponseEnvelope response)
{
if (_retryCount == 11)
return ApiOperation.Abort;

await Task.Delay(500);
_retryCount++;

if (_retryCount % 5 == 0)
{
try
{
DoLogin();
}
catch (PtcOfflineException)
{
await Task.Delay(20000);
}
catch (AccessTokenExpiredException)
{
await Task.Delay(2000);
}
catch (Exception ex) when (ex is InvalidResponseException || ex is TaskCanceledException)
{
await Task.Delay(1000);
}
}

return ApiOperation.Retry;
}
}
}
}
857 changes: 444 additions & 413 deletions PokemonGo.RocketBot.Logic/Common/Translations.cs

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions PokemonGo.RocketBot.Logic/Event/EvolveCountEvent.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PokemonGo.RocketBot.Logic.Event
namespace PokemonGo.RocketBot.Logic.Event
{
public class EvolveCountEvent : IEvent
{
public int Evolves;
}
}
}
2 changes: 1 addition & 1 deletion PokemonGo.RocketBot.Logic/Event/FortFailedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
public class FortFailedEvent : IEvent
{
public bool Looted;
public int Max;
public string Name;
public int Try;
public bool Looted;
}
}
11 changes: 11 additions & 0 deletions PokemonGo.RocketBot.Logic/Event/GetHumanizeRouteEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using GeoCoordinatePortable;

namespace PokemonGo.RocketBot.Logic.Event
{
public class GetHumanizeRouteEvent : IEvent
{
public GeoCoordinate Destination;
public List<GeoCoordinate> Route;
}
}
5 changes: 2 additions & 3 deletions PokemonGo.RocketBot.Logic/Event/HumanWalkingEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
public class HumanWalkingEvent : IEvent
{
public double OldWalkingSpeed;
public double CurrentWalkingSpeed;
public double OldWalkingSpeed;
}
}

}
10 changes: 3 additions & 7 deletions PokemonGo.RocketBot.Logic/Event/InventoryListEvent.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using POGOProtos.Inventory.Item;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using POGOProtos.Inventory.Item;

namespace PokemonGo.RocketBot.Logic.Event
{
public class InventoryListEvent : IEvent
{
public List<ItemData> Items;
}
}
}
9 changes: 2 additions & 7 deletions PokemonGo.RocketBot.Logic/Event/LootPokestopEvent.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using POGOProtos.Map.Fort;
using POGOProtos.Map.Fort;

namespace PokemonGo.RocketBot.Logic.Event
{
public class LootPokestopEvent : IEvent
{
public FortData Pokestop;
}
}
}
9 changes: 2 additions & 7 deletions PokemonGo.RocketBot.Logic/Event/OptimizeRouteEvent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using GMap.NET.WindowsForms;
using System.Collections.Generic;
using POGOProtos.Map.Fort;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PokemonGo.RocketBot.Logic.Event
{
public class OptimizeRouteEvent : IEvent
{
public List<FortData> OptimizedRoute { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions PokemonGo.RocketBot.Logic/Event/PokemonCaptureEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class PokemonCaptureEvent : IEvent
public int Exp;
public int FamilyCandies;
public PokemonId Id;
public double Latitude;
public double Level;
public double Longitude;
public int MaxCp;
public double Perfection;
public ItemId Pokeball;
public double Probability;
public int Stardust;
public CatchPokemonResponse.Types.CatchStatus Status;
public double Latitude;
public double Longitude;
}
}
2 changes: 2 additions & 0 deletions PokemonGo.RocketBot.Logic/Event/PokemonEvolveEvent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#region using directives

using POGOProtos.Enums;
using POGOProtos.Networking.Responses;

#endregion

namespace PokemonGo.RocketBot.Logic.Event
Expand Down
9 changes: 2 additions & 7 deletions PokemonGo.RocketBot.Logic/Event/PokemonsEncounterEvent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using POGOProtos.Data;
using System.Collections.Generic;
using POGOProtos.Map.Pokemon;

namespace PokemonGo.RocketBot.Logic.Event
Expand All @@ -12,4 +7,4 @@ public class PokemonsEncounterEvent : IEvent
{
public List<MapPokemon> EncounterPokemons;
}
}
}
7 changes: 4 additions & 3 deletions PokemonGo.RocketBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#region using directives

using System.Collections.Generic;
using POGOProtos.Enums;
using POGOProtos.Inventory.Item;
using System.Collections.Generic;

#endregion

Expand Down Expand Up @@ -46,7 +46,8 @@ public TransferFilter()
{
}

public TransferFilter(int keepMinCp, int keepMinLvl, bool useKeepMinLvl, float keepMinIvPercentage, string keepMinOperator, int keepMinDuplicatePokemon,
public TransferFilter(int keepMinCp, int keepMinLvl, bool useKeepMinLvl, float keepMinIvPercentage,
string keepMinOperator, int keepMinDuplicatePokemon,
List<PokemonMove> moves = null, string movesOperator = "or")
{
KeepMinCp = keepMinCp;
Expand Down Expand Up @@ -200,4 +201,4 @@ public interface ILogicSettings

bool StartupWelcomeDelay { get; }
}
}
}
1 change: 1 addition & 0 deletions PokemonGo.RocketBot.Logic/Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface ILogger
/// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
/// <param name="color">Optional. Default automatic color.</param>
void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black);

void lineSelect(int lineChar = 0, int linesUp = 1);
}
}
5 changes: 3 additions & 2 deletions PokemonGo.RocketBot.Logic/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public static void SetLoggerContext(ISession session)
/// <param name="message">The message to log.</param>
/// <param name="level">Optional level to log. Default <see cref="LogLevel.Info" />.</param>
/// <param name="color">Optional. Default is automatic color.</param>
public static void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black, bool force = false)
public static void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black,
bool force = false)
{
if (_logger == null || _lastLogMessage == message)
return;
Expand Down Expand Up @@ -114,6 +115,6 @@ public enum LogLevel
New = 15,
SoftBan = 16,
LevelUp = 17,
Debug = 18,
Debug = 18
}
}
10 changes: 10 additions & 0 deletions PokemonGo.RocketBot.Logic/Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace PokemonGo.RocketBot.Logic
{
public delegate void UpdatePositionDelegate(double lat, double lng);

public delegate void GetHumanizeRouteDelegate(List<GeoCoordinate> route, GeoCoordinate destination);

public class Navigation
{
private const double SpeedDownTo = 10/3.6;
Expand Down Expand Up @@ -210,6 +212,8 @@ public async Task<PlayerUpdateResponse> Move(GeoCoordinate targetLocation,
foreach (var item in route)
points.Add(new GeoCoordinate(item.ToArray()[1], item.ToArray()[0]));

OnGetHumanizeRouteEvent(points, targetLocation);

for (var i = 0; i < points.Count; i++)
{
var speedInMetersPerSecond = session.LogicSettings.UseWalkingSpeedVariant
Expand Down Expand Up @@ -413,5 +417,11 @@ public async Task<PlayerUpdateResponse> HumanPathWalking(GpxReader.Trkpt trk,
}

public event UpdatePositionDelegate UpdatePositionEvent;
public static event GetHumanizeRouteDelegate GetHumanizeRouteEvent;

protected virtual void OnGetHumanizeRouteEvent(List<GeoCoordinate> route, GeoCoordinate destination)
{
GetHumanizeRouteEvent?.Invoke(route, destination);
}
}
}
9 changes: 5 additions & 4 deletions PokemonGo.RocketBot.Logic/PoGoUtils/PokemonInfo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#region using directives

using System;
using System.Collections.Generic;
using System.Linq;
using POGOProtos.Data;
using POGOProtos.Enums;
using POGOProtos.Inventory;
using System.Collections.Generic;
using POGOProtos.Settings.Master;
using System.Linq;

#endregion

Expand Down Expand Up @@ -583,7 +583,8 @@ public static PokemonMove GetPokemonMove2(PokemonData poke)
return move2;
}

public static int GetCandy(PokemonData pokemon, List<Candy> PokemonFamilies, IEnumerable<PokemonSettings> PokemonSettings)
public static int GetCandy(PokemonData pokemon, List<Candy> PokemonFamilies,
IEnumerable<PokemonSettings> PokemonSettings)
{
var setting = PokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId.Equals(pokemon.PokemonId));
var family = PokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId.Equals(setting.FamilyId));
Expand All @@ -596,4 +597,4 @@ public static int GetPowerUpLevel(PokemonData poke)
return (int) (GetLevel(poke)*2.0);
}
}
}
}
Loading

0 comments on commit f7f23e3

Please sign in to comment.