diff --git a/config.py b/config.py index 4f569c4..e9b0b9b 100644 --- a/config.py +++ b/config.py @@ -1,17 +1,15 @@ +from autohelper.util.path import get_path_in_package from task.ManXunTask import ManXunTask config = { - 'debug': True, # Optional, default: False + 'debug': False, # Optional, default: False 'use_gui': True, - 'ocr': { - 'lang': 'ch' - }, 'config_folder': 'configs', - # 'gui_icon': 'icon.png', # Optional - 'gui_title': 'BJ Helper', # Optional, default: False + 'gui_icon': get_path_in_package(__file__, 'icon.ico'), + 'ocr': 'RapidOCR', + 'gui_title': '白荆科技-漫巡助手', # Optional, default: False 'capture': 'adb', # adb/windows, see #autohelper.capture - 'capture_window_title': 'Mumu Player 12', # required when using windows capture - 'interaction': 'adb', # adb/windows, see #autohelper.interaction + 'capture_window_title': r'^白荆回廊\[[0-9.]+\]$', # required when using windows capture # 'coco_feature_folder': get_path(__file__, 'assets/coco_feature'), # required if using feature detection 'log_file': 'logs/auto_helper.log', # Optional, auto rotating every day 'error_log_file': 'logs/auto_helper_error.log', diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..348c1de Binary files /dev/null and b/icon.ico differ diff --git a/main_adb.py b/main.py similarity index 100% rename from main_adb.py rename to main.py diff --git a/main_adb.spec b/main.spec similarity index 90% rename from main_adb.spec rename to main.spec index 4495001..b1e06f0 100644 --- a/main_adb.spec +++ b/main.spec @@ -2,6 +2,7 @@ from pathlib import Path import rapidocr_onnxruntime + block_cipher = None package_name = 'rapidocr_onnxruntime' @@ -24,9 +25,11 @@ for v in yaml_paths: add_data = list(set(yaml_add_data + onnx_add_data)) excludes = ['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter', 'resources', 'matplotlib'] +add_data.append(('icon.ico', '.')) +print(f"add_data {add_data}") a = Analysis( - ['main_adb.py'], + ['main.py'], pathex=[], binaries=[], datas=add_data, @@ -47,12 +50,13 @@ exe = EXE( a.binaries, a.datas, [], - name='main_adb', + name='BaiJingZhuShou', + icon='carrot.ico', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, - console=True, + console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, diff --git a/main_debug.py b/main_debug.py new file mode 100644 index 0000000..7f17b65 --- /dev/null +++ b/main_debug.py @@ -0,0 +1,6 @@ +from autohelper.AutoHelper import AutoHelper +from config import config + +config = config +config.debug = True +autoui = AutoHelper(config) diff --git a/main_pc.py b/main_pc.py deleted file mode 100644 index 0246569..0000000 --- a/main_pc.py +++ /dev/null @@ -1,10 +0,0 @@ -import re - -from autohelper.AutoHelper import AutoHelper -from config import config - -config = config -config['capture'] = 'windows' -config['capture_window_title'] = re.compile(r'^白荆回廊') -config['interaction'] = 'windows' -autoui = AutoHelper(config) diff --git a/task/ManXunTask.py b/task/ManXunTask.py index 09420b8..dd77738 100644 --- a/task/ManXunTask.py +++ b/task/ManXunTask.py @@ -10,7 +10,6 @@ class ManXunTask(BJTask): def __init__(self): super().__init__() - self.level = 0 self.name = "自动漫巡任务" self.description = """自动漫巡 """ @@ -27,11 +26,10 @@ def __init__(self): "深度等级最多提升到": 12 } self.destination = None - self.skill_counter = {} self.stats_up_re = re.compile(r"([\u4e00-\u9fff]+)\+(\d+)(?:~(\d+))?") def end(self, message, result=False): - self.logger.info(f"执行结束:{message}") + self.log_info(f"执行结束:{message}") return result @property @@ -45,18 +43,18 @@ def dialog_zone(self): @override def run_frame(self): if not self.check_is_manxun_ui(): - self.logger.error("必须从漫巡选项界面开始, 并且开启路线追踪") + self.log_error("必须从漫巡选项界面开始, 并且开启路线追踪", notify=True) self.set_done() return False - try: while self.loop(): pass except Exception as e: - self.logger.error(f"运行异常:", e) + self.log_error(f"运行异常:", e, True) pass - self.logger.info("漫巡完成") + self.log_info("漫巡完成") + self.notification("漫巡完成") return True def check_is_manxun_ui(self): @@ -85,13 +83,13 @@ def loop(self, choice=-1): def do_handle_dialog(self, choice, choices, choice_clicked): boxes = self.ocr(self.dialog_zone) if self.find_depth(boxes) > 0: - self.logger.info(f"没有弹窗, 进行下一步") + self.log_info(f"没有弹窗, 进行下一步") return True self.logger.debug(f"检测对话框区域 {boxes} ") if find_box_by_name(boxes, "提升攻击"): box = self.find_highest_gaowei_number(boxes) self.click_box(box) - self.logger.info(f"高位同调 点击最高 {box}") + self.log_info(f"高位同调 点击最高 {box}") elif confirm := find_box_by_name(boxes, "完成漫巡"): self.click_box(confirm) self.wait_click_box(lambda: self.ocr(self.dialog_zone, match="确认")) @@ -101,11 +99,11 @@ def do_handle_dialog(self, choice, choices, choice_clicked): elif confirm := find_box_by_name(boxes, "解锁技能和区域"): self.handle_skill_dialog(boxes, confirm) elif find_box_by_name(boxes, "获得了一些技能点"): - self.logger.info(f"获取技能点成功") + self.log_info(f"获取技能点成功") self.click_box(find_box_by_name(boxes, re.compile(r"^\+\d+"))) elif find_box_by_name(boxes, "刻印技能上限"): confirm = find_box_by_name(boxes, re.compile(r"前进!解锁")) - self.logger.info(f"区域技能,点击两次") + self.log_info(f"区域技能,点击两次") self.click_box(confirm) self.sleep(0.5) self.click_box(confirm) @@ -114,17 +112,19 @@ def do_handle_dialog(self, choice, choices, choice_clicked): self.logger.debug( f"开始战斗 跳过战斗查询结果:{skip_battle} abs(choice):{abs(choice)} len(choices) {len(choices)}") if skip_battle and abs(choice) < len(choices): - self.logger.info(f"回避配置列表里的战斗 {skip_battle}") + self.log_info(f"回避配置列表里的战斗 {skip_battle}") self.click_cancel() return self.loop(choice=choice - 1) elif self.config.get("无法直接胜利, 自动投降跳过"): - self.logger.info(f"开始自动跳过战斗") + self.log_info(f"开始自动跳过战斗") self.click_box(stat_combat) self.auto_skip_combat() else: - raise RuntimeError("未开启自动战斗, 无法继续漫巡, 结束") + message = "未开启自动战斗, 无法继续漫巡, 结束" + self.log_info(message, True) + raise RuntimeError(message) elif no_brain_box := self.click_box_if_name_match(boxes, self.click_no_brainer): - self.logger.info(f"点击固定对话框: {no_brain_box.name}") + self.log_info(f"点击固定对话框: {no_brain_box.name}") elif stats_up_choices := self.find_stats_up(boxes): self.handle_stats_up(stats_up_choices) else: @@ -176,10 +176,10 @@ def handle_stats_up(self, stats_up_choices): # Assuming stats_up_parsed[stat] is a list of tuples (value, box) # and we want the one with the highest 'value' value, box = max(stats_up_parsed[stat], key=lambda x: x[0]) - self.logger.info(f"查找最高优先级提升属性结果 {box.name}") + self.log_info(f"查找最高优先级提升属性结果 {box.name}") target = box break - self.logger.info( + self.log_info( f"选择升级属性 {stats_up_choices} stats_up_parsed:{stats_up_parsed} target:{target}") self.click_box(target) @@ -189,7 +189,8 @@ def handle_skill_dialog(self, boxes, confirm): 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) - self.logger.info(f"获取技能 {skills}") + self.info_add_to_list("获得技能", [obj.name for obj in skills]) + self.log_info(f"获取技能 {skills}") self.click_box(confirm) def click_choice(self, index=-1): @@ -199,18 +200,20 @@ def click_choice(self, index=-1): else: if choices[index].name == "深度等级提升": depth = self.find_depth() - self.logger.info(f"提升深度, {depth} 目前是第{abs(index)}个选项, 共有{len(choices)}选项") + self.log_info(f"提升深度, {depth} 目前是第{abs(index)}个选项, 共有{len(choices)}选项") if depth < self.config['深度等级最多提升到'] or abs(index) == len(choices): - self.logger.info(f"提升深度,当前深度{depth}") + self.log_info(f"提升深度,当前深度{depth}") else: - self.logger.info(f"不提升深度,当前深度{depth}") + self.log_info(f"不提升深度,当前深度{depth}") index -= - 1 - priority = self.config['低深度选项优先级'] if self.level < self.config['高低深度分界'] else self.config[ - '高深度选项优先级'] + priority = self.config['低深度选项优先级'] if self.info.get('漫巡深度', 0) < self.config[ + '高低深度分界'] else \ + self.config[ + '高深度选项优先级'] index = find_priority_string(choices, priority, index) self.click_box(choices[index]) self.sleep(3) # 等待动画 - self.logger.info(f"点击选项:{choices[index]}, 使用优先级 {priority}, index {index}") + self.log_info(f"点击选项:{choices[index]}, 使用优先级 {priority}, index {index}") return choices, choices[index] def do_find_choices(self): @@ -223,7 +226,7 @@ def do_find_choices(self): self.destination = choices[i].name choices[i].height *= 3 if self.destination != choices[i].name: - self.logger.info("排除错误追踪目标") + self.log_info("排除错误追踪目标") del choices[i] continue right_text_box = choices[i].find_closest_box("right", boxes) @@ -251,7 +254,7 @@ def find_depth(self, boxes=None): if depth_box is not None: depth_box.name = depth_box.name.replace("D", "2") depth = int(depth_box.name) - self.level = depth + self.info['漫巡深度'] = depth return depth def click_cancel(self):