Skip to content

Commit

Permalink
fixl bus
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Mar 24, 2024
1 parent e548b2e commit 4129d16
Showing 1 changed file with 51 additions and 46 deletions.
97 changes: 51 additions & 46 deletions task/ManXunTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def dialog_zone(self):

@property
def stats_zone(self):
return self.box_of_screen(0.3, 0.8, 0.4, 0.2, "属性检测区域,PC端虚化效果无法检测")
return self.box_of_screen(0.3, 0.8, 0.4, 0.2, "属性测区域,PC端虚化效果无法检测")

@override
def run_frame(self):
Expand All @@ -56,7 +56,6 @@ def run_frame(self):
pass

self.logger.info("漫巡完成")
self.set_done()
return True

def check_is_manxun_ui(self):
Expand All @@ -77,14 +76,13 @@ def loop(self, choice=-1):
if not choice_clicked:
self.logger.error(f"没有选项可以点击")
return False
dialog_handled = self.wait_until(lambda: self.do_handle_dialog(choice, choices, choice_clicked))
if not dialog_handled:
raise RuntimeError(f"未知弹窗 无法处理")
return dialog_handled
self.wait_until(lambda: self.do_handle_dialog(choice, choices, choice_clicked))
if self.done:
return False

def do_handle_dialog(self, choice, choices, choice_clicked):
boxes = self.ocr(self.dialog_zone)
if self.find_depth() > 0:
if self.find_depth(boxes) > 0:
self.logger.info(f"没有弹窗, 进行下一步")
return True
self.logger.debug(f"检测对话框区域 {boxes} ")
Expand All @@ -95,7 +93,9 @@ def do_handle_dialog(self, choice, choices, choice_clicked):
elif confirm := find_box_by_name(boxes, "完成漫巡"):
self.click_box(confirm)
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match="确认"))
return False
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match="跳过漫巡回顾"))
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match="点击屏幕确认结算"))
self.set_done()
elif confirm := find_box_by_name(boxes, "解锁技能和区域"):
self.handle_skill_dialog(boxes, confirm)
elif find_box_by_name(boxes, "获得了一些技能点"):
Expand All @@ -115,56 +115,56 @@ def do_handle_dialog(self, choice, choices, choice_clicked):
self.logger.info(f"回避配置列表里的战斗 {skip_battle}")
self.click_cancel()
return self.loop(choice=choice - 1)
elif self.config.get("auto_combat"):
self.logger.info(f"开始自动战斗")
elif self.config.get("无法直接胜利, 自动投降跳过"):
self.logger.info(f"开始自动跳过战斗")
self.click_box(stat_combat)
if self.auto_combat():
pass
else:
self.click_cancel()
self.sleep(1)
self.click_box(choice_clicked)
self.sleep(1)
self.logger.info("自动战斗失败 点击回避")
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match=re.compile(r"回避")))
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match=re.compile(r"确\s?认")))
self.auto_skip_combat()
else:
raise RuntimeError("未开启自动战斗, 无法继续漫巡, 结束")
elif no_brain_box := self.click_box_if_name_match(boxes, self.click_no_brainer):
self.logger.info(f"点击固定对话框: {no_brain_box.name}")
elif stats_up_choices := self.find_stats_up(boxes):
self.handle_stats_up(stats_up_choices)
else:
return False
raise RuntimeError(f"未知弹窗 无法处理")
return True

def find_stats_up(self, boxes):
for box in boxes:
if re.search(r"^[\u4e00-\u9fa5]{2}$", box.name):
closest = box.find_closest_box("right", boxes)
if closest is not None:
match = re.search(r"^\+(\d+)(?:~(\d+))?", closest.name)
distance = closest.closest_distance(box)
if match and distance < box.width:
box.name += closest.name
self.logger.debug(f"合并距离较近的属性值 {box.name} {closest} {distance}")
distance = closest.closest_distance(box)
if distance < box.width:
match = re.search(r"\+(\d+)(?:~(\d+))?", closest.name)
if match:
box.name += match.group(0)
self.logger.debug(f"合并较近属性和数值, {box} {closest.name}")
closest.name = ""

return find_boxes_by_name(boxes, self.stats_up_re)

