diff --git a/data/pokemon.json b/data/pokemon.json index f853600129..2c10429f27 100644 --- a/data/pokemon.json +++ b/data/pokemon.json @@ -4554,7 +4554,9 @@ "Next Evolution Requirements": { "Amount": 50, "Family": 95, - "Name": "Onix candies" + "Name": "Onix candies", + "EvoItem": 1103, + "EvoItemNeeded": 1 }, "Next evolution(s)": [ { diff --git a/pokemongo_bot/cell_workers/pokemon_optimizer.py b/pokemongo_bot/cell_workers/pokemon_optimizer.py index b1f0c9a1aa..174ab65698 100644 --- a/pokemongo_bot/cell_workers/pokemon_optimizer.py +++ b/pokemongo_bot/cell_workers/pokemon_optimizer.py @@ -543,9 +543,18 @@ def get_evolution_plan(self, family_id, family_list, keep, try_evolve, try_upgra evolve = [] for pokemon in try_evolve: + pokemon_id = pokemon.pokemon_id + needed_evolution_item = inventory.pokemons().evolution_item_for(pokemon_id) + if needed_evolution_item is not None: + # We need a special Item to evolve this Pokemon! + item = inventory.items().get(needed_evolution_item) + needed = inventory.pokemons().evolution_items_needed_for(pokemon_id) + if item.count < needed: + self.logger.info("To evolve a {} we need {} of {}. We have {}".format(pokemon.name, needed, item.name, item.count)) + continue + if self.config_evolve_to_final: pokemon_id = pokemon.pokemon_id - while inventory.pokemons().has_next_evolution(pokemon_id): candies -= inventory.pokemons().evolution_cost_for(pokemon_id) pokemon_id = inventory.pokemons().next_evolution_ids_for(pokemon_id)[0] diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index f0dba4c5ca..016066bf28 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -487,6 +487,14 @@ def has_next_evolution(cls, pokemon_id): def evolution_cost_for(cls, pokemon_id): return cls.data_for(pokemon_id).evolution_cost + @classmethod + def evolution_item_for(cls, pokemon_id): + return cls.data_for(pokemon_id).evolution_item + + @classmethod + def evolution_items_needed_for(cls, pokemon_id): + return cls.data_for(pokemon_id).evolution_item_needed + def parse(self, item): if 'is_egg' in item: return Egg(item) @@ -753,7 +761,6 @@ def add(self, amount): raise Exception('Must add positive amount of candy') self.quantity += amount - class Egg(object): def __init__(self, data): self._data = data @@ -823,6 +830,9 @@ def __init__(self, data): # Number of candies for the next evolution (if possible) self.evolution_cost = 0 + # Next evolution doesn't need a special item + self.evolution_item = None + self.evolution_item_needed = 0 # next evolution flag self.has_next_evolution = 'Next evolution(s)' in data \ or 'Next Evolution Requirements' in data @@ -833,12 +843,14 @@ def __init__(self, data): #candies self.candyid = int(data['Candy']['FamilyID']) self.candyName = (data['Candy']['Name']) - # ids of all available next evolutions in the family self.next_evolutions_all = [] if self.has_next_evolution: ids = [int(e['Number']) for e in data['Next evolution(s)']] self.next_evolutions_all = ids self.evolution_cost = int(data['Next Evolution Requirements']['Amount']) + if 'EvoItem' in data['Next Evolution Requirements']: + self.evolution_item = int(data['Next Evolution Requirements']['EvoItem']) + self.evolution_item_needed = int(data['Next Evolution Requirements']['EvoItemNeeded']) @property def family_id(self): @@ -1013,8 +1025,14 @@ def update_nickname(self, new_nickname): self.nickname = self.nickname_raw or self.name def can_evolve_now(self): - return self.has_next_evolution() and \ - self.candy_quantity >= self.evolution_cost + if self.evolution_item is None: + return self.has_next_evolution() and \ + self.candy_quantity >= self.evolution_cost + else: + evo_items = items().get(self.evolution_item).count + return self.has_next_evolution() and \ + self.candy_quantity >= self.evolution_cost and \ + evo_items >= self.evolution_items_needed def has_next_evolution(self): return self.static.has_next_evolution @@ -1053,6 +1071,14 @@ def candy_quantity(self): def evolution_cost(self): return self.static.evolution_cost + @property + def evolution_item(self): + return self.static.evolution_item + + @property + def evolution_items_needed(self): + return self.static.evolution_item_needed + @property def iv_display(self): return '{}/{}/{}'.format(self.iv_attack, self.iv_defense, self.iv_stamina)