Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queue exit on timeout subroutine to the queue loop. #90

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions alune/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,12 @@ def get_chance_to_buy_xp(self) -> int:
The chance in percent from 0 to 100.
"""
return self._config["chances"]["buy_xp"]

def get_queue_timeout(self) -> int:
"""
Get the queue timeout in seconds.

Returns:
The queue timeout in seconds.
"""
return self._config["queue_timeout"]
1 change: 1 addition & 0 deletions alune/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Button:
# Buttons with an image, the variable name must be the same as the image name.
play = ImageButton(BoundingBox(950, 600, 1200, 650))
accept = ImageButton(BoundingBox(525, 520, 755, 545))
exit_lobby = ImageButton(BoundingBox(50, 600, 130, 680))
exit_now = ImageButton(
click_box=BoundingBox(550, 425, 740, 440),
capture_area=BoundingBox(520, 400, 775, 425),
Expand Down
Binary file added alune/images/exit_lobby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions alune/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ log_level: "INFO"
# Please note that changing this may require changing traits as well.
game_mode: "normal"

# Timeout for the bot to stay in the queue. I've seen some instances where the bot is in a queue for several dozen minutes.
# This is the maximum time the bot will wait in the queue before it will exit the game. 150 secs seems to be a good value.
queue_timeout: 150

# The traits you want the bot to roll for.
# The trait names are almost as written in-game, with spaces replaced by _ and . and : being ignored.
# For example: admin, star_guardian, mecha_prime, lasercorps
Expand Down
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ async def wait_for_accept_button(adb_instance: ADB):
search_result = screen.get_button_on_screen(screenshot, Button.accept)


async def queue(adb_instance: ADB):
async def queue(adb_instance: ADB, config: AluneConfig):
"""
Utility method to queue a match.

Args:
adb_instance: An instance of the ADB connection to click in.
"""
try:
await asyncio.wait_for(wait_for_accept_button(adb_instance), timeout=120)
await asyncio.wait_for(wait_for_accept_button(adb_instance), timeout=config.get_queue_timeout())
except asyncio.TimeoutError:
logger.warning("Waiting for accept button timed out, re-checking app state")
await adb_instance.click_button(Button.exit_lobby)
logger.info("Queue exited due to timeout.")
return
await adb_instance.click_button(Button.accept)
await asyncio.sleep(2)
Expand All @@ -103,7 +104,7 @@ async def queue(adb_instance: ADB):
screenshot = await adb_instance.get_screen()
if screen.get_button_on_screen(screenshot, Button.accept) or screen.get_button_on_screen(screenshot, Button.play):
logger.debug("Queue was declined by someone else, staying in queue lock state")
await queue(adb_instance)
await queue(adb_instance, config)


_random = Random()
Expand Down Expand Up @@ -325,7 +326,7 @@ async def take_app_decision(game_state_image_result: GameStateImageResult, adb_i
case GameState.LOBBY:
logger.info("App state is in lobby, locking bot into queue logic.")
await adb_instance.click_button(Button.play)
await queue(adb_instance)
await queue(adb_instance, config)
logger.info("Queue lock released, likely loading into game now.")
case GameState.IN_GAME:
logger.info("App state is in game, looping decision making and waiting for the exit button.")
Expand Down