async def do_evolve(candy_, pid, pokemon_id, worker, fast): evo = await worker.do_evolve_pokemon(pid) candy = candy_.get(pokemon_id, 0) if evo.result != 1: worker.log.warning( u"Evolve status {}, {}({}) candy post-evolve {}".format( str(evo.result), pokemon_name(pokemon_id), str(pokemon_id), str(candy))) worker.log.info( "Enqueing evolved {} for transfer, {} candy post-evolve {}".format( evo.evolved_pokemon_data.id, pokemon_name(pokemon_id), str(candy))) if not fast: await asyncio.sleep(17) return evo.evolved_pokemon_data.id
def catch_it(self, pos, to_catch, fast=False): encounter_id = to_catch.encounter_id spawn_point_id = to_catch.spawn_point_id pokemon_id = to_catch.pokemon_id self.worker.add_log(pokemon_name(pokemon_id)) encounter_response = self.worker.do_encounter_pokemon( encounter_id, spawn_point_id, pos) probability = EncounterPokemon(encounter_response, encounter_id).probability() is_vip = pokemon_id in self.candy12 or pokemon_id in self.candy25 if probability and len( [x for x in probability.capture_probability if x > 0.38]) > 0: caught = beh_catch_encountered_pokemon(self.worker, pos, encounter_id, spawn_point_id, probability, pokemon_id, is_vip, fast) return caught else: if probability: log.info( "Encounter {} is too hard to catch {}, skipping".format( str(encounter_id), str(probability.capture_probability))) else: log.info("Encounter {} failed, skipping".format( str(encounter_id)))
async def beh_catch_encountered_pokemon(pogoservice, position, encounter_id, spawn_point_id, probablity, pokemon_id, is_vip=False, fast=False): start_catch_at = datetime.datetime.now() if probablity: name = pokemon_name(pokemon_id) catch_rate_by_ball = [0] + list(probablity.capture_probability) level = pogoservice.account_info()["level"] pogoservice.add_log(name) pcw = PokemonCatchWorker(position, spawn_point_id, pogoservice, fast) elements = pogoservice.account_info()["items"] catch = await pcw.do_catch(encounter_id, catch_rate_by_ball, elements, is_vip) if catch == WorkerResult.ERROR_NO_BALLS: return catch if catch: pogoservice.log.info(u"{} level {} caught {} id {} in {}".format( str(pogoservice.name()), str(level), name, str(catch), str(datetime.datetime.now() - start_catch_at))) return catch else: pogoservice.log.warning("Encounter did not succeed")
def append(self, player_postion, item, pos_idx): if item.pokemon_id not in self.seen: log.info( "OneofEachfeed Broadcasting {} encounter {} to other workers at pos {}" .format(pokemon_name(item.pokemon_id), str(item.encounter_id), str(pos_idx))) self.seen.add(item.pokemon_id) self.items[pos_idx][item.encounter_id] = (player_postion, item)
def append(self, player_postion, item, pos_idx): if item.pokemon_id in candy12 and item.encounter_id not in self.items[ pos_idx]: log.info( "Candy12Broadcasting {} encounter {}@{} to other workers at pos {}" .format(pokemon_name(item.pokemon_id), str(item.encounter_id), str((item.latitude, item.longitude)), str(pos_idx))) self.items[pos_idx][item.encounter_id] = (player_postion, item)
def pokemon_names(catch_list): return ", ".join([pokemon_name(x.pokemon_id) for x in catch_list])
def do_catch_moving(self, map_objects, player_pos, next_pos, pos_idx, catch_condition, broadcast=True): all_caught = {} if not self.is_within_catch_limit(): log.info("Catch limit {} exceeeded, not catching any more".format( str(self.catch_limit))) return catch_list = catchable_pokemon_by_distance(map_objects, next_pos) log.info("{} pokemon in map_objects: {}".format( str(len(catch_list)), pokemon_names([x[1] for x in catch_list]))) while len(catch_list) > 0: to_catch = catch_list[0][1] # print str(to_catch) encounter_id = to_catch.encounter_id pokemon_id = to_catch.pokemon_id unseen_catch = catch_condition.only_unseen and ( pokemon_id not in self.caught_pokemon_ids) candy_catch = catch_condition.is_candy_catch(pokemon_id) candy_12_catch = catch_condition.is_candy_12_catch(pokemon_id) encountered_previously = self.is_encountered_previously( encounter_id) candy_50_catch = catch_condition.is_candy_50_catch(pokemon_id) will_catch = (catch_condition.catch_anything or unseen_catch or candy_catch or candy_12_catch or candy_50_catch) if encountered_previously: log.info("{} {} encountered previously".format( str(pokemon_name(pokemon_id)), str(encounter_id))) elif will_catch: if broadcast and catch_condition.is_candy_pokemon(pokemon_id): self.catch_feed.append(player_pos, to_catch, pos_idx) # log.debug("To_catch={}".format(str(to_catch))) pokemon_distance_to_next_position = catch_list[0][0] player_distance_to_next_position = equi_rect_distance_m( player_pos, next_pos) on_other_side = ( player_pos[1] < next_pos[1] < catch_list[0][1]) or ( player_pos[1] > next_pos[1] > catch_list[0][1]) if on_other_side: available_mobility = self.travel_time.meters_available_right_now( ) actual_meters = min(available_mobility, player_distance_to_next_position) log.info( "Moving closer {} metres. {} meters_available right now" .format(str(actual_meters), str(available_mobility))) player_pos = move_towards(player_pos, next_pos, actual_meters) if pokemon_distance_to_next_position < player_distance_to_next_position: m_to_move = player_distance_to_next_position - pokemon_distance_to_next_position available_mobility = self.travel_time.meters_available_right_now( ) actual_meters = min(available_mobility, m_to_move) log.info( "player_distance_to_next_position={},pokemon_distance_to_next_position={}" .format(str(player_distance_to_next_position), str(pokemon_distance_to_next_position))) log.info( "Could move towards next position {} meters. {} meters_available, {}m by pokemon!" .format(str(actual_meters), str(available_mobility), str(m_to_move))) player_pos = move_towards(player_pos, next_pos, actual_meters) if self.travel_time.must_gmo(): self.worker.do_get_map_objects(player_pos) self.processed_encounters.add( encounter_id) # leaks memory. fix todo log.info( "Catching {} because catch_all={} unseen={} candy_catch={} candy_12_catch={}" .format(pokemon_name(pokemon_id), str(catch_condition.catch_anything), str(unseen_catch), str(candy_catch), str(candy_12_catch))) caught = self.catch_it(player_pos, to_catch, fast=True) if caught: found_new = pokemon_id not in self.caught_pokemon_ids self.caught_pokemon_ids.add(pokemon_id) if isinstance(caught, numbers.Number): all_caught[caught] = pokemon_id else: log.warning("Did not caEtch because {}".format( str(caught))) else: log.info( "{} {} will not catch, is_catch_anything={}, is_unseen_catch={}, is_candy_catch={}, is_candy12_catch={}" .format(str(pokemon_name(pokemon_id)), str(encounter_id), str(catch_condition.catch_anything), str(unseen_catch), str(candy_catch), str(candy_12_catch))) del catch_list[0] self.pokemon_caught += len(all_caught) self.process_evolve_transfer_list(all_caught) return player_pos