Skip to content

Commit

Permalink
input values(hof pos, arena rem. time, iterator fix
Browse files Browse the repository at this point in the history
bot is working
  • Loading branch information
JED0050 committed Aug 15, 2024
1 parent 80442a9 commit 951b916
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
26 changes: 16 additions & 10 deletions src/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,37 @@
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
if timer.is_arena_ready():
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__":
Expand Down
9 changes: 6 additions & 3 deletions src/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!")
Expand All @@ -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
8 changes: 4 additions & 4 deletions src/utils/window_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 951b916

Please sign in to comment.