def click_start_button(): raid_screenshot = get_screen() height, width, _ = raid_screenshot.shape template_pixel = raid_screenshot[height - 2, width - 2] template_pixel_tuple = uint8(template_pixel) top_rect_collection = 0 for y in range(height - 2, 0, -1): if (raid_screenshot[y, width - 2] != template_pixel).any(): top_rect_collection = y break cropped = raid_screenshot[top_rect_collection:height, :] mask = cv2.inRange(cropped, template_pixel_tuple, template_pixel_tuple) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2)) mask = cv2.morphologyEx(mask, cv2.RETR_TREE, kernel) contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) boxes = [cv2.boundingRect(cnt) for cnt in contours] boxes.sort(key=lambda box: box[0], reverse=True) if boxes[0][1] > boxes[1][1]: start_point = Point(boxes[0][0], boxes[0][1] + top_rect_collection, boxes[0][2], boxes[0][3]) else: start_point = Point(boxes[1][0], boxes[1][1] + top_rect_collection, boxes[1][2], boxes[1][3]) __mouse_move(start_point.center()[0], start_point.center()[1]) mouse.click()
def auto_configure(): global battle_position global __current_screen global dungeon_position global campaign_position global location_position global start_position global level sleep(__random_deviation(0.5)) __current_screen = get_current_screen() if __current_screen != RaidScreen.MAIN_MENU: print('Please go to main menu and try again') return raid_screenshot = get_screen() _, width, height = raid_screenshot.shape[::-1] battle_loc = search_module.get_battle_btn( raid_screenshot[int(height * 0.7):height, int(width * 0.7):width]) battle_position = Point(battle_loc[0] + int(width * 0.7), battle_loc[1] + int(height * 0.7), battle_loc[2], battle_loc[3]) print('Found battle button') __mouse_move(battle_position.center()[0], battle_position.center()[1]) mouse.click() sleep(__random_deviation(0.5)) actions = search_module.get_actions_rectangles(get_screen()) if actions is None: print('Error while searching for actions') return campaign_position = Point(actions[0][0], actions[0][1], actions[0][2], actions[0][3]) dungeon_position = Point(actions[1][0], actions[1][1], actions[1][2], actions[1][3]) print('Found actions') __mouse_move(campaign_position.center()[0], campaign_position.center()[1]) mouse.click() sleep(__random_deviation(0.5)) go_scroll_location(5) raid_screenshot = get_screen() location_avatars = search_module.get_rect_features(raid_screenshot) location_avatars = list( filter(lambda loc: loc.height > loc.width, location_avatars)) location_position = location_avatars[-1] print('Found location position (sulfur trail)') __mouse_move(location_position.center()[0], location_position.center()[1]) mouse.click() sleep(__random_deviation(0.5)) level = 6 __click_level() start_position = search_module.get_start_btn_pre_fight(get_screen()) print('Found start button from pre fight screen')
def find_button(self, elapsed=0, pix=None): #print "Trying to find the button." here = self.cursor_location if not pix: screen_offset = here.plus(-300, -200) bbox = (here.x-300, here.y-200, here.x+300, here.y+200) ss = ImageGrab.grab(bbox) #print "Got image: %r" % ss pix = ss.load() else: screen_offset = Point(*self.layout.main_bbox[:2]) grab_size = Point(600, 400) localhere = grab_size.center() def is_in_circle(p): if p.x < 0 or p.y < 0 or p.x >= grab_size.x or p.y >= grab_size.y: return False c = pix[p.t()] if c[0] > 0 and c[1] == c[2] == 0: return False answer = not (c[0] == c[1] == c[2] and c[0] >= 15) and p.x < grab_size.x and p.y < grab_size.y and p.x > 0 and p.y > 0 if not answer: pass #print "Stopping at ", c return answer return pix[p.t()] == (200, 100, 0) reference_point = localhere.copy() color = pix[reference_point.t()] for l in xrange(3): # Search left and right from the previous point # until it stops being 200, 100, 0 # Left: min_x = max_x = reference_point.x min_y = max_y = reference_point.y p = reference_point.copy() while is_in_circle(p): min_x = p.x p.x -= 1 # Right: p.x = max_x while is_in_circle(p): max_x = p.x p.x += 1 p.x = int(round((max_x - min_x +0) / 2.0)) + min_x # Up while is_in_circle(p): min_y = p.y p.y -= 1 p.y = max_y while is_in_circle(p): max_y = p.y p.y += 1 p.y = int(round((max_y - min_y +0) / 2.0, 0)) + min_y reference_point = p #print "Hmm. ", (min_x, max_x, min_y, max_y) #print "Got closer: ", p.t() center_point = reference_point.plus(screen_offset.x, screen_offset.y) return center_point