Skip to content

Commit

Permalink
Update for set11 encounter add one round
Browse files Browse the repository at this point in the history
Not tested yet
  • Loading branch information
anthony5301 authored Apr 5, 2024
1 parent 7a590de commit 3a19692
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 23 deletions.
81 changes: 70 additions & 11 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Game:
def __init__(self, message_queue: multiprocessing.Queue) -> None:
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
Expand Down Expand Up @@ -60,7 +60,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)
Expand Down Expand Up @@ -115,21 +115,80 @@ def game_loop(self) -> None:
game_functions.forfeit()
return

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}")
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":
game_assets.CAROUSEL_ROUND = {
carousel_round
for carousel_round in game_assets.CAROUSEL_ROUND
if not carousel_round.startswith(self.round[0].split("-"))
}
game_assets.PVE_ROUND = {
pve_round
for pve_round in game_assets.PVE_ROUND
if not pve_round.startswith(self.round[0].split("-"))
}
game_assets.PVP_ROUND = {
pvp_round
for pvp_round in game_assets.PVP_ROUND
if not pvp_round.startswith(self.round[0].split("-"))
}
game_assets.ANVIL_ROUNDS = {
anvil_round
for anvil_round in game_assets.ANVIL_ROUNDS
if not anvil_round.startswith(self.round[0].split("-"))
}
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("-"))
}
for index, round_msg in enumerate(
game_functions.check_encounter_round()
):
if index == 0:
continue
if round_msg == "carousel":
game_assets.CAROUSEL_ROUND.add(
self.round[0].split("-") + "-" + str(index + 1)
)
game_assets.ANVIL_ROUNDS.add(
self.round[0].split("-") + "-" + str(index + 2)
)
game_assets.ITEM_PLACEMENT_ROUNDS.add(
self.round[0].split("-") + "-" + str(index + 2)
)
elif round_msg == "pve":
game_assets.PVE_ROUND.add(
self.round[0].split("-") + "-" + str(index + 1)
)
elif round_msg == "pvp":
game_assets.PVP_ROUND.add(
self.round[0].split("-") + "-" + str(index + 1)
)
elif round_msg == "encounter":
game_assets.ENCOUNTER_ROUNDS.add(
self.round[0].split("-") + "-" + str(index + 1)
)
sleep(0.5)

def second_round(self) -> None:
Expand Down
13 changes: 7 additions & 6 deletions game_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -132,6 +132,7 @@

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"

Expand Down
35 changes: 29 additions & 6 deletions game_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,45 @@
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

return [game_round, 1]


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"]):
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"""
Expand All @@ -43,7 +66,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)
Expand Down
11 changes: 11 additions & 0 deletions screen_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(926, 49, 1191, 75))],
[Vec2(869, 20), Vec4(GameWindow(962, 49, 1227, 75))],
[Vec2(905, 20), Vec4(GameWindow(998, 49, 1263, 75))],
[Vec2(941, 20), Vec4(GameWindow(1034, 49, 1299, 75))],
[Vec2(977, 20), Vec4(GameWindow(1070, 49, 1335, 75))],
[Vec2(1013, 20), Vec4(GameWindow(1106, 49, 1371, 75))],
[Vec2(1049, 20), Vec4(GameWindow(1142, 49, 1407, 75))],
[Vec2(1085, 20), Vec4(GameWindow(1178, 49, 1443, 75))],
]

SHOP_POS: Vec4 = Vec4(GameWindow(481, 1039, 1476, 1070))

CHAMP_NAME_POS: list[Vec4] = [
Expand Down

0 comments on commit 3a19692

Please sign in to comment.