51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""Mailbox daily task. Ported from baas-reference module/mail.py's color-probe pattern."""
|
|
|
|
from ba_auto import navigation
|
|
|
|
# "Claim all" renders as flat grey (153,153,153) when there is nothing to claim.
|
|
CLAIM_ALL_PROBE = (1710, 1128)
|
|
CLAIM_ALL_DISABLED_RGB = (153, 153, 153)
|
|
CLAIM_ALL_DISABLED_TOLERANCE = 12
|
|
|
|
OPEN_RETRIES = 3
|
|
|
|
|
|
def _claim_all_disabled(driver):
|
|
r, g, b = driver.color_at(*CLAIM_ALL_PROBE)
|
|
tr, tg, tb = CLAIM_ALL_DISABLED_RGB
|
|
return (
|
|
abs(r - tr) <= CLAIM_ALL_DISABLED_TOLERANCE
|
|
and abs(g - tg) <= CLAIM_ALL_DISABLED_TOLERANCE
|
|
and abs(b - tb) <= CLAIM_ALL_DISABLED_TOLERANCE
|
|
)
|
|
|
|
|
|
def run(driver, config):
|
|
driver.focus_game()
|
|
|
|
opened = False
|
|
for attempt in range(1, OPEN_RETRIES + 1):
|
|
driver.click(*config.MAILBOX_ICON)
|
|
driver.wait(1.5)
|
|
if navigation.is_on_subscreen(driver):
|
|
opened = True
|
|
break
|
|
print(f"[mailbox] panel not detected after click (attempt {attempt}/{OPEN_RETRIES})")
|
|
|
|
if not opened:
|
|
print("[mailbox] could not confirm mailbox is open, aborting without pressing further keys")
|
|
return
|
|
|
|
if _claim_all_disabled(driver):
|
|
print("[mailbox] nothing to claim")
|
|
else:
|
|
print("[mailbox] claiming all")
|
|
driver.click(*config.CLAIM_ALL)
|
|
driver.wait(1)
|
|
driver.keypress("Return")
|
|
driver.wait(1)
|
|
|
|
driver.keypress("Escape")
|
|
driver.wait(1)
|
|
print("[mailbox] Done.")
|