Exemple #1
0
 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)
Exemple #2
0
 def get_pod(self):
     # open inventory
     self.debug('Opening inventory')
     screen = tools.screen_game(self.game_location)
     self.press_key(data.KeyboardShortcuts['Inventory'])
     # wait for inventory to open
     self.monitor_game_screen(tolerance=2.5, screen=screen)
     # check for pause or suspend
     self.pause_event.wait()
     if self.suspend: return
     # get podbar color & percentage
     location = self.get_box_location('PodBar')
     screen = tools.screen_game(location)
     color, percentage = tools.get_dominant_color(screen)
     # close inventory
     self.debug('Closing inventory')
     screen = tools.screen_game(self.game_location)
     self.press_key(data.KeyboardShortcuts['Inventory'])
     # wait for inventory to close
     self.monitor_game_screen(tolerance=2.5, screen=screen)
     # check for pause or suspend
     self.pause_event.wait()
     if self.suspend: return
     # check if podbar is empty
     if tools.color_matches(color,
                            data.Colors['Empty PodBar'],
                            tolerance=10):
         return 0
     else:
         # update pod bar
         self.set_pod(percentage)
         return percentage
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 def wait_for_box_appear(self, box_name, box_color=None, timeout=30):
     # set box color
     if box_color is None:
         if box_name in data.Colors:
             box_color = data.Colors[box_name]
         else:
             return False
     # wait for box to appear
     elapsed_time = 0
     while elapsed_time < timeout:
         # wait 1 second
         self.sleep(1)
         # check for pause or suspend
         self.pause_event.wait()
         if self.suspend: return False
         # check box color
         location = self.get_box_location(box_name)
         screen = tools.screen_game(location)
         percentage = tools.get_color_percentage(screen, box_color)
         has_appeared = percentage >= 99
         debug_level = DebugLevel.Normal if has_appeared else DebugLevel.High
         self.debug(
             '{} has appeared: {}, percentage: {}%, timeout: {}'.format(
                 box_name, has_appeared, percentage, timeout), debug_level)
         if has_appeared:
             return True
         elapsed_time += 1
     # if box did not appear before timeout
     return False
Exemple #6
0
	def move_dragodinde(self, action, dragodinde_image=None, dragodinde_location=None):
		if dragodinde_location is None:
			dragodinde_location = self.get_box_location('Dragodinde Card')
		if dragodinde_image is None:
			dragodinde_image = tools.screen_game(dragodinde_location)
		self.press_key(data.KeyboardShortcuts[action])
		self.monitor_game_screen(screen=dragodinde_image, location=dragodinde_location)
Exemple #7
0
    def monitor_game_screen(self,
                            timeout=10,
                            tolerance=0.0,
                            screen=None,
                            location=None,
                            wait_after_timeout=True):
        if self.game_location or location:
            # screen game
            if location is None:
                location = self.game_location
            if screen is None:
                prev_screen = tools.screen_game(location)
            else:
                prev_screen = screen
            elapsed_time = 0
            # wait for game screen to change
            while elapsed_time < timeout:
                # wait 1 second
                self.sleep(1)
                # check for pause or suspend
                self.pause_event.wait()
                if self.suspend: return False
                # take a new screen & compare it with the previous one
                new_screen = tools.screen_game(location)
                if new_screen.size != prev_screen.size:
                    self.debug('Screen size has changed, retry',
                               DebugLevel.High)
                else:
                    diff_percent = round(
                        imgcompare.image_diff_percent(prev_screen, new_screen),
                        2)
                    has_changed = diff_percent > tolerance
                    debug_level = DebugLevel.Normal if has_changed else DebugLevel.High
                    self.debug(
                        'Game screen has changed: {}, diff: {}%, tolerance: {}, timeout: {}'
                        .format(has_changed, diff_percent, tolerance,
                                timeout), debug_level)
                    if has_changed:
                        return True
                prev_screen = new_screen
                elapsed_time += 1
            # if game screen hasn't change before timeout
            if wait_after_timeout and elapsed_time == timeout:
                self.pause()
                self.log('Game screen did not change', LogType.Error)

        return False
Exemple #8
0
	def inventory_is_empty(self):
		location = self.get_box_location('Inventory First Place')
		screen = tools.screen_game(location)
		percentage = tools.get_color_percentage(screen, data.Colors['Empty Inventory'])
		is_empty = percentage >= 99
		debug_level = DebugLevel.Normal if is_empty else DebugLevel.High
		self.debug('Inventory is empty: {}, percentage: {}%'.format(is_empty, percentage), debug_level)
		return is_empty
