Add: Loop rogue domains

This commit is contained in:
LmeSzinc 2023-10-07 23:20:28 +08:00
parent d04ca2c3c6
commit 7a22c2394f
3 changed files with 55 additions and 5 deletions

View File

@ -277,7 +277,7 @@ class UI( MainPage):
def is_in_main(self): def is_in_main(self):
if self.appear(page_main.check_button): if self.appear(page_main.check_button):
if self.image_color_count(page_main.check_button, color=(235, 235, 235), threshold=221, count=400): if self.image_color_count(page_main.check_button, color=(235, 235, 235), threshold=234, count=400):
return True return True
if self.appear(MAP_EXIT): if self.appear(MAP_EXIT):
if self.image_color_count(MAP_EXIT, color=(235, 235, 235), threshold=221, count=50): if self.image_color_count(MAP_EXIT, color=(235, 235, 235), threshold=221, count=50):

View File

@ -1,3 +1,6 @@
from module.base.button import ClickButton
from module.base.timer import Timer
from module.base.utils import area_offset
from module.logger import logger from module.logger import logger
from tasks.base.page import page_rogue from tasks.base.page import page_rogue
from tasks.map.control.waypoint import ensure_waypoints from tasks.map.control.waypoint import ensure_waypoints
@ -62,6 +65,7 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
out: is_in_main() out: is_in_main()
""" """
logger.info('Clear blessing') logger.info('Clear blessing')
switched = False
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
skip_first_screenshot = False skip_first_screenshot = False
@ -71,9 +75,12 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
# End # End
if self.is_in_main(): if self.is_in_main():
logger.info(f'clear_blessing() ended at page_main') logger.info(f'clear_blessing() ended at page_main')
if switched:
self.wait_until_minimap_stabled()
break break
if self.handle_blessing(): if self.handle_blessing():
switched = True
continue continue
def clear_occurrence(self, skip_first_screenshot=True): def clear_occurrence(self, skip_first_screenshot=True):
@ -114,6 +121,13 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
self.clear_blessing() self.clear_blessing()
return result return result
def wait_until_minimap_stabled(self):
logger.info('Wait until minimap stabled')
radius = self.minimap.MINIMAP_RADIUS
area = area_offset((-radius, -radius, radius, radius), offset=self.minimap.MINIMAP_CENTER)
minimap = ClickButton(area, name='MINIMAP')
self.wait_until_stable(minimap, timeout=Timer(1.5, count=5))
""" """
Additional rogue methods Additional rogue methods
""" """
@ -215,6 +229,7 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
# End # End
if self.is_in_main(): if self.is_in_main():
logger.info('Entered another domain') logger.info('Entered another domain')
self.wait_until_minimap_stabled()
break break
if self.ui_page_appear(page_rogue): if self.ui_page_appear(page_rogue):
logger.info('Rogue cleared') logger.info('Rogue cleared')
@ -271,6 +286,7 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
end_point.expected_end.append(self._domain_exit_expected_end) end_point.expected_end.append(self._domain_exit_expected_end)
end_point.lock_direction = direction end_point.lock_direction = direction
self.goto(end_point) self.goto(end_point)
self._domain_exit_wait_next()
return result return result

View File

@ -5,6 +5,7 @@ import numpy as np
from module.base.decorator import cached_property from module.base.decorator import cached_property
from module.logger import logger from module.logger import logger
from tasks.base.main_page import MainPage from tasks.base.main_page import MainPage
from tasks.base.page import page_rogue
from tasks.map.keywords import MapPlane from tasks.map.keywords import MapPlane
from tasks.map.keywords.plane import ( from tasks.map.keywords.plane import (
Herta_MasterControlZone, Herta_MasterControlZone,
@ -29,7 +30,7 @@ def model_from_json(model, file: str):
class MinimapWrapper: class MinimapWrapper:
@cached_property @cached_property
def all_minimap(self) -> dict[(str, str), Minimap]: def all_minimap(self) -> dict[str, Minimap]:
""" """
Returns: Returns:
dict: Key: {world}_{plane}_{floor}, e.g. Jarilo_SilvermaneGuardRestrictedZone_F1 dict: Key: {world}_{plane}_{floor}, e.g. Jarilo_SilvermaneGuardRestrictedZone_F1
@ -161,16 +162,51 @@ class RouteLoader(MinimapWrapper, RouteLoader_, MainPage):
""" """
Run a rogue domain Run a rogue domain
Returns:
bool: True if success, False if route unknown
Pages: Pages:
in: page_main in: page_main
out: page_main, at another domain out: page_main, at another domain
or page_rogue if rogue cleared
""" """
route = self.position_find_known(self.device.image) route = self.position_find_known(self.device.image)
if route is not None: if route is not None:
super().route_run(route) super().route_run(route)
return True
else: else:
self.position_find_bruteforce(self.device.image) self.position_find_bruteforce(self.device.image)
logger.error('New route detected, please record it') logger.error('New route detected, please record it')
return False
def rogue_run(self, skip_first_screenshot=True):
"""
Do a complete rogue run, no error handle yet.
Pages:
in: page_rogue, LAUNCH_SIMULATED_UNIVERSE
out: page_rogue, world selecting page
"""
base = RouteBase(config=self.config, device=self.device, task=self.config.task.command)
count = 1
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
logger.hr(f'Route run: {count}', level=1)
base.clear_blessing()
success = self.route_run()
if not success:
# self.device.image_save()
continue
# End
if self.ui_page_appear(page_rogue):
break
count += 1
if __name__ == '__main__': if __name__ == '__main__':
@ -180,6 +216,4 @@ if __name__ == '__main__':
# self.position_find_bruteforce(self.device.image) # self.position_find_bruteforce(self.device.image)
self.device.screenshot() self.device.screenshot()
base = RouteBase(config=self.config, device=self.device, task='Rogue') self.rogue_run()
base.clear_blessing()
self.route_run()