Skip to content

Commit

Permalink
Improve bench_occupied_check and encounter round shop delay
Browse files Browse the repository at this point in the history
Avoid detecting green champion on board as health bar, and right click on empty slot to check unknown champion
  • Loading branch information
anthony5301 authored Mar 30, 2024
1 parent c3882dd commit 517afed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
10 changes: 8 additions & 2 deletions arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ def spend_gold(self, speedy=False) -> None:

# For set 11 encounter round shop delay and choose items popup
for _ in range(15):
print("checking shop == blank")
if speedy:
return
if shop == [(1,""), (2,""), (3,""), (4,""), (5,"")]:
if all(champ[1] == "" for champ in shop):
print("shop == blank")
sleep(1)
anvil_msg: str = ocr.get_text(
screenxy=screen_coords.ANVIL_MSG_POS.get_coords(),
Expand All @@ -379,8 +381,12 @@ def spend_gold(self, speedy=False) -> None:
if anvil_msg in ["ChooseOne", "Feelinglucky"]:
print(" Choosing item")
mk_functions.left_click(screen_coords.BUY_LOC[2].get_coords())
sleep(1)
sleep(1.5)
shop: list = arena_functions.get_shop()
break
shop: list = arena_functions.get_shop()
else:
break

for champion in shop:
if (
Expand Down
21 changes: 16 additions & 5 deletions arena_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def empty_slot() -> int:
for slot, positions in enumerate(screen_coords.BENCH_HEALTH_POS):
screen_capture = ImageGrab.grab(bbox=positions.get_coords())
screenshot_array = np.array(screen_capture)
if not (np.abs(screenshot_array - (0, 255, 18)) <= 3).all(axis=2).any():
is_health_color = np.all(screenshot_array == [0, 255, 18], axis=-1)
if not any(np.convolve(is_health_color.reshape(-1), np.ones(5), mode='valid') >= 5):
return slot # Slot 0-8
return -1 # No empty slot

Expand All @@ -111,12 +112,22 @@ def bench_occupied_check() -> list:
for positions in screen_coords.BENCH_HEALTH_POS:
screen_capture = ImageGrab.grab(bbox=positions.get_coords())
screenshot_array = np.array(screen_capture)
if not (np.abs(screenshot_array - (0, 255, 18)) <= 2).all(axis=2).any():
bench_occupied.append(False)
else:
bench_occupied.append(True)
is_health_color = np.all(screenshot_array == [0, 255, 18], axis=-1)
occupied = any(np.convolve(is_health_color.reshape(-1), np.ones(5), mode='valid') >= 5)
bench_occupied.append(occupied)
return bench_occupied

# def board_occupied_check(known: bool, destination: tuple) -> bool:
# if known:
# mk_functions.left_click(destination.get_coords())
# sleep(0.1)
# screen_capture = ImageGrab.grab(bbox=screen_coords.SELL_MSG_POS.get_coords())
# mk_functions.left_click(destination.get_coords())
# screenshot_array = np.array(screen_capture)
# if (np.sum(np.abs(screenshot_array - (255, 247, 153)) == 0).all(axis=2)) >= 5:
# return True
# else:
# return False

def valid_item(item: str) -> str | None:
"""Checks if the item passed in arg one is valid"""
Expand Down
22 changes: 12 additions & 10 deletions screen_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from vec2 import Vec2

BENCH_HEALTH_POS: list[Vec4] = [
Vec4(GameWindow(369, 622, 472, 757)),
Vec4(GameWindow(485, 622, 588, 757)),
Vec4(GameWindow(601, 622, 704, 757)),
Vec4(GameWindow(728, 622, 831, 757)),
Vec4(GameWindow(844, 622, 947, 757)),
Vec4(GameWindow(960, 622, 1063, 757)),
Vec4(GameWindow(1076, 622, 1179, 757)),
Vec4(GameWindow(1192, 622, 1295, 757)),
Vec4(GameWindow(1308, 622, 1411, 757)),
Vec4(GameWindow(369, 670, 472, 757)),
Vec4(GameWindow(485, 670, 588, 757)),
Vec4(GameWindow(601, 670, 704, 757)),
Vec4(GameWindow(728, 670, 831, 757)),
Vec4(GameWindow(844, 670, 947, 757)),
Vec4(GameWindow(960, 670, 1063, 757)),
Vec4(GameWindow(1076, 670, 1179, 757)),
Vec4(GameWindow(1192, 670, 1295, 757)),
Vec4(GameWindow(1308, 670, 1411, 757)),
]

ITEM_POS: list[list] = [
Expand Down Expand Up @@ -56,6 +56,8 @@

ANVIL_MSG_POS: Vec4 = Vec4(GameWindow(818, 838, 932, 859))

SELL_MSG_POS: Vec4 = Vec4(GameWindow(817, 1001, 828, 1001))

EXIT_NOW_POS: Vec4 = Vec4(GameWindow(910, 560, 1029, 583))

AUGMENT_POS: list[Vec4] = [
Expand All @@ -81,7 +83,7 @@
ITEM_PICKUP_LOC: list[Vec2] = [
Vec2(1440, 611),
Vec2(406, 544),
Vec2(1412, 486),
Vec2(1440, 486),
Vec2(469, 440),
Vec2(1380, 381),
Vec2(644, 323),
Expand Down

0 comments on commit 517afed

Please sign in to comment.