Skip to content

Commit

Permalink
Fix pokezz
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryddag1 committed Aug 9, 2016
1 parent fd45164 commit 6e934c4
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 74 deletions.
13 changes: 13 additions & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@
<HintPath>$(SolutionDir)\packages\C5.2.2.5073.27396\lib\portable-net40+sl50+wp80+win\C5.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EngineIoClientDotNet, Version=0.9.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EngineIoClientDotNet.0.9.22\lib\net45\EngineIoClientDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="S2Geometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\S2Geometry.1.0.1\lib\portable-net45+wp8+win8\S2Geometry.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SocketIoClientDotNet, Version=0.9.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SocketIoClientDotNet.0.9.13\lib\net45\SocketIoClientDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -67,6 +75,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -86,6 +95,10 @@
<HintPath>..\packages\Telegram.Bot.10.3.1\lib\net45\Telegram.Bot.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WebSocket4Net, Version=0.14.1.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Common\ApiFailureStrategy.cs" />
Expand Down
154 changes: 80 additions & 74 deletions PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using POGOProtos.Inventory.Item;
using POGOProtos.Map.Pokemon;
using POGOProtos.Networking.Responses;
using Quobject.SocketIoClientDotNet.Client;
using Newtonsoft.Json.Linq;

#endregion

Expand Down Expand Up @@ -97,7 +99,7 @@ public double _iv
{
return Convert.ToDouble(iv);
}
catch
catch
{
return 0;
}
Expand Down Expand Up @@ -176,22 +178,22 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
}
else
{
pokemonIds = session.LogicSettings.PokemonToSnipe.Pokemon;
pokemonIds = session.LogicSettings.PokemonToSnipe.Pokemon;
}

if (session.LogicSettings.UseSnipeLocationServer)
{
var locationsToSnipe = SnipeLocations?.Where(q =>
(!session.LogicSettings.UseTransferIvForSnipe ||
(q.IV == 0 && !session.LogicSettings.SnipeIgnoreUnknownIv) ||
(q.IV >= session.Inventory.GetPokemonTransferFilter(q.Id).KeepMinIvPercentage)) &&
!LocsVisited.Contains(new PokemonLocation(q.Latitude, q.Longitude))
&& !(q.ExpirationTimestamp != default(DateTime) &&
q.ExpirationTimestamp > new DateTime(2016) &&
// make absolutely sure that the server sent a correct datetime
q.ExpirationTimestamp < DateTime.Now) &&
(q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
new List<SniperInfo>();
var locationsToSnipe = SnipeLocations?.Where(q =>
(!session.LogicSettings.UseTransferIvForSnipe ||
(q.IV == 0 && !session.LogicSettings.SnipeIgnoreUnknownIv) ||
(q.IV >= session.Inventory.GetPokemonTransferFilter(q.Id).KeepMinIvPercentage)) &&
!LocsVisited.Contains(new PokemonLocation(q.Latitude, q.Longitude))
&& !(q.ExpirationTimestamp != default(DateTime) &&
q.ExpirationTimestamp > new DateTime(2016) &&
// make absolutely sure that the server sent a correct datetime
q.ExpirationTimestamp < DateTime.Now) &&
(q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
new List<SniperInfo>();

if (locationsToSnipe.Any())
{
Expand All @@ -205,7 +207,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
Iv = location.IV
});

if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1,
if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1,
session, cancellationToken))
return;

Expand All @@ -220,30 +222,33 @@ public static async Task Execute(ISession session, CancellationToken cancellatio

if (session.LogicSettings.GetSniperInfoFromPokezz)
{
var _locationsToSnipe = GetSniperInfoFrom_pokezz(session, pokemonIds);
var _locationsToSnipe = GetSniperInfoFrom_pokezz(session, pokemonIds);
if (_locationsToSnipe.Any())
{
_lastSnipe = DateTime.Now;
foreach (var location in _locationsToSnipe)
{
session.EventDispatcher.Send(new SnipeScanEvent
if (DateTime.Now.AddSeconds(12) < location.ExpirationTimestamp)
{
Bounds = new Location(location.Latitude, location.Longitude),
PokemonId = location.Id,
//Iv = location.IV
});

if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1,
session, cancellationToken))
return;

await Snipe(session, pokemonIds, location.Latitude, location.Longitude, cancellationToken);
LocsVisited.Add(new PokemonLocation(location.Latitude, location.Longitude));
session.EventDispatcher.Send(new SnipeScanEvent
{
Bounds = new Location(location.Latitude, location.Longitude),
PokemonId = location.Id,
Iv = location.IV
});

if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1,
session, cancellationToken))
return;

await Snipe(session, pokemonIds, location.Latitude, location.Longitude, cancellationToken);
LocsVisited.Add(new PokemonLocation(location.Latitude, location.Longitude));
}
}
}
}



