Added option to transfer pokemons based on their IV in %

rlehmann [2016-07-26 16:27:28]
Added option to transfer pokemons based on their IV in %
Lucky egg button gets disabled for 30min after using an egg
Filename
PokemonGo/RocketAPI/Console/App.config
PokemonGo/RocketAPI/Console/Program.cs
PokemonGo/RocketAPI/Console/Settings.cs
PokemonGo/RocketAPI/ISettings.cs
PokemonGo/RocketAPI/Window/App.config
PokemonGo/RocketAPI/Window/MainForm.cs
PokemonGo/RocketAPI/Window/Settings.cs
diff --git a/PokemonGo/RocketAPI/Console/App.config b/PokemonGo/RocketAPI/Console/App.config
index 1ad5872..d7cfe10 100644
--- a/PokemonGo/RocketAPI/Console/App.config
+++ b/PokemonGo/RocketAPI/Console/App.config
@@ -25,8 +25,9 @@
     <add key="Language" value="english" /> <!--Languages english/german-->
     <add key="RazzBerryMode" value="probability" /> <!--When to use RazzBerry cp/probability-->
     <add key="RazzBerrySetting" value="0.4" /> <!--Cp Mode: Use RazzBerry when Pokemon is over this value; pobability Mode: Use Razzberry when % between 0 and 1 of catching is under this value-->
-    <add key="TransferType" value="duplicate" /> <!--none/cp/leaveStrongest/duplicate/all Whitelists/blackslists for each type is in Program.cs-->
+    <add key="TransferType" value="duplicate" /> <!--none/cp/iv/leaveStrongest/duplicate/all Whitelists/blackslists for each type is in Program.cs-->
     <add key="TransferCPThreshold" value="0" /> <!--transfer pokemon with CP less than this value if cp transfer type is selected. Whitelist in Program.cs-->
+    <add key="TransferIVThreshold" value="80" /> <!--transfer pokemon with IV less than this value if iv transfer type is selected. Whitelist in Program.cs-->
     <add key="EvolveAllGivenPokemons" value="false" />
     <add key="ClientSettingsProvider.ServiceUri" value="" />
   </appSettings>
diff --git a/PokemonGo/RocketAPI/Console/Program.cs b/PokemonGo/RocketAPI/Console/Program.cs
index 3603486..d7fc3e5 100644
--- a/PokemonGo/RocketAPI/Console/Program.cs
+++ b/PokemonGo/RocketAPI/Console/Program.cs
@@ -208,6 +208,9 @@ namespace PokemonGo.RocketAPI.Console
                     case "cp":
                         await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
                         break;
+                    case "iv":
+                        await TransferAllGivenPokemons(client, pokemons, ClientSettings.TransferIVThreshold);
+                        break;
                     default:
                         ColoredConsoleWrite(ConsoleColor.DarkGray, "Transfering pokemon disabled");
                         break;
@@ -284,6 +287,7 @@ namespace PokemonGo.RocketAPI.Console
                 var update = await client.UpdatePlayerLocation(pokemon.Latitude, pokemon.Longitude);
                 var encounterPokemonResponse = await client.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnpointId);
                 var pokemonCP = encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp;
+                var pokemonIV = Perfect(encounterPokemonResponse?.WildPokemon?.PokemonData);
                 CatchPokemonResponse caughtPokemonResponse;
                 do
                 {
@@ -306,15 +310,16 @@ namespace PokemonGo.RocketAPI.Console
                 }
                 else
                     pokemonName = Convert.ToString(pokemon.PokemonId);
+
                 if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                 {
-                    ColoredConsoleWrite(ConsoleColor.Green, $"We caught a {pokemonName} with {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} CP");
+                    ColoredConsoleWrite(ConsoleColor.Green, $"We caught a {pokemonName} with {pokemonCP} CP and {pokemonIV}% IV");
                     foreach (int xp in caughtPokemonResponse.Scores.Xp)
                         TotalExperience += xp;
                     TotalPokemon += 1;
                 }
                 else
