From 3de13e63884526c03511875f7b85368c94a1c55b Mon Sep 17 00:00:00 2001 From: Enterly <36875936+anthony5301@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:01:52 +0800 Subject: [PATCH 1/2] Fix bug, goodbye headliner, update augment coords, crown check are back --- arena.py | 52 +++----------- comp_editor.py | 171 +---------------------------------------------- comps.py | 61 ++++++----------- game.py | 2 +- screen_coords.py | 12 +--- 5 files changed, 34 insertions(+), 264 deletions(-) diff --git a/arena.py b/arena.py index f6c594d3..617c9ee7 100644 --- a/arena.py +++ b/arena.py @@ -33,7 +33,6 @@ def __init__(self, message_queue) -> None: self.level = 0 self.augment_roll = True self.spam_roll = False - self.have_headliner = False def fix_bench_state(self) -> None: """Iterates through bench and fixes invalid slots""" @@ -235,9 +234,12 @@ def place_items(self) -> None: def add_item_to_champs(self, item_index: int) -> None: """Iterates through champions in the board and checks if the champion needs items""" - for champ in self.board: - if champ.does_need_items() and self.items[item_index] is not None: - self.add_item_to_champ(item_index, champ) + for champ_name in comps.COMP: + for champ in self.board: + if champ_name == champ.name: + if champ.does_need_items() and self.items[item_index] is not None: + self.add_item_to_champ(item_index, champ) + break def add_item_to_champ(self, item_index: int, champ: Champion) -> None: """Takes item index and champ and applies the item""" @@ -356,54 +358,16 @@ def spend_gold(self, speedy=False) -> None: print(" Rerolling shop") shop: list = arena_functions.get_shop() print(f" Shop: {shop}") - for champion in reversed(shop): + for champion in shop: if ( self.champs_to_buy.get(champion[1], -1) >= 0 and arena_functions.get_gold() - game_assets.CHAMPIONS[champion[1]]["Gold"] >= 0 ): - if ( - champion[0] != 4 or not arena_functions.check_headliner() - ) and self.champs_to_buy.get(champion[1], -1) > 0: - self.buy_champion(champion, 1) - elif ( - champion[0] == 4 - and ( - arena_functions.check_headliner() - & comps.get_headliner_tag(champion[1]) - != 0 - ) - and not self.have_headliner - and comps.COMP[champion[1]]["final_comp"] - and arena_functions.get_gold() - - game_assets.CHAMPIONS[champion[1]]["Gold"] * 3 - >= 0 - ): - self.buy_headliner(champion[1]) + self.buy_champion(champion, 1) first_run = False - def buy_headliner(self, champion: str) -> None: - """Buy headliner and replace the normal one if level not equal 3""" - if comps.COMP[champion]["level"] < 3: - for champ in self.board: - if champ.name == champion: - self.remove_champion(champ) - self.buy_champion([4, champion], 0) - for newchamp in self.bench: - if isinstance(newchamp, Champion) and newchamp.name == champion: - self.move_known(newchamp) - break - else: - for index, slot in enumerate(self.bench): - if isinstance(slot, Champion) and slot.name == champion: - mk_functions.press_e(slot.coords) - self.bench[index] = None - self.buy_champion([4, champion], 3) - else: - self.buy_champion([4, champion], 3) - self.have_headliner = True - def buy_champion(self, champion, quantity) -> None: """Buy champion in shop""" none_slot: int = arena_functions.empty_slot() diff --git a/comp_editor.py b/comp_editor.py index 7fbfd962..c6ac5ab2 100644 --- a/comp_editor.py +++ b/comp_editor.py @@ -34,13 +34,12 @@ def __init__(self, comp_data): self.geometry("1280x720") self.comp_tree = ttk.Treeview( - self, columns=("board_position", "level", "items", "traits", "final_comp") + self, columns=("board_position", "level", "items", "final_comp") ) self.comp_tree.heading("#0", text="Champion") self.comp_tree.heading("board_position", text="Board Position") self.comp_tree.heading("level", text="Level") self.comp_tree.heading("items", text="Items") - self.comp_tree.heading("traits", text="Traits") self.comp_tree.heading("final_comp", text="Final Comp") self.comp_tree.grid(row=0, column=1, rowspan=8, sticky="nsew") @@ -59,9 +58,6 @@ def __init__(self, comp_data): self.champion_dropdown.grid( row=0, column=0, columnspan=2, pady=5, padx=5, sticky="w" ) - self.champion_dropdown.bind( - "<>", lambda event: self.update_traits_dropdowns() - ) self.board_position_var = tk.StringVar() self.create_label_entry( @@ -84,9 +80,6 @@ def __init__(self, comp_data): item_dropdown.grid(row=i + 3, column=1, columnspan=2, pady=5, sticky="w") self.item_dropdowns.append(item_var) - self.trait_dropdowns = self.create_trait_dropdowns(left_frame) - self.update_traits_dropdowns() - self.final_comp_var = tk.BooleanVar() self.create_checkbox( left_frame, "Final Composition:", self.final_comp_var, row=9 @@ -116,10 +109,6 @@ def __init__(self, comp_data): left_frame.grid_columnconfigure(1, weight=1) left_frame.grid_rowconfigure(11, weight=1) - # Bind the validation function to the variables - self.champion_dropdown.bind( - "<>", lambda event: self.update_traits_dropdowns() - ) self.board_position_var.trace_add("write", lambda *args: self.validate_inputs()) self.level_var.trace_add("write", lambda *args: self.validate_inputs()) self.comp_tree.bind("", lambda event: self.on_tree_double_click()) @@ -159,115 +148,6 @@ def load_champion_details(self, champion): else: item_var.set("") - # Update traits dropdowns based on the selected champion - self.update_traits_dropdowns() - - # Set headliner traits - headliner_traits = details.get("headliner", []) - for i, (trait_var, trait_dropdown) in enumerate( - zip(self.trait_vars, self.trait_dropdowns) - ): - if i < len(headliner_traits) and headliner_traits[i]: - # Set trait only if headliner value is True - trait_name = CHAMPIONS[champion].get(f"Trait{i + 1}", "") - trait_var.set(trait_name) - trait_dropdown.set(trait_name) - else: - trait_var.set("") - trait_dropdown.set("") - - def create_trait_dropdown(self, frame, label_text, variable, row): - """ - Create a single trait dropdown in the given frame. - - Args: - frame (ttk.Frame): The frame in which to create the dropdown. - label_text (str): The text for the dropdown label. - variable: The variable associated with the dropdown. - row (int): The row in which to place the dropdown. - """ - trait_dropdown = ttk.Combobox(frame, textvariable=variable, values=[""]) - ttk.Label(frame, text=label_text).grid(row=row, column=0, sticky="w", padx=5) - trait_dropdown.grid(row=row, column=1, columnspan=2, pady=5, sticky="w") - return trait_dropdown - - def create_trait_dropdowns(self, frame): - """ - Create trait dropdowns for the given champion. - - Args: - frame (ttk.Frame): The frame in which to create the trait dropdowns. - - Returns: - list: List of trait dropdowns. - """ - trait_dropdowns = [] - for i in range(3): - trait_var = tk.StringVar() - trait_dropdown = self.create_trait_dropdown( - frame, f"Trait {i + 1}:", trait_var, i + 6 - ) - trait_dropdowns.append(trait_dropdown) - return trait_dropdowns - - def update_traits_dropdowns(self): - """ - Update the traits dropdowns based on the selected champion. - """ - selected_champion = self.champion_name_var.get() - - if selected_champion in CHAMPIONS: - champion_traits = CHAMPIONS[selected_champion] - traits = [ - champion_traits["Trait1"], - champion_traits["Trait2"], - champion_traits["Trait3"], - ] - num_traits = sum(1 for trait in traits if trait) - else: - traits = ["", "", ""] - num_traits = 0 - - filtered_traits = [] - seen_traits = set() - - for item in traits: - if item and item not in seen_traits: - filtered_traits.append(item) - seen_traits.add(item) - - # Update the values in the dropdowns - for i, (trait_var, trait_dropdown) in enumerate( - zip(self.trait_vars, self.trait_dropdowns) - ): - trait_var.set("") # Set the default choice to blank - trait_dropdown["values"] = [""] + filtered_traits - trait_dropdown.set("") - - # Disable dropdowns based on the number of available traits - trait_dropdown["state"] = "normal" # Reset state to normal - if i >= num_traits: - # Reset value to blank for disabled dropdowns - trait_dropdown.set("") - trait_dropdown["state"] = "disabled" - - def map_traits_to_headliner(self, selected_traits, champion_traits): - """ - Map selected traits to positions in the headliner list. - - Args: - selected_traits (list): List of selected traits by the user. - champion_traits (list): List of traits associated with the selected champion. - - Returns: - list: A list representing the headliner with True at positions corresponding to selected traits. - """ - headliner = [False] * 3 - for trait in selected_traits: - if trait in champion_traits and trait != "": - headliner[champion_traits.index(trait)] = True - return headliner - def create_label_entry(self, frame, label_text, variable, row=None): """ Create a label and entry widget pair in the given frame. @@ -304,25 +184,6 @@ def populate_tree(self): for champion, details in sorted( self.comp.items(), key=lambda x: x[1]["board_position"] ): - # Fetch traits from CHAMPIONS - champion_data = CHAMPIONS.get(champion, {}) - traits = [champion_data.get(f"Trait{i+1}", "") for i in range(3)] - - # Update traits based on headliner values - headliner_values = details.get("headliner", [False, False, False]) - traits = [ - trait if headliner else "" - for trait, headliner in zip(traits, headliner_values) - ] - - filtered_traits = [] - seen_traits = set() - - for item in traits: - if item and item not in seen_traits: - filtered_traits.append(item) - seen_traits.add(item) - self.comp_tree.insert( "", "end", @@ -331,7 +192,6 @@ def populate_tree(self): details["board_position"], details["level"], ", ".join(details["items"]), - ", ".join(filtered_traits), details["final_comp"], ), ) @@ -431,24 +291,13 @@ def add_champion(self): items = self.validate_and_filter_items() level = self.validate_level() final_comp = self.final_comp_var.get() - selected_traits = self.get_selected_traits() selected_champion = self.champion_name_var.get() - if selected_champion in CHAMPIONS: - champion_traits = CHAMPIONS[selected_champion] - traits = [champion_traits[f"Trait{i+1}"] for i in range(3)] - else: - traits = ["", "", ""] - - headliner = self.map_traits_to_headliner(selected_traits, traits) - new_champion = { "board_position": board_position, "level": level, "items": items, - "traits": selected_traits, "final_comp": final_comp, - "headliner": headliner, } self.comp[selected_champion] = new_champion @@ -509,24 +358,6 @@ def validate_level(self): return None return int(level_str) - def get_selected_traits(self): - """ - Retrieve and filter the selected traits entered by the user. - - Returns: - list: The filtered list of selected traits. - """ - selected_traits = [trait_var.get() for trait_var in self.trait_dropdowns] - filtered_traits = [] - seen_traits = set() - - for item in selected_traits: - if item and item not in seen_traits: - filtered_traits.append(item) - seen_traits.add(item) - - return filtered_traits - def is_valid_item(self, item): """ Check if the item string is valid. diff --git a/comps.py b/comps.py index a3a1e0c6..186b88f3 100644 --- a/comps.py +++ b/comps.py @@ -12,73 +12,63 @@ COMP = { "Galio": { "board_position": 25, - "items": ["BrambleVest", "Dragonsclaw", "WarmogsArmor"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["BrambleVest", "DragonsClaw", "WarmogsArmor"], + "final_comp": True }, "Kaisa": { "board_position": 5, - "items": ["InfinityEdge", "LastWhisper", "SpearofShojin"], "level": 3, - "final_comp": True, - "headliner": [False, False, False] + "items": ["InfinityEdge", "LastWhisper", "SpearofShojin"], + "final_comp": True }, "Sivir": { "board_position": 4, - "items": ["StatikkShiv"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["StatikkShiv"], + "final_comp": True }, "Aatrox": { "board_position": 27, - "items": ["Evenshroud"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["Evenshroud"], + "final_comp": True }, "Riven": { "board_position": 21, - "items": ["ThiefsGloves"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["ThiefsGloves"], + "final_comp": True }, "Teemo": { "board_position": 0, - "items": ["JeweledGauntlet","SpearofShojin"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["JeweledGauntlet", "SpearofShojin"], + "final_comp": True }, "Sylas": { "board_position": 23, - "items": ["ThiefsGloves"], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": ["ThiefsGloves"], + "final_comp": True }, "Xayah": { "board_position": 6, - "items": [], "level": 2, - "final_comp": True, - "headliner": [False, False, False] + "items": [], + "final_comp": True }, "Kobuko": { "board_position": 24, - "items": [], "level": 2, - "final_comp": False, - "headliner": [False, False, False] + "items": [], + "final_comp": False }, "Zoe": { - "board_position": 5, - "items": [], + "board_position": 3, "level": 2, - "final_comp": False, - "headliner": [False, False, False] + "items": [], + "final_comp": False } } @@ -168,12 +158,3 @@ def get_unknown_slots() -> list: for _, champion_data in COMP.items(): container.append(champion_data["board_position"]) return [n for n in range(27) if n not in container] - - -def get_headliner_tag(name: str) -> int: - """Return what trait of specify champion can become headliner""" - return ( - int(COMP[name]["headliner"][0]) - + int(COMP[name]["headliner"][1]) * 2 - + int(COMP[name]["headliner"][2]) * 4 - ) diff --git a/game.py b/game.py index 95878da2..69be262a 100644 --- a/game.py +++ b/game.py @@ -171,7 +171,7 @@ def pve_round(self) -> None: self.arena.clear_anvil() self.arena.anvil_free[:2] = [True, False] self.arena.clear_anvil() - # self.arena.tacticians_crown_check() #not getting any item in set9 round 1-3, skipped + self.arena.tacticians_crown_check() self.arena.fix_bench_state() self.arena.spend_gold() diff --git a/screen_coords.py b/screen_coords.py index 7eb7aa2f..8d7a0b0c 100644 --- a/screen_coords.py +++ b/screen_coords.py @@ -57,9 +57,9 @@ EXIT_NOW_POS: Vec4 = Vec4(GameWindow(910, 560, 1029, 583)) AUGMENT_POS: list[Vec4] = [ - Vec4(GameWindow(417, 536, 687, 566)), - Vec4(GameWindow(825, 536, 1095, 566)), - Vec4(GameWindow(1230, 536, 1500, 566)), + Vec4(GameWindow(417, 552, 687, 582)), + Vec4(GameWindow(825, 552, 1095, 582)), + Vec4(GameWindow(1230, 552, 1500, 582)), ] AUGMENT_LOC: list[Vec2] = [Vec2(549, 445), Vec2(955, 445), Vec2(1365, 445)] @@ -68,12 +68,6 @@ VICTORY_POS: Vec4 = Vec4(GameWindow(906, 560, 1030, 587)) -HEADLINER_POS: list[Vec4] = [ - Vec4(GameWindow(1280, 1018, 1289, 1030)), - Vec4(GameWindow(1280, 990, 1289, 1002)), - Vec4(GameWindow(1280, 964, 1289, 976)) -] - BUY_LOC: list[Vec2] = [ Vec2(575, 992), Vec2(775, 992), From ef33b3b92b6a825c67f35d6892800f68bad4fe6f Mon Sep 17 00:00:00 2001 From: Enterly <36875936+anthony5301@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:13:26 +0800 Subject: [PATCH 2/2] Fix bug, goodbye headliner, update augment coords and comp editor, crown check are back --- arena_functions.py | 15 --------------- comp_editor.py | 10 ++-------- comps.py | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/arena_functions.py b/arena_functions.py index 8d9bb73a..914fe3b4 100644 --- a/arena_functions.py +++ b/arena_functions.py @@ -145,18 +145,3 @@ def get_items() -> list: item_bench.append(valid_item(item)) mk_functions.move_mouse(screen_coords.DEFAULT_LOC.get_coords()) return item_bench - - -def check_headliner() -> bool: - """Check if the last Champion in the store is a headliner""" - result: int = 0 - for index, positions in enumerate(screen_coords.HEADLINER_POS): - headliner: str = ocr.get_text( - screenxy=positions.get_coords(), - scale=3, - psm=10, - whitelist=ocr.ROUND_WHITELIST.replace("-", ""), - ) - if headliner == "2": - result += 2**index - return result diff --git a/comp_editor.py b/comp_editor.py index c6ac5ab2..6ce3ff11 100644 --- a/comp_editor.py +++ b/comp_editor.py @@ -8,7 +8,6 @@ from tkinter import ttk, simpledialog import json import os -import re from comps import COMP from game_assets import FULL_ITEMS, CHAMPIONS @@ -295,8 +294,8 @@ def add_champion(self): new_champion = { "board_position": board_position, - "level": level, "items": items, + "level": level, "final_comp": final_comp, } @@ -412,12 +411,7 @@ def save_changes(self): updated_file_content = ( file_content[:comp_line_start] + "COMP = " - + re.sub( - r'"traits": \[.*?\],\n?', - "", - json.dumps(self.comp, indent=4), - flags=re.DOTALL, - ) + + json.dumps(self.comp, indent=4) .replace("false", "False") .replace("true", "True") .replace(" ", " ") diff --git a/comps.py b/comps.py index 186b88f3..8471e15a 100644 --- a/comps.py +++ b/comps.py @@ -12,62 +12,62 @@ COMP = { "Galio": { "board_position": 25, - "level": 2, "items": ["BrambleVest", "DragonsClaw", "WarmogsArmor"], + "level": 2, "final_comp": True }, "Kaisa": { "board_position": 5, - "level": 3, "items": ["InfinityEdge", "LastWhisper", "SpearofShojin"], + "level": 3, "final_comp": True }, "Sivir": { "board_position": 4, + "items": ["SpearofShojin", "StatikkShiv"], "level": 2, - "items": ["StatikkShiv"], "final_comp": True }, "Aatrox": { "board_position": 27, - "level": 2, "items": ["Evenshroud"], + "level": 2, "final_comp": True }, "Riven": { "board_position": 21, - "level": 2, "items": ["ThiefsGloves"], + "level": 2, "final_comp": True }, "Teemo": { "board_position": 0, + "items": ["BlueBuff", "RabadonsDeathcap"], "level": 2, - "items": ["JeweledGauntlet", "SpearofShojin"], "final_comp": True }, "Sylas": { "board_position": 23, - "level": 2, "items": ["ThiefsGloves"], + "level": 2, "final_comp": True }, "Xayah": { "board_position": 6, - "level": 2, "items": [], + "level": 2, "final_comp": True }, "Kobuko": { "board_position": 24, - "level": 2, "items": [], + "level": 2, "final_comp": False }, "Zoe": { "board_position": 3, - "level": 2, "items": [], + "level": 2, "final_comp": False } }