Repository: PokemonGoF/PokemonGo-Bot

Issue:
PokemonOptimizer stopped working
### Expected Behavior

PokemonOptimizer should transfer and evolve pokemon when bag is getting full.
### Actual Behavior

No pokemon are being transferred or evolved.
### Additional info

It worked in 8eba07a. Maybe it's related to the new inventory commit.
One thing I noticed is that before it showed:
`[PokemonOptimizer] [INFO] Pokemon Bag: 192/250`
after every catch, but now it doesn't.
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

```
      {
          "type": "PokemonOptimizer",
          "config": {
              "transfer": true,
              "transfer_wait_min": 1,
              "transfer_wait_max": 4,
              "evolve": true,
              "evolve_time": 20,
              "evolve_for_xp": true,
              "evolve_only_with_lucky_egg": true,
              "evolve_count_for_lucky_egg": 90,
              "may_use_lucky_egg": true,
              "keep": [
                  {
                      "top": 1,
                      "evolve": true,
                      "sort": ["dps","ncp","iv"]
                  },
                  {
                      "top": 1,
                      "evolve": true,
                      "sort": ["cp"]
                  }
              ]
          }
      },
```
### Output when issue occurred

```
[PokemonCatchWorker] [INFO] [pokemon_inventory_full] Your Pokemon inventory is full! Could not catch!
```
### Steps to Reproduce
### Other Information

OS: Ubuntu
Branch: dev
Git Commit: 198510b70388f7d70478db847e77bf12095d004a
Python Version: Python 2.7.6
Any other relevant files/configs (eg: path files) 



Discussion:
+1 same here with commit 324b752 ("Configurable altitude range  (#4250)", 2016-08-19)

The problem is caused by commit a58d437 ("Hotfix/remove old inventory (#4238)", 2016-08-19)

Same issue here getting the following message's in the log.

> 016-08-19 11:14:48,205 [PokemonCatchWorker] [INFO] [pokemon_inventory_full] Your Pokemon inventory is full! Could not catch!
> 2016-08-19 11:14:48,217 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop Together - 0.13km
> 2016-08-19 11:14:49,616 [PokemonCatchWorker] [INFO] [pokemon_inventory_full] Your Pokemon inventory is full! Could not catch!
> 2016-08-19 11:14:49,630 [MoveToFort] [INFO] [moving_to_fort] Moving towards pokestop Together - 0.12km
> 2016-08-19 11:14:50,894 [PokemonCatchWorker] [INFO] [pokemon_inventory_full] Your Pokemon inventory is full! Could not catch!

Same for me, Git Commit: 324b752f031cdb39d52c396ea50e14a59841535e

Something seems wrong with how a full bag is calculated.
In the app, I'm seeing 250/250, a full bag.
The bot however shows this : 

```
2016-08-19 11:46:17,322 [PokemonGoBot] [INFO] Pokemon Captured: 241 | Pokestops Visited: 94
2016-08-19 11:46:17,463 [PokemonGoBot] [INFO]
2016-08-19 11:46:17,463 [PokemonGoBot] [INFO] --- redacted ---
2016-08-19 11:46:18,640 [PokemonGoBot] [INFO] Pokemon Bag: 241/250
2016-08-19 11:46:18,641 [PokemonGoBot] [INFO] Items: 225/350
```

Seems to be related to the new inventory system not counting eggs. Are eggs considered as used space in a bag.. ?


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py
--- a/pokemongo_bot/cell_workers/pokemon_optimizer.py
+++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py
@@ -290,10 +290,7 @@ def transfer_pokemon(self, pokemon):
         return True
 
     def get_candy_gained_count(self, response_dict):
-        total_candy_gained = 0
-        for candy_gained in response_dict['responses']['CATCH_POKEMON']['capture_award']['candy']:
-            total_candy_gained += candy_gained
-        return total_candy_gained
+        return response_dict['responses']['RELEASE_POKEMON']['candy_awarded']
 
     def use_lucky_egg(self):
         lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value)  # @UndefinedVariable
diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py
--- a/pokemongo_bot/inventory.py
+++ b/pokemongo_bot/inventory.py
@@ -266,7 +266,7 @@ def get_space_used(cls):
         :return: The space used in pokemon inventory.
         :rtype: int
         """
-        return len(_inventory.pokemons.all())
+        return len(_inventory.pokemons.all_with_eggs())
 
     @classmethod
     def get_space_left(cls):
@@ -322,6 +322,10 @@ def all(self):
         # makes caller's lives more difficult)
         return [p for p in super(Pokemons, self).all() if not isinstance(p, Egg)]
 
+    def all_with_eggs(self):
+        # count pokemon AND eggs, since eggs are counted as bag space
+        return super(Pokemons, self).all()
+
     def add(self, pokemon):
         if pokemon.unique_id <= 0:
             raise ValueError("Can't add a pokemon without id")


Test patch: