Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #463 from Necrobot-Private/feature/snipe_enhanceme…
Browse files Browse the repository at this point in the history
…nt_misc

Fix bulk transfer > 100 pkm
  • Loading branch information
samuraitruong authored Jan 2, 2017
2 parents 9661ad2 + 824cf56 commit f5b7787
Show file tree
Hide file tree
Showing 32 changed files with 439 additions and 68 deletions.
2 changes: 1 addition & 1 deletion FeroxRev
4 changes: 2 additions & 2 deletions PoGo.NecroBot.CLI/BotDataSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ private static void OnPokemonData(ISession session, string message)
session.EventDispatcher.Send(data);
if (session.LogicSettings.AllowAutoSnipe)
{
var move1 = PokemonMove.Absorb;
var move2 = PokemonMove.Absorb;
var move1 = PokemonMove.MoveUnset;
var move2 = PokemonMove.MoveUnset;
Enum.TryParse<PokemonMove>(data.Move1, true, out move1);
Enum.TryParse<PokemonMove>(data.Move1, true, out move2);
ulong encounterid = 0;
Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.CLI/PoGo.NecroBot.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
<HintPath>$(SolutionDir)\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="POGOProtos.NetStandard1, Version=2.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\POGOProtos.NetStandard1.2.4.0\lib\net45\POGOProtos.NetStandard1.dll</HintPath>
<Reference Include="POGOProtos.NetStandard1, Version=2.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.NetStandard1.2.4.2\lib\net45\POGOProtos.NetStandard1.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PushbulletSharp, Version=2.3.3.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<package id="Microsoft.NETCore.Platforms" version="1.0.1" targetFramework="net452" />
<package id="Microsoft.Win32.Primitives" version="4.0.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="POGOProtos.NetStandard1" version="2.4.0" targetFramework="net452" />
<package id="POGOProtos.NetStandard1" version="2.4.2" targetFramework="net452" />
<package id="PushBulletSharp" version="2.3.3" targetFramework="net452" />
<package id="S2Geometry" version="1.0.3" targetFramework="net452" />
<package id="Selenium.Support" version="3.0.1" targetFramework="net452" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public interface ILogicSettings
bool AllowMultipleBot { get; }
CaptchaConfig CaptchaConfig { get; }
int BulkTransferStogareBuffer { get; }
int BulkTransferSize { get; }

bool AutosnipeVerifiedOnly { get; }
}
}
8 changes: 4 additions & 4 deletions PoGo.NecroBot.Logic/Model/Settings/CaptchaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ public CaptchaConfig() : base() { }
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 4)]
[ExcelConfig(Position = 12, Description = "Enable Auto captcha solve with CaptchaSolutions.com")]

public bool EnableCaptchaSolutions { get; internal set; }
public bool EnableCaptchaSolutions { get; set; }

[DefaultValue("")]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 4)]
[ExcelConfig(Position = 13, Description = "CaptchaSolutions API KEY")]

public string CaptchaSolutionAPIKey { get; internal set; }
public string CaptchaSolutionAPIKey { get; set; }
[DefaultValue("")]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 4)]
[ExcelConfig(Position = 14, Description = "Captcha Solutions Secret key")]

public string CaptchaSolutionsSecretKey { get; internal set; }
public string CaptchaSolutionsSecretKey { get; set; }

[DefaultValue(120)]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 4)]
[ExcelConfig(Position = 15, Description = "Timeout for auto captcha solving")]
public int AutoCaptchaTimeout { get; internal set; }
public int AutoCaptchaTimeout { get; set; }
}
}
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Model/Settings/EvolveFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class EvolveFilter
public EvolveFilter()
{
Moves = new List<List<PokemonMove>>();
EnableEvolve = true;
EnableEvolve = true;
Operator = "or";
}


