Skip to content

Commit

Permalink
merge with base master
Browse files Browse the repository at this point in the history
  • Loading branch information
samuraitruong committed Sep 5, 2016
2 parents a58b8dc + ab0f08b commit a5d7e2d
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 35 deletions.
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private static void Main(string[] args)
if (settings.TelegramConfig.UseTelegramAPI)
_session.Telegram = new TelegramService(settings.TelegramConfig.TelegramAPIKey, _session);

if (_session.LogicSettings.UseSnipeLocationServer)
if (session.LogicSettings.UseSnipeLocationServer || session.LogicSettings.HumanWalkingSnipeUsePogoLocationFeeder)
SnipePokemonTask.AsyncStart(_session);

settings.checkProxy(_session.Translation);
Expand Down
10 changes: 10 additions & 0 deletions PoGo.NecroBot.CLI/SniperEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ private static void HandleEvent(PokemonCaptureEvent pokemonCaptureEvent, ISessio
pokemonCaptureEvent.Id);
}

public static void HandleEvent(SnipePokemonFoundEvent ev, ISession session)
{
Logic.Tasks.HumanWalkSnipeTask.AddSnipePokemon("Local Feeder", ev.PokemonFound.Id,
ev.PokemonFound.Latitude,
ev.PokemonFound.Longitude,
ev.PokemonFound.ExpirationTimestamp,
ev.PokemonFound.IV,
session
);
}
internal void Listen(IEvent evt, ISession session)
{
dynamic eve = evt;
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.GUI/PoGo.NecroBot.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
<When Condition="('$(SolutionName)'!='Awesomium.NET') And ('$(SolutionName)'!='Awesomium.Windows')" />
</Choose>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PostBuildEvent>
</PostBuildEvent>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Event/HumanWalkSnipeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class HumanWalkSnipeEvent : IEvent
{
public double Latitude { get; set; }
public double Longitude { get; set; }

public string Rarity { get; set; }
public double Distance { get; set; }

public double WalkTimes { get; set; }
Expand Down
13 changes: 13 additions & 0 deletions PoGo.NecroBot.Logic/Event/SnipePokemonFoundEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using PoGo.NecroBot.Logic.Tasks;

namespace PoGo.NecroBot.Logic.Event
{
public class SnipePokemonFoundEvent : IEvent
{
public SniperInfo PokemonFound { get; set; }
public override string ToString()
{
return PokemonFound.Id.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public interface ILogicSettings
bool RandomizeRecycle { get; }
int RandomRecycleValue { get; }
int TotalAmountOfPokeballsToKeep { get; }
int MaxPokeballsToKeep { get; }

int TotalAmountOfPotionsToKeep { get; }
int TotalAmountOfRevivesToKeep { get; }
int TotalAmountOfBerriesToKeep { get; }
Expand Down Expand Up @@ -181,11 +183,14 @@ public interface ILogicSettings
bool HumanWalkingSnipeIncludeDefaultLocation { get; }
bool HumanWalkingSnipeUsePokeRadar { get; }
bool HumanWalkingSnipeUseSkiplagged { get; }
bool HumanWalkingSnipeUseFastPokemap { get; }
bool HumanWalkingSnipeUseSnipePokemonList { get; }
Dictionary<PokemonId, HumanWalkSnipeFilter> HumanWalkSnipeFilters { get; }
double HumanWalkingSnipeMaxSpeedUpSpeed { get; }
int HumanWalkingSnipeDelayTimeAtDestination { get; }
bool HumanWalkingSnipeAllowSpeedUp { get; }
bool HumanWalkingSnipeUsePogoLocationFeeder { get; }

int EvolveActionDelay { get; }
int TransferActionDelay { get; }
int RecycleActionDelay { get; }
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/Model/Settings/HumanWalkSnipeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ public class HumanWalkSnipeConfig
[Range(0, 999999)]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate)]
public int DelayTimeAtDestination = 10000;// 10 sec
public bool UseFastPokemap = true;
public bool UsePogoLocationFeeder = false;
}
}
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Model/Settings/HumanWalkSnipeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class HumanWalkSnipeFilter
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 8)]
public int DelayTimeAtDestination { get; set; }

