Added pokeball stuffs

Detective Squirrel [2016-07-21 13:06:54]
Added pokeball stuffs

better pokeball usage
Filename
.vs/Pokemon Go Rocket API/v14/.suo
PokemonGo/RocketAPI/Client.cs
PokemonGo/RocketAPI/Console/Program.cs
diff --git a/.vs/Pokemon Go Rocket API/v14/.suo b/.vs/Pokemon Go Rocket API/v14/.suo
new file mode 100644
index 0000000..e04100d
Binary files /dev/null and b/.vs/Pokemon Go Rocket API/v14/.suo differ
diff --git a/PokemonGo/RocketAPI/Client.cs b/PokemonGo/RocketAPI/Client.cs
index 063235d..859142d 100644
--- a/PokemonGo/RocketAPI/Client.cs
+++ b/PokemonGo/RocketAPI/Client.cs
@@ -50,12 +50,12 @@ namespace PokemonGo.RocketAPI
         }

         public async Task<CatchPokemonResponse> CatchPokemon(ulong encounterId, string spawnPointGuid, double pokemonLat,
-            double pokemonLng, MiscEnums.Item pokeball)
+            double pokemonLng, MiscEnums.Item pokeball, int? pokemonCP)
         {
             var customRequest = new Request.Types.CatchPokemonRequest
             {
                 EncounterId = encounterId,
-                Pokeball = (int) GetBestBall().Result,
+                Pokeball = (int) GetBestBall(pokemonCP).Result,
                 SpawnPointGuid = spawnPointGuid,
                 HitPokemon = 1,
                 NormalizedReticleSize = Utils.FloatAsUlong(1.950),
@@ -137,7 +137,7 @@ namespace PokemonGo.RocketAPI
                         releasePokemonRequest);
         }

-        private async Task<MiscEnums.Item> GetBestBall()
+        private async Task<MiscEnums.Item> GetBestBall(int? pokemonCP)
         {
             var inventory = await GetInventory();

@@ -159,18 +159,58 @@ namespace PokemonGo.RocketAPI
             var masterBallsCount = ballCollection.Where(p => p.ItemId == MiscEnums.Item.ITEM_MASTER_BALL).
                 DefaultIfEmpty(new {ItemId = MiscEnums.Item.ITEM_MASTER_BALL, Amount = 0}).FirstOrDefault().Amount;

-            if (masterBallsCount > 0)
+            // Use better balls for high CP pokemon
+            if (masterBallsCount > 0 && pokemonCP >= 1000)
+            {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Master Ball is being used");
                 return MiscEnums.Item.ITEM_MASTER_BALL;
+            }

-            if (ultraBallsCount > 0)
+            if (ultraBallsCount > 0 && pokemonCP >= 600)
+            {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Ultra Ball is being used");
                 return MiscEnums.Item.ITEM_ULTRA_BALL;
+            }
+
+            if (greatBallsCount > 0 && pokemonCP >= 350)
+            {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Great Ball is being used");
+                return MiscEnums.Item.ITEM_GREAT_BALL;
+            }

-            if (greatBallsCount > 0)
+            // If low CP pokemon, but no more pokeballs; only use better balls if pokemon are of semi-worthy quality
+            if (pokeBallsCount > 0)
+            {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Poke Ball is being used");
+                return MiscEnums.Item.ITEM_POKE_BALL;
+            }
+            else if ((greatBallsCount < 40 && pokemonCP >= 200) || greatBallsCount >= 40)
+                {
+                    ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Great Ball is being used");
                 return MiscEnums.Item.ITEM_GREAT_BALL;
+            }
+            else if (ultraBallsCount > 0 && pokemonCP >= 500)
+                {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Ultra Ball is being used");
+                return MiscEnums.Item.ITEM_ULTRA_BALL;
+            }
+            else if (masterBallsCount > 0 && pokemonCP >= 700)
+            {
+                ColoredConsoleWrite(ConsoleColor.Green, $"[{DateTime.Now.ToString("HH:mm:ss")}] Master Ball is being used");
+                return MiscEnums.Item.ITEM_MASTER_BALL;
+            }

             return MiscEnums.Item.ITEM_POKE_BALL;
         }

+        public static void ColoredConsoleWrite(ConsoleColor color, string text)
+        {
+            ConsoleColor originalColor = System.Console.ForegroundColor;
+            System.Console.ForegroundColor = color;
+            System.Console.WriteLine(text);
+            System.Console.ForegroundColor = originalColor;
+        }
+
         public async Task<FortDetailsResponse> GetFort(string fortId, double fortLat, double fortLng)
         {
             var customRequest = new Request.Types.FortDetailsRequest
diff --git a/PokemonGo/RocketAPI/Console/Program.cs b/PokemonGo/RocketAPI/Console/Program.cs
index a276c09..e1c441b 100644
--- a/PokemonGo/RocketAPI/Console/Program.cs
+++ b/PokemonGo/RocketAPI/Console/Program.cs
@@ -105,7 +105,7 @@ namespace PokemonGo.RocketAPI.Console

                     if (evolvePokemonOutProto.Result == 1)
                     {
-                        ColoredConsoleWrite(ConsoleColor.White,
+                        ColoredConsoleWrite(ConsoleColor.Cyan,
                             $"[{DateTime.Now.ToString("HH:mm:ss")}] Evolved {pokemon.PokemonId} successfully for {evolvePokemonOutProto.ExpAwarded}xp");

                         countOfEvolvedUnits++;
@@ -123,7 +123,7 @@ namespace PokemonGo.RocketAPI.Console
                     }
                 } while (evolvePokemonOutProto.Result == 1);
                 if (countOfEvolvedUnits > 0)
-                    ColoredConsoleWrite(ConsoleColor.White,
+                    ColoredConsoleWrite(ConsoleColor.Cyan,
                         $"[{DateTime.Now.ToString("HH:mm:ss")}] Evolved {countOfEvolvedUnits} pieces of {pokemon.PokemonId} for {xpCount}xp");

                 await Task.Delay(3000);
@@ -205,13 +205,14 @@ 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;
                 CatchPokemonResponse caughtPokemonResponse;
                 do
                 {
                     caughtPokemonResponse =
                         await
                             client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude,
-                                pokemon.Longitude, MiscEnums.Item.ITEM_POKE_BALL);
+                                pokemon.Longitude, MiscEnums.Item.ITEM_POKE_BALL, pokemonCP);
                     ; //note: reverted from settings because this should not be part of settings but part of logic
                 } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed);
                 ColoredConsoleWrite(ConsoleColor.Green, caughtPokemonResponse.Status ==
You may download the files in Public Git.