foreach (var location in session.LogicSettings.PokemonToSnipe.Locations)
{
Expand Down Expand Up @@ -314,12 +319,12 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
var CurrentLongitude = session.Client.CurrentLongitude;
var catchedPokemon = false;

session.EventDispatcher.Send(new SnipeModeEvent {Active = true});
session.EventDispatcher.Send(new SnipeModeEvent { Active = true });

List<MapPokemon> catchablePokemon;
try
{
await
await
session.Client.Player.UpdatePlayerLocation(latitude, longitude, session.Client.CurrentAltitude);

session.EventDispatcher.Send(new UpdatePositionEvent
Expand All @@ -337,7 +342,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
}
finally
{
await
await
session.Client.Player.UpdatePlayerLocation(CurrentLatitude, CurrentLongitude, session.Client.CurrentAltitude);
}

Expand Down Expand Up @@ -373,9 +378,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
{
if (session.LogicSettings.EvolveAllPokemonAboveIv ||
session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
session.LogicSettings.UseLuckyEggsWhileEvolving ||
session.LogicSettings.KeepPokemonsThatCanEvolve)
session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
{
await EvolvePokemonTask.Execute(session, cancellationToken);
}
Expand Down Expand Up @@ -418,13 +421,13 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
});
}

session.EventDispatcher.Send(new SnipeModeEvent {Active = false});
session.EventDispatcher.Send(new SnipeModeEvent { Active = false });
await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken);
}