public HumanWalkSnipeFilter(double maxDistance, double maxWalkTimes, int priority, bool catchPokemon, bool spinPokestop, bool allowSpeedUp, double speedUpSpeed, double delay = 10)
public HumanWalkSnipeFilter(double maxDistance, double maxWalkTimes, int priority, bool catchPokemon, bool spinPokestop, bool allowSpeedUp, double speedUpSpeed, int delay = 10)
{
this.MaxDistance = maxDistance;
this.MaxWalkTimes = maxWalkTimes;
Expand All @@ -56,6 +56,7 @@ public HumanWalkSnipeFilter(double maxDistance, double maxWalkTimes, int priorit
this.SpinPokestopWhileWalking = spinPokestop;
this.AllowSpeedUp = allowSpeedUp;
this.MaxSpeedUpSpeed = speedUpSpeed;
this.DelayTimeAtDestination = delay;
}

internal static Dictionary<PokemonId, HumanWalkSnipeFilter> Default()
Expand Down
4 changes: 3 additions & 1 deletion PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public LogicSettings(GlobalSettings settings)
public bool SnipePokemonNotInPokedex => _settings.SnipeConfig.SnipePokemonNotInPokedex;
public bool RandomizeRecycle => _settings.RecycleConfig.RandomizeRecycle;
public int RandomRecycleValue => _settings.RecycleConfig.RandomRecycleValue;
public int MaxPokeballsToKeep => _settings.RecycleConfig.MaxPokeballsToKeep;
public int TotalAmountOfPokeballsToKeep => _settings.RecycleConfig.TotalAmountOfPokeballsToKeep;
public int TotalAmountOfPotionsToKeep => _settings.RecycleConfig.TotalAmountOfPotionsToKeep;
public int TotalAmountOfRevivesToKeep => _settings.RecycleConfig.TotalAmountOfRevivesToKeep;
Expand All @@ -176,7 +177,6 @@ public LogicSettings(GlobalSettings settings)
public int ResumeTrack => _settings.LocationConfig.ResumeTrack;
public int ResumeTrackSeg => _settings.LocationConfig.ResumeTrackSeg;
public int ResumeTrackPt => _settings.LocationConfig.ResumeTrackPt;

public bool HumanWalkingSnipeDisplayList => _settings.HumanWalkSnipeConfig.DisplayPokemonList;
public double HumanWalkingSnipeMaxDistance => _settings.HumanWalkSnipeConfig.MaxDistance;
public double HumanWalkingSnipeMaxEstimateTime => _settings.HumanWalkSnipeConfig.MaxEstimateTime;
Expand All @@ -188,6 +188,7 @@ public LogicSettings(GlobalSettings settings)
public int HumanWalkingSnipeCatchEmAllMinBalls => _settings.HumanWalkSnipeConfig.CatchEmAllMinBalls;
public bool EnableHumanWalkingSnipe => _settings.HumanWalkSnipeConfig.Enable;
public Dictionary<PokemonId, HumanWalkSnipeFilter> HumanWalkSnipeFilters => _settings.HumanWalkSnipeFilters;
public bool HumanWalkingSnipeUseFastPokemap => _settings.HumanWalkSnipeConfig.UseFastPokemap;
public bool HumanWalkingSnipeUsePokeRadar => _settings.HumanWalkSnipeConfig.UsePokeRadar;
public bool HumanWalkingSnipeUseSkiplagged => _settings.HumanWalkSnipeConfig.UseSkiplagged;
public bool HumanWalkingSnipeUseSnipePokemonList => _settings.HumanWalkSnipeConfig.UseSnipePokemonList;
Expand All @@ -196,5 +197,6 @@ public LogicSettings(GlobalSettings settings)
public double HumanWalkingSnipeMaxSpeedUpSpeed => _settings.HumanWalkSnipeConfig.MaxSpeedUpSpeed;
public bool HumanWalkingSnipeAllowSpeedUp => _settings.HumanWalkSnipeConfig.AllowSpeedUp;
public int HumanWalkingSnipeDelayTimeAtDestination => _settings.HumanWalkSnipeConfig.DelayTimeAtDestination;
public bool HumanWalkingSnipeUsePogoLocationFeeder => _settings.HumanWalkSnipeConfig.UsePogoLocationFeeder;
}
}
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<Compile Include="Event\KillSwitchEvent.cs" />
<Compile Include="Event\LogEvent.cs" />
<Compile Include="Event\NoPokeballEvent.cs" />
<Compile Include="Event\SnipePokemonFoundEvent.cs" />
<Compile Include="Event\SnipeEvent.cs" />
<Compile Include="Event\SnipeModeEvent.cs" />
<Compile Include="Event\PokemonListEvent.cs" />
Expand Down Expand Up @@ -325,6 +326,7 @@
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<Compile Include="Tasks\HumanWalkSnipeTask.FastPokemap.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FeroxRev\PokemonGo.RocketAPI\PokemonGo.RocketAPI.csproj">
Expand Down
148 changes: 148 additions & 0 deletions PoGo.NecroBot.Logic/Tasks/HumanWalkSnipeTask.FastPokemap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using Newtonsoft.Json;
using PoGo.NecroBot.Logic.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using POGOProtos.Enums;

