def select(): global NEW_GAME, THE_COIN logging.info("[ENTER] select") NEW_GAME = True if defines.MULLIGAN: src = vision.screen_cap() choose_3 = [] choose_4 = [] for box in defines.starting_hand_costs_3: choose_3.append(vision.read_white_data(src, c(box))) for box in defines.starting_hand_costs_4: choose_4.append(vision.read_white_data(src, c(box))) #print choose_3 #print choose_4 return_list = [] if '' not in choose_3: THE_COIN = False for choice in range(0, len(choose_3)): if int(choose_3[choice]) >= 4: coord = defines.starting_hand_costs_3[choice] return_list.append( [coord[2], coord[3]] ) #return the lower right of the detection box which is over the card to click on elif '' not in choose_4: THE_COIN = True for choice in range(0, len(choose_4)): if int(choose_4[choice]) >= 5: coord = defines.starting_hand_costs_4[choice] return_list.append( [coord[2], coord[3]] ) #return the lower right of the detection box which is over the card to click on if int(choose_4[choice]) == 1: coord = defines.starting_hand_costs_4[choice] return_list.append( [coord[2], coord[3]] ) #return the lower right of the detection box which is over the card to click on for coord in return_list: control_success = actions.move_and_leftclick(c(coord)) control_success = actions.move_and_leftclick(c( defines.confirm_hand_button)) control_success = actions.move_and_leftclick(c(defines.neutral))
def select(): global NEW_GAME, THE_COIN logging.info("[ENTER] select") NEW_GAME = True if defines.MULLIGAN: src = vision.screen_cap() choose_3 = [] choose_4 = [] for box in defines.starting_hand_costs_3: choose_3.append(vision.read_white_data(src, c(box))) for box in defines.starting_hand_costs_4: choose_4.append(vision.read_white_data(src, c(box))) # print choose_3 # print choose_4 return_list = [] if "" not in choose_3: THE_COIN = False for choice in range(0, len(choose_3)): if int(choose_3[choice]) >= 4: coord = defines.starting_hand_costs_3[choice] return_list.append( [coord[2], coord[3]] ) # return the lower right of the detection box which is over the card to click on elif "" not in choose_4: THE_COIN = True for choice in range(0, len(choose_4)): if int(choose_4[choice]) >= 5: coord = defines.starting_hand_costs_4[choice] return_list.append( [coord[2], coord[3]] ) # return the lower right of the detection box which is over the card to click on if int(choose_4[choice]) == 1: coord = defines.starting_hand_costs_4[choice] return_list.append( [coord[2], coord[3]] ) # return the lower right of the detection box which is over the card to click on for coord in return_list: control_success = actions.move_and_leftclick(c(coord)) control_success = actions.move_and_leftclick(c(defines.confirm_hand_button)) control_success = actions.move_and_leftclick(c(defines.neutral))
def run(self): self.new_state = 0 self.old_state = 0 self.queue.put("Starting bot") wait_count = 0 previous_hour = 99 wait_for_start_time = True defines.set_defines() next_img = vision.imread("images//next.png") match_coord_next = [0, 0] while not self.stopped(): # timing controls current_hour = int(strftime("%X")[:2]) if current_hour == 0: current_hour = 24 if ( current_hour == defines.STOP_HOUR and defines.STOP_HOUR != 0 and (self.new_state == defines.State.PLAY or self.new_state == defines.State.HOME) ): if defines.STOP_HOUR >= 12 and defines.STOP_HOUR != 24: am_or_pm = "pm" else: am_or_pm = "am" time_to_stop = defines.STOP_HOUR % 12 if time_to_stop == 0: time_to_stop = 12 wait_for_start_time = True self.queue.put("stopped at %s o'clock %s" % (time_to_stop, am_or_pm)) if not wait_for_start_time: # check if battle net is running and Hearthstone is running and shown if actions.check_bnet("Battle.net"): if actions.check_game("Hearthstone") == False: self.new_state = defines.State.DESKTOP else: update_resolutions() try: src = vision.screen_cap() state_name = vision.get_state_sift(src, state_descs) if state_name != None: self.new_state = defines.state_dict[state_name] else: self.new_state = defines.State.DESKTOP if self.new_state == self.old_state and ( self.new_state == defines.State.PLAY or self.new_state == defines.State.HOME ): # Might have been a connection error. self.queue.put("Must enable at least one custom deck in Options!") control_success = actions.move_and_leftclick(c(defines.error_1)) control_success = actions.move_and_leftclick(c(defines.error_2)) control_success = actions.move_and_leftclick(c(defines.neutral)) if self.new_state == defines.State.PLAY and self.old_state == defines.State.QUEUE: self.new_state = defines.State.VERSUS except: self.queue.put("Error: Invalid state, starting the bot again may help") self.stop() else: self.queue.put("Error: Battle.net may not be running, please start Battle.net") self.stop() # check and reroll 40 gold quests once per day at reroll time if defines.REROLL_QUESTS: time_str = strftime("%X", localtime()) if ( int(time_str[:2]) != previous_hour and (self.new_state == defines.State.HOME or self.new_state == defines.State.PLAY) and not self.stopped() ): self.queue.put("checking quests") control_success = actions.move_and_leftclick(c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick(c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick(c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick(c(defines.quest_button)) actions.pause_pensively(3) src = vision.screen_cap() if "40" in vision.read_white_data(src, c(defines.quest_box_1)): # vision.imwrite('reroll_before.png',src) control_success = actions.move_and_leftclick(c(defines.reroll_quest_button_1)) # vision.imwrite('reroll_after.png',src) if "40" in vision.read_white_data(src, c(defines.quest_box_2)): control_success = actions.move_and_leftclick(c(defines.reroll_quest_button_2)) if "40" in vision.read_white_data(src, c(defines.quest_box_3)): control_success = actions.move_and_leftclick(c(defines.reroll_quest_button_3)) control_success = actions.move_and_leftclick(c(defines.main_menu_nuetral)) self.new_state = defines.State.HOME previous_hour = int(time_str[:2]) src = vision.screen_cap() self.queue.put(self.state_desc[self.new_state]) # check if waiting for a long time, try clicking just in case if ( self.state_desc[self.new_state] == "waiting" or self.state_desc[self.new_state] == "finding opponent" or self.state_desc[self.new_state] == "home screen" or self.state_desc[self.new_state] == "select_deck" ): if wait_count >= 5: control_success = actions.move_and_leftclick(c(defines.main_screen_splash)) wait_count = 0 else: wait_count += 1 if self.new_state != defines.State.DESKTOP and not self.stopped(): states[self.new_state]() elif self.new_state == defines.State.DESKTOP and not self.stopped(): # on the desktop for some reason, try to start the game or reshow the window if it's already running actions.pause_pensively(1) if not self.stopped(): actions.restart_game() update_resolutions() control_success = actions.move_and_leftclick(c(defines.neutral)) self.old_state = self.new_state else: if defines.START_HOUR >= 12 and defines.START_HOUR != 24: am_or_pm = "pm" else: am_or_pm = "am" time_to_start = defines.START_HOUR % 12 if time_to_start == 0: time_to_start = 12 current_hour = int(strftime("%X")[:2]) if current_hour == 0: current_hour = 24 modified_stop_hour = defines.STOP_HOUR if defines.START_HOUR > defines.STOP_HOUR: modified_stop_hour += 24 # STOP_HOUR is desired by the player to be the next day if ( defines.START_HOUR == current_hour or defines.START_HOUR == 0 or defines.START_HOUR < current_hour < modified_stop_hour ): wait_for_start_time = False else: self.queue.put("waiting for %s o'clock %s" % (time_to_start, am_or_pm)) if actions.game_running("Hearthstone") == True: actions.close_game_window("Hearthstone") actions.pause_pensively(60) # check for splash screens src = vision.screen_cap() _, match_coord_next = vision.calc_sift(src, next_img, ratio=0.2) if match_coord_next != [0, 0]: brown_box = ( match_coord_next[0] - 50, match_coord_next[1] - 40, match_coord_next[0] + 50, match_coord_next[1] + 40, ) data = vision.read_brown_text(src, brown_box) if "Next" in data or "Done" in data: control_success = actions.move_and_leftclick(match_coord_next) self.queue.put("splash screen") actions.pause_pensively(2) else: match_coord_next = [0, 0]
def run(self): self.new_state = 0 self.old_state = 0 self.queue.put("Starting bot") wait_count = 0 previous_hour = 99 wait_for_start_time = True defines.set_defines() next_img = vision.imread('images//next.png') match_coord_next = [0, 0] while (not self.stopped()): #timing controls current_hour = int(strftime("%X")[:2]) if current_hour == 0: current_hour = 24 if current_hour == defines.STOP_HOUR and defines.STOP_HOUR != 0 and ( self.new_state == defines.State.PLAY or self.new_state == defines.State.HOME): if defines.STOP_HOUR >= 12 and defines.STOP_HOUR != 24: am_or_pm = 'pm' else: am_or_pm = 'am' time_to_stop = defines.STOP_HOUR % 12 if time_to_stop == 0: time_to_stop = 12 wait_for_start_time = True self.queue.put("stopped at %s o'clock %s" % (time_to_stop, am_or_pm)) if not wait_for_start_time: #check if battle net is running and Hearthstone is running and shown if actions.check_bnet("Battle.net"): if actions.check_game("Hearthstone") == False: self.new_state = defines.State.DESKTOP else: update_resolutions() try: src = vision.screen_cap() state_name = vision.get_state_sift( src, state_descs) if state_name != None: self.new_state = defines.state_dict[state_name] else: self.new_state = defines.State.DESKTOP if self.new_state == self.old_state and ( self.new_state == defines.State.PLAY or self.new_state == defines.State.HOME): #Might have been a connection error. self.queue.put( "Must enable at least one custom deck in Options!" ) control_success = actions.move_and_leftclick( c(defines.error_1)) control_success = actions.move_and_leftclick( c(defines.error_2)) control_success = actions.move_and_leftclick( c(defines.neutral)) if self.new_state == defines.State.PLAY and self.old_state == defines.State.QUEUE: self.new_state = defines.State.VERSUS except: self.queue.put( "Error: Invalid state, starting the bot again may help" ) self.stop() else: self.queue.put( "Error: Battle.net may not be running, please start Battle.net" ) self.stop() #check and reroll 40 gold quests once per day at reroll time if defines.REROLL_QUESTS: time_str = strftime("%X", localtime()) if int(time_str[:2]) != previous_hour and ( self.new_state == defines.State.HOME or self.new_state == defines.State.PLAY) and not self.stopped(): self.queue.put('checking quests') control_success = actions.move_and_leftclick( c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick( c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick( c(defines.play_back_button)) actions.pause_pensively(3) control_success = actions.move_and_leftclick( c(defines.quest_button)) actions.pause_pensively(3) src = vision.screen_cap() if '40' in vision.read_white_data( src, c(defines.quest_box_1)): #vision.imwrite('reroll_before.png',src) control_success = actions.move_and_leftclick( c(defines.reroll_quest_button_1)) #vision.imwrite('reroll_after.png',src) if '40' in vision.read_white_data( src, c(defines.quest_box_2)): control_success = actions.move_and_leftclick( c(defines.reroll_quest_button_2)) if '40' in vision.read_white_data( src, c(defines.quest_box_3)): control_success = actions.move_and_leftclick( c(defines.reroll_quest_button_3)) control_success = actions.move_and_leftclick( c(defines.main_menu_nuetral)) self.new_state = defines.State.HOME previous_hour = int(time_str[:2]) src = vision.screen_cap() self.queue.put(self.state_desc[self.new_state]) #check if waiting for a long time, try clicking just in case if self.state_desc[ self.new_state] == 'waiting' or self.state_desc[ self. new_state] == 'finding opponent' or self.state_desc[ self. new_state] == 'home screen' or self.state_desc[ self.new_state] == 'select_deck': if wait_count >= 5: control_success = actions.move_and_leftclick( c(defines.main_screen_splash)) wait_count = 0 else: wait_count += 1 if self.new_state != defines.State.DESKTOP and not self.stopped( ): states[self.new_state]() elif self.new_state == defines.State.DESKTOP and not self.stopped( ): #on the desktop for some reason, try to start the game or reshow the window if it's already running actions.pause_pensively(1) if not self.stopped(): actions.restart_game() update_resolutions() control_success = actions.move_and_leftclick( c(defines.neutral)) self.old_state = self.new_state else: if defines.START_HOUR >= 12 and defines.START_HOUR != 24: am_or_pm = 'pm' else: am_or_pm = 'am' time_to_start = defines.START_HOUR % 12 if time_to_start == 0: time_to_start = 12 current_hour = int(strftime("%X")[:2]) if current_hour == 0: current_hour = 24 modified_stop_hour = defines.STOP_HOUR if defines.START_HOUR > defines.STOP_HOUR: modified_stop_hour += 24 #STOP_HOUR is desired by the player to be the next day if defines.START_HOUR == current_hour or defines.START_HOUR == 0 or defines.START_HOUR < current_hour < modified_stop_hour: wait_for_start_time = False else: self.queue.put("waiting for %s o'clock %s" % (time_to_start, am_or_pm)) if actions.game_running("Hearthstone") == True: actions.close_game_window("Hearthstone") actions.pause_pensively(60) #check for splash screens src = vision.screen_cap() _, match_coord_next = vision.calc_sift(src, next_img, ratio=0.2) if match_coord_next != [0, 0]: brown_box = (match_coord_next[0] - 50, match_coord_next[1] - 40, match_coord_next[0] + 50, match_coord_next[1] + 40) data = vision.read_brown_text(src, brown_box) if 'Next' in data or 'Done' in data: control_success = actions.move_and_leftclick( match_coord_next) self.queue.put('splash screen') actions.pause_pensively(2) else: match_coord_next = [0, 0]