diff --git a/game.py b/game.py index 2aa07d6..f324737 100644 --- a/game.py +++ b/game.py @@ -5,6 +5,7 @@ from time import sleep, perf_counter import random import multiprocessing +import importlib from win32con import BM_CLICK import win32gui import settings @@ -20,9 +21,10 @@ class Game: """Game class that handles game logic such as round tasks""" def __init__(self, message_queue: multiprocessing.Queue) -> None: + importlib.reload(game_assets) self.message_queue = message_queue self.arena = Arena(self.message_queue) - self.round: str = "0-0" + self.round: list[str, int] = ["0-0", 0] self.time: None = None self.forfeit_time: int = settings.FORFEIT_TIME + random.randint(50, 150) self.found_window = False @@ -60,7 +62,7 @@ def callback(self, hwnd, extra) -> None: # pylint: disable=unused-argument def loading_screen(self) -> None: """Loop that runs while the game is in the loading screen""" game_functions.default_pos() - while game_functions.get_round() != "1-1": + while game_functions.get_round()[0] != "1-1": if self.check_failed_to_connect_window(): return sleep(1) @@ -84,6 +86,7 @@ def check_failed_to_connect_window(self) -> bool: print(" Reconnect button not found.") return False + # pylint: disable=too-many-branches def game_loop(self) -> None: """Loop that runs while the game is active, handles calling the correct tasks for round and exiting game""" ran_round: str = None @@ -113,28 +116,95 @@ def game_loop(self) -> None: and perf_counter() - self.start_time > self.forfeit_time ): game_functions.forfeit() - return + continue - if self.round != ran_round: - if self.round in game_assets.PVP_ROUND: + if self.round[0] != ran_round: + if self.round[0] in game_assets.PVP_ROUND: game_functions.default_pos() self.pvp_round() - ran_round: str = self.round - elif self.round in game_assets.PVE_ROUND: + ran_round: str = self.round[0] + elif self.round[0] in game_assets.PVE_ROUND: game_functions.default_pos() self.pve_round() - ran_round: str = self.round - elif self.round in game_assets.CAROUSEL_ROUND: + ran_round: str = self.round[0] + elif self.round[0] in game_assets.CAROUSEL_ROUND: self.carousel_round() - ran_round: str = self.round - elif self.round in game_assets.SECOND_ROUND: + ran_round: str = self.round[0] + elif self.round[0] in game_assets.SECOND_ROUND: self.second_round() - ran_round: str = self.round + ran_round: str = self.round[0] + elif self.round[0] in game_assets.ENCOUNTER_ROUNDS: + print(f"\n[Encounter Round] {self.round[0]}") + print(" Do nothing") + self.message_queue.put("CLEAR") + self.arena.check_health() + ran_round: str = self.round[0] + if self.round[1] == 1 and self.round[0].split("-")[1] == "1": + print("\n[Encounter round setup]") + self.encounter_round_setup() sleep(0.5) + def encounter_round_setup(self) -> None: + """Remove rounds from game_assets and add it back by checking round message""" + game_assets.CAROUSEL_ROUND = { + carousel_round + for carousel_round in game_assets.CAROUSEL_ROUND + if not carousel_round.startswith(self.round[0].split("-")[0]) + } + game_assets.PVE_ROUND = { + pve_round + for pve_round in game_assets.PVE_ROUND + if not pve_round.startswith(self.round[0].split("-")[0]) + } + game_assets.PVP_ROUND = { + pvp_round + for pvp_round in game_assets.PVP_ROUND + if not pvp_round.startswith(self.round[0].split("-")[0]) + } + game_assets.ANVIL_ROUNDS = { + anvil_round + for anvil_round in game_assets.ANVIL_ROUNDS + if not anvil_round.startswith(self.round[0].split("-")[0]) + } + game_assets.ITEM_PLACEMENT_ROUNDS = { + item_placement_round + for item_placement_round in game_assets.ITEM_PLACEMENT_ROUNDS + if not item_placement_round.startswith(self.round[0].split("-")[0]) + } + for index, round_msg in enumerate(game_functions.check_encounter_round()): + print(f" Round {self.round[0].split('-')[0]}-{str(index + 1)}: {round_msg.upper()} ROUND") + if index == 0: + continue + if round_msg == "carousel": + game_assets.CAROUSEL_ROUND.add( + self.round[0].split("-")[0] + "-" + str(index + 1) + ) + game_assets.ANVIL_ROUNDS.add( + self.round[0].split("-")[0] + "-" + str(index + 2) + ) + game_assets.ITEM_PLACEMENT_ROUNDS.add( + self.round[0].split("-")[0] + "-" + str(index + 2) + ) + elif round_msg == "pve": + game_assets.PVE_ROUND.add( + self.round[0].split("-")[0] + "-" + str(index + 1) + ) + elif round_msg == "pvp": + game_assets.PVP_ROUND.add( + self.round[0].split("-")[0] + "-" + str(index + 1) + ) + elif round_msg == "encounter": + game_assets.ENCOUNTER_ROUNDS.add( + self.round[0].split("-")[0] + "-" + str(index + 1) + ) + if index+1 == 2 and int(self.round[0].split("-")[0]) <= 4: + game_assets.AUGMENT_ROUNDS.add( + self.round[0].split("-")[0] + "-" + str(index + 2) + ) + def second_round(self) -> None: """Move unknown champion to board after first carousel""" - print(f"\n[Second Round] {self.round}") + print(f"\n[Second Round] {self.round[0]}") self.message_queue.put("CLEAR") while True: result = arena_functions.bench_occupied_check() @@ -147,26 +217,26 @@ def second_round(self) -> None: def carousel_round(self) -> None: """Handles tasks for carousel rounds""" - print(f"\n[Carousel Round] {self.round}") + print(f"\n[Carousel Round] {self.round[0]}") self.message_queue.put("CLEAR") - if self.round == "3-4": + if self.round[0] == "3-4": self.arena.final_comp = True self.arena.check_health() print(" Getting a champ from the carousel") - game_functions.get_champ_carousel(self.round) + game_functions.get_champ_carousel(self.round[0]) def pve_round(self) -> None: """Handles tasks for PVE rounds""" - print(f"\n[PvE Round] {self.round}") + print(f"\n[PvE Round] {self.round[0]}") self.message_queue.put("CLEAR") sleep(0.5) - if self.round in game_assets.AUGMENT_ROUNDS: + if self.round[0] in game_assets.AUGMENT_ROUNDS: sleep(1) self.arena.augment_roll = True self.arena.pick_augment() # Can't purchase champions for a short period after choosing augment sleep(2.5) - if self.round == "1-3": + if self.round[0] == "1-3": sleep(1.5) self.arena.fix_unknown() self.arena.anvil_free[1:] = [True] * 8 @@ -186,32 +256,32 @@ def pve_round(self) -> None: def pvp_round(self) -> None: """Handles tasks for PVP rounds""" - print(f"\n[PvP Round] {self.round}") + print(f"\n[PvP Round] {self.round[0]}") self.message_queue.put("CLEAR") sleep(0.5) - if self.round in game_assets.AUGMENT_ROUNDS: + if self.round[0] in game_assets.AUGMENT_ROUNDS: sleep(1) self.arena.augment_roll = True self.arena.pick_augment() sleep(2.5) - if self.round in ("2-1", "2-5"): + if self.round[0] in ("2-1", "2-5"): self.arena.buy_xp_round() - if self.round in game_assets.PICKUP_ROUNDS: + if self.round[0] in game_assets.PICKUP_ROUNDS: print(" Picking up items") game_functions.pickup_items() self.arena.fix_bench_state() self.arena.bench_cleanup() - if self.round in game_assets.ANVIL_ROUNDS: + if self.round[0] in game_assets.ANVIL_ROUNDS: self.arena.clear_anvil() - self.arena.spend_gold(speedy=self.round in game_assets.PICKUP_ROUNDS) + self.arena.spend_gold(speedy=self.round[0] in game_assets.PICKUP_ROUNDS) self.arena.move_champions() self.arena.replace_unknown() if self.arena.final_comp: self.arena.final_comp_check() self.arena.bench_cleanup() - if self.round in game_assets.ITEM_PLACEMENT_ROUNDS: + if self.round[0] in game_assets.ITEM_PLACEMENT_ROUNDS: sleep(1) self.arena.place_items() self.end_round_tasks() diff --git a/game_assets.py b/game_assets.py index a02cc9c..f0521f8 100644 --- a/game_assets.py +++ b/game_assets.py @@ -104,12 +104,12 @@ ROUNDS: set[str] = {"1-1", "1-2", "1-3", "1-4", - "2-1", "2-2", "2-3", "2-4", "2-5", "2-6", "2-7", - "3-1", "3-2", "3-3", "3-4", "3-5", "3-6", "3-7", - "4-1", "4-2", "4-3", "4-4", "4-5", "4-6", "4-7", - "5-1", "5-2", "5-3", "5-4", "5-5", "5-6", "5-7", - "6-1", "6-2", "6-3", "6-4", "6-5", "6-6", "6-7", - "7-1", "7-2", "7-3", "7-4", "7-5", "7-6", "7-7"} + "2-1", "2-2", "2-3", "2-4", "2-5", "2-6", "2-7", "2-8", + "3-1", "3-2", "3-3", "3-4", "3-5", "3-6", "3-7", "3-8", + "4-1", "4-2", "4-3", "4-4", "4-5", "4-6", "4-7", "4-8", + "5-1", "5-2", "5-3", "5-4", "5-5", "5-6", "5-7", "5-8", + "6-1", "6-2", "6-3", "6-4", "6-5", "6-6", "6-7", "6-8", + "7-1", "7-2", "7-3", "7-4", "7-5", "7-6", "7-7", "7-8"} SECOND_ROUND: set[str] = {"1-2"} @@ -133,6 +133,8 @@ ITEM_PLACEMENT_ROUNDS: set[str] = {"2-2", "3-2", "4-2", "5-2", "6-2", "7-2", "2-5", "3-5", "4-5", "5-5", "6-5", "7-5"} +ENCOUNTER_ROUNDS: set[str] = {"0-0"} + FINAL_COMP_ROUND = "4-5" FULL_ITEMS = {"DryadEmblem":("Spatula","GiantsBelt"), diff --git a/game_functions.py b/game_functions.py index d82448e..0e4082b 100644 --- a/game_functions.py +++ b/game_functions.py @@ -10,22 +10,47 @@ import mk_functions -def get_round() -> str: +def get_round() -> list[str, int]: """Gets the current game round""" screen_capture = ImageGrab.grab(bbox=screen_coords.ROUND_POS.get_coords()) round_three = screen_capture.crop(screen_coords.ROUND_POS_THREE.get_coords()) game_round: str = ocr.get_text_from_image(image=round_three, whitelist=ocr.ROUND_WHITELIST) if game_round in game_assets.ROUNDS: - return game_round + return [game_round, 3] round_two = screen_capture.crop(screen_coords.ROUND_POS_TWO.get_coords()) game_round: str = ocr.get_text_from_image(image=round_two, whitelist=ocr.ROUND_WHITELIST) if game_round in game_assets.ROUNDS: - return game_round + return [game_round, 2] + round_one = screen_capture.crop(screen_coords.ROUND_POS_ONE.get_coords()) game_round: str = ocr.get_text_from_image(image=round_one, whitelist=ocr.ROUND_WHITELIST) - return game_round - + if game_round in game_assets.ROUNDS: + return [game_round, 1] + return ["999-999",0] + + +def check_encounter_round() -> list[str]: + """Get the game round list by checking round text for encounter add rounds""" + round_list: list = [] + for positions in screen_coords.ROUND_ENCOUNTER_ICON_POS: + mk_functions.move_mouse(positions[0].get_coords()) + round_message: str = ocr.get_text( + screenxy=positions[1].get_coords(), + scale=3, + psm=7, + whitelist=(ocr.ALPHABET_WHITELIST + " "), + ) + if any(keyword in round_message for keyword in ["Carousel"]): + round_list.append("carousel") + elif any(keyword in round_message for keyword in ["Get pulled into an Encounter"]): + round_list.append("encounter") + elif any(keyword in round_message for keyword in ["Krugs", "Murk Wolves", "Raptors", "Elder Dragon"]): + round_list.append("pve") + else: + round_list.append("pvp") + mk_functions.move_mouse(screen_coords.DEFAULT_LOC.get_coords()) + return round_list def pickup_items() -> None: # Refacor this function to make it more clear whats happening """Picks up items from the board after PVP round""" @@ -43,7 +68,7 @@ def pickup_items() -> None: # Refacor this function to make it more clear whats def get_champ_carousel(tft_round: str) -> None: """Gets a champion from the carousel""" - while tft_round == get_round(): + while tft_round == get_round()[0]: mk_functions.right_click(screen_coords.CAROUSEL_LOC.get_coords()) sleep(0.7) sleep(3) diff --git a/screen_coords.py b/screen_coords.py index 9444625..cab85f4 100644 --- a/screen_coords.py +++ b/screen_coords.py @@ -40,6 +40,17 @@ ROUND_POS_THREE: Vec4 = Vec4(GameWindow(71, 0, 110, 24), use_screen_offset=False) +ROUND_ENCOUNTER_ICON_POS: list[list[Vec2, Vec4]] = [ + [Vec2(833, 20), Vec4(GameWindow(890, 49, 1218, 75))], + [Vec2(869, 20), Vec4(GameWindow(926, 49, 1254, 75))], + [Vec2(905, 20), Vec4(GameWindow(962, 49, 1290, 75))], + [Vec2(941, 20), Vec4(GameWindow(998, 49, 1326, 75))], + [Vec2(977, 20), Vec4(GameWindow(1034, 49, 1362, 75))], + [Vec2(1013, 20), Vec4(GameWindow(1070, 49, 1398, 75))], + [Vec2(1049, 20), Vec4(GameWindow(1106, 49, 1434, 75))], + [Vec2(1085, 20), Vec4(GameWindow(1142, 49, 1470, 75))], +] + SHOP_POS: Vec4 = Vec4(GameWindow(481, 1039, 1476, 1070)) CHAMP_NAME_POS: list[Vec4] = [