namespace PoGo.NecroBot.Logic.Tasks
{
public partial class HumanWalkSnipeTask
{
private static string ip;

private static Task taskDataLive;
public class FastPokemapItem
{
public class Lnglat
{
public string type { get; set; }
public List<double> coordinates { get; set; }
}

public string _id { get; set; }
public string pokemon_id { get; set; }
public string encounter_id { get; set; }
public string spawn_id { get; set; }
public DateTime expireAt { get; set; }
public int __v { get; set; }
public Lnglat lnglat { get; set; }
}

private static string GetIP()
{

if (string.IsNullOrEmpty(ip))
{
var client = new HttpClient();
var task = client.GetStringAsync("http://checkip.dyndns.org");
task.Wait();
ip = task.Result.Split(':')[1].Trim();
}
return ip;

}
private static void EnsureDataLive()
{
int liveUpdateCount = 6;

if (taskDataLive != null && !taskDataLive.IsCompleted) return;
taskDataLive = Task.Run(async () =>
{
while(liveUpdateCount>0)
{
liveUpdateCount--;
var lat = _session.Client.CurrentLatitude;
var lng = _session.Client.CurrentLongitude;
var api = $"https://api.fastpokemap.se/?key=allow-all&ts=0&lat={lat}&lng={lng}";
await DownloadContent(api);
await Task.Delay(10000);
}
});
}
private static SnipePokemonInfo Map(FastPokemapItem result)
{
return new SnipePokemonInfo()
{
Latitude = result.lnglat.coordinates[1],
Longitude = result.lnglat.coordinates[0],
Id = GetId(result.pokemon_id),
ExpiredTime = result.expireAt.ToLocalTime(),
Source = "Fastpokemap"
};
}

public static int GetId(string name)
{

var t = name[0];
var realName = new StringBuilder(name.ToLower());
realName[0] = t;
try
{
var p = (PokemonId)Enum.Parse(typeof(PokemonId), realName.ToString());
return (int)p;
}
catch (Exception)
{

}
return 0;

}
private static async Task<string> DownloadContent(string url)
{
HttpClient client = new HttpClient();

var request = new HttpRequestMessage()
{
RequestUri = new Uri(url),
Method = HttpMethod.Get,
};
request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.Add("origin", "https://fastpokemap.se");
request.Headers.Add("authority", "cache.fastpokemap.se");

string result = "";
try {
var task = await client.SendAsync(request);
result = await task.Content.ReadAsStringAsync();
}
catch(Exception ex) { }

return result;

}
private static async Task<List<SnipePokemonInfo>> FetchFromFastPokemap(double lat, double lng)
{
List<SnipePokemonInfo> results = new List<SnipePokemonInfo>();
if (!_setting.HumanWalkingSnipeUseFastPokemap) return results;
try
{
EnsureDataLive();
string url = $"https://cache.fastpokemap.se/?key=allow-all&ts=0&compute={GetIP()}&lat={lat}&lng={lng}";

var json = await DownloadContent(url);
var data = JsonConvert.DeserializeObject<List<FastPokemapItem>>(json);
foreach (var item in data)
{
var pItem = Map(item);
if (pItem != null && pItem.Id > 0)
{
results.Add(pItem);
}
}

}
catch (Exception)
{
Logger.Write("Error loading data fastpokemap", LogLevel.Error, ConsoleColor.DarkRed);
}
return results;
}

}
}
4 changes: 3 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/HumanWalkSnipeTask.PokeZZ.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PoGo.NecroBot.Logic.Utils;
using PoGo.NecroBot.Logic.Logging;
using PoGo.NecroBot.Logic.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -43,6 +44,7 @@ private static async Task<List<SnipePokemonInfo>> FetchFromPokeZZ(double lat, do
}
catch (Exception )
{
Logger.Write("Error loading data from Pokezz", LogLevel.Error, ConsoleColor.DarkRed);

}

Expand Down
6 changes: 2 additions & 4 deletions PoGo.NecroBot.Logic/Tasks/HumanWalkSnipeTask.Pokecrew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using POGOProtos.Enums;

namespace PoGo.NecroBot.Logic.Tasks
{
public partial class HumanWalkSnipeTask
{


public class PokecrewWrap
{
public class PokecrewItem
Expand Down Expand Up @@ -41,8 +40,7 @@ private static SnipePokemonInfo Map(PokecrewWrap.PokecrewItem result)
Source = "Pokecrew"
};
}

private static async Task<List<SnipePokemonInfo>> FetchFromPokecrew(double lat, double lng)
private static async Task<List<SnipePokemonInfo>> FetchFromPokecrew(double lat, double lng)
{
List<SnipePokemonInfo> results = new List<SnipePokemonInfo>();
// if (!_setting.HumanWalkingSnipeUsePokeRadar) return results;
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Tasks/HumanWalkSnipeTask.Pokeradar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static async Task<List<SnipePokemonInfo>> FetchFromPokeradar(double lat,
}
catch (Exception )
{
Logger.Write("Error loading data", LogLevel.Error, ConsoleColor.DarkRed);
Logger.Write("Error loading data pokeradar", LogLevel.Error, ConsoleColor.DarkRed);
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static async Task<List<SnipePokemonInfo>> FetchFromPokesnipers(double la
}
catch (Exception)
{
Logger.Write("Error loading data", LogLevel.Error, ConsoleColor.DarkRed);
Logger.Write("Error loading data from pokesnipers", LogLevel.Error, ConsoleColor.DarkRed);
}
return results;
}
Expand Down
4 changes: 3 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/HumanWalkSnipeTask.Skiplagged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private static async Task<List<SnipePokemonInfo>> FetchFromSkiplagged(double lat
results = GetJsonList(json);
}
catch (Exception )
{}
{
Logger.Write("Error loading data from skiplagged", LogLevel.Error, ConsoleColor.DarkRed);
}
return results;
}

Expand Down
Loading

0 comments on commit a5d7e2d

Please sign in to comment.