-                    ColoredConsoleWrite(ConsoleColor.Red, $"{pokemonName} with {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} CP got away..");
+                    ColoredConsoleWrite(ConsoleColor.Red, $"{pokemonName} with {pokemonCP} CP and {pokemonIV}% IV");

                 if (ClientSettings.TransferType == "leaveStrongest")
                     await TransferAllButStrongestUnwantedPokemon(client);
@@ -324,6 +329,8 @@ namespace PokemonGo.RocketAPI.Console
                     await TransferDuplicatePokemon(client);
                 else if (ClientSettings.TransferType == "cp")
                     await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
+                else if (ClientSettings.TransferType == "iv")
+                    await TransferAllGivenPokemons(client, pokemons2, ClientSettings.TransferIVThreshold);

                 await Task.Delay(3000);
             }
diff --git a/PokemonGo/RocketAPI/Console/Settings.cs b/PokemonGo/RocketAPI/Console/Settings.cs
index 25f86b8..8361c91 100644
--- a/PokemonGo/RocketAPI/Console/Settings.cs
+++ b/PokemonGo/RocketAPI/Console/Settings.cs
@@ -19,6 +19,7 @@ namespace PokemonGo.RocketAPI.Console
         /// </summary>
         public string TransferType => GetSetting() != string.Empty ? GetSetting() : "none";
         public int TransferCPThreshold => GetSetting() != string.Empty ? int.Parse(GetSetting(), CultureInfo.InvariantCulture) : 0;
+        public int TransferIVThreshold => GetSetting() != string.Empty ? int.Parse(GetSetting(), CultureInfo.InvariantCulture) : 0;
         public bool EvolveAllGivenPokemons => GetSetting() != string.Empty ? System.Convert.ToBoolean(GetSetting(), CultureInfo.InvariantCulture) : false;


diff --git a/PokemonGo/RocketAPI/ISettings.cs b/PokemonGo/RocketAPI/ISettings.cs
index c6a607d..4500371 100644
--- a/PokemonGo/RocketAPI/ISettings.cs
+++ b/PokemonGo/RocketAPI/ISettings.cs
@@ -21,6 +21,7 @@ namespace PokemonGo.RocketAPI
         bool EvolveAllGivenPokemons { get; }
         string TransferType { get; }
         int TransferCPThreshold { get; }
+        int TransferIVThreshold { get; }
         bool Recycler { get; }
         ICollection<KeyValuePair<AllEnum.ItemId, int>> ItemRecycleFilter { get; }
         int RecycleItemsInterval { get; }
diff --git a/PokemonGo/RocketAPI/Window/App.config b/PokemonGo/RocketAPI/Window/App.config
index f769fbf..c12da02 100644
--- a/PokemonGo/RocketAPI/Window/App.config
+++ b/PokemonGo/RocketAPI/Window/App.config
@@ -38,9 +38,11 @@
     <add key="RazzBerrySetting" value="0.4" />
     <!--Cp Mode: Use RazzBerry when Pokemon is over this value; pobability Mode: Use Razzberry when % between 0 and 1 of catching is under this value-->
     <add key="TransferType" value="duplicate" />
-    <!--none/cp/leaveStrongest/duplicate/all Whitelists/blackslists for each type is in Program.cs-->
+    <!--none/cp/iv/leaveStrongest/duplicate/all Whitelists/blackslists for each type is in Program.cs-->
     <add key="TransferCPThreshold" value="0" />
     <!--transfer pokemon with CP less than this value if cp transfer type is selected. Whitelist in Program.cs-->
+    <add key="TransferIVThreshold" value="80" />
+    <!--transfer pokemon with IV less than this value if iv transfer type is selected. Whitelist in Program.cs-->
     <add key="EvolveAllGivenPokemons" value="false" />
     <add key="ClientSettingsProvider.ServiceUri" value="" />
   </appSettings>
diff --git a/PokemonGo/RocketAPI/Window/MainForm.cs b/PokemonGo/RocketAPI/Window/MainForm.cs
index 85f18f5..1fa506e 100644
--- a/PokemonGo/RocketAPI/Window/MainForm.cs
+++ b/PokemonGo/RocketAPI/Window/MainForm.cs
@@ -237,6 +237,9 @@ namespace PokemonGo.RocketAPI.Window
                     case "cp":
                         await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
                         break;
