2020-03-29 01:22:46 +08:00
|
|
|
from module.base.timer import Timer
|
|
|
|
|
from module.base.utils import red_overlay_transparency, get_color
|
2020-04-27 22:49:30 +08:00
|
|
|
from module.exception import CampaignEnd
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.handler.assets import *
|
2020-05-15 14:18:14 +08:00
|
|
|
from module.handler.info_handler import InfoHandler
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.logger import logger
|
2020-07-28 15:59:54 +08:00
|
|
|
from module.map.assets import *
|
2020-09-18 18:45:20 +08:00
|
|
|
from module.ui.assets import EVENT_CHECK, SP_CHECK, CAMPAIGN_CHECK
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
|
2020-05-15 14:18:14 +08:00
|
|
|
class EnemySearchingHandler(InfoHandler):
|
2020-03-29 01:22:46 +08:00
|
|
|
MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD = 0.5 # Usually (0.70, 0.80).
|
2020-04-30 17:11:47 +08:00
|
|
|
MAP_ENEMY_SEARCHING_TIMEOUT_SECOND = 5
|
2020-09-18 01:02:53 +08:00
|
|
|
in_stage_timer = Timer(0.5, count=2)
|
2020-06-17 17:56:10 +08:00
|
|
|
stage_entrance = None
|
2020-08-11 00:08:29 +08:00
|
|
|
|
|
|
|
|
map_is_clear = False # Will be override in fast_forward.py
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-04-17 23:35:20 +08:00
|
|
|
def enemy_searching_color_initial(self):
|
2020-03-29 01:22:46 +08:00
|
|
|
MAP_ENEMY_SEARCHING.load_color(self.device.image)
|
|
|
|
|
|
2020-04-15 15:14:35 +08:00
|
|
|
def enemy_searching_appear(self):
|
2020-03-29 01:22:46 +08:00
|
|
|
return red_overlay_transparency(
|
|
|
|
|
MAP_ENEMY_SEARCHING.color, get_color(self.device.image, MAP_ENEMY_SEARCHING.area)
|
|
|
|
|
) > self.MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD
|
|
|
|
|
|
2020-04-15 15:14:35 +08:00
|
|
|
def handle_enemy_flashing(self):
|
2020-04-17 23:35:20 +08:00
|
|
|
self.device.sleep(1.2)
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
def handle_in_stage(self):
|
2020-04-24 15:26:11 +08:00
|
|
|
if self.is_in_stage():
|
2020-04-24 17:57:40 +08:00
|
|
|
if self.in_stage_timer.reached():
|
|
|
|
|
logger.info('In stage.')
|
|
|
|
|
self.ensure_no_info_bar(timeout=1.2)
|
|
|
|
|
raise CampaignEnd('In stage.')
|
2020-04-27 22:49:30 +08:00
|
|
|
else:
|
|
|
|
|
return False
|
2020-03-29 01:22:46 +08:00
|
|
|
else:
|
2020-08-26 00:01:37 +08:00
|
|
|
if self.appear(MAP_PREPARATION) or self.appear(FLEET_PREPARATION):
|
|
|
|
|
self.device.click(MAP_PREPARATION_CANCEL)
|
2020-04-24 17:57:40 +08:00
|
|
|
self.in_stage_timer.reset()
|
2020-03-29 01:22:46 +08:00
|
|
|
return False
|
|
|
|
|
|
2020-04-24 15:26:11 +08:00
|
|
|
def is_in_stage(self):
|
2020-09-18 18:45:20 +08:00
|
|
|
appear = [self.appear(check, offset=(20, 20)) for check in [CAMPAIGN_CHECK, EVENT_CHECK, SP_CHECK]]
|
|
|
|
|
if not any(appear):
|
2020-06-17 17:56:10 +08:00
|
|
|
return False
|
2020-09-18 18:45:20 +08:00
|
|
|
|
2020-09-18 01:02:53 +08:00
|
|
|
# campaign_extract_name_image in CampaignOcr.
|
2020-09-20 00:22:29 +08:00
|
|
|
try:
|
|
|
|
|
if not len(self.campaign_extract_name_image(self.device.image)):
|
|
|
|
|
return False
|
|
|
|
|
except IndexError:
|
2020-06-17 17:56:10 +08:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
return True
|
2020-04-24 15:26:11 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def is_in_map(self):
|
|
|
|
|
return self.appear(IN_MAP)
|
|
|
|
|
|
|
|
|
|
def handle_in_map_with_enemy_searching(self):
|
|
|
|
|
if not self.is_in_map():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
timeout = Timer(self.MAP_ENEMY_SEARCHING_TIMEOUT_SECOND)
|
|
|
|
|
appeared = False
|
|
|
|
|
while 1:
|
2020-04-30 17:11:47 +08:00
|
|
|
if self.is_in_map():
|
|
|
|
|
timeout.start()
|
|
|
|
|
else:
|
|
|
|
|
timeout.reset()
|
|
|
|
|
|
2020-04-23 01:58:35 +08:00
|
|
|
if self.handle_in_stage():
|
|
|
|
|
return True
|
2020-04-29 17:45:35 +08:00
|
|
|
if self.handle_story_skip():
|
2020-05-22 21:48:56 +08:00
|
|
|
self.ensure_no_story()
|
2020-04-30 17:11:47 +08:00
|
|
|
timeout.limit = 10
|
2020-04-29 17:45:35 +08:00
|
|
|
timeout.reset()
|
2020-05-22 21:48:56 +08:00
|
|
|
|
|
|
|
|
# End
|
2020-04-15 15:14:35 +08:00
|
|
|
if self.enemy_searching_appear():
|
2020-03-29 01:22:46 +08:00
|
|
|
appeared = True
|
|
|
|
|
else:
|
|
|
|
|
if appeared:
|
2020-04-15 15:14:35 +08:00
|
|
|
self.handle_enemy_flashing()
|
2020-11-02 15:59:21 +08:00
|
|
|
self.device.sleep(1)
|
2020-06-16 17:51:34 +08:00
|
|
|
logger.info('Enemy searching appeared.')
|
2020-03-29 01:22:46 +08:00
|
|
|
break
|
2020-04-17 23:35:20 +08:00
|
|
|
self.enemy_searching_color_initial()
|
2020-03-29 01:22:46 +08:00
|
|
|
if timeout.reached():
|
|
|
|
|
logger.info('Enemy searching timeout.')
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
self.device.screenshot()
|
|
|
|
|
return True
|
|
|
|
|
|
2020-04-27 19:32:58 +08:00
|
|
|
def handle_in_map_no_enemy_searching(self):
|
2020-03-29 01:22:46 +08:00
|
|
|
if not self.is_in_map():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
self.device.sleep((1, 1.2))
|
|
|
|
|
return True
|