Expand Down
27 changes: 22 additions & 5 deletions PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,28 @@ private static JSchema JsonSchema
public static GlobalSettings Load(string path, bool validate = false)
{
GlobalSettings settings;
var profilePath = Path.Combine(Directory.GetCurrentDirectory(), path);
var profileConfigPath = Path.Combine(profilePath, "config");
var configFile = Path.Combine(profileConfigPath, "config.json");
var schemaFile = Path.Combine(profileConfigPath, "config.schema.json");
var shouldExit = false;

var profilePath = "";
var profileConfigPath = "";
var configFile = "";
var schemaFile = "";


if (Path.IsPathRooted(path))
{
profileConfigPath = Path.GetDirectoryName(path);
configFile = path;
schemaFile = path.Replace(".json", ".schema.json");


}
else {
profilePath = Path.Combine(Directory.GetCurrentDirectory(), path);
profileConfigPath = Path.Combine(profilePath, "config");
configFile = Path.Combine(profileConfigPath, "config.json");
schemaFile = Path.Combine(profileConfigPath, "config.schema.json");
}
var shouldExit = false;
int schemaVersionBeforeUpgrade = 0;

if (File.Exists(configFile))
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public LogicSettings(GlobalSettings settings)
public bool TransferDuplicatePokemon => _settings.PokemonConfig.TransferDuplicatePokemon;
public bool TransferDuplicatePokemonOnCapture => _settings.PokemonConfig.TransferDuplicatePokemonOnCapture;
public bool UseBulkTransferPokemon => _settings.PokemonConfig.UseBulkTransferPokemon;

public int BulkTransferSize => _settings.PokemonConfig.BulkTransferSize;
public int BulkTransferStogareBuffer => _settings.PokemonConfig.BulkTransferStogareBuffer;

public bool UseEggIncubators => _settings.PokemonConfig.UseEggIncubators;
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Model/Settings/MultipleBotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static MultipleBotConfig Default()

public static bool IsMultiBotActive(ILogicSettings logicSettings)
{
return logicSettings.AllowMultipleBot && logicSettings.Bots != null && logicSettings.Bots.Count > 1;
return logicSettings.AllowMultipleBot && logicSettings.Bots != null && logicSettings.Bots.Count >= 1;
}
}
}
5 changes: 5 additions & 0 deletions PoGo.NecroBot.Logic/Model/Settings/PokemonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,10 @@ internal enum CpIv
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 62)]
public int BulkTransferStogareBuffer { get; set; }

[DefaultValue(100)]
[ExcelConfig(Description = "Maximun number of pokemon in 1 transfer", Position = 63)]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 63)]
[Range(1,100)]
public int BulkTransferSize { get; internal set; }
}
}
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Model/Settings/SnipeFIlter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SnipeFilter(int snipeMinIV, List<List<PokemonMove>> moves = null) :base

[ExcelConfig(Key = "Snipe Min IV" , Description ="Min Pokemon IV for auto snipe", Position =2)]
[DefaultValue(76)]
[Range(0, 100)]
[Range(0, 101)]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)]
public int SnipeIV {get; set;}

Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Model/Settings/TransferFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TransferFilter
public TransferFilter()
{
MovesOperator = "and";
KeepMinOperator = Operator.or.ToString();
Moves = new List<List<PokemonMove>>();
DeprecatedMoves = new List<PokemonMove>();

Expand Down
9 changes: 5 additions & 4 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
<HintPath>$(SolutionDir)\packages\Newtonsoft.Json.Schema.2.0.6\lib\net45\Newtonsoft.Json.Schema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="POGOProtos.NetStandard1, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\POGOProtos.NetStandard1.2.1.0\lib\net45\POGOProtos.NetStandard1.dll</HintPath>
<Reference Include="POGOProtos.NetStandard1, Version=2.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.NetStandard1.2.4.2\lib\net45\POGOProtos.NetStandard1.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="S2Geometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -154,12 +154,13 @@
<HintPath>$(SolutionDir)\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml">
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="Telegram.Bot, Version=10.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\Telegram.Bot.10.3.1\lib\net45\Telegram.Bot.dll</HintPath>
<Reference Include="Telegram.Bot, Version=10.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Telegram.Bot.10.4.0\lib\net45\Telegram.Bot.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WebDriver, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
5 changes: 3 additions & 2 deletions PoGo.NecroBot.Logic/Tasks/CatchPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,11 @@ public static async Task UseBerry(ISession session, ulong encounterId, string sp
await DelayingUtils.DelayAsync(session.LogicSettings.DelayBetweenPlayerActions, 500, cancellationToken);

var useCaptureItem = await session.Client.Encounter.UseCaptureItem(encounterId, ItemId.ItemRazzBerry, spawnPointId);
berry.Count -= 1;
//berry.Count -= 1;

session.EventDispatcher.Send(new UseBerryEvent { BerryType = ItemId.ItemRazzBerry, Count = berry.Count -1});
await session.Inventory.UpdateInventoryItem(berry.ItemId, -1);

session.EventDispatcher.Send(new UseBerryEvent { BerryType = ItemId.ItemRazzBerry, Count = berry.Count });
}
}
}
17 changes: 14 additions & 3 deletions PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,27 +326,36 @@ await LocationUtils.UpdatePlayerLocationWithAltitude(session,
await Task.Delay(1000, cancellationToken);

encounter = await session.Client.Encounter.EncounterPokemon(encounterId.EncounterId, encounterId.SpawnPointId);



}
catch (CaptchaException ex)
{
captchaShowed = true;
throw ex;
}
catch (Exception ex)
{
captchaShowed = true;
return false;
}
finally
{
if (!captchaShowed)
await LocationUtils.UpdatePlayerLocationWithAltitude(session,
{
//TODO - What if udpate location failed
var response = await LocationUtils.UpdatePlayerLocationWithAltitude(session,
new GeoCoordinate(lat, lon, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed.


}
else
session.Client.Player.SetCoordinates(lat, lon, session.Client.CurrentAltitude); //only reset d
}

if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
{
Logger.Write("Pokemon bag full, snipe cancel");
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
return false;
}
PokemonData encounteredPokemon;
Expand Down Expand Up @@ -410,6 +419,8 @@ private static void RefreshLocationQueue()
public static async Task AddSnipeItem(ISession session, MSniperInfo2 item, bool byPassValidation = false)
{
if (isBlocking) return;
if (Math.Abs(item.Latitude) > 90 || Math.Abs(item.Longitude) > 180) return;

lock (locker)
{
item.AddedTime = DateTime.Now;
Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ public static async Task<bool> Snipe(ISession session, IEnumerable<PokemonId> po
}
catch(CaptchaException ex)
{
isCaptchaShow = true;
//isCaptchaShow = true;
throw ex;
}
finally
{
if(!isCaptchaShow)
//if(!isCaptchaShow)
await
LocationUtils.UpdatePlayerLocationWithAltitude(session,
new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0); // Set speed to 0 for random speed.
Expand Down
17 changes: 11 additions & 6 deletions PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,21 @@ public static async Task Execute(ISession session, CancellationToken cancellatio

if (session.LogicSettings.UseBulkTransferPokemon)
{
var t = await session.Client.Inventory.TransferPokemons(orderedPokemon.Select(x => x.Id).ToList());
if (t.Result == POGOProtos.Networking.Responses.ReleasePokemonResponse.Types.Result.Success)
int page = orderedPokemon.Count() / session.LogicSettings.BulkTransferSize + 1;
for (int i = 0; i < page; i++)
{
foreach (var duplicatePokemon in orderedPokemon)
var batchTransfer = orderedPokemon.Skip(i * session.LogicSettings.BulkTransferSize).Take(session.LogicSettings.BulkTransferSize);
var t = await session.Client.Inventory.TransferPokemons(batchTransfer.Select(x => x.Id).ToList());
if (t.Result == POGOProtos.Networking.Responses.ReleasePokemonResponse.Types.Result.Success)
{
await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);
await PrintPokemonInfo(session, pokemonSettings, pokemonFamilies, duplicatePokemon);
foreach (var duplicatePokemon in batchTransfer)
{
await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);
await PrintPokemonInfo(session, pokemonSettings, pokemonFamilies, duplicatePokemon);
}
}
else session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(Common.TranslationString.BulkTransferFailed, orderedPokemon.Count()) });
}
else session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(Common.TranslationString.BulkTransferFailed, orderedPokemon.Count()) });
}
else
foreach (var duplicatePokemon in orderedPokemon)
Expand Down
19 changes: 12 additions & 7 deletions PoGo.NecroBot.Logic/Tasks/TransferWeakPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,22 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
}
if (session.LogicSettings.UseBulkTransferPokemon && pokemonToTransfers.Count >0)
{
var t = await session.Client.Inventory.TransferPokemons(orderedPokemon.Select(x => x.Id).ToList());
if (t.Result == POGOProtos.Networking.Responses.ReleasePokemonResponse.Types.Result.Success)
int page = orderedPokemon.Count() / session.LogicSettings.BulkTransferSize + 1;
for (int i = 0; i < page; i++)
{
foreach (var duplicatePokemon in pokemonToTransfers)
var batchTransfer = orderedPokemon.Skip(i * session.LogicSettings.BulkTransferSize).Take(session.LogicSettings.BulkTransferSize);
var t = await session.Client.Inventory.TransferPokemons(batchTransfer.Select(x => x.Id).ToList());
if (t.Result == POGOProtos.Networking.Responses.ReleasePokemonResponse.Types.Result.Success)
{
await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);
await PrintTransferedPokemonInfo(session, duplicatePokemon);
foreach (var duplicatePokemon in batchTransfer)
{
await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);
await PrintTransferedPokemonInfo(session, duplicatePokemon);
}
}
else session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(Common.TranslationString.BulkTransferFailed, orderedPokemon.Count()) });
}
else session.EventDispatcher.Send(new WarnEvent() { Message = session.Translation.GetTranslation(Common.TranslationString.BulkTransferFailed, orderedPokemon.Count()) });
}
}
}

private static async Task PrintTransferedPokemonInfo(ISession session, PokemonData pokemon)
Expand Down
15 changes: 11 additions & 4 deletions PoGo.NecroBot.Logic/Utils/LocationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ public static double CalculateDistanceInMeters(double sourceLat, double sourceLn
double destLng)
// from http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates
{
var sourceLocation = new GeoCoordinate(sourceLat, sourceLng);
var targetLocation = new GeoCoordinate(destLat, destLng);

return sourceLocation.GetDistanceTo(targetLocation);
try {
var sourceLocation = new GeoCoordinate(sourceLat, sourceLng);
var targetLocation = new GeoCoordinate(destLat, destLng);
return sourceLocation.GetDistanceTo(targetLocation);
}
catch ( ArgumentOutOfRangeException ex)
{
return double.MaxValue;
}

return 0;
}

public static double CalculateDistanceInMeters(GeoCoordinate sourceLocation, GeoCoordinate destinationLocation)
Expand Down
6 changes: 3 additions & 3 deletions PoGo.NecroBot.Logic/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<package id="CloudFlareUtilities" version="0.2.1-alpha" targetFramework="net452" />
<package id="EngineIoClientDotNet" version="0.9.22" targetFramework="net452" />
<package id="EPPlus" version="4.1.0" targetFramework="net452" />
<package id="GeoCoordinate" version="1.1.0" targetFramework="net452" />
<package id="GeoCoordinate" version="2.0.1" targetFramework="net452" />
<package id="GeoCoordinate.NetStandard1" version="1.0.0" targetFramework="net452" />
<package id="Google.Protobuf" version="3.1.0" targetFramework="net452" />
<package id="GPSOAuthSharp.NetStandard1" version="1.0.0" targetFramework="net452" />
Expand All @@ -18,7 +18,7 @@
<package id="Newtonsoft.Json.Schema" version="2.0.6" targetFramework="net452" />
<package id="POGOLib.Official" version="1.2.1" targetFramework="net452" />
<package id="POGOLib.Official.Google" version="1.0.0" targetFramework="net452" />
<package id="POGOProtos.NetStandard1" version="2.1.0" targetFramework="net452" />
<package id="POGOProtos.NetStandard1" version="2.4.2" targetFramework="net452" />
<package id="Portable.BouncyCastle" version="1.8.1.1" targetFramework="net452" />
<package id="PushBulletSharp" version="2.3.3" targetFramework="net452" />
<package id="S2Geometry" version="1.0.3" targetFramework="net452" />
Expand Down Expand Up @@ -56,6 +56,6 @@
<package id="System.Threading.Timer" version="4.0.1" targetFramework="net452" />
<package id="System.Xml.ReaderWriter" version="4.0.11" targetFramework="net452" />
<package id="System.Xml.XDocument" version="4.0.11" targetFramework="net452" />
<package id="Telegram.Bot" version="10.3.1" targetFramework="net452" />
<package id="Telegram.Bot" version="10.4.0" targetFramework="net452" />
<package id="WebSocket4Net" version="0.14.1" targetFramework="net452" />
</packages>
Loading

0 comments on commit f5b7787

Please sign in to comment.