Skip to content

Commit

Permalink
#334 模拟宇宙结算指令 增加兼容所有场景 保证退出
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Jun 16, 2024
1 parent 319bdb1 commit a2eb1fd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/sr/sim_uni/op/sim_uni_battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def _handle_not_in_world(self, screen: MatLike) -> OperationOneRoundResult:
curio=True,
empty_to_close=True,
fast_recover=True, # 目前黄泉连续使用秘技时 弹出快速恢复的话 会触发祝福 因此处理完祝福 还需要处理快速恢复
express_supply=True
)
if state == ScreenState.SIM_BLESS.value:
return self._choose_bless()
Expand Down
31 changes: 30 additions & 1 deletion src/sr/sim_uni/op/sim_uni_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

from basic.i18_utils import gt
from sr.context import Context
from sr.image.sceenshot import screen_state
from sr.image.sceenshot.screen_state_enum import ScreenState
from sr.operation import Operation, OperationOneRoundResult, StateOperation, StateOperationEdge, StateOperationNode
from sr.screen_area.screen_sim_uni import ScreenSimUni
from sr.sim_uni.op.sim_uni_battle import SimUniEnterFight


class SimUniExit(StateOperation):
Expand All @@ -18,7 +21,11 @@ def __init__(self, ctx: Context):
"""
edges: List[StateOperationEdge] = []

check_screen = StateOperationNode('检测画面', self._check_screen)

open_menu = StateOperationNode('打开菜单', self._open_menu)
edges.append(StateOperationEdge(check_screen, open_menu))

click_exit = StateOperationNode('点击结算', self._click_exit)
edges.append(StateOperationEdge(open_menu, click_exit))
edges.append(StateOperationEdge(click_exit, open_menu, status=SimUniExit.STATUS_BACK_MENU))
Expand All @@ -34,7 +41,7 @@ def __init__(self, ctx: Context):
(gt('模拟宇宙', 'ui'),
gt('结束并结算', 'ui')),
edges=edges,
specified_start_node=open_menu
specified_start_node=check_screen
)

def _init_before_execute(self):
Expand All @@ -43,6 +50,28 @@ def _init_before_execute(self):
"""
super()._init_before_execute()

def _check_screen(self) -> OperationOneRoundResult:
"""
检查屏幕
这个指令作为兜底的退出模拟宇宙的指令 应该兼容当前处于模拟宇宙的任何一种场景
:return:
"""
screen = self.screenshot()
state = screen_state.get_sim_uni_screen_state(
screen, self.ctx.im, self.ctx.ocr,
in_world=True,
battle=True
)
if state == ScreenState.NORMAL_IN_WORLD.value: # 只有在大世界画面才继续
return self.round_success()
else: # 其他情况 统一交给 battle 处理
op = SimUniEnterFight(self.ctx)
op_result = op.execute()
if op_result.success:
return self.round_wait() # 重新判断
else:
return self.round_retry()

def _open_menu(self) -> OperationOneRoundResult:
"""
打开菜单 或者 战斗中的打开退出
Expand Down

0 comments on commit a2eb1fd

Please sign in to comment.