104 lines
4.1 KiB
Python

"""Mission/task-menu AP+pyroxene claim. Ported from baas-reference module/collect_daily_task_power.py's claim-loop pattern (its rgb_in_range checks replaced with driver.color_at probes).
The reference's `implement` checks TWO separate button regions, not one:
the main 一括受取 (claim-all) area is drained in a loop first, then a
second, separate "claim daily pyroxenes" button is checked and clicked
independently -- 一括受取 does not also claim it. This was originally
missed here (only the first region was ported), reported live by the user
against a real account state where the second button ("デイリーミッショ
ンを8回クリア", a gem x20 reward) was still showing claimable after
一括受取 had already gone grey -- see config.py's
`MISSION_DAILY_GEM_CLAIM_BUTTON` for the live-calibration writeup.
"""
from ba_auto import navigation
OPEN_RETRIES = 3
# One claim-all round is normally enough (button goes grey right after), but
# bound it in case multiple reward reveals need dismissing in sequence.
CLAIM_MAX_ROUNDS = 5
DAILY_GEM_CLAIM_MAX_ATTEMPTS = 3
# Yellow "one-click claim all" button vs. its own flat-grey disabled state --
# same background-pixel-probe idea as mailbox.CLAIM_ALL_PROBE/cafe.CLAIM_PROBE,
# but distinguished by hue (yellow has a big r-b gap; grey doesn't) since the
# button's grey isn't a single fixed RGB the way mailbox/cafe's are. Also
# shared by the separate daily-gem claim button (config.MISSION_DAILY_GEM_CLAIM_BUTTON),
# which uses the same bright-yellow-vs-grey visual style.
CLAIM_ENABLED_MIN_R = 230
CLAIM_ENABLED_MIN_RB_GAP = 100
def _button_claimable(driver, probe):
r, g, b = driver.color_at(*probe)
return r > CLAIM_ENABLED_MIN_R and (r - b) > CLAIM_ENABLED_MIN_RB_GAP
def _claim_enabled(driver, config):
return _button_claimable(driver, config.MISSION_CLAIM_PROBE)
def _daily_gem_claimable(driver, config):
return _button_claimable(driver, config.MISSION_DAILY_GEM_CLAIM_BUTTON)
def _claim_daily_gem(driver, config):
for attempt in range(1, DAILY_GEM_CLAIM_MAX_ATTEMPTS + 1):
driver.click(*config.MISSION_DAILY_GEM_CLAIM_BUTTON)
driver.wait(1.5)
# Dismiss the reward-reveal popup the same way the main claim-all
# loop does below -- this button has no Enter keybind of its own,
# but Enter still dismisses the reward card that appears after.
driver.keypress("Return")
driver.wait(1.5)
if not _daily_gem_claimable(driver, config):
return True
print(f"[stamina] daily gem reward still showing claimable after click (attempt {attempt}/{DAILY_GEM_CLAIM_MAX_ATTEMPTS})")
return not _daily_gem_claimable(driver, config)
def run(driver, config):
driver.focus_game()
opened = False
for attempt in range(1, OPEN_RETRIES + 1):
driver.focus_game()
driver.click(*config.MISSION_ICON)
driver.wait(2)
if navigation.is_on_subscreen(driver):
opened = True
break
print(f"[stamina] mission panel not detected after click (attempt {attempt}/{OPEN_RETRIES})")
if not opened:
print("[stamina] could not confirm mission panel is open, aborting without pressing further keys")
return
claimed_any = False
for _ in range(CLAIM_MAX_ROUNDS):
if not _claim_enabled(driver, config):
break
print("[stamina] claiming mission rewards")
driver.keypress("Return")
driver.wait(1.5)
# dismiss the reward-reveal popup ("TOUCH" prompt); harmless no-op if
# nothing is actually showing, same assumption as cafe's room-entry dismiss
driver.keypress("Return")
driver.wait(1.5)
claimed_any = True
if _daily_gem_claimable(driver, config):
print("[stamina] claiming daily gem mission reward")
if _claim_daily_gem(driver, config):
claimed_any = True
else:
print("[stamina] warning: could not confirm the daily gem reward was claimed")
if not claimed_any:
print("[stamina] nothing to claim")
if navigation.is_on_subscreen(driver):
driver.keypress("Escape")
driver.wait(1.5)
print("[stamina] Done.")