Exemple #9
0
	def enclos_is_empty(self):
		location = self.get_box_location('Enclos First Place')
		screen = tools.screen_game(location)
		empty_percentage = tools.get_color_percentage(screen, data.Colors['Empty Enclos'])
		selected_percentage = tools.get_color_percentage(screen, data.Colors['Selected Row'])
		is_empty = empty_percentage >= 99 or selected_percentage >= 99
		debug_level = DebugLevel.Normal if is_empty else DebugLevel.High
		self.debug('Enclos is empty: {}, empty percentage: {}%, selected percentage: {}%'.format(is_empty, empty_percentage, selected_percentage), debug_level)
		return is_empty
Exemple #10
0
	def take_dragodinde_image(self, name, location=None):
		# get location
		if location is None:
			location = self.get_box_location('Dragodinde Card')
		# take dragodinde image
		if location:
			if self.save_dragodindes_images:
				# create directory(s) to store dragodindes images
				directory = tools.get_resource_path('../dragodindes') + '/' + tools.get_date()
				tools.create_directory(directory)
				save_to = directory + '/' + name
			else:
				save_to = None
			return tools.screen_game(location, save_to)
		else:
			return None
Exemple #11
0
 def has_box_appeared(self, box_name, box_color=None):
     # set box color
     if box_color is None:
         if box_name in data.Colors:
             box_color = data.Colors[box_name]
         else:
             return False
     location = self.get_box_location(box_name)
     screen = tools.screen_game(location)
     percentage = tools.get_color_percentage(screen, box_color)
     has_appeared = percentage >= 70
     debug_level = DebugLevel.Normal if has_appeared else DebugLevel.High
     self.debug(
         f"{box_name} has appeared: {has_appeared}, percentage: {percentage}",
         debug_level)
     return has_appeared
Exemple #12
0
    def get_pod(self):
        '''
		Detects the level of pod by looking at the bar below the spells
		'''
        self.pause_event.wait()
        if self.suspend: return
        # get podbar color & percentage
        location = self.get_box_location('PodBar')
        screen = tools.screen_game(location)
        color, percentage = tools.get_dominant_color(screen)
        if tools.color_matches(color,
                               data.Colors['Empty PodBar'],
                               tolerance=10):
            percentage = 100.0 - percentage
        # update pod bar
        self.log(f"Pod {percentage}%, color: {color}")
        self.set_pod(percentage)
        return percentage
Exemple #13
0
    def use_zaap(self, zaap_from, zaap_to):
        '''
		Always use the havenbag to 'from' location and searches the destination
		by clicking in the search bar and typing the name of destination
		'''
        self.press_key(data.KeyboardShortcuts['Havenbag'])
        self.wait_for_map_change()
        # check for pause or suspend
        self.pause_event.wait()
        if self.suspend: return
        self.click(data.Zaap['ZaapItself'])
        self.sleep(3.0)
        self.click(data.Zaap['SearchBar'])
        self.sleep(1.0)
        for letter in zaap_to:
            if letter == " ":
                letter = "space"
            self.press_key(letter)
        self.sleep(3.0)
        screen = tools.screen_game(self.game_location)
        self.double_click(data.Zaap['FirstDestination'])
        # wait for map to change
        self.wait_for_map_change(screen=screen)
Exemple #14
0
 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)
