Repository: PokemonGoF/PokemonGo-Bot

Issue:
[BUG] Bot neither uses greatballs when out of pokeballs nor switches to farm mode
### Expected Behavior

No more pokeballs but more than ten greatballs, bot should use greatballs
### Actual Behavior

2016-07-24 13:51:10] [#] A Wild Voltorb appeared! [CP 223] [Potential 0.42]
[2016-07-24 13:51:10] [#] IV [Stamina/Attack/Defense] = [14/2/3]
[2016-07-24 13:51:13] [x] Using Pokeball (chance: 45.14%)... (-1 left!)
### Steps to Reproduce

just run the bot
### Other Information

OS: OSX
Git Commit: ee730249167e4d6d28191e4c36c819fe29652dad



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py
--- a/pokemongo_bot/__init__.py
+++ b/pokemongo_bot/__init__.py
@@ -212,6 +212,7 @@ def _setup_api(self):
         logger.log('[#] PokeBalls: ' + str(balls_stock[1]))
         logger.log('[#] GreatBalls: ' + str(balls_stock[2]))
         logger.log('[#] UltraBalls: ' + str(balls_stock[3]))
+        logger.log('[#] Razz Berries: ' + str(self.item_inventory_count(701)))
 
         self.get_player_info()
 
diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
--- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py
+++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
@@ -33,8 +33,11 @@ def work(self):
             if 'ENCOUNTER' in response_dict['responses']:
                 if 'status' in response_dict['responses']['ENCOUNTER']:
                     if response_dict['responses']['ENCOUNTER']['status'] is 7:
-                        logger.log('[x] Pokemon Bag is full!', 'red')
-                        return PokemonCatchWorker.BAG_FULL
+                        if self.config.initial_transfer:
+                            logger.log('[x] Pokemon Bag is full!', 'red')
+                            return PokemonCatchWorker.BAG_FULL
+                        else:
+                            raise RuntimeError('Pokemon Bag is full!')
 
                     if response_dict['responses']['ENCOUNTER']['status'] is 1:
                         cp = 0
@@ -81,8 +84,28 @@ def work(self):
                                     pokeball = 2 # then use great balls
                                 elif balls_stock[3] > 0: # or if great balls are out of stock too, and player has ultra balls...
                                     pokeball = 3 # then use ultra balls
+                            
+                            ## Use berry to increase success chance.
+                            berry_id = 701 # @ TODO: use better berries if possible
+                            berries_count = self.bot.item_inventory_count(berry_id)
+                            if(catch_rate[pokeball-1] < 0.5 and berries_count > 0): # and berry is in stock
+                                success_percentage = '{0:.2f}'.format(catch_rate[pokeball-1]*100)
+                                logger.log('[x] Catch Rate with normal Pokeball is low ({}%). Throwing {}... ({} left!)'.format(success_percentage,self.item_list[str(berry_id)],berries_count-1))
+                                self.api.use_item_capture(
+                                    item_id=berry_id, 
+                                    encounter_id = encounter_id, 
+                                    spawn_point_guid = spawnpoint_id
+                                )
+                                response_dict = self.api.call()
+                                if response_dict and response_dict['status_code'] is 1 and 'item_capture_mult' in response_dict['responses']['USE_ITEM_CAPTURE']:
+                                
+                                    for i in range(len(catch_rate)):
+                                        catch_rate[i] = catch_rate[i] * response_dict['responses']['USE_ITEM_CAPTURE']['item_capture_mult']
+                                        
+                                    success_percentage = '{0:.2f}'.format(catch_rate[pokeball-1]*100)
+                                    logger.log('[#] Catch Rate with normal Pokeball has increased to {}%'.format(success_percentage))
                                 else:
-                                    pokeball = 0 # player doesn't have any of pokeballs, great balls or ultra balls
+                                    logger.log('[x] Fail to use berry. Status Code: {}'.format(response_dict['status_code']),'red')
 
                             while(pokeball < 3):
                                 if catch_rate[pokeball-1] < 0.35 and balls_stock[pokeball+1] > 0:
@@ -92,8 +115,8 @@ def work(self):
                                     break
 
                             # @TODO, use the best ball in stock to catch VIP (Very Important Pokemon: Configurable)
-
-                            if pokeball is 0:
+                            
+                            if balls_stock[pokeball] is 0:
                                 logger.log(
                                     '[x] Out of pokeballs, switching to farming mode...', 'red')
                                 # Begin searching for pokestops.
@@ -126,23 +149,24 @@ def work(self):
                                     'CATCH_POKEMON']['status']
                                 if status is 2:
                                     logger.log(
-                                        '[-] Attempted to capture {}- failed.. trying again!'.format(pokemon_name), 'red')
+                                        '[-] Attempted to capture {} - failed.. trying again!'.format(pokemon_name), 'red')
                                     sleep(2)
                                     continue
                                 if status is 3:
                                     logger.log(
                                         '[x] Oh no! {} vanished! :('.format(pokemon_name), 'red')
                                 if status is 1:
-                                    logger.log(
-                                        '[x] Captured {}! [CP {}] [IV {}]'.format(
-                                            pokemon_name,
-                                            cp,
-                                            pokemon_potential
-                                        ), 'green'
-                                    )
-
+                                    
                                     id_list2 = self.count_pokemon_inventory()
-
+                                    
+                                    logger.log('[x] Captured {}! [CP {}] [{}/{}/{}]'.format(
+                                        pokemon_name, 
+                                        cp,
+                                        pokemon['pokemon_data']['individual_stamina'],
+                                        pokemon['pokemon_data']['individual_attack'],
+                                        pokemon['pokemon_data']['individual_defense']
+                                    ), 'blue')
+                                        
                                     if self.config.evolve_captured:
                                         pokemon_to_transfer = list(Set(id_list2) - Set(id_list1))
                                         self.api.evolve_pokemon(pokemon_id=pokemon_to_transfer[0])
@@ -166,9 +190,7 @@ def work(self):
                                             pokemon_to_transfer[0])
                                         logger.log(
                                             '[#] {} has been exchanged for candy!'.format(pokemon_name), 'green')
-                                    else:
-                                        logger.log(
-                                        '[x] Captured {}! [CP {}]'.format(pokemon_name, cp), 'green')
+
                             break
         time.sleep(5)
 
diff --git a/pokemongo_bot/logger.py b/pokemongo_bot/logger.py
--- a/pokemongo_bot/logger.py
+++ b/pokemongo_bot/logger.py
@@ -9,9 +9,10 @@
 
 def log(string, color = 'white'):
     colorHex = {
+        'red': '91m',
         'green': '92m',
         'yellow': '93m',
-        'red': '91m'
+        'blue': '94m'
     }
     if color not in colorHex:
         print('[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] '+ string)


Test patch: