def capture(num, prefix, delay=0): win = windep.WinDep() for i in range(num): current_screen = win.capture() current_screen.save(prefix + '_' + str(i + 1) + '.png') time.sleep(delay)
def fetch_colors(): win = windep.WinDep() red_min = 255 red_max = 0 blue_min = 255 blue_max = 0 green_min = 255 green_max = 0 while True: current_screen = win.capture() np_arr = np.array(current_screen) arr = np_arr[317:319 + 1, 319:322 + 1, :] for i, c in enumerate(np.nditer(arr)): if i % 3 is 0: # red if c > red_max: red_max = c if c < red_min: red_min = c elif (i + 2) % 3 is 0: # green if c > green_max: green_max = c if c < green_min: green_min = c print("R", red_min, red_max, "G", green_min, green_max, "B", blue_min, blue_max)
def mouse_click(self): win = windep.WinDep() try: l, t, w, h = win.window_found(self.win_name.text()) except: return #x1 = int(self.mouse_x_input.text()) #y1 = int(self.mouse_y_input.text()) time.sleep(1) self.srunner.mouse_click(l + 100, t + 10)
def compare_test(): while True: win = windep.WinDep() arr = np.load('data' + os.sep + 'no_more.npy') current_screen = win.capture() current_arr = np.array(current_screen) current_arr = current_arr[408:424, 132:408, :] current_arr = cv2.cvtColor(current_arr, cv2.COLOR_BGR2GRAY) (xscore, xdiff) = compare_ssim(current_arr, arr, full=True) print(xscore) time.sleep(1)
def type_loop(): tt = ['infantry', 'archer', 'knight', 'tank'] type = [] for t in tt: type.append(np.load('data' + os.sep + t + '.npy')) win = windep.WinDep() while True: current_screen = win.capture() new_c = current_screen.crop((254, 302, 283, 331)) current_arr = cv2.cvtColor(np.array(new_c), cv2.COLOR_BGR2GRAY) for i in range(len(tt)): (score, diff) = compare_ssim(current_arr, type[i], full=True) print(tt[i], score) time.sleep(1)
def template_match_test(): mine = np.load('data' + os.sep + 'mine.npy') target = np.load('data' + os.sep + 'target.npy') win = windep.WinDep() while True: current_screen = win.capture() current_arr = np.array(current_screen) current_arr = current_arr[648:704, 64:524, :] current_arr = cv2.cvtColor(current_arr, cv2.COLOR_BGR2GRAY) res = cv2.matchTemplate(current_arr, mine, cv2.TM_CCORR_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) print("mine: ", min_val, max_val, min_loc, max_loc) res = cv2.matchTemplate(current_arr, target, cv2.TM_CCORR_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) print("target: ", min_val, max_val, min_loc, max_loc) time.sleep(1)
def run_script(self): if self.srunner.running: self.srunner.running = False self.button_enable_while_play(True) self.start_button.setText('RUN') else: win = windep.WinDep() try: l, t, w, h = win.window_found(self.win_name.text()) except: return if w == -1 and h == -1: QMessageBox.warning( self, 'ERROR', 'Cannot find window ' + self.win_name.text()) else: self.srunner.set_script(self.edit_area.toPlainText()) self.srunner.running = True self.srunner.start() self.button_enable_while_play(False) self.start_button.setText('STOP')
def autoheal_script(self): if self.heal_check_timer.isActive(): self.key_release() self.heal_check_timer.stop() self.fill_mp_mode = False self.on_hp_potion = False self.last_mp_start_time = datetime.now() self.boost_mode = False self.key_tmp_rl = False self.enemy_time = None self.autoheal_button.setText('START AUTO HEAL') else: self.heal_check_timer.start() self.autoheal_button.setText('STOP AUTO HEAL') self.enemy_time = None if self.keep_press_key: win = windep.WinDep() try: l, t, w, h = win.window_found(self.win_name.text()) except: return self.key_press()
def start_capture(self): win = windep.WinDep() try: l, t, w, h = win.window_found(self.win_name.text()) except: return #print('window', l, t, w, h) if w == -1 and h == -1: QMessageBox.warning(self, 'ERROR', 'Cannot find window ' + self.win_name.text()) else: win.window_width = w win.window_height = h im = win.capture(l, t) filename, file_ext = 'capture', 'jpeg' path = '.' + os.sep + '%s.%s' % (filename, file_ext) uniq = 1 while os.path.exists(path): path = '.' + os.sep + '%s_%d.%s' % (filename, uniq, file_ext) uniq += 1 im.save(path) self.extra_info.setText('SAVED AS ' + path)
return False def is_hunting_available(h): if eventtime.is_event_time(): return False if datetime.datetime.now().hour is not h.get_last_no_ticket_time().hour: return True return False if __name__ == '__main__': win = windep.WinDep() army = checkarmy.CheckArmy() miners = [] hunt = None players = [player.Player((5, 2)), player.Player((1, 3))] BLOCK_HUNTING = False hunter = hunter.Hunter([0, 3]) # ['infantry', 'archer', 'knight', 'tank'] while True: current_screen = win.capture() waiting_exist = False if occasion_exist(current_screen): continue
def heal_check(self): win = windep.WinDep() try: l, t, w, h = win.window_found(self.win_name.text()) except: return print('heal window', l, t, w, h) win.window_width = w win.window_height = h im = win.capture(l, t) step = 3 start_x = 32 step_x = (206 - start_x) / (100 / step) current_hp, current_mp = 0, 0 for i in range(int(100 / step)): r, g, b = im.getpixel((int(32 + step_x * (i + 1)), 28)) #print(r, g, b, (int(32 + step_x * (i+1)), 28)) if r > 120 and g < 100 and b < 100: current_hp += step else: break for i in range(int(100 / step)): r, g, b = im.getpixel((int(32 + step_x * (i + 1)), 43)) print(r, g, b, (int(32 + step_x * (i + 1)), 28)) if b > 50: current_mp += step else: break print('hp', current_hp, 'mp', current_mp) enemy = False extra_info = '' cap = False if (self.check_oneline_red(im, 1103, 1106, 432) and self.check_oneline_red(im, 1103, 1106, 449) and self.check_box_white(im, 1104, 1107, 440, 442)): enemy = True cap = True if current_hp == 0: return #enemy = False if self.keep_press_key and (0 < current_mp < 30 or current_hp <= 35): self.key_release() self.key_tmp_rl = True elif self.keep_press_key and self.key_tmp_rl and current_mp > 40 and current_hp > 45: self.key_press() self.key_tmp_rl = False if enemy: self.key_release() self.key_tmp_rl = True self.enemy_time = datetime.now() self.do_capture(im) self.srunner.key_input(KEY_ENEMY_ATTACK) self.srunner.key_input(KEY_ENEMY_ATTACK) self.srunner.key_input(KEY_ENEMY_ATTACK) self.srunner.key_input(KEY_ENEMY_ATTACK) heal_hp_level = 80 if current_hp <= 20: self.srunner.key_input(KEY_HOME) cap = True play(self.song) self.autoheal_script() elif self.enemy_time is not None or current_hp <= 50: self.set_hp_potion(True) self.set_boost_mode(True) self.turn_on_guard() self.srunner.key_input(KEY_HEAL) self.srunner.key_input(KEY_HEAL) self.srunner.key_input(KEY_HEAL) self.srunner.key_input(KEY_GROUP_HEAL) self.srunner.key_input(KEY_GROUP_HEAL) self.srunner.key_input(KEY_GROUP_HEAL) elif current_hp <= heal_hp_level: self.srunner.key_input(KEY_HEAL) elif not enemy and current_hp >= 70: self.set_hp_potion(False) if current_mp > 50: self.set_boost_mode(False) if self.enemy_time is not None and datetime.now( ) - self.enemy_time > timedelta(seconds=30): self.enemy_time = None self.srunner.key_input(KEY_AUTO) extra_info = ' ' if self.key_tmp_rl: extra_info += '(RL)' if enemy: extra_info += '(PK)' if self.on_hp_potion: extra_info += '(HP)' elif self.fill_mp_mode: extra_info += '(MP)' if self.boost_mode: extra_info += '(BOOST)' self.extra_info.setText('HP: ' + str(current_hp) + ' MP: ' + str(current_mp) + extra_info) if cap: self.do_capture(im)
def capture_stress(): win = windep.WinDep() while True: win.capture()