mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-07-04 03:56:27 +08:00
Chore: Abstract _meow_get_buy_count for testing
This commit is contained in:
@@ -13,15 +13,15 @@ MEOWFFICER_COINS = Digit(OCR_MEOWFFICER_COINS, letter=(99, 69, 41), threshold=64
|
||||
|
||||
|
||||
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
|
||||
how many meowfficer boxes to buy this run.
|
||||
|
||||
Baseline: buy up to Meowfficer_BuyAmount per day.
|
||||
Overflow: when Meowfficer_OverflowCoins is not -1 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:
|
||||
buy_amount (int): User configured purchase amount (Meowfficer_BuyAmount).
|
||||
overflow_th (int): Coin overflow threshold (Meowfficer_OverflowCoins),
|
||||
< 0 to disable overflow buy.
|
||||
|
||||
Pages:
|
||||
in: page_meowfficer
|
||||
@@ -29,9 +29,16 @@ class MeowfficerBuy(MeowfficerBase):
|
||||
Returns:
|
||||
int: 0 to BUY_MAX, number of boxes to buy now.
|
||||
"""
|
||||
self.device.screenshot()
|
||||
remain, bought, total = MEOWFFICER.ocr(self.device.image)
|
||||
coins = MEOWFFICER_COINS.ocr(self.device.image)
|
||||
for _ in self.loop(timeout=2):
|
||||
remain, bought, total = MEOWFFICER.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_coins', coins)
|
||||
|
||||
@@ -40,19 +47,46 @@ class MeowfficerBuy(MeowfficerBase):
|
||||
total = BUY_MAX
|
||||
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)
|
||||
if today_left <= 0:
|
||||
logger.info(f'Already bought {bought}/{total} today, stopped')
|
||||
return 0
|
||||
|
||||
# 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_th = self.config.Meowfficer_OverflowCoins
|
||||
extra = 0
|
||||
if overflow_th != -1 and coins > overflow_th:
|
||||
extra = -(-(coins - overflow_th) // BUY_PRIZE)
|
||||
if overflow_th >= 0 and coins > overflow_th:
|
||||
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 = max(0, extra)
|
||||
|
||||
@@ -147,8 +181,15 @@ class MeowfficerBuy(MeowfficerBase):
|
||||
out: page_meowfficer
|
||||
"""
|
||||
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:
|
||||
return
|
||||
self.meow_choose(count)
|
||||
self.meow_confirm()
|
||||
|
||||
logger.warning('Too many trial in meowfficer buy, stopped.')
|
||||
|
||||
@@ -34,7 +34,7 @@ class RewardMeowfficer(MeowfficerBuy, MeowfficerFort, MeowfficerTrain):
|
||||
out: page_meowfficer
|
||||
"""
|
||||
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.MeowfficerTrain_Enable:
|
||||
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
|
||||
|
||||
if self.config.Meowfficer_BuyAmount > 0 \
|
||||
or self.config.Meowfficer_OverflowCoins != -1:
|
||||
or self.config.Meowfficer_OverflowCoins >= 0:
|
||||
self.meow_buy()
|
||||
if self.config.Meowfficer_FortChoreMeowfficer:
|
||||
self.meow_fort()
|
||||
|
||||
Reference in New Issue
Block a user