def find_up_to_date_buy_price(runescape_window, ge_slot): # click correct sell bag move_mouse_to_image_within_region('Tools/screenshots/sell_bag.png', ge_slot) pyautogui.click() wait_for('Tools/screenshots/quantity_box.png', runescape_window) # sell item for cheap coords_of_item = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-180, runescape_window.bottom_right_corner[1]-372), (runescape_window.bottom_right_corner[0]-166, runescape_window.bottom_right_corner[1]-349)) realmouse.move_mouse_to(coords_of_item[0], coords_of_item[1]) pyautogui.click() move_mouse_to_image_within_region('Tools/screenshots/-5perc_button.png', runescape_window) for i in range(random.randint(20,35)): pyautogui.click() time.sleep(random.random()/7) time.sleep(random.random()+1) move_mouse_to_image_within_region('Tools/screenshots/confirm_offer_button.png', runescape_window) pyautogui.click() wait_for('Tools/screenshots/lent_item_box.png', runescape_window) # collect money collect_items_from_ge_slot(ge_slot, runescape_window) # click sale history move_mouse_to_image_within_region('Tools/screenshots/sale_history_button.png', runescape_window) pyautogui.click() wait_for('Tools/screenshots/sale_history_check.png', runescape_window) # check price sell_price = check_price(runescape_window) # update price ge_slot.item.set_price_instant_sold_at(sell_price) # click grand exchange window move_mouse_to_box('Tools/screenshots/grand_exchange_button.png', runescape_window.top_left_corner, runescape_window.bottom_right_corner) pyautogui.click() wait_for('Tools/screenshots/lent_item_box.png', runescape_window) runescape_window.set_time_of_last_action() print('{} instantly sold for a price of {}'.format(ge_slot.item.item_name, ge_slot.item.price_instant_sold_at))
def wait_for(image, runescape_window): # adding a possible failsafe in here time_entered = time.time() # time_entered = time() # could add a failsafe in here incase we misclick or something, this # should be something to come back to failsafe_count = 0 while (True): found = pyautogui.locateOnScreen(image) if found != None: break elif failsafe_count > 10: print( "We can't seem to fix the problem so the script is now aborting" ) quit() # If the image can't be found it moves the mouse in case the mouse is over the image. elif time.time() - time_entered > 5: # elif time() - time_entered > 5: failsafe_count += 1 print( 'We appear to be stuck so attempting to move the mouse and see if this fixes it' ) move_mouse_to( random.randint(runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[0]), random.randint(runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[1])) # pyautogui.click() time_entered = time.time()
def sell_items(runescape_window, ge_slot): # click correct sell bag move_mouse_to_image_within_region('Tools/screenshots/sell_bag.png', ge_slot) pyautogui.click() wait_for('Tools/screenshots/quantity_box.png', runescape_window) # click item in inv coords_of_item = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-180, runescape_window.bottom_right_corner[1]-372), (runescape_window.bottom_right_corner[0]-166, runescape_window.bottom_right_corner[1]-349)) realmouse.move_mouse_to(coords_of_item[0], coords_of_item[1]) pyautogui.click() # click all button incase move_mouse_to_image_within_region("Tools/screenshots/all_button.png", runescape_window) pyautogui.click() # click price button coords_of_price_box = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-384, runescape_window.bottom_right_corner[1]-272), (runescape_window.bottom_right_corner[0]-291, runescape_window.bottom_right_corner[1]-259)) realmouse.move_mouse_to(coords_of_price_box[0], coords_of_price_box[1]) pyautogui.click() time.sleep(2+random.random()) # type price in and hit enter random_typer(str(ge_slot.item.price_instant_bought_at)) pyautogui.press('enter') # click confirm move_mouse_to_image_within_region("Tools/screenshots/confirm_offer_button.png", runescape_window) pyautogui.click() # update state of ge slot ge_slot.update_buy_or_sell_state('sell') wait_for('Tools/screenshots/lent_item_box.png', runescape_window) runescape_window.set_time_of_last_action() print('Placed a sell order for {} {} at {} each'.format(ge_slot.item.quantity_to_buy, ge_slot.item.item_name, ge_slot.item.price_instant_bought_at))
def locateAndMoveToCenter(self, primaryImagePath:str, secondaryImagePath:str, confidenceLevel=.95, waitTime=0,checkForMarks=False) -> None: """Move to one of two images on the screen. Keyword arguments: primaryImagePath -- relative path of primary image to query secondaryImagePath -- relative path of secondary image to query confidenceLevel -- confidence level for image recognition (default .95) waitTime -- time to wait after click (default 0) checkForMarks -- whether or not to query a Mark of Grace on the ground (default False) """ if checkForMarks: self.moveToCenter('MarkOfGraceFilePath') location1 = pyautogui.locateCenterOnScreen( primaryImagePath, confidence=confidenceLevel) location2 = pyautogui.locateCenterOnScreen( secondaryImagePath, confidence=confidenceLevel) while not location1 and location2 and confidenceLevel > 0: location1 = pyautogui.locateCenterOnScreen( primaryImagePath, confidence=confidenceLevel) location2 = pyautogui.locateCenterOnScreen( secondaryImagePath, confidence=confidenceLevel) confidenceLevel -= .05 if location1: pos = self.induceError(location1, 10, 7) else: pos = self.induceError(location2, 10 , 7) realmouse.move_mouse_to(pos[0]/self.pixelConversion, pos[1]/self.pixelConversion) self.mouse.click(Button.left, 1) time.sleep(waitTime)
def move_mouse_to_image_within_region(image, region=None): """ # Locates an image on screen and moves the mouse to a random point within that image. """ image_loc = pyautogui.locateOnScreen(image, region=region) while image_loc is None: image_loc = pyautogui.locateOnScreen(image, region=region) point_to_click = random_point( (image_loc[0], image_loc[1]), (image_loc[0] + image_loc[2], image_loc[1] + image_loc[3])) move_mouse_to(point_to_click[0], point_to_click[1])
def examine_money(position): # this whole block just examines the amount of money point = pointfrombox.random_point((138, 94), (189, 109)) # that the account has just for auto log out purposes money_pouch = (position[0] - point[0], position[1] - point[1]) # so that it has a recording of the last time an action realmouse.move_mouse_to(money_pouch[0], money_pouch[1]) # was taken and can keep track of this value in future to stop logouts # occuring pyautogui.click(button='right') point = pointfrombox.random_point((-75, -35), (74, -24)) examine = (money_pouch[0] - point[0], money_pouch[1] - point[1]) realmouse.move_mouse_to(examine[0], examine[1]) pyautogui.click()
def buy_item(runescape_window, ge_slot): # click the correct buy bag move_mouse_to_image_within_region('Tools/screenshots/buy_bag.png', ge_slot) pyautogui.click() wait_for('Tools/screenshots/quantity_box.png', runescape_window) # click search box move_mouse_to_image_within_region('Tools/screenshots/search_box.png', runescape_window) pyautogui.click() # type in item random_typer(str(ge_slot.item.item_name)) wait_for(ge_slot.item.image_in_ge_search, runescape_window) # click item move_mouse_to_image_within_region(ge_slot.item.image_in_ge_search, runescape_window) pyautogui.click() # click price box coords_of_price_box = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-384, runescape_window.bottom_right_corner[1]-272), (runescape_window.bottom_right_corner[0]-291, runescape_window.bottom_right_corner[1]-259)) realmouse.move_mouse_to(coords_of_price_box[0], coords_of_price_box[1]) pyautogui.click() time.sleep(random.random()+1) # type in correct price and hit enter random_typer(str(ge_slot.item.price_instant_sold_at)) pyautogui.press('enter') # click quantity box move_mouse_to_image_within_region("Tools/screenshots/quantity_box.png", runescape_window) pyautogui.click() time.sleep(random.random()+2) # type in correct quantity and hit enter ge_slot.item.set_quantity_to_buy(int(min(ge_slot.item.number_available_to_buy, (runescape_window.money/ge_slot.item.price_instant_sold_at)/runescape_window.number_of_empty_ge_slots))) runescape_window.update_money(runescape_window.money - (ge_slot.item.quantity_to_buy*ge_slot.item.price_instant_sold_at)) random_typer(str(ge_slot.item.quantity_to_buy)) time.sleep(random.random()) pyautogui.press('enter') # click confirm off move_mouse_to_image_within_region("Tools/screenshots/confirm_offer_button.png", runescape_window) pyautogui.click() ge_slot.item.set_time_item_buy_was_placed() wait_for('Tools/screenshots/lent_item_box.png', runescape_window) # update states accordingly runescape_window.set_time_of_last_action() ge_slot.update_buy_or_sell_state('buy') runescape_window.check_for_empty_ge_slots() print('Placed a buy order for {} {} at {} each'.format(ge_slot.item.quantity_to_buy, ge_slot.item.item_name, ge_slot.item.price_instant_sold_at))
def moveToCenter(self, primaryImagePath:str, confidenceLevel=.7, waitTime=0): """Move to the center of an image on the screen. Keyword arguments: primaryImagePath -- relative path of image to query confidenceLevel -- confidence level for image recognition (default .95) waitTime -- time to wait after click (default 0) """ location1 = pyautogui.locateCenterOnScreen( primaryImagePath, confidence=confidenceLevel) while not location1: location1 = pyautogui.locateCenterOnScreen( primaryImagePath, confidence=.5) print('Located') pos = self.induceError(location1) realmouse.move_mouse_to(pos[0]/self.pixelConversion, pos[1]/self.pixelConversion) print("Moved") self.mouse.click(Button.left,1) time.sleep(waitTime)
def collect_items_from_ge_slot(ge_slot, runescape_window): point_to_click = pointfrombox.random_point(ge_slot.top_left_corner, ge_slot.bottom_right_corner) realmouse.move_mouse_to(point_to_click[0], point_to_click[1]) pyautogui.click() wait_for('Tools/screenshots/completed_offer_page.png', runescape_window) point_of_item_collection_box_1 = pointfrombox.random_point((runescape_window.bottom_right_corner[0] - 303, runescape_window.bottom_right_corner[ 1] - 166), (runescape_window.bottom_right_corner[0] - 273, runescape_window.bottom_right_corner[1] - 138)) point_of_item_collection_box_2 = pointfrombox.random_point((runescape_window.bottom_right_corner[0] - 254, runescape_window.bottom_right_corner[ 1] - 166), (runescape_window.bottom_right_corner[0] - 222, runescape_window.bottom_right_corner[1] - 138)) realmouse.move_mouse_to(point_of_item_collection_box_2[0], point_of_item_collection_box_2[1]) pyautogui.click() realmouse.move_mouse_to(point_of_item_collection_box_1[0], point_of_item_collection_box_1[1]) pyautogui.click() wait_for('Tools/screenshots/lent_item_box.png', runescape_window)
def move_mouse_to_box(image_of_box, top_left_corner, bottom_right_corner): box_to_click = pyautogui.locateOnScreen(image_of_box) random_x = random.randint(0, box_to_click[2]) random_y = random.randint(0, box_to_click[3]) move_mouse_to(box_to_click[0] + random_x, box_to_click[1] + random_y)
def select_inventory_item(self): item_location = pointfrombox.random_point(*self.loc_inventory_item) move_mouse_to(item_location[0], item_location[1]) pyautogui.click()
def open_ge_slot(self, ge_slot): move_mouse_to(*ge_slot.location) pyautogui.click()
def collect_2(self): top_left, bottom_right = pointfrombox.random_point( *self.loc_collection_box_item) move_mouse_to(top_left, bottom_right) pyautogui.click()
def move_mouse_to_box(image_of_box, top_left_corner, bottom_right_corner): box_to_click = pyautogui.locateOnScreen(image_of_box, region=(top_left_corner[0], top_left_corner[ 1], bottom_right_corner[0] - top_left_corner[0], bottom_right_corner[1] - top_left_corner[1])) random_x = random.randint(0, box_to_click[2]) random_y = random.randint(0, box_to_click[3]) realmouse.move_mouse_to(box_to_click[0] + random_x, box_to_click[1] + random_y)
def move_mouse_to_image_within_region(image, region): # region takes in an object image_loc = pyautogui.locateOnScreen(image, region=(region.top_left_corner[0], region.top_left_corner[1], region.bottom_right_corner[0]-region.top_left_corner[0], region.bottom_right_corner[1]-region.top_left_corner[1])) while(image_loc == None): image_loc = pyautogui.locateOnScreen(image, region=(region.top_left_corner[0], region.top_left_corner[1], region.bottom_right_corner[0]-region.top_left_corner[0], region.bottom_right_corner[1]-region.top_left_corner[1])) point_to_click = pointfrombox.random_point((image_loc[0], image_loc[1]), (image_loc[0]+image_loc[2], image_loc[1]+image_loc[3])) realmouse.move_mouse_to(point_to_click[0], point_to_click[1])