def ignore_right_stats(self, box, boxes):
closest = box.find_closest_box("right", boxes)
if closest is not None and isinstance(closest.name, str):
match = re.search(r"\+(\d+)(?:~(\d+))?", closest.name)
if match:
distance = closest.closest_distance(box)
if distance < box.width:
start, end = match.groups()
# Calculate the value. If 'end' is None, use 'start'; otherwise, calculate the average.
self.logger.debug(f"忽略右边最近的属性值 {box} {closest} {distance}")
closest.name = 0

def auto_skip_combat(self):
start_combat = self.wait_until(lambda: self.ocr(self.star_combat_zone, "开始战斗"), time_out=30)
start_combat = self.wait_until(lambda: self.ocr(self.star_combat_zone, "开始战斗"), time_out=50)
if not start_combat:
raise RuntimeError("无法找到开始战斗按钮")
self.click_box(start_combat)
result = self.wait_until(lambda: self.ocr(self.dialog_zone, "配置技能") or self.check_is_manxun_ui(),
time_out=600)
if result is None:
raise RuntimeError("等待战斗结束超时")
elif result.name == "配置技能":
self.logger.info("自动战斗失败")
return False
else:
self.logger.info("自动战斗成功")
return True
self.click_relative(0.04, 0.065)
self.wait_click_box(lambda: self.ocr(self.dialog_zone, "离开战斗"))
self.wait_click_box(lambda: self.ocr(self.dialog_zone, "离开战斗"))
self.wait_click_box(lambda: self.ocr(self.dialog_zone, "继续"), time_out=30)
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match=re.compile(r"回避")))
self.wait_click_box(lambda: self.ocr(self.dialog_zone, match=re.compile(r"确\s?认")))

def handle_stats_up(self, stats_up_choices):
stats_up_parsed = self.parse_stats_choices(stats_up_choices)
Expand All @@ -181,8 +181,8 @@ def handle_stats_up(self, stats_up_choices):
f"选择升级属性 {stats_up_choices} stats_up_parsed:{stats_up_parsed} current_stats:{current_stats} target:{target.name}")

def handle_skill_dialog(self, boxes, confirm):
search_skill_name_box = confirm.copy(-confirm.width / 2, -confirm.height * 1.7, confirm.width,
confirm.height * 0.4)
search_skill_name_box = confirm.copy(-confirm.width / 2, -confirm.height * 2, confirm.width,
confirm.height * 0.7)
self.draw_boxes("skill_search_area", search_skill_name_box)
skills = find_boxes_within_boundary(boxes, search_skill_name_box)
self.draw_boxes("skills", skills)
Expand All @@ -203,6 +203,7 @@ def click_choice(self, index=-1):
self.logger.info(f"不提升深度,当前深度{depth}")
index -= - 1
self.click_box(choices[index])
self.sleep(3) # 等待动画
self.logger.info(f"点击选项:{choices[index]}")
return choices, choices[index]

Expand All @@ -222,6 +223,8 @@ def do_find_choices(self):
right_text_box = choices[i].find_closest_box("right", boxes)
if right_text_box is not None:
choices[i].name = right_text_box.name
else:
choices = find_boxes_by_name(boxes, "风险区")
self.logger.debug(f"检测选项区域结果: {choices}")
return choices

Expand All @@ -247,17 +250,19 @@ def find_depth(self, boxes=None):
def click_cancel(self):
self.click_relative(0.5, 0.1)

@staticmethod
def find_highest_gaowei_number(boxes):
def find_highest_gaowei_number(self, boxes):
highest_gaowei_number = 0
highest_gaowei_box = None
for box in boxes:
if box.name[0] == '+' and all(char.isdigit() or char == '+' or char == ' ' for char in box.name):
if isinstance(box.name, str) and box.name[0] == '+' and all(
char.isdigit() or char == '+' or char == ' ' for char in box.name):
# Split the string by '+' and sum the numbers
numbers = box.name.split('+')
sum_gaowei = sum(int(number) for number in numbers if number)
if sum_gaowei > highest_gaowei_number:
highest_gaowei_number = sum_gaowei
box.name = sum_gaowei
self.ignore_right_stats(box, boxes)
if box.name > highest_gaowei_number:
highest_gaowei_number = box.name
highest_gaowei_box = box

return highest_gaowei_box
Expand Down

0 comments on commit 4129d16

Please sign in to comment.