Exemple #15
0
	def interpret(self, instructions, ignore_start_from_step=False):
		# split instructions
		if not isinstance(instructions, list):
			lines = instructions.splitlines()
		else:
			lines = instructions
		# ignore instructions before start step
		if not ignore_start_from_step and self.start_from_step > 1 and self.start_from_step <= len(lines):
			self.debug('Start from step: %d' % self.start_from_step)
			step = self.start_from_step - 1
			lines = lines[step:]

		game_screen = None
		for i, line in enumerate(lines, start=1):
			# check for pause or suspend
			self.pause_event.wait()
			if self.suspend: break

			if self.wait_for_box_appear(box_name='Fight Button Light', timeout=1):
				self.handle_fight()

			# parse instruction
			self.debug('Instruction (%d): %s' % (i, line), DebugLevel.Low)
			instruction = parser.parse_instruction(line)
			self.debug('Parse result: ' + str(instruction), DebugLevel.High)

			# save game screen before those instructions
			if instruction['name'] in ['Click', 'PressKey']:
				game_screen = tools.screen_game(self.game_location)
			elif instruction['name'] != 'MonitorGameScreen':
				game_screen = None

			# begin interpretation
			if instruction['name'] == 'Move':
				self.move(instruction['value'])

			elif instruction['name'] == 'Enclos':
				self.check_enclos(instruction['location'], instruction['type'])

			elif instruction['name'] == 'Zaap':
				self.use_zaap(instruction['from'], instruction['to'])

			elif instruction['name'] == 'Zaapi':
				self.use_zaapi(instruction['from'], instruction['to'])

			elif instruction['name'] == 'Collect':
				if self.collect(instruction['map'], instruction['store_path']):
					# If collect return 1, we need to go to the bank. We forward 1 to the caller
					return 1

			elif instruction['name'] == 'Click':
				coordinates = {
					'x': int(instruction['x']),
					'y': int(instruction['y']),
					'width': int(instruction['width']),
					'height': int(instruction['height'])
				}
				# Handle the case when the click location need to match the stored color
				if 'r' in instruction:
					coordinates['color'] = f"({instruction['r']}, {instruction['g']}, {instruction['b']})"
					while not self.check_location_color(coordinates):
						self.log("Click location has a different color, waiting ...")
						self.pause_event.wait()
						if self.suspend: return
						self.sleep(0.01)

				if 'hotkey' in instruction:
					self.hot_click(instruction['hotkey'], coordinates, instruction['twice'])
				elif instruction['twice'] == 'True':
					self.double_click(coordinates)
				else:
					self.click(coordinates)

			elif instruction['name'] == 'GoToBank':
				self.go_to_bank()
				# Return to skip the end of the ongoing path
				return

			elif instruction['name'] == 'Scroll':
				times = int(instruction['times'])
				value = times if instruction['direction'] == 'up' else -times
				self.scroll(value)

			elif instruction['name'] == 'Pause':
				self.pause()

			elif instruction['name'] == 'MonitorGameScreen':
				self.monitor_game_screen(tolerance=2.5, screen=game_screen)

			elif instruction['name'] == 'Wait':
				duration = int(instruction['value'])
				self.sleep(duration)

			elif instruction['name'] == 'PressKey':
				self.press_key(instruction['value'])

			elif instruction['name'] == 'TypeText':
				self.type_text(instruction['value'])

			elif instruction['name'] == 'Connect':
				if instruction['account_id'].isdigit():
					account_id = int(instruction['account_id'])
				else:
					account_id = instruction['account_id']
				self.connect(account_id)

			elif instruction['name'] == 'Disconnect':
				self.disconnect(instruction['value'])

			else:
				self.debug('Unknown instruction', DebugLevel.Low)
Exemple #16
0
    def manage_inventory(self, enclos_type, enclos_free_places):
        # select dragodinde from inventory
        self.debug('Select dragodinde from inventory')
        screen = tools.screen_game(self.game_location)
        self.click(data.Locations['Select From Inventory'])
        # wait for dragodinde card to show
        self.debug('Waiting for dragodinde card to show')
        self.monitor_game_screen(tolerance=0.1, screen=screen)
        # manage dragodinde(s)
        dragodinde_number = 0
        moved_dragodinde_number = 0
        dragodinde_location = self.get_box_location('Dragodinde Card')
        while moved_dragodinde_number < enclos_free_places:
            # check for pause or suspend
            self.pause_event.wait()
            if self.suspend: return
            # break if inventory empty
            if self.inventory_is_empty():
                break
            # take dragodinde image
            dragodinde_name = self.get_dragodinde_name()
            dragodinde_image = self.take_dragodinde_image(
                dragodinde_name, dragodinde_location)
            # increase dragodindes number
            dragodinde_number += 1
            # get dragodinde stats
            if self.save_dragodindes_images:
                self.debug("Get dragodinde '%s' stats" % dragodinde_name)
            else:
                self.debug('Get dragodinde stats')
            stats = self.get_dragodinde_stats(dragodinde_image)
            if stats:
                Stats = data.DragodindeStats
                Serenity = data.DragodindeSerenity
                # move dragodinde
                dragodinde_moved = False
                energy, amour, maturity, endurance, serenity = stats
                energy_percent, energy_state = energy
                amour_percent, amour_state = amour
                maturity_percent, maturity_state = maturity
                endurance_percent, endurance_state = endurance
                serenity_percent, serenity_state = serenity
                # get dragodinde needs
                need_energy = energy_state in (Stats.Empty, Stats.InProgress)
                need_amour = amour_state in (Stats.Empty, Stats.InProgress)
                need_maturity = maturity_state in (Stats.Empty,
                                                   Stats.InProgress)
                need_endurance = endurance_state in (Stats.Empty,
                                                     Stats.InProgress)
                self.debug(
                    'Need Energy: %s, Amour: %s, Maturity: %s, Endurance: %s' %
                    (need_energy, need_amour, need_maturity, need_endurance),
                    DebugLevel.High)
                # enclos 'Amour'
                if enclos_type == 'Amour':
                    if need_amour and serenity_state == Serenity.Positive:
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # enclos 'Endurance'
                elif enclos_type == 'Endurance':
                    if need_endurance and serenity_state == Serenity.Negative:
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # enclos 'NegativeSerenity'
                elif enclos_type == 'NegativeSerenity':
                    if ((need_maturity or (need_endurance and not need_amour))
                            and serenity_state == Serenity.Positive) or (
                                need_endurance
                                and serenity_state == Serenity.Medium
                                and maturity_state == Stats.Full):
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # enclos 'PositiveSerenity'
                elif enclos_type == 'PositiveSerenity':
                    if ((need_maturity or (need_amour and not need_endurance))
                            and serenity_state == Serenity.Negative
                        ) or (need_amour and serenity_state == Serenity.Medium
                              and maturity_state == Stats.Full):
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # enclos 'Energy'
                elif enclos_type == 'Energy':
                    if need_energy and all(
                            state == Stats.Full
                            for state in (amour_state, maturity_state,
                                          endurance_state)):
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # enclos 'Maturity'
                elif enclos_type == 'Maturity':
                    if need_maturity and serenity_state == Serenity.Medium:
                        dragodinde_moved = self.move_dragodinde_to_enclos(
                            dragodinde_image, dragodinde_location)
                # Nothing to do
                if not dragodinde_moved:
                    self.debug('Nothing to do')
                else:
                    moved_dragodinde_number += 1
                    continue
            else:
                continue
            # check for pause or suspend
            self.pause_event.wait()
            if self.suspend: return
            # check next dragodinde
            self.debug('Check next dragodinde')
            self.press_key(data.KeyboardShortcuts['Down'])
            # break if there is no more dragodinde
            if not self.monitor_game_screen(tolerance=0.01,
                                            screen=dragodinde_image,
                                            location=dragodinde_location,
                                            wait_after_timeout=False):
                if not self.suspend:
                    self.debug('No more dragodinde')
                    break
                else:
                    return

        # print managed dragodindes number when break from loop
        self.debug(
            '(Inventory) Managed dragodindes: %d, Moved dragodindes: %d' %
            (dragodinde_number, moved_dragodinde_number), DebugLevel.Low)