private static ScanResult SnipeScanForPokemon(ISession session, Location location)
{
var formatter = new NumberFormatInfo {NumberDecimalSeparator = "."};
var formatter = new NumberFormatInfo { NumberDecimalSeparator = "." };

var offset = session.LogicSettings.SnipingScanOffset;
// 0.003 = half a mile; maximum 0.06 is 10 miles
Expand Down Expand Up @@ -459,7 +462,7 @@ private static ScanResult SnipeScanForPokemon(ISession session, Location locatio
catch (Exception ex)
{
// most likely System.IO.IOException
session.EventDispatcher.Send(new ErrorEvent {Message = ex.Message});
session.EventDispatcher.Send(new ErrorEvent { Message = ex.Message });
scanResult = new ScanResult
{
Status = "fail",
Expand All @@ -469,46 +472,45 @@ private static ScanResult SnipeScanForPokemon(ISession session, Location locatio
return scanResult;
}


private static List<SniperInfo> GetSniperInfoFrom_pokezz(ISession session, List<PokemonId> pokemonIds)
{
var options = new IO.Options();
options.Transports = Quobject.Collections.Immutable.ImmutableList.Create<string>("websocket");

var uri = $"http://pokezz.com/pokemons.json";
var socket = IO.Socket("http://pokezz.com", options);

ScanResult_pokezz scanResult_pokezz;
try
{
var request = WebRequest.CreateHttp(uri);
request.Accept = "application/json";
request.UserAgent =
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\r\n";
request.Method = "GET";
request.Timeout = 15000;
request.ReadWriteTimeout = 32000;
var hasError = false;

var resp = request.GetResponse();
var reader = new StreamReader(resp.GetResponseStream());
var fullresp = "{\"pokemons\": " + reader.ReadToEnd().Replace(" M", "Male").Replace(" F", "Female").Replace("Farfetch'd", "Farfetchd").Replace("Mr.Maleime", "MrMime") +"}";

scanResult_pokezz = JsonConvert.DeserializeObject<ScanResult_pokezz>(fullresp);
}
catch (Exception ex)
{
// most likely System.IO.IOException
session.EventDispatcher.Send(new ErrorEvent { Message = ex.Message });
scanResult_pokezz = new ScanResult_pokezz
ManualResetEventSlim waitforbroadcast = new ManualResetEventSlim(false);

List<PokemonLocation_pokezz> pokemons = new List<PokemonLocation_pokezz>();

socket.On("pokemons", (msg) => {
JArray data = JArray.FromObject(msg);
foreach (var pokeToken in data.Children())
{
Status = "fail",
pokemons = new List<PokemonLocation_pokezz>()
};
return new List<SniperInfo>();
}
if (scanResult_pokezz.pokemons != null)
{
var temp = pokeToken.ToString().Replace(" M", "Male").Replace(" F", "Female").Replace("Farfetch'd", "Farfetchd").Replace("Mr.Maleime", "MrMime");
var fixedToken = JToken.Parse(temp);
pokemons.Add(fixedToken.ToObject<PokemonLocation_pokezz>());
}
waitforbroadcast.Set();
});

SnipeLocations.RemoveAll(x => DateTime.Now > x.TimeStampAdded.AddMinutes(15));
socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_ERROR, () => {
hasError = true;
waitforbroadcast.Set();
});

foreach (var pokemon in scanResult_pokezz.pokemons)
socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT_ERROR, () => {
hasError = true;
waitforbroadcast.Set();
});

waitforbroadcast.Wait();
if (!hasError)
{
foreach (var pokemon in pokemons)
{
var SnipInfo = new SniperInfo();
SnipInfo.Id = pokemon.name;
Expand All @@ -531,14 +533,18 @@ private static List<SniperInfo> GetSniperInfoFrom_pokezz(ISession session, List<
&& !(q.ExpirationTimestamp != default(DateTime) &&
q.ExpirationTimestamp > new DateTime(2016) &&
// make absolutely sure that the server sent a correct datetime
q.ExpirationTimestamp < DateTime.Now) &&
(q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
q.ExpirationTimestamp < DateTime.Now.AddSeconds(10))).ToList() ??
//(q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
new List<SniperInfo>();
return locationsToSnipe;
}
return new List<SniperInfo>();
else
{
return new List<SniperInfo>();
}
}


public static async Task Start(Session session, CancellationToken cancellationToken)
{
while (true)
Expand Down Expand Up @@ -585,10 +591,10 @@ public static async Task Start(Session session, CancellationToken cancellationTo
catch (Exception ex)
{
// most likely System.IO.IOException
session.EventDispatcher.Send(new ErrorEvent {Message = ex.ToString()});
session.EventDispatcher.Send(new ErrorEvent { Message = ex.ToString() });
}
await Task.Delay(100, cancellationToken);
}
}
}
}
}
3 changes: 3 additions & 0 deletions PoGo.NecroBot.Logic/packages.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="C5" version="2.2.5073.27396" targetFramework="net452" />
<package id="EngineIoClientDotNet" version="0.9.22" targetFramework="net452" />
<package id="GeoCoordinate" version="1.1.0" targetFramework="net45" />
<package id="Google.Protobuf" version="3.0.0-beta4" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="S2Geometry" version="1.0.1" targetFramework="net452" />
<package id="SocketIoClientDotNet" version="0.9.13" targetFramework="net452" />
<package id="Telegram.Bot" version="10.3.1" targetFramework="net452" />
<package id="WebSocket4Net" version="0.14.1" targetFramework="net452" />
</packages>

0 comments on commit 6e934c4

Please sign in to comment.