Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 31 additions & 14 deletions core/actions/daily_race.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from core.perception.ocr.interface import OCRInterface
from core.perception.yolo.interface import IDetector
from core.types import DetectionDict
from core.utils.abort import abort_requested
from core.utils.logger import logger_uma
from core.utils.waiter import Waiter
from core.utils import nav
Expand Down Expand Up @@ -49,7 +50,8 @@ def enter_from_menu(self) -> bool:
)
if not ok:
return False
sleep(1.7)
if not nav.cooperative_sleep(1.7):
return False
# Often need to click the 'monies' card
self.waiter.click_when(
classes=("race_daily_races_monies",),
Expand Down Expand Up @@ -78,7 +80,8 @@ def confirm_and_next_to_race(self) -> bool:
"""
NEXT -> RACE
"""
sleep(1.5)
if not nav.cooperative_sleep(1.5):
return False
ok = self.waiter.click_when(
classes=("button_green",),
prefer_bottom=False,
Expand All @@ -99,7 +102,8 @@ def confirm_and_next_to_race(self) -> bool:
timeout_s=2.0,
tag="daily_race_cancel",
):
sleep(1.5)
if not nav.cooperative_sleep(1.5):
return False
img, dets = nav.collect_snapshot(
self.waiter, self.yolo_engine, tag="daily_race_cancel"
)
Expand All @@ -110,10 +114,11 @@ def confirm_and_next_to_race(self) -> bool:
timeout_s=3.0,
tag="daily_race_ui_home",
)
sleep(1.5)
nav.cooperative_sleep(1.5)
logger_uma.debug("[DailyRace] Canceling races")
return False
sleep(1.5)
if not nav.cooperative_sleep(1.5):
return False
if self.waiter.click_when(
classes=("button_green",),
prefer_bottom=True,
Expand All @@ -133,12 +138,16 @@ def run_race_and_collect(self) -> bool:
finalized = False
counter = 5
while race_again and counter > 0:
sleep(3)
if abort_requested():
break
if not nav.cooperative_sleep(3.0):
break
if isinstance(self.ctrl, ScrcpyController) or (
BlueStacksController is not None
and isinstance(self.ctrl, BlueStacksController)
):
sleep(1.5)
if not nav.cooperative_sleep(1.5):
break
if self.waiter.click_when(
classes=("button_green",),
prefer_bottom=True,
Expand All @@ -149,7 +158,8 @@ def run_race_and_collect(self) -> bool:
else:
race_again = False
continue
sleep(1.5)
if not nav.cooperative_sleep(1.5):
break

if self.waiter.click_when(
classes=("button_green",),
Expand All @@ -162,7 +172,8 @@ def run_race_and_collect(self) -> bool:
race_again = False
continue
counter -= 1
sleep(2.0)
if not nav.cooperative_sleep(2.0):
break
# After race, click 'View Results' / proceed with white button spamming
img, _ = nav.collect_snapshot(
self.waiter, self.yolo_engine, tag="daily_race_view_results"
Expand All @@ -177,7 +188,8 @@ def run_race_and_collect(self) -> bool:
clicks=1,
tag="daily_race_view_results_white",
)
sleep(2.0)
if not nav.cooperative_sleep(2.0):
break
# nav.random_center_tap(
# self.ctrl, img, clicks=random.randint(3, 4), dev_frac=0.20
# )
Expand All @@ -199,6 +211,7 @@ def run_race_and_collect(self) -> bool:
self.ctrl,
tag_prefix="daily_race_shop",
ensure_enter=True,
should_stop=abort_requested,
)
if did_shop:
logger_uma.info("[DailyRace] Completed shop exchange flow")
Expand All @@ -218,7 +231,8 @@ def run_race_and_collect(self) -> bool:
finalized = True
break
else:
sleep(2.0)
if not nav.cooperative_sleep(2.0):
break
if self.waiter.seen(
classes=("button_green",),
texts=("OK",),
Expand All @@ -232,20 +246,23 @@ def run_race_and_collect(self) -> bool:
timeout_s=2.0,
tag="daily_race_ok",
)
sleep(2)
if not nav.cooperative_sleep(2.0):
break
# Click in button_advance using the waiter
self.waiter.click_when(
classes=("button_advance",),
prefer_bottom=True,
timeout_s=4,
tag="daily_race_advance",
)
sleep(2)
if not nav.cooperative_sleep(2.0):
break
if isinstance(self.ctrl, ScrcpyController) or (
BlueStacksController is not None
and isinstance(self.ctrl, BlueStacksController)
):
sleep(4.0)
if not nav.cooperative_sleep(4.0):
break
# Click object with class ui_home
self.waiter.click_when(
classes=("ui_home",),
Expand Down
26 changes: 25 additions & 1 deletion core/actions/lobby.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from core.utils.pal_memory import PalMemoryManager
from core.actions.events import _count_chain_steps
from core.utils.event_processor import predict_next_chain_has_energy_from_raw
from core.utils.abort import abort_requested

from core.utils.date_uma import (
DateInfo,
Expand Down Expand Up @@ -1435,7 +1436,30 @@ def _go_training_screen_from_lobby(self, img, dets, reason: Optional[str] = None
timeout_s=2.5,
tag="lobby_training",
)
clicked = True
if not clicked:
logger_uma.warning("[lobby] Training button click failed")
return False

confirmed = False
deadline = time.time() + 2.5
while time.time() < deadline:
if abort_requested():
logger_uma.info("[lobby] Training confirmation aborted")
return False
if self.waiter.seen(
classes=("training_button",),
conf_min=0.35,
tag="lobby_training_confirm",
):
confirmed = True
break
time.sleep(0.15)

if not confirmed:
logger_uma.warning("[lobby] Training screen not confirmed after click")
return False

logger_uma.info("[lobby] Training screen confirmed")
if clicked:
# This replaces a time.sleep... time.sleep(1.2)
# If the machine is ultra powerful, then you should neet a time.sleep(1.2)
Expand Down
Loading