2020-03-28 17:22:46 +00:00
|
|
|
from module.base.timer import Timer
|
|
|
|
from module.base.utils import red_overlay_transparency, get_color
|
2020-04-27 14:49:30 +00:00
|
|
|
from module.exception import CampaignEnd
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.handler.assets import *
|
2020-05-15 06:18:14 +00:00
|
|
|
from module.handler.info_handler import InfoHandler
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.logger import logger
|
|
|
|
|
|
|
|
|
2020-05-15 06:18:14 +00:00
|
|
|
class EnemySearchingHandler(InfoHandler):
|
2020-03-28 17:22:46 +00:00
|
|
|
MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD = 0.5 # Usually (0.70, 0.80).
|
2020-04-30 09:11:47 +00:00
|
|
|
MAP_ENEMY_SEARCHING_TIMEOUT_SECOND = 5
|
2020-05-29 09:22:19 +00:00
|
|
|
in_stage_timer = Timer(1.5, count=5)
|
2020-06-17 09:56:10 +00:00
|
|
|
stage_entrance = None
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-17 15:35:20 +00:00
|
|
|
def enemy_searching_color_initial(self):
|
2020-03-28 17:22:46 +00:00
|
|
|
MAP_ENEMY_SEARCHING.load_color(self.device.image)
|
|
|
|
|
2020-04-15 07:14:35 +00:00
|
|
|
def enemy_searching_appear(self):
|
2020-03-28 17:22:46 +00: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 07:14:35 +00:00
|
|
|
def handle_enemy_flashing(self):
|
2020-04-17 15:35:20 +00:00
|
|
|
self.device.sleep(1.2)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
def handle_in_stage(self):
|
2020-04-24 07:26:11 +00:00
|
|
|
if self.is_in_stage():
|
2020-04-24 09:57:40 +00: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 14:49:30 +00:00
|
|
|
else:
|
|
|
|
return False
|
2020-03-28 17:22:46 +00:00
|
|
|
else:
|
2020-04-24 09:57:40 +00:00
|
|
|
self.in_stage_timer.reset()
|
2020-03-28 17:22:46 +00:00
|
|
|
return False
|
|
|
|
|
2020-04-24 07:26:11 +00:00
|
|
|
def is_in_stage(self):
|
2020-06-17 09:56:10 +00:00
|
|
|
if not self.appear(IN_STAGE, offset=(10, 10)):
|
|
|
|
return False
|
|
|
|
if self.stage_entrance is not None and not self.appear(self.stage_entrance, threshold=30):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2020-04-24 07:26:11 +00:00
|
|
|
|
2020-03-28 17:22:46 +00: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 09:11:47 +00:00
|
|
|
if self.is_in_map():
|
|
|
|
timeout.start()
|
|
|
|
else:
|
|
|
|
timeout.reset()
|
|
|
|
|
2020-04-22 17:58:35 +00:00
|
|
|
if self.handle_in_stage():
|
|
|
|
return True
|
2020-04-29 09:45:35 +00:00
|
|
|
if self.handle_story_skip():
|
2020-05-22 13:48:56 +00:00
|
|
|
self.ensure_no_story()
|
2020-04-30 09:11:47 +00:00
|
|
|
timeout.limit = 10
|
2020-04-29 09:45:35 +00:00
|
|
|
timeout.reset()
|
2020-05-22 13:48:56 +00:00
|
|
|
|
|
|
|
# End
|
2020-04-15 07:14:35 +00:00
|
|
|
if self.enemy_searching_appear():
|
2020-03-28 17:22:46 +00:00
|
|
|
appeared = True
|
|
|
|
else:
|
|
|
|
if appeared:
|
2020-04-15 07:14:35 +00:00
|
|
|
self.handle_enemy_flashing()
|
2020-03-28 17:22:46 +00:00
|
|
|
self.device.sleep(0.3)
|
2020-06-16 09:51:34 +00:00
|
|
|
logger.info('Enemy searching appeared.')
|
2020-03-28 17:22:46 +00:00
|
|
|
break
|
2020-04-17 15:35:20 +00:00
|
|
|
self.enemy_searching_color_initial()
|
2020-03-28 17:22:46 +00:00
|
|
|
if timeout.reached():
|
|
|
|
logger.info('Enemy searching timeout.')
|
|
|
|
break
|
|
|
|
|
|
|
|
self.device.screenshot()
|
|
|
|
return True
|
|
|
|
|
2020-04-27 11:32:58 +00:00
|
|
|
def handle_in_map_no_enemy_searching(self):
|
2020-03-28 17:22:46 +00:00
|
|
|
if not self.is_in_map():
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.device.sleep((1, 1.2))
|
|
|
|
return True
|