Skip to content

Commit

Permalink
修复should_keep报错+改进状态转移异常处理 (#695)
Browse files Browse the repository at this point in the history
* 修复取消名称传入后端中改错的部分

* 增加重启游戏函数

* 修改重启模拟器函数返回值

* 改进场景转移异常的处理

来源mowerng

* 删除空的不养闲人任务

* 删除注释代码

* 格式化代码

* 修复合并bug

* 修复不生成非高效干员的不养闲人任务
  • Loading branch information
Anyk00 authored Oct 2, 2024
1 parent 0881f6c commit 76dac16
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
14 changes: 6 additions & 8 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ def plan_metadata(self):
_name = dorm.name
if _name == "":
continue
if self.op_data.operators[dorm.name].operator_type != "high":
continue
# 如果是rest in full,则新增单独任务..
if (
_name in self.op_data.operators.keys()
Expand Down Expand Up @@ -592,14 +590,14 @@ def plan_metadata(self):
def should_keep(task):
if task.type != TaskTypes.RELEASE_DORM:
return True
elif len(task.plan) == 0:
return False
name = task.meta_data
for key, value in task.plan.items():
dorm_name = key
dorm_op = value
break
free_room = list(task.plan.keys())[0]
free_op = task.plan[free_room]
if (
self.op_data.operators[name].current_room != dorm_name
or dorm_op[self.op_data.operators[name].current_index] != "Free"
self.op_data.operators[name].current_room != free_room
or free_op[self.op_data.operators[name].current_index] != "Free"
):
logger.info(f"检测到{task.meta_data}不在对应位置,移除相关任务")
return False
Expand Down
26 changes: 22 additions & 4 deletions arknights_mower/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ class SceneGraphSolver(BaseSolver):
def scene_graph_navigation(self, scene: int):
if scene not in DG.nodes:
logger.error(f"{SceneComment[scene]}不在场景图中")
return False
return

error_count = 0

while (current := self.scene()) != scene:
if current in self.waiting_scene:
Expand All @@ -453,7 +455,7 @@ def scene_graph_navigation(self, scene: int):
self.device.start_droidcast()
if config.conf.touch_method == "scrcpy":
self.device.control.scrcpy = Scrcpy(self.device.client)
return False
return

logger.debug(sp)

Expand All @@ -462,11 +464,12 @@ def scene_graph_navigation(self, scene: int):

try:
transition(self)
error_count = 0
except MowerExit:
raise
except Exception as e:
logger.exception(f"场景转移异常:{e}")
restart_simulator()
"""restart_simulator()
self.device.client.check_server_alive()
Session().connect(config.conf.adb)
if config.conf.droidcast.enable:
Expand All @@ -475,7 +478,22 @@ def scene_graph_navigation(self, scene: int):
self.device.control.scrcpy = Scrcpy(self.device.client)
self.check_current_focus()
return False
return True
return True"""
if error_count <= 5:
self.sleep()
error_count += 1
continue
if restart_simulator():
self.device.client.check_server_alive()
Session().connect(config.conf.adb)
if config.conf.droidcast.enable:
self.device.start_droidcast()
if config.conf.touch_method == "scrcpy":
self.device.control.scrcpy = Scrcpy(self.device.client)
self.check_current_focus()
else:
self.restart_game()
error_count = 0

def back_to_index(self):
logger.info("场景图导航:back_to_index")
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/utils/scheduler_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def merge_release_dorm(tasks, merge_interval):
if last_not_release is not None:
continue
elif task.time + timedelta(minutes=merge_interval) > tasks[-idx + 1].time:
task.time = tasks[-idx + 1].time + timedelta(seconds=1)
tasks[-idx].time = tasks[-idx + 1].time + timedelta(seconds=1)
tasks[-idx], tasks[-idx + 1] = (
tasks[-idx + 1],
tasks[-idx],
Expand Down
3 changes: 2 additions & 1 deletion arknights_mower/utils/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def restart_simulator(stop=True, start=True):
if simulator_type not in [types.value for types in Simulator_Type]:
logger.warning(f"尚未支持{simulator_type}重启/自动启动")
csleep(10)
return
return False

if simulator_type == Simulator_Type.Nox.value:
cmd = "Nox.exe"
Expand Down Expand Up @@ -95,6 +95,7 @@ def restart_simulator(stop=True, start=True):

pyautogui.FAILSAFE = False
pyautogui.hotkey(*hotkey)
return True


def exec_cmd(cmd, folder_path, wait_time, blocking):
Expand Down
5 changes: 5 additions & 0 deletions arknights_mower/utils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def ctap(self, pos: tp.Location, max_seconds: int = 10):
def check_current_focus(self):
self.recog.check_current_focus()

def restart_game(self):
self.device.exit()
self.device.launch()
self.recog.update()

def tap_element(
self,
element_name: tp.Res,
Expand Down

0 comments on commit 76dac16

Please sign in to comment.