1
0
mirror of https://github.com/sui-feng-cb/AzurLaneAutoScript1.git synced 2026-08-06 17:36:44 +08:00

Chore: Abstract _meow_get_buy_count for testing

This commit is contained in:
LmeSzinc
2026-07-01 16:52:29 +08:00
parent 410ea1de3c
commit 21382ba6af
2 changed files with 56 additions and 15 deletions

View File

@@ -13,15 +13,15 @@ MEOWFFICER_COINS = Digit(OCR_MEOWFFICER_COINS, letter=(99, 69, 41), threshold=64
class MeowfficerBuy(MeowfficerBase): class MeowfficerBuy(MeowfficerBase):
def meow_get_buy_count(self) -> int: def meow_get_buy_count(self, buy_amount, overflow_th):
""" """
OCR remaining buys and coins, combine with user configs to decide OCR remaining buys and coins, combine with user configs to decide
how many meowfficer boxes to buy this run. how many meowfficer boxes to buy this run.
Baseline: buy up to Meowfficer_BuyAmount per day. Args:
Overflow: when Meowfficer_OverflowCoins is not -1 and current coins buy_amount (int): User configured purchase amount (Meowfficer_BuyAmount).
exceed it, keep buying extra boxes until coins drop to threshold or overflow_th (int): Coin overflow threshold (Meowfficer_OverflowCoins),
today's quota runs out. The 1st box per day is free. < 0 to disable overflow buy.
Pages: Pages:
in: page_meowfficer in: page_meowfficer
@@ -29,9 +29,16 @@ class MeowfficerBuy(MeowfficerBase):
Returns: Returns:
int: 0 to BUY_MAX, number of boxes to buy now. int: 0 to BUY_MAX, number of boxes to buy now.
""" """
self.device.screenshot() for _ in self.loop(timeout=2):
remain, bought, total = MEOWFFICER.ocr(self.device.image) remain, bought, total = MEOWFFICER.ocr(self.device.image)
coins = MEOWFFICER_COINS.ocr(self.device.image) coins = MEOWFFICER_COINS.ocr(self.device.image)
if total > 0:
break
# else: retry if MEOWFFICER has ocr error
else:
logger.warning('Failed to get meowfficer buy status')
return 0
logger.attr('Meowfficer_remain', remain) logger.attr('Meowfficer_remain', remain)
logger.attr('Meowfficer_coins', coins) logger.attr('Meowfficer_coins', coins)
@@ -40,19 +47,46 @@ class MeowfficerBuy(MeowfficerBase):
total = BUY_MAX total = BUY_MAX
bought = total - remain bought = total - remain
return self._meow_get_buy_count(bought, total, coins, buy_amount, overflow_th)
@staticmethod
def _meow_get_buy_count(bought, total, coins, buy_amount, overflow_th):
"""
Calculate how many meowfficer boxes to buy.
Baseline: buy up to Meowfficer_BuyAmount per day.
Overflow: when Meowfficer_OverflowCoins >= 0 and current coins
exceed it, keep buying extra boxes until coins drop to threshold or
today's quota runs out. The 1st box per day is free.
Args:
bought (int): Number of boxes already bought today.
total (int): Total available boxes per day (typically BUY_MAX=15).
coins (int): Current coins.
buy_amount (int): User configured purchase amount (Meowfficer_BuyAmount).
overflow_th (int): Coin overflow threshold (Meowfficer_OverflowCoins),
< 0 to disable overflow buy.
Returns:
int: 0 to BUY_MAX, number of boxes to buy now.
"""
today_left = max(0, total - bought) today_left = max(0, total - bought)
if today_left <= 0: if today_left <= 0:
logger.info(f'Already bought {bought}/{total} today, stopped') logger.info(f'Already bought {bought}/{total} today, stopped')
return 0 return 0
# Baseline buy # Baseline buy
baseline = min(max(0, self.config.Meowfficer_BuyAmount - bought), today_left) baseline = min(max(0, buy_amount - bought), today_left)
# Overflow buy # Overflow buy
overflow_th = self.config.Meowfficer_OverflowCoins
extra = 0 extra = 0
if overflow_th != -1 and coins > overflow_th: if overflow_th >= 0 and coins > overflow_th:
extra = -(-(coins - overflow_th) // BUY_PRIZE) if bought == 0:
# First box of the day is free, compensate so (extra-1)*BUY_PRIZE
# coins are spent, ensuring coins drop below overflow_th
extra = -(-(coins - overflow_th + BUY_PRIZE) // BUY_PRIZE)
else:
extra = -(-(coins - overflow_th) // BUY_PRIZE)
extra = min(extra, today_left - baseline) extra = min(extra, today_left - baseline)
extra = max(0, extra) extra = max(0, extra)
@@ -147,8 +181,15 @@ class MeowfficerBuy(MeowfficerBase):
out: page_meowfficer out: page_meowfficer
""" """
logger.hr('Meowfficer buy', level=1) logger.hr('Meowfficer buy', level=1)
count = self.meow_get_buy_count()
buy_amount = self.config.Meowfficer_BuyAmount
buy_amount = max(min(buy_amount, 15), 1)
overflow_th = self.config.Meowfficer_OverflowCoins
count = self.meow_get_buy_count(buy_amount, overflow_th)
if count <= 0: if count <= 0:
return return
self.meow_choose(count) self.meow_choose(count)
self.meow_confirm() self.meow_confirm()
logger.warning('Too many trial in meowfficer buy, stopped.')

View File

@@ -34,7 +34,7 @@ class RewardMeowfficer(MeowfficerBuy, MeowfficerFort, MeowfficerTrain):
out: page_meowfficer out: page_meowfficer
""" """
if self.config.Meowfficer_BuyAmount <= 0 \ if self.config.Meowfficer_BuyAmount <= 0 \
and self.config.Meowfficer_OverflowCoins == -1 \ and self.config.Meowfficer_OverflowCoins < 0 \
and not self.config.Meowfficer_FortChoreMeowfficer \ and not self.config.Meowfficer_FortChoreMeowfficer \
and not self.config.MeowfficerTrain_Enable: and not self.config.MeowfficerTrain_Enable:
self.config.Scheduler_Enable = False self.config.Scheduler_Enable = False
@@ -44,7 +44,7 @@ class RewardMeowfficer(MeowfficerBuy, MeowfficerFort, MeowfficerTrain):
self.wait_meowfficer_buttons() # Wait for the ui to load fully self.wait_meowfficer_buttons() # Wait for the ui to load fully
if self.config.Meowfficer_BuyAmount > 0 \ if self.config.Meowfficer_BuyAmount > 0 \
or self.config.Meowfficer_OverflowCoins != -1: or self.config.Meowfficer_OverflowCoins >= 0:
self.meow_buy() self.meow_buy()
if self.config.Meowfficer_FortChoreMeowfficer: if self.config.Meowfficer_FortChoreMeowfficer:
self.meow_fort() self.meow_fort()