diff --git a/src/album.py b/src/album.py index 9a0468d..4898438 100644 --- a/src/album.py +++ b/src/album.py @@ -16,7 +16,7 @@ def __init__(self, screen_size, position, direction="up", config=None): self.config = config self.old_image_crop = None self.speed = 1 - self.min_diff_scrap = 30 + self.min_diff_scrap = 20 # images init_crop_img = crop_screenshot(self.screen_size, self.cropbox) self.black_bg_img = None @@ -35,7 +35,7 @@ def _open_HoF(self, position): def _find_player(self): t_before = time() sleep(self.speed*3) - for iter in range(1000): + for iter in range(100): if keyboard.is_pressed("q") or keyboard.is_pressed("esc"): break base_image_crop = crop_and_mask_screenshot(self.screen_size, self.cropbox, self.black_bg_img, self.mask_img) @@ -52,19 +52,25 @@ def _find_player(self): base_image_crop = crop_and_mask_screenshot(self.screen_size, self.cropbox, self.black_bg_img, self.mask_img) # Check next player self.old_image_crop = base_image_crop - base_image_crop.save(f"DEBUG/base_image_{iter}.png") - for k in range(3): - sleep(self.speed*0.3) + #base_image_crop.save(f"DEBUG/base_image_{iter}.png") + min_diff = 0 + for k in range(6): + sleep(self.speed*0.2) tmp_image_crop = crop_and_mask_screenshot(self.screen_size, self.cropbox, self.black_bg_img, self.mask_img) - tmp_image_crop.save(f"DEBUG/tmp_image_{iter}_{k}.png") + #tmp_image_crop.save(f"DEBUG/tmp_image_{iter}_{k}.png") diff_img = compare(base_image_crop, tmp_image_crop) - print(f"Taking screenshot {k} player {self.position} - new difference {diff_img}") + #print(f"Taking screenshot {k} player {self.position} - new difference {diff_img}") + if diff_img > min_diff: + min_diff = diff_img + if k == 2 and min_diff < 0.1: + break if diff_img > self.min_diff_scrap: t_after = time() seconds = math.ceil(t_after - t_before) - print(f"πŸ€ΊπŸ”βœ…\tNew player with scrap was found! Searching time: {seconds} seconds. Position HoF: {self.position} ({iter}/1000)") + print(f"πŸ€ΊπŸ”βœ…\tNew player with scrap was found! Searching time: {seconds} seconds. HoF pos: {self.position} ({iter}/100)") return (True, seconds) # found, searching time if iter % 20 == 0: + print("πŸ”šπŸŽΉ\t Hold 'q' or 'esc' to exit program") print(f"πŸ€ΊπŸ”βŒ\tNew player with scrap not found ({iter}/1000)") self._move_to_next_player() t_after = time() @@ -80,9 +86,9 @@ def _move_to_next_player(self): def _attack(self): for _ in range(4): - #keyboard.press_and_release("enter") + keyboard.press_and_release("enter") sleep(1) - print("Player killed") + print(f"πŸ€ΊπŸ’€βœ…\tPlayer {self.position} killed!") def find_and_kill_player(self): found, _ = self._find_player() diff --git a/src/main.py b/src/main.py index 9b5dcfa..47e96bf 100644 --- a/src/main.py +++ b/src/main.py @@ -3,20 +3,22 @@ from album import Album -def main(): +def main(): # intro talk - version = "0.1" + version = "1.0" print("\nWelvome to SFGame-DailyBot v" + version) print("\t\t\t-by Gaara3San\n") print("Place your game on main monitor and on fullscreen\n") # init - timer = Timer(sleep_duration=5) app_screen_size = get_full_window_size() - position = 50006 - album = Album(screen_size=app_screen_size, position=position) + hof_position = int(input("🀴\t Hall of Fame start position: ")) + arena_rem_time = int((float(input("🀺\t Arena remaining time (minutes): ")))*60.0) + 5 + timer = Timer(sleep_duration=5, arena_remaining_time=arena_rem_time) + album = Album(screen_size=app_screen_size, position=hof_position) + print() # main loop while True: # player attack @@ -24,13 +26,14 @@ def main(): searching_time = album.find_and_kill_player() timer.restart_arena_timer() timer.redute_timer(searching_time) + print() # wait until next iteration timer.print_remaining_time() if timer.sleep(10): # press 'q' or 'esc' to exit program break - print("See you soon! 😼\n") + print("😼😴\t SFGame-DailyBot deactivated. See you soon!\n") if __name__ == "__main__": diff --git a/src/utils/timer.py b/src/utils/timer.py index 08da403..02a2738 100644 --- a/src/utils/timer.py +++ b/src/utils/timer.py @@ -23,7 +23,6 @@ def sleep(self, new_duration=None): self.redute_timer(duration) def redute_timer(self, duration): - self.iterator = 0 self.arena_remaining_time -= duration if self.arena_remaining_time < 0: self.arena_remaining_time = 0 @@ -32,11 +31,12 @@ def is_arena_ready(self): return self.arena_remaining_time == 0 def restart_arena_timer(self): + self._restart_iterator() self.arena_remaining_time = self.arena_total_time def print_remaining_time(self): if self.iterator == 0: - self.iterator = self.max_iterator + self._restart_iterator() print("πŸ”šπŸŽΉ\t Hold 'q' or 'esc' to exit program") if self.arena_remaining_time == 0: print("πŸ€Ίβœ…\tAttack is ready!") @@ -51,7 +51,10 @@ def print_remaining_time(self): if self.arena_remaining_time == 1: suffix = suffix[:-1] time_of_attack = datetime.datetime.now() + datetime.timedelta(seconds=self.arena_remaining_time) - print(f"🀺❌\tAttack will be rady in {suffix}! ({time_of_attack.strftime('%H:%M:%S')})") + print(f"🀺❌\tAttack will be ready in {suffix}! ({time_of_attack.strftime('%H:%M:%S')})") print() else: self.iterator -= 1 + + def _restart_iterator(self): + self.iterator = self.max_iterator diff --git a/src/utils/window_size.py b/src/utils/window_size.py index 5326be1..6750d29 100644 --- a/src/utils/window_size.py +++ b/src/utils/window_size.py @@ -21,21 +21,21 @@ def get_full_window_size(config=None): # search for the Game Window and store it in the shakes variable if config is not None and isinstance(config.WINDOW_SIZE, tuple): rect = [0, 0, config.WINDOW_SIZE[0], config.WINDOW_SIZE[1]] - print(f"πŸ“πŸ““\tWindow size set by config file - {rect}") + print(f"πŸ“πŸ““\tWindow size set by config file {rect}") else: appwindows = _get_app_list() if len(appwindows) == 0: # SFGame app not found rect = [0, 0, 1928, 1048] - print(f"πŸ“βŒ\tSteam game not found, set to default value - {rect}") + print(f"πŸ“βŒ\tSteam game not found, set to default value {rect}") else: shakes = appwindows[0][0] # set the Game Window as the active window win32gui.SetForegroundWindow(shakes) # store the coordinates which we use later to find and crop the images rect = win32gui.GetWindowRect(shakes) - print(f"πŸ“πŸ§Ώ\tWindow size set by Steam app - {rect}") + print(f"πŸ“πŸ§Ώ\tWindow size set by Steam app {rect}") if rect[2] < 10 or rect[3] < 10: - print(f"πŸ“βŒ\tSteam game is minimalized or invalid config values (too small size values), set to default value - {rect}") + print(f"πŸ“βŒ\tSteam game is minimalized or invalid config values (too small size values), set to default value {rect}") rect = [0, 0, 1928, 1048] print() return rect