Skip to content

Commit

Permalink
Fix bug, goodbye headliner, update augment coords and comp editor, cr…
Browse files Browse the repository at this point in the history
…own check are back

Fix bug, goodbye headliner, update augment coords and comp editor, crown check are back
  • Loading branch information
anthony5301 authored Mar 22, 2024
2 parents 6d4a3f8 + ef33b3b commit 84105d5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 280 deletions.
52 changes: 8 additions & 44 deletions arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 0 additions & 15 deletions arena_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
181 changes: 3 additions & 178 deletions comp_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,13 +33,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")

Expand All @@ -59,9 +57,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(
"<<ComboboxSelected>>", lambda event: self.update_traits_dropdowns()
)

self.board_position_var = tk.StringVar()
self.create_label_entry(
Expand All @@ -84,9 +79,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
Expand Down Expand Up @@ -116,10 +108,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(
"<<ComboboxSelected>>", 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("<Double-1>", lambda event: self.on_tree_double_click())
Expand Down Expand Up @@ -159,115 +147,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.
Expand Down Expand Up @@ -304,25 +183,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",
Expand All @@ -331,7 +191,6 @@ def populate_tree(self):
details["board_position"],
details["level"],
", ".join(details["items"]),
", ".join(filtered_traits),
details["final_comp"],
),
)
Expand Down Expand Up @@ -431,24 +290,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,
"level": level,
"final_comp": final_comp,
"headliner": headliner,
}

self.comp[selected_champion] = new_champion
Expand Down Expand Up @@ -509,24 +357,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.
Expand Down Expand Up @@ -581,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(" ", " ")
Expand Down
Loading

0 comments on commit 84105d5

Please sign in to comment.