Exemple #17
0
    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+')
Exemple #18
0
    def interpret(self, instructions, ignore_start_from_step=False):
        # split instructions
        if not isinstance(instructions, list):
            lines = instructions.splitlines()
        else:
            lines = instructions
        # ignore instructions before start step
        if not ignore_start_from_step and self.start_from_step > 1 and self.start_from_step <= len(
                lines):
            self.debug('Start from step: %d' % self.start_from_step)
            step = self.start_from_step - 1
            lines = lines[step:]

        game_screen = None
        for i, line in enumerate(lines, start=1):
            # check for pause or suspend
            self.pause_event.wait()
            if self.suspend: break

            # parse instruction
            self.debug('Instruction (%d): %s' % (i, line), DebugLevel.Low)
            instruction = parser.parse_instruction(line)
            self.debug('Parse result: ' + str(instruction), DebugLevel.High)

            # save game screen before those instructions
            if instruction['name'] in ['Click', 'PressKey']:
                game_screen = tools.screen_game(self.game_location)
            elif instruction['name'] != 'MonitorGameScreen':
                game_screen = None

            # begin interpretation
            if instruction['name'] == 'Move':
                self.move(instruction['value'])

            elif instruction['name'] == 'Enclos':
                self.check_enclos(instruction['location'], instruction['type'])

            elif instruction['name'] == 'Zaap':
                self.use_zaap(instruction['from'], instruction['to'])

            elif instruction['name'] == 'Zaapi':
                self.use_zaapi(instruction['from'], instruction['to'])

            elif instruction['name'] == 'Collect':
                self.collect(instruction['map'], instruction['store_path'])

            elif instruction['name'] == 'Click':
                coordinates = {
                    'x': int(instruction['x']),
                    'y': int(instruction['y']),
                    'width': int(instruction['width']),
                    'height': int(instruction['height'])
                }
                if instruction['twice'] == 'True':
                    self.double_click(coordinates)
                else:
                    self.click(coordinates)

            elif instruction['name'] == 'Scroll':
                times = int(instruction['times'])
                value = times if instruction['direction'] == 'up' else -times
                self.scroll(value)

            elif instruction['name'] == 'Pause':
                self.pause()

            elif instruction['name'] == 'MonitorGameScreen':
                self.monitor_game_screen(tolerance=2.5, screen=game_screen)

            elif instruction['name'] == 'Wait':
                duration = int(instruction['value'])
                self.sleep(duration)

            elif instruction['name'] == 'PressKey':
                self.press_key(instruction['value'])

            elif instruction['name'] == 'TypeText':
                self.type_text(instruction['value'])

            elif instruction['name'] == 'Connect':
                if instruction['account_id'].isdigit():
                    account_id = int(instruction['account_id'])
                else:
                    account_id = instruction['account_id']
                self.connect(account_id)

            elif instruction['name'] == 'Disconnect':
                self.disconnect(instruction['value'])

            else:
                self.debug('Unknown instruction', DebugLevel.Low)
Exemple #19
0
 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)