def use_zaap(self, zaap_from, zaap_to): # get coordinates zaap_from_coordinates = parser.parse_data(data.Zaap['From'], zaap_from) zaap_to_coordinates = parser.parse_data(data.Zaap['To'], zaap_to) if zaap_from_coordinates and zaap_to_coordinates: # if a keyboard shortcut is set (like for Havenbag) if 'keyboardShortcut' in zaap_from_coordinates: # press key self.press_key(zaap_from_coordinates['keyboardShortcut']) # wait for map to change self.wait_for_map_change() # check for pause or suspend self.pause_event.wait() if self.suspend: return # click on zaap from screen = tools.screen_game(self.game_location) self.click(zaap_from_coordinates) # wait for zaap list to show self.debug('Waiting for zaap list to show') self.monitor_game_screen(tolerance=2.5, screen=screen) # check for pause or suspend self.pause_event.wait() if self.suspend: return # if we need to scroll zaap list if 'scroll' in zaap_to_coordinates: # scroll self.scroll(zaap_to_coordinates['scroll']) # check for pause or suspend self.pause_event.wait() if self.suspend: return # double click on zaap to screen = tools.screen_game(self.game_location) self.double_click(zaap_to_coordinates) # wait for map to change self.wait_for_map_change(screen=screen)
def use_zaapi(self, zaapi_from, zaapi_to): # get coordinates zaapi_from_coordinates = parser.parse_data(data.Zaapi['From'], zaapi_from) zaapi_to_coordinates = parser.parse_data(data.Zaapi['To'], zaapi_to) if zaapi_from_coordinates and zaapi_to_coordinates: # click on zaapi from screen = tools.screen_game(self.game_location) self.click(zaapi_from_coordinates) # wait for zaapi list to show self.debug('Waiting for zaapi list to show') self.monitor_game_screen(tolerance=2.5, screen=screen) # check for pause or suspend self.pause_event.wait() if self.suspend: return # choose tab/location from zaapi list self.click(zaapi_to_coordinates['location']) self.sleep(2) # check for pause or suspend self.pause_event.wait() if self.suspend: return # if we need to scroll zaapi list if 'scroll' in zaapi_to_coordinates: # scroll self.scroll(zaapi_to_coordinates['scroll']) # check for pause or suspend self.pause_event.wait() if self.suspend: return # double click on zaapi to screen = tools.screen_game(self.game_location) self.double_click(zaapi_to_coordinates) # wait for map to change self.wait_for_map_change(screen=screen)
def collect(self, map_name, store_path): map_data = parser.parse_data(maps.load(), map_name) if map_data: # show resources on minimap self.update_minimap(map_data, 'Resource', MiniMap.point_colors['Resource']) # collect resources for i, resource in enumerate(map_data): # check for pause or suspend self.pause_event.wait() if self.suspend: return # TODO: check pixel color # click on resource self.debug("Collecting resource {'x': %d, 'y': %d, 'color': %s}" % (resource['x'], resource['y'], resource['color'])) self.click(resource) # wait before collecting next one if i == 0: self.sleep(5) # wait 5 more seconds for 1st resource self.sleep(4) # remove current resource from minimap (index = 0) self.remove_from_minimap(0) # check for pause or suspend self.pause_event.wait() if self.suspend: return # TODO: check for level up # TODO: check for fight # get pod if self.get_pod() >= 99: # pod is full, go to store if store_path != 'None': # TODO: implement go_to_store function print('go to store') else: self.await() self.log('Bot is full pod', LogType.Error)
def move(self, direction): # get coordinates coordinates = parser.parse_data(data.Movements, direction) if coordinates: # click self.click(coordinates) # wait for map to change self.wait_for_map_change()
def collect(self, map_name, store_path): map_data = parser.parse_data(maps.load(), map_name) if map_data: # show resources on minimap self.update_minimap(map_data, 'Resource', MiniMap.point_colors['Resource']) # collect resources wait_before_collecting = True for resource in map_data: # check for pause or suspend self.pause_event.wait() if self.suspend: return # check resource color if not self.check_resource_color(resource): # go to next resource continue # screen game screen = tools.screen_game(self.game_location) # click on resource self.debug( "Collecting resource {'x': %d, 'y': %d, 'color': %s}" % (resource['x'], resource['y'], resource['color'])) self.click(resource) # wait before collecting next one if wait_before_collecting: wait_before_collecting = False self.sleep(5) # wait 5 more seconds for 1st resource self.sleep(4) # remove current resource from minimap (index = 0) self.remove_from_minimap(0) # check for pause or suspend self.pause_event.wait() if self.suspend: return # check for level up self.debug('Checking for level up') if self.monitor_game_screen(tolerance=2.5, screen=screen, timeout=1, wait_after_timeout=False): # close level up popup self.debug('Closing level up popup') screen = tools.screen_game(self.game_location) self.press_key(data.KeyboardShortcuts['Esc']) # wait for level up popup to close self.monitor_game_screen(tolerance=2.5, screen=screen) # check for pause or suspend self.pause_event.wait() if self.suspend: return # TODO: check for fight # get pod if self.get_pod() >= 99: # pod is full, go to store if store_path != 'None': self.go_to_store(store_path) else: self.wait() self.log('Bot is full pod', LogType.Error)
def check_enclos(self, enclos_location, enclos_type): # get enclos coordinates enclos = parser.parse_data(data.Enclos, enclos_location) if enclos and enclos_type in data.EnclosType: self.debug('Check enclos %s (%s)' % (enclos_location, enclos_type)) # click on enclos self.click(enclos) # wait for enclos to open self.debug('Waiting for enclos to open') if self.monitor_game_screen(timeout=30, tolerance=2.5): # wait for enclos to load self.sleep(1) # check for pause or suspend self.pause_event.wait() if self.suspend: return # check enclos enclos_free_places = 0 if not self.enclos_is_empty(): enclos_free_places = self.manage_enclos(enclos_type) else: enclos_free_places = 10 # check for pause or suspend self.pause_event.wait() if self.suspend: return # check inventory if enclos_free_places > 0 and not self.inventory_is_empty(): self.manage_inventory(enclos_type, enclos_free_places) # check for pause or suspend self.pause_event.wait() if self.suspend: return # close enclos self.debug('Closing enclos') screen = tools.screen_game(self.game_location) self.press_key(data.KeyboardShortcuts['Esc']) # wait for enclos to close self.debug('Waiting for enclos to close') self.monitor_game_screen(tolerance=2.5, screen=screen)
def on_keyboard_add_button_clicked(self, button): if self.press_key_radio.get_active(): selected = self.keys_combo.get_active_text() self.path_listbox.append_text('PressKey(%s)' % parser.parse_data(data.KeyboardShortcuts, selected)) else: self.path_listbox.append_text('TypeText(%s)' % self.type_text_entry.get_text())
def collect(self, map_name, store_path): map_data = parser.parse_data(maps.load(), map_name) if map_data: # show resources on minimap self.update_minimap(map_data, 'Resource', MiniMap.point_colors['Resource']) # collect resources is_first_resource = True for resource in map_data: # check for pause or suspend self.pause_event.wait() if self.suspend: return # check resource color if not self.check_resource_color(resource): # go to next resource continue # screen game screen = tools.screen_game(self.game_location) # click on resource self.debug( "Collecting resource {'x': %d, 'y': %d, 'color': %s}" % (resource['x'], resource['y'], resource['color'])) self.click(resource) if self.game_version == GameVersion.Retro: # re-click to validate self.click({ 'x': resource['x'] + 30, 'y': resource['y'] + 40, 'width': resource['width'], 'height': resource['height'] }) # wait before collecting next one if is_first_resource: is_first_resource = False self.sleep(self.first_resource_additional_collection_time ) # wait more for 1st resource self.sleep(self.collection_time) # remove current resource from minimap (index = 0) self.remove_from_minimap(0) # check for pause or suspend self.pause_event.wait() if self.suspend: return # check for screen change self.debug('Checking for screen change') if self.monitor_game_screen(tolerance=2.5, screen=screen, timeout=1, wait_after_timeout=False): # check for fight if self.game_version != GameVersion.Retro and self.wait_for_box_appear( box_name='Fight Button', timeout=1): self.pause() self.log('Fight detected! human help wanted..', LogType.Error) elif self.auto_close_popups: # it should be a popup (level up, ...) self.debug('Closing popup') screen = tools.screen_game(self.game_location) if self.game_version == GameVersion.Retro: self.press_key(data.KeyboardShortcuts['Enter']) elif self.wait_for_box_appear( box_name='Job Level Up Popup', timeout=1): location = self.get_box_location( 'Job Level Up Popup') self.click(location) else: self.press_key(data.KeyboardShortcuts['Esc']) # wait for popup to close self.monitor_game_screen(tolerance=2.5, screen=screen) # check for pause or suspend self.pause_event.wait() if self.suspend: return # get pod if self.game_version != GameVersion.Retro and self.get_pod( ) >= 99: # pod is full, go to store if store_path != 'None': self.go_to_store(store_path) else: self.pause() self.log('Bot is full pod', LogType.Error)
def collect(self, map_name, store_path): ''' Collects all resources until the map is done. If the character has no longer any pod capacity, returns 1 to signify that we need to go to the bank. ''' map_data = parser.parse_data(maps.load(), map_name) if map_data: # show resources on minimap self.update_minimap(map_data, 'Resource', MiniMap.point_colors['Resource']) # collect resources is_first_resource = True miss = 0 for resource in map_data: # check for pause or suspend self.pause_event.wait() if self.suspend: return # check resource color if not self.check_resource_color(resource): miss += 1 # go to next resource continue # screen game screen = tools.screen_game(self.game_location) # click on resource self.debug( "Collecting resource {'x': %d, 'y': %d, 'color': %s}" % (resource['x'], resource['y'], resource['color'])) self.click(resource) if self.game_version == GameVersion.Retro: # re-click to validate self.click({ 'x': resource['x'] + 30, 'y': resource['y'] + 40, 'width': resource['width'], 'height': resource['height'] }) # wait before collecting next one if is_first_resource: is_first_resource = False self.sleep(self.first_resource_additional_collection_time ) # wait more for 1st resource self.sleep(self.collection_time) # remove current resource from minimap (index = 0) self.remove_from_minimap(0) # check for pause or suspend self.pause_event.wait() if self.suspend: return # check for screen change self.debug('Checking for screen change') if self.monitor_game_screen(tolerance=2.5, screen=screen, timeout=1, wait_after_timeout=False): # check for fight if self.game_version != GameVersion.Retro and self.wait_for_box_appear( box_name='Fight Button Light', timeout=1): self.handle_fight() elif self.auto_close_popups: # it should be a popup (level up, ...) self.debug('Closing popup') screen = tools.screen_game(self.game_location) if self.game_version == GameVersion.Retro: self.press_key(data.KeyboardShortcuts['Enter']) elif self.wait_for_box_appear( box_name='Job Level Up Popup', timeout=1): location = self.get_box_location( 'Job Level Up Popup') self.click(location) else: self.press_key(data.KeyboardShortcuts['Esc']) # wait for popup to close self.monitor_game_screen(tolerance=2.5, screen=screen) # check for pause or suspend self.pause_event.wait() if self.suspend: return # get pod if self.game_version != GameVersion.Retro and \ self.get_pod() >= self.go_to_bank_pod_percentage: self.log('Bot is full pod', LogType.Info) return 1 if self.ratio_collection: ratio = (len(map_data) - miss) / len(map_data) tools.save_text_to_file(f"{map_name}: {ratio}\n", self.name_ratio_collection_map, 'a+')