mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-07-25 21:42:12 +08:00
Opt: share screenshot for oil and coin reading, and cache limit
This commit is contained in:
@@ -62,35 +62,6 @@ class CampaignStatus(UI):
|
||||
self.config.update()
|
||||
return pt
|
||||
|
||||
def get_coin(self, skip_first_screenshot=True, update=False):
|
||||
"""
|
||||
Returns:
|
||||
int: Coin amount
|
||||
"""
|
||||
_coin = {}
|
||||
timeout = Timer(1, count=2).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if timeout.reached():
|
||||
logger.warning('Get coin timeout')
|
||||
break
|
||||
|
||||
_coin = {
|
||||
'Value': self._get_num(OCR_COIN, 'OCR_COIN', (239, 239, 239)),
|
||||
'Limit': self._get_num(OCR_COIN_LIMIT, 'OCR_COIN_LIMIT', (239, 239, 239))
|
||||
}
|
||||
if _coin['Value'] >= 100:
|
||||
break
|
||||
LogRes(self.config).Coin = _coin
|
||||
if update:
|
||||
self.config.update()
|
||||
|
||||
return _coin['Value']
|
||||
|
||||
def _get_num(self, _button, name, letter):
|
||||
# Update offset
|
||||
_ = self.appear(OCR_OIL_CHECK)
|
||||
@@ -120,13 +91,33 @@ class CampaignStatus(UI):
|
||||
|
||||
return ocr.ocr(self.device.image)
|
||||
|
||||
def _get_oil_limit(self):
|
||||
if not hasattr(self, '_oil_limit_cache'):
|
||||
limit = self._get_num(OCR_OIL_LIMIT, 'OCR_OIL_LIMIT', (247, 247, 247))
|
||||
if 1000 < limit <= 25000:
|
||||
self._oil_limit_cache = limit
|
||||
else:
|
||||
logger.warning(f'Invalid oil limit: {limit}')
|
||||
return 0
|
||||
return self._oil_limit_cache
|
||||
|
||||
def _get_coin_limit(self):
|
||||
if not hasattr(self, '_coin_limit_cache'):
|
||||
limit = self._get_num(OCR_COIN_LIMIT, 'OCR_COIN_LIMIT', (239, 239, 239))
|
||||
if 10000 < limit <= 150000:
|
||||
self._coin_limit_cache = limit
|
||||
else:
|
||||
logger.warning(f'Invalid coin limit: {limit}')
|
||||
return 0
|
||||
return self._coin_limit_cache
|
||||
|
||||
def get_oil(self, skip_first_screenshot=True, update=False):
|
||||
"""
|
||||
Returns:
|
||||
int: Oil amount
|
||||
"""
|
||||
_oil = {}
|
||||
last = 0
|
||||
oil = 0
|
||||
last_oil = 0
|
||||
timeout = Timer(1, count=2).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
@@ -136,24 +127,40 @@ class CampaignStatus(UI):
|
||||
|
||||
if not self.appear(OCR_OIL_CHECK, offset=(10, 2)):
|
||||
logger.info('No oil icon')
|
||||
self.device.sleep(1)
|
||||
continue
|
||||
|
||||
if timeout.reached():
|
||||
logger.warning('Get oil timeout')
|
||||
oil = 0
|
||||
break
|
||||
|
||||
_oil = {
|
||||
'Value': self._get_num(OCR_OIL, 'OCR_OIL', (247, 247, 247)),
|
||||
'Limit': self._get_num(OCR_OIL_LIMIT, 'OCR_OIL_LIMIT', (247, 247, 247))
|
||||
}
|
||||
if last == _oil['Value'] and _oil['Value'] >= 100 and _oil['Limit'] <= 50000:
|
||||
oil = self._get_num(OCR_OIL, 'OCR_OIL', (247, 247, 247))
|
||||
if last_oil == oil and oil >= 100:
|
||||
break
|
||||
last = _oil['Value']
|
||||
LogRes(self.config).Oil = _oil
|
||||
last_oil = oil
|
||||
|
||||
if oil:
|
||||
LogRes(self.config).Oil = {'Value': oil, 'Limit': self._get_oil_limit()}
|
||||
if update:
|
||||
self.config.update()
|
||||
|
||||
return _oil['Value']
|
||||
return oil
|
||||
|
||||
def get_oil_and_coin(self, skip_first_screenshot=True, update=False):
|
||||
"""
|
||||
Read oil and coin sharing a single screenshot.
|
||||
|
||||
Returns:
|
||||
tuple[int, int]: (oil, coin)
|
||||
"""
|
||||
oil = self.get_oil(skip_first_screenshot=skip_first_screenshot, update=False)
|
||||
coin = 0
|
||||
if oil:
|
||||
coin = self._get_num(OCR_COIN, 'OCR_COIN', (239, 239, 239))
|
||||
LogRes(self.config).Coin = {'Value': coin, 'Limit': self._get_coin_limit()}
|
||||
if update:
|
||||
self.config.update()
|
||||
return oil, coin
|
||||
|
||||
def is_balancer_task(self):
|
||||
"""
|
||||
|
||||
@@ -99,8 +99,7 @@ class CampaignRun(CampaignEvent, ShopStatus):
|
||||
# Oil limit
|
||||
if oil_check:
|
||||
self.status_get_gems()
|
||||
self.get_coin()
|
||||
_oil = self.get_oil()
|
||||
_oil, _ = self.get_oil_and_coin()
|
||||
if _oil < max(500, self.config.StopCondition_OilLimit):
|
||||
logger.hr('Triggered stop condition: Oil limit')
|
||||
self.config.task_delay(minute=60)
|
||||
|
||||
Reference in New Issue
Block a user