+                    case "iv":
+                        await TransferAllGivenPokemons(client, pokemons, ClientSettings.TransferIVThreshold);
+                        break;
                     default:
                         ColoredConsoleWrite(Color.DarkGray, "Transfering pokemon disabled");
                         break;
@@ -313,6 +316,7 @@ namespace PokemonGo.RocketAPI.Window
                 var update = await client.UpdatePlayerLocation(pokemon.Latitude, pokemon.Longitude);
                 var encounterPokemonResponse = await client.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnpointId);
                 var pokemonCP = encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp;
+                var pokemonIV = Math.Round(Perfect(encounterPokemonResponse?.WildPokemon?.PokemonData));
                 CatchPokemonResponse caughtPokemonResponse;
                 do
                 {
@@ -335,15 +339,16 @@ namespace PokemonGo.RocketAPI.Window
                 }
                 else
                     pokemonName = Convert.ToString(pokemon.PokemonId);
+
                 if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                 {
-                    ColoredConsoleWrite(Color.Green, $"We caught a {pokemonName} with {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} CP");
+                    ColoredConsoleWrite(Color.Green, $"We caught a {pokemonName} with {pokemonCP} CP and {pokemonIV}% IV");
                     foreach (int xp in caughtPokemonResponse.Scores.Xp)
                         TotalExperience += xp;
                     TotalPokemon += 1;
                 }
                 else
-                    ColoredConsoleWrite(Color.Red, $"{pokemonName} with {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} CP got away..");
+                    ColoredConsoleWrite(Color.Red, $"{pokemonName} with {pokemonCP} CP and {pokemonIV}% IV got away..");

                 if (ClientSettings.TransferType == "leaveStrongest")
                     await TransferAllButStrongestUnwantedPokemon(client);
@@ -353,6 +358,8 @@ namespace PokemonGo.RocketAPI.Window
                     await TransferDuplicatePokemon(client);
                 else if (ClientSettings.TransferType == "cp")
                     await TransferAllWeakPokemon(client, ClientSettings.TransferCPThreshold);
+                else if (ClientSettings.TransferType == "iv")
+                    await TransferAllGivenPokemons(client, pokemons2, ClientSettings.TransferIVThreshold);

                 await Task.Delay(3000);
             }
@@ -799,6 +806,11 @@ namespace PokemonGo.RocketAPI.Window
                         var useItemXpBoostRequest = await client.UseItemXpBoost(ItemId.ItemLuckyEgg);
                         ColoredConsoleWrite(Color.Green, $"Using a Lucky Egg, we have {LuckyEgg.Count} left.");
                         ColoredConsoleWrite(Color.Yellow, $"Lucky Egg Valid until: {DateTime.Now.AddMinutes(30).ToString()}");
+
+                        var stripItem = sender as ToolStripMenuItem;
+                        stripItem.Enabled = false;
+                        await Task.Delay(30000);
+                        stripItem.Enabled = true;
                     }
                     else
                     {
diff --git a/PokemonGo/RocketAPI/Window/Settings.cs b/PokemonGo/RocketAPI/Window/Settings.cs
index 12a8091..76f1a6e 100644
--- a/PokemonGo/RocketAPI/Window/Settings.cs
+++ b/PokemonGo/RocketAPI/Window/Settings.cs
@@ -45,6 +45,7 @@ namespace PokemonGo.RocketAPI.Window
         /// </summary>
         public string TransferType => GetSetting() != string.Empty ? GetSetting() : "none";
         public int TransferCPThreshold => GetSetting() != string.Empty ? int.Parse(GetSetting(), CultureInfo.InvariantCulture) : 0;
+        public int TransferIVThreshold => GetSetting() != string.Empty ? int.Parse(GetSetting(), CultureInfo.InvariantCulture) : 0;
         public bool EvolveAllGivenPokemons => GetSetting() != string.Empty && Convert.ToBoolean(GetSetting(), CultureInfo.InvariantCulture);

You may download the files in Public Git.