From 02582779d5daec9fd2d92ae12ca48b75d097c959 Mon Sep 17 00:00:00 2001 From: Ryuichiro Date: Fri, 29 Jul 2016 21:50:16 +0200 Subject: [PATCH 1/5] Fixed MinPokeballsToSnipe Now the Bot will snipe until he's out of pokeballs and tell you why he stopped or didn't start. I never worked with CancellationToken so please double check the code. --- PoGo.NecroBot.Logic/Common/Translations.cs | 2 ++ PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs | 28 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/PoGo.NecroBot.Logic/Common/Translations.cs b/PoGo.NecroBot.Logic/Common/Translations.cs index 5da8ed536..519a9852a 100644 --- a/PoGo.NecroBot.Logic/Common/Translations.cs +++ b/PoGo.NecroBot.Logic/Common/Translations.cs @@ -115,6 +115,7 @@ public enum TranslationString MissingCredentialsPtc, SnipeScan, NoPokemonToSnipe, + NotEnoughPokeballsToSnipe, } public class Translation : ITranslation @@ -240,6 +241,7 @@ public class Translation : ITranslation new KeyValuePair(Common.TranslationString.MissingCredentialsPtc, "You need to fill out PtcUsername and PtcPassword in auth.json!"), new KeyValuePair(Common.TranslationString.SnipeScan, "[Sniper] Scanning for Snipeable Pokemon at {0}..."), new KeyValuePair(Common.TranslationString.NoPokemonToSnipe, "[Sniper] No Pokemon found to snipe!"), + new KeyValuePair(Common.TranslationString.NotEnoughPokeballsToSnipe, "Not enough Pokeballs to start sniping! ({0}/{1})"), }; public string GetTranslation(TranslationString translationString, params object[] data) diff --git a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs index 386eaff6a..a4ace3a1a 100644 --- a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs @@ -241,7 +241,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio } } } - else + else if (await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsToSnipe, session, cancellationToken)) foreach (var location in session.LogicSettings.PokemonToSnipe.Locations) { @@ -260,12 +260,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio lastSnipe = DateTime.Now; foreach (var pokemonLocation in locationsToSnipe) { - var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall); - var greatBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall); - var ultraBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall); - var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall); - - if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount < session.LogicSettings.MinPokeballsToSnipe) + if (!await CheckPokeballsToSnipe(1, session, cancellationToken)) return; locsVisited.Add(pokemonLocation); @@ -313,5 +308,24 @@ private static ScanResult SnipeScanForPokemon(Location location) } return scanResult; } + + public static async Task CheckPokeballsToSnipe(int minPokeballs, ISession session, CancellationToken cancellationToken) + { + var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall); + pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall); + pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall); + pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall); + + if (pokeBallsCount < minPokeballs) + { + session.EventDispatcher.Send(new NoticeEvent() + { + Message = session.Translation.GetTranslation(Common.TranslationString.NotEnoughPokeballsToSnipe, pokeBallsCount, minPokeballs) + }); + return false; + } + + return true; + } } } From cbb9b8b030b1a66b71eafe722231f0756523bd74 Mon Sep 17 00:00:00 2001 From: Ryuichiro Date: Sat, 30 Jul 2016 00:49:59 +0200 Subject: [PATCH 2/5] Added MinPokeballsWhileSnipe Added MinPokeballsWhileSnipe which takes place of the old MinPokeballsToSnipe. The Bot will end sniping if you have only inPokeballsWhileSnipe pokeballs left. --- PoGo.NecroBot.Logic/ILogicSettings.cs | 1 + PoGo.NecroBot.Logic/Settings.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/PoGo.NecroBot.Logic/ILogicSettings.cs b/PoGo.NecroBot.Logic/ILogicSettings.cs index a6f6f53ef..223db771a 100644 --- a/PoGo.NecroBot.Logic/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/ILogicSettings.cs @@ -91,6 +91,7 @@ public interface ILogicSettings string GeneralConfigPath { get; } bool SnipeAtPokestops { get; } int MinPokeballsToSnipe { get; } + int MinPokeballsWhileSnipe { get; } string SnipeLocationServer { get; } int SnipeLocationServerPort { get; } bool UseSnipeLocationServer { get; } diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index 8475765f0..74de73da4 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -132,6 +132,7 @@ public class GlobalSettings public bool StartupWelcomeDelay = true; public bool SnipeAtPokestops = false; public int MinPokeballsToSnipe = 20; + public int MinPokeballsWhileSnipe = 0; public string SnipeLocationServer = "localhost"; public int SnipeLocationServerPort = 16969; public bool UseSnipeLocationServer = false; @@ -548,6 +549,7 @@ public LogicSettings(GlobalSettings settings) public bool StartupWelcomeDelay => _settings.StartupWelcomeDelay; public bool SnipeAtPokestops => _settings.SnipeAtPokestops; public int MinPokeballsToSnipe => _settings.MinPokeballsToSnipe; + public int MinPokeballsWhileSnipe => _settings.MinPokeballsWhileSnipe; public SnipeSettings PokemonToSnipe => _settings.PokemonToSnipe; public string SnipeLocationServer => _settings.SnipeLocationServer; public int SnipeLocationServerPort => _settings.SnipeLocationServerPort; From 7a524242a6520ec3c19447a63961f5784225be45 Mon Sep 17 00:00:00 2001 From: Ryuichiro Date: Sat, 30 Jul 2016 00:50:57 +0200 Subject: [PATCH 3/5] forgot the logic file... --- PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs index a4ace3a1a..9e940570d 100644 --- a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs @@ -260,7 +260,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio lastSnipe = DateTime.Now; foreach (var pokemonLocation in locationsToSnipe) { - if (!await CheckPokeballsToSnipe(1, session, cancellationToken)) + if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) return; locsVisited.Add(pokemonLocation); From c19f6c2d1db91f746d681c9e828312ab5eedc26d Mon Sep 17 00:00:00 2001 From: Ryuichiro Date: Sat, 30 Jul 2016 14:02:04 +0200 Subject: [PATCH 4/5] Enhanced Renaming 1. The bot won't rename favorites. 2. Instead of "RenameAboveIv" you now have "RenamePokemon" which renames all pokemon not transfered and "RenameOnlyAboveIv" which skips pokemon with less than KeepMinIvPercentage IV. With both true you have the old behavior. "RenameOnlyAboveIv" alone will do nothing. --- PoGo.NecroBot.Logic/ILogicSettings.cs | 3 ++- PoGo.NecroBot.Logic/Settings.cs | 6 ++++-- PoGo.NecroBot.Logic/State/FarmState.cs | 2 +- PoGo.NecroBot.Logic/Tasks/Farm.cs | 2 +- PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs | 2 +- PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs | 2 +- PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs | 5 +++-- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/PoGo.NecroBot.Logic/ILogicSettings.cs b/PoGo.NecroBot.Logic/ILogicSettings.cs index e8011f72a..ca0bce0f8 100644 --- a/PoGo.NecroBot.Logic/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/ILogicSettings.cs @@ -83,7 +83,8 @@ public interface ILogicSettings bool EvolveAllPokemonAboveIv { get; } float EvolveAboveIvValue { get; } bool DumpPokemonStats { get; } - bool RenameAboveIv { get; } + bool RenamePokemon { get; } + bool RenameOnlyAboveIv { get; } string RenameTemplate { get; } int AmountOfPokemonToDisplayOnStart { get; } string TranslationLanguageCode { get; } diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index f0d7092f1..d6052d3ce 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -124,7 +124,8 @@ public class GlobalSettings public float KeepMinIvPercentage = 95; public bool KeepPokemonsThatCanEvolve = false; public bool PrioritizeIvOverCp = true; - public bool RenameAboveIv = true; + public bool RenamePokemon = false; + public bool RenameOnlyAboveIv = true; public string RenameTemplate = "{1}_{0}"; public bool TransferDuplicatePokemon = true; public string TranslationLanguageCode = "en"; @@ -582,7 +583,8 @@ public LogicSettings(GlobalSettings settings) public int UseLuckyEggsMinPokemonAmount => _settings.UseLuckyEggsMinPokemonAmount; public bool EvolveAllPokemonAboveIv => _settings.EvolveAllPokemonAboveIv; public float EvolveAboveIvValue => _settings.EvolveAboveIvValue; - public bool RenameAboveIv => _settings.RenameAboveIv; + public bool RenamePokemon => _settings.RenamePokemon; + public bool RenameOnlyAboveIv => _settings.RenameOnlyAboveIv; public string RenameTemplate => _settings.RenameTemplate; public int AmountOfPokemonToDisplayOnStart => _settings.AmountOfPokemonToDisplayOnStart; public bool DumpPokemonStats => _settings.DumpPokemonStats; diff --git a/PoGo.NecroBot.Logic/State/FarmState.cs b/PoGo.NecroBot.Logic/State/FarmState.cs index 46c0a18f9..987d72d79 100644 --- a/PoGo.NecroBot.Logic/State/FarmState.cs +++ b/PoGo.NecroBot.Logic/State/FarmState.cs @@ -22,7 +22,7 @@ public async Task Execute(ISession session, CancellationToken cancellati await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } - if (session.LogicSettings.RenameAboveIv) + if (session.LogicSettings.RenamePokemon) { await RenamePokemonTask.Execute(session, cancellationToken); } diff --git a/PoGo.NecroBot.Logic/Tasks/Farm.cs b/PoGo.NecroBot.Logic/Tasks/Farm.cs index fc0eb0f7a..5946b4b2b 100644 --- a/PoGo.NecroBot.Logic/Tasks/Farm.cs +++ b/PoGo.NecroBot.Logic/Tasks/Farm.cs @@ -30,7 +30,7 @@ public void Run(CancellationToken cancellationToken) TransferDuplicatePokemonTask.Execute(_session, cancellationToken).Wait(); } - if (_session.LogicSettings.RenameAboveIv) + if (_session.LogicSettings.RenamePokemon) { RenamePokemonTask.Execute(_session, cancellationToken).Wait(); } diff --git a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs index 67298cb82..ff03446c7 100644 --- a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs @@ -126,7 +126,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } - if (session.LogicSettings.RenameAboveIv) + if (session.LogicSettings.RenamePokemon) { await RenamePokemonTask.Execute(session, cancellationToken); } diff --git a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs index 071d9e1c8..4896c24d0 100644 --- a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs @@ -168,7 +168,7 @@ await session.Navigation.HumanLikeWalking(new GeoCoordinate(pokeStop.Latitude, p { await TransferDuplicatePokemonTask.Execute(session, cancellationToken); } - if (session.LogicSettings.RenameAboveIv) + if (session.LogicSettings.RenamePokemon) { await RenamePokemonTask.Execute(session, cancellationToken); } diff --git a/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs index 05cdf44fe..d0cebd392 100644 --- a/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs @@ -36,8 +36,9 @@ public static async Task Execute(ISession session, CancellationToken cancellatio string newNickname = String.Format(session.LogicSettings.RenameTemplate, pokemonName, perfection); string oldNickname = (pokemon.Nickname.Length != 0) ? pokemon.Nickname : pokemon.PokemonId.ToString(); - if (perfection >= session.LogicSettings.KeepMinIvPercentage && newNickname != oldNickname && - session.LogicSettings.RenameAboveIv) + // If "RenameOnlyAboveIv" = true only rename pokemon with IV over "KeepMinIvPercentage" + // Favorites will be skipped + if ((!session.LogicSettings.RenameOnlyAboveIv || perfection >= session.LogicSettings.KeepMinIvPercentage) && newNickname != oldNickname && pokemon.Favorite == 0) { await session.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname); From 89b0a51a59155cfa10a7add891b843599430285d Mon Sep 17 00:00:00 2001 From: Ryuichiro Date: Sat, 30 Jul 2016 15:46:10 +0200 Subject: [PATCH 5/5] Revert a false merge --- PoGo.NecroBot.Logic/Common/Translations.cs | 2 -- PoGo.NecroBot.Logic/Settings.cs | 2 -- PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs | 28 +++++-------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/PoGo.NecroBot.Logic/Common/Translations.cs b/PoGo.NecroBot.Logic/Common/Translations.cs index e7e7f2fac..633e8e4e1 100644 --- a/PoGo.NecroBot.Logic/Common/Translations.cs +++ b/PoGo.NecroBot.Logic/Common/Translations.cs @@ -116,7 +116,6 @@ public enum TranslationString MissingCredentialsPtc, SnipeScan, NoPokemonToSnipe, - NotEnoughPokeballsToSnipe, } public class Translation : ITranslation @@ -225,7 +224,6 @@ public class Translation : ITranslation new KeyValuePair(Common.TranslationString.MissingCredentialsPtc, "You need to fill out PtcUsername and PtcPassword in auth.json!"), new KeyValuePair(Common.TranslationString.SnipeScan, "[Sniper] Scanning for Snipeable Pokemon at {0}..."), new KeyValuePair(Common.TranslationString.NoPokemonToSnipe, "[Sniper] No Pokemon found to snipe!"), - new KeyValuePair(Common.TranslationString.NotEnoughPokeballsToSnipe, "Not enough Pokeballs to start sniping! ({0}/{1})"), }; public string GetTranslation(TranslationString translationString, params object[] data) diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index 18e44eed2..d6052d3ce 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -134,7 +134,6 @@ public class GlobalSettings public bool StartupWelcomeDelay = true; public bool SnipeAtPokestops = false; public int MinPokeballsToSnipe = 20; - public int MinPokeballsWhileSnipe = 0; public string SnipeLocationServer = "localhost"; public int SnipeLocationServerPort = 16969; public bool UseSnipeLocationServer = false; @@ -598,7 +597,6 @@ public LogicSettings(GlobalSettings settings) public bool StartupWelcomeDelay => _settings.StartupWelcomeDelay; public bool SnipeAtPokestops => _settings.SnipeAtPokestops; public int MinPokeballsToSnipe => _settings.MinPokeballsToSnipe; - public int MinPokeballsWhileSnipe => _settings.MinPokeballsWhileSnipe; public SnipeSettings PokemonToSnipe => _settings.PokemonToSnipe; public string SnipeLocationServer => _settings.SnipeLocationServer; public int SnipeLocationServerPort => _settings.SnipeLocationServerPort; diff --git a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs index dc5dfb527..4c4de6c28 100644 --- a/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs @@ -241,7 +241,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio } } } - else if (await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsToSnipe, session, cancellationToken)) + else foreach (var location in session.LogicSettings.PokemonToSnipe.Locations) { @@ -264,7 +264,12 @@ public static async Task Execute(ISession session, CancellationToken cancellatio lastSnipe = DateTime.Now; foreach (var pokemonLocation in locationsToSnipe) { - if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken)) + var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall); + var greatBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall); + var ultraBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall); + var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall); + + if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount < session.LogicSettings.MinPokeballsToSnipe) return; locsVisited.Add(pokemonLocation); @@ -312,24 +317,5 @@ private static ScanResult SnipeScanForPokemon(Location location) } return scanResult; } - - public static async Task CheckPokeballsToSnipe(int minPokeballs, ISession session, CancellationToken cancellationToken) - { - var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall); - pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall); - pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall); - pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall); - - if (pokeBallsCount < minPokeballs) - { - session.EventDispatcher.Send(new NoticeEvent() - { - Message = session.Translation.GetTranslation(Common.TranslationString.NotEnoughPokeballsToSnipe, pokeBallsCount, minPokeballs) - }); - return false; - } - - return true; - } } }