Skip to content

Commit

Permalink
Merge pull request #5929 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
First try at the new evo items (#5927)
  • Loading branch information
solderzzc authored Feb 21, 2017
2 parents e00e8db + 85522bb commit 6141640
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
4 changes: 3 additions & 1 deletion data/pokemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -4554,7 +4554,9 @@
"Next Evolution Requirements": {
"Amount": 50,
"Family": 95,
"Name": "Onix candies"
"Name": "Onix candies",
"EvoItem": 1103,
"EvoItemNeeded": 1
},
"Next evolution(s)": [
{
Expand Down
11 changes: 10 additions & 1 deletion pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 30 additions & 4 deletions pokemongo_bot/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6141640

Please sign in to comment.