Skip to content

Commit

Permalink
#337 位面饰品提取 测试完成
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Jun 22, 2024
1 parent e356a13 commit dc273fe
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 143 deletions.
31 changes: 25 additions & 6 deletions src/gui/settings/settings_trailblaze_power_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ def __init__(self, ctx: Context,
plan_times=1, run_times=0,
team_num=1 if history is None else history['team_num'],
support='none' if history is None else history['support'])
self.category_dropdown = ft.Dropdown(options=[
ft.dropdown.Option(text=i.value.ui_cn, key=i.value.ui_cn)
for i in GuideCategoryEnum
if i not in [GuideCategoryEnum.ECHO_OF_WAR, GuideCategoryEnum.SU_SIM_UNI, GuideCategoryEnum.SU_OE]
],
self.category_dropdown = ft.Dropdown(
options=[
ft.dropdown.Option(text=i.value.ui_cn, key=i.value.ui_cn)
for i in GuideCategoryEnum
if i not in [GuideCategoryEnum.ECHO_OF_WAR, GuideCategoryEnum.SU_SIM_UNI, GuideCategoryEnum.SU_OE]
],
label='类目', width=100, on_change=self._on_category_changed)
self.tp_dropdown = ft.Dropdown(label='挑战关卡', width=180, on_change=self._on_tp_changed)
self.team_num_dropdown = ft.Dropdown(options=[ft.dropdown.Option(text=str(i), key=str(i)) for i in range(1, 10)],
self.team_num_dropdown = ft.Dropdown(options=[ft.dropdown.Option(text=str(i), key=str(i)) for i in range(10)],
label='使用配队', width=80, on_change=self._on_team_num_changed)
self.support_dropdown = ft.Dropdown(label='支援', value='none', disabled=True, width=80,
options=[ft.dropdown.Option(text='无', key='none')])
Expand All @@ -56,6 +57,7 @@ def __init__(self, ctx: Context,

self.category_dropdown.value = self.chosen_point.cate.ui_cn
self._update_tp_dropdown_list()
self.auto_set_team_dropdown_label()
self.tp_dropdown.value = self.chosen_point.unique_id
self.team_num_dropdown.value = self.value['team_num']
self.support_dropdown.value = self.value['support']
Expand All @@ -80,8 +82,25 @@ def _update_tp_dropdown_list(self):
self.tp_dropdown.options = [ft.dropdown.Option(text=i.ui_cn, key=i.unique_id) for i in point_list]
self.tp_dropdown.value = self.tp_dropdown.options[0].key

def auto_set_team_dropdown_label(self) -> None:
"""
根据选项 自动设置配队下拉框的文本
:return:
"""
team_num_label = '使用配队'
if self.category_dropdown.value == GuideCategoryEnum.ORNAMENT_EXTRACTION.value.ui_cn:
team_num_label = '使用存档'
self.team_num_dropdown.label = gt(team_num_label, 'ui')

def _on_category_changed(self, e):
"""
更改类别后的回调
:param e:
:return:
"""
self._update_tp_dropdown_list()
self.auto_set_team_dropdown_label()

self.plan_times_input.value = 1
self.run_times_input.value = 0
self._load_history()
Expand Down
41 changes: 32 additions & 9 deletions src/sr/app/trailblaze_power/trailblaze_power_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sr.const import phone_menu_const
from sr.const.map_const import TransportPoint
from sr.context import Context
from sr.div_uni.op.ornamenet_extraction import ChallengeOrnamentExtraction
from sr.operation import StateOperationNode, StateOperationEdge, OperationOneRoundResult
from sr.operation.combine.use_trailblaze_power import UseTrailblazePower
from sr.operation.common.back_to_normal_world_plus import BackToNormalWorldPlus
Expand Down Expand Up @@ -52,7 +53,7 @@ def __init__(self, ctx: Context):

execute = StateOperationNode('执行开拓力计划', self._execute_plan)
edges.append(StateOperationEdge(check_power, execute))
edges.append(StateOperationEdge(execute, check_task)) # 循环挑战
edges.append(StateOperationEdge(execute, execute)) # 循环挑战

back = StateOperationNode('完成后返回大世界', op=BackToNormalWorldPlus(ctx))
edges.append(StateOperationEdge(execute, back, status=TrailblazePower.STATUS_NO_ENOUGH_POWER))
Expand Down Expand Up @@ -96,9 +97,6 @@ def _check_power(self) -> OperationOneRoundResult:
识别开拓力和沉浸器
:return:
"""
if self.qty is not None:
return self.round_success()

ops = [
OpenPhoneMenu(self.ctx),
ClickPhoneMenuItem(self.ctx, phone_menu_const.INTERASTRAL_GUIDE),
Expand Down Expand Up @@ -156,21 +154,29 @@ def _execute_plan(self) -> OperationOneRoundResult:

self.ctx.sim_uni_run_record.check_and_update_status()

if isinstance(mission.tp, TransportPoint):
if mission.tp is not None:
op = UseTrailblazePower(self.ctx, mission, plan['team_num'], run_times,
support=plan['support'] if plan['support'] != 'none' else None,
on_battle_success=self._on_normal_task_success,
need_transport=mission != self.last_mission)
elif isinstance(mission.tp, SimUniWorld):
elif mission.sim_world is not None:
op = SimUniApp(self.ctx,
specified_uni_num=mission.tp.idx,
specified_uni_num=mission.sim_world.idx,
max_reward_to_get=can_run_times,
get_reward_callback=self._on_sim_uni_get_reward
)
op.init_context_before_start = False
op.stop_context_after_stop = False
elif isinstance(mission.tp, OrnamentExtraction):
pass
elif mission.ornament_extraction is not None:
op = ChallengeOrnamentExtraction(self.ctx, mission.ornament_extraction,
run_times=run_times,
diff=0,
file_num=plan['team_num'],
support_character=plan['support'] if plan['support'] != 'none' else None,
get_reward_callback=self.on_oe_get_reward)
else:
return self.round_fail('未知副本类型')

self.last_mission = mission
return self.round_by_op(op.execute())

Expand Down Expand Up @@ -199,3 +205,20 @@ def _on_sim_uni_get_reward(self, use_power: int, user_qty: int):

self.power -= use_power
self.qty -= user_qty

def on_oe_get_reward(self, qty: int):
"""
饰品提取 获取奖励后的回调
:return:
"""
log.info('饰品提取获取奖励 次数 %d', qty)
plan: Optional[TrailblazePowerPlanItem] = self.ctx.tp_config.next_plan_item
mission: Optional[GuideMission] = GuideMissionEnum.get_by_unique_id(plan['mission_id'])
for _ in range(qty):
if self.qty > 0: # 优先使用沉浸器
self.qty -= 1
elif self.power >= mission.power:
self.power -= mission.power

plan['run_times'] += 1
self.ctx.tp_config.save()
47 changes: 31 additions & 16 deletions src/sr/div_uni/op/choose_oe_file.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import time
from typing import Optional

from basic import str_utils
from basic.i18_utils import gt
from sr.context import Context
from basic.img import cv2_utils
from sr.context import Context, get_context
from sr.div_uni.screen_div_uni import ScreenDivUni
from sr.operation import StateOperation, OperationOneRoundResult, StateOperationNode, Operation
from sr.screen_area.screen_phone_menu import ScreenPhoneMenu


class ChooseOeFile(StateOperation):

def __init__(self, ctx: Context, num: int):
"""
选择存档
选择存档 最终返回【位面饰品提取】画面
"""
super().__init__(ctx, op_name=gt('选择存档', 'ui'))

Expand Down Expand Up @@ -68,22 +71,16 @@ def check_screen(self) -> OperationOneRoundResult:
if self.find_area(area, screen):
return self.round_success(area.status)

return self.round_retry(status='未在指定页面', wait_round_time=0.5)
return self.round_retry(status='未在指定页面', wait_round_time=1)

def click_switch_file(self) -> OperationOneRoundResult:
"""
点击切换存档
:return:
"""
screen = self.screenshot()

area = ScreenDivUni.OE_SWITCH_FILE_BTN.value
click = self.find_and_click_area(area, screen)

if click == Operation.OCR_CLICK_SUCCESS:
return self.round_success()
else:
return self.round_retry(f'点击{area.status}失败', wait_round_time=0.5)
return self.round_by_find_and_click_area(screen, area, success_wait=1.5, retry_wait_round=0.5)

def wait_management_screen(self) -> OperationOneRoundResult:
"""
Expand Down Expand Up @@ -116,10 +113,28 @@ def choose_file(self) -> OperationOneRoundResult:
time.sleep(0.25)

screen = self.screenshot()
area = ScreenDivUni.OC_CONFIRM_SWITCH_BTN.value
click = self.find_and_click_area(area, screen)

if click == Operation.OCR_CLICK_SUCCESS:
return self.round_success(wait=1) # 选择后 等待一会返回外层界面
area1 = ScreenDivUni.OE_CONFIRM_SWITCH_BTN.value
area2 = ScreenDivUni.OE_FILE_USING_BTN.value
part = cv2_utils.crop_image_only(screen, area1.rect)
ocr_result = self.ctx.ocr.ocr_for_single_line(part)

if str_utils.find_by_lcs(ocr_result, area1.text, percent=area1.lcs_percent):
self.ctx.controller.click(area1.center)
return self.round_success(wait=1.5) # 选择后 等待一会返回外层界面
elif str_utils.find_by_lcs(ocr_result, area2.text, percent=area2.lcs_percent): # 已经在使用了 返回即可
self.ctx.controller.click(ScreenPhoneMenu.EXIT_BTN.value.center)
return self.round_success(wait=1.5) # 选择后 等待一会返回外层界面
else:
return self.round_retry(f'点击{area.status}失败', wait_round_time=0.5)
return self.round_retry(f'点击{area1.status}失败', wait_round_time=0.5)


def __debug_op():
ctx = get_context()
ctx.start_running()

op = ChooseOeFile(ctx, 2)
op.execute()


if __name__ == '__main__':
__debug_op()
53 changes: 49 additions & 4 deletions src/sr/div_uni/op/choose_oe_support.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from typing import Optional

from basic.i18_utils import gt
from sr.context import Context
from sr.context import Context, get_context
from sr.div_uni.screen_div_uni import ScreenDivUni
from sr.operation import StateOperation, OperationOneRoundResult, StateOperationNode
from sr.operation.battle.choose_support import ChooseSupport


class ChooseOeSupport(StateOperation):

found_character: bool
"""是否找到支援角色"""

def __init__(self, ctx: Context, character_id: Optional[str]):
"""
在饰品提取画面 选择支援
在位面饰品提取画面 选择支援
执行后停留在 位面饰品提取画面
"""
super().__init__(ctx, op_name=f"{gt('饰品提取', 'ui')} {gt('选择支援', 'ui')}")

Expand All @@ -28,9 +32,13 @@ def add_edges_and_nodes(self) -> None:
click_support = StateOperationNode('点击支援按钮', self.click_support)
self.add_edge(check_screen, click_support)

choose_support = StateOperationNode('选择支援', op=ChooseSupport(self.ctx, self.character_id))
choose_support = StateOperationNode('选择支援角色', self.choose_support)
self.add_edge(click_support, choose_support)

back = StateOperationNode('返回', self.click_empty)
self.add_edge(choose_support, back)
self.add_edge(choose_support, back, success=False)

def handle_init(self) -> Optional[OperationOneRoundResult]:
"""
执行前的初始化 由子类实现
Expand All @@ -43,6 +51,8 @@ def handle_init(self) -> Optional[OperationOneRoundResult]:
if self.character_id is None:
return self.round_success('无需支援')

self.found_character: bool = False

def check_screen(self) -> OperationOneRoundResult:
"""
识别画面
Expand All @@ -63,6 +73,41 @@ def click_support(self) -> OperationOneRoundResult:
"""
area = ScreenDivUni.OE_SUPPORT_BTN.value
if self.ctx.controller.click(area.center):
return self.round_success()
return self.round_success(wait=1)
else:
return self.round_retry(f'点击{area.status}失败', wait_round_time=0.5)

def choose_support(self) -> OperationOneRoundResult:
"""
选择支援角色
:return:
"""
screen = self.screenshot()
round_result = ChooseSupport.click_avatar(self, screen, self.character_id)
if round_result.is_success:
self.found_character = True
return round_result

def click_empty(self) -> OperationOneRoundResult:
"""
选择后 点击空白继续
:return:
"""
area = ScreenDivUni.OE_SUPPORT_BTN.value
self.ctx.controller.click(area.center)
if self.found_character:
return self.round_success(wait=0.25)
else:
return self.round_fail(status=ChooseSupport.STATUS_SUPPORT_NOT_FOUND)


def __debug_op():
ctx = get_context()
ctx.start_running()

op = ChooseOeSupport(ctx, 'firefly')
op.execute()


if __name__ == '__main__':
__debug_op()
Loading

0 comments on commit dc273fe

Please sign in to comment.