2020-03-31 14:16:21 +00:00
|
|
|
from datetime import datetime, time
|
|
|
|
|
2020-04-10 06:18:10 +00:00
|
|
|
from module.device.app import AppControl
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.device.control import Control
|
|
|
|
from module.device.screenshot import Screenshot
|
2020-03-31 14:16:21 +00:00
|
|
|
from module.handler.assets import GET_MISSION
|
|
|
|
from module.logger import logger
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
|
2020-04-10 06:18:10 +00:00
|
|
|
class Device(Screenshot, Control, AppControl):
|
2020-05-30 19:33:51 +00:00
|
|
|
_screen_size_checked = False
|
|
|
|
|
2020-05-05 14:04:36 +00:00
|
|
|
def handle_night_commission(self, hour=21, threshold=30):
|
2020-03-31 14:16:21 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
hour (int): Hour that night commission refresh.
|
|
|
|
threshold (int): Seconds around refresh time.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: If handled.
|
|
|
|
"""
|
|
|
|
now = datetime.now().time()
|
|
|
|
if now < time(hour - 1, 59, 60 - threshold):
|
|
|
|
return False
|
|
|
|
if now > time(hour, 0, threshold):
|
|
|
|
return False
|
|
|
|
|
2020-05-05 14:04:36 +00:00
|
|
|
if GET_MISSION.match(self.image, offset=True):
|
|
|
|
logger.info('Night commission appear.')
|
|
|
|
self.click(GET_MISSION)
|
|
|
|
return True
|
2020-03-31 14:16:21 +00:00
|
|
|
|
2020-05-05 14:04:36 +00:00
|
|
|
return False
|
2020-03-31 14:16:21 +00:00
|
|
|
|
|
|
|
def screenshot(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
PIL.Image.Image:
|
|
|
|
"""
|
2020-05-05 14:04:36 +00:00
|
|
|
super().screenshot()
|
|
|
|
if self.handle_night_commission():
|
|
|
|
super().screenshot()
|
2020-04-06 17:52:47 +00:00
|
|
|
|
2020-05-30 19:33:51 +00:00
|
|
|
if not self._screen_size_checked:
|
|
|
|
self.check_screen_size()
|
|
|
|
self._screen_size_checked = True
|
|
|
|
|
2020-05-05 14:04:36 +00:00
|
|
|
return self.image
|
2020-05-30 19:33:51 +00:00
|
|
|
|
|
|
|
def check_screen_size(self):
|
|
|
|
"""
|
|
|
|
Screen size must be 1280x720, if not exit.
|
|
|
|
Take a screenshot before call.
|
|
|
|
"""
|
|
|
|
width, height = self.image.size
|
|
|
|
if height > width:
|
|
|
|
width, height = height, width
|
|
|
|
|
|
|
|
logger.attr('Screen_size', f'{width}x{height}')
|
|
|
|
|
|
|
|
if width == 1280 and height == 720:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
logger.warning(f'Not supported screen size: {width}x{height}')
|
|
|
|
logger.warning('Alas requires 1280x720')
|
|
|
|
logger.hr('Script end')
|
|
|
|
exit(1)
|