From 7bfb55af36f89f0584648b5e7644d26b83082746 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Tue, 12 Sep 2023 00:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlog=5Fmaa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/solvers/base_schedule.py | 70 ++++++++++++------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 917ced9b0..f5f8e3138 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -30,6 +30,8 @@ from paddleocr import PaddleOCR import cv2 +from ctypes import CFUNCTYPE, c_int, c_char_p, c_void_p + # 借用__main__.py里的时间计算器 from arknights_mower.__main__ import format_time @@ -1871,6 +1873,36 @@ def reload(self): if not error: self.reload_time = datetime.now() + @CFUNCTYPE(None, c_int, c_char_p, c_void_p) + def log_maa(msg, details, arg): + m = Message(msg) + d = json.loads(details.decode('utf-8')) + logger.debug(d) + logger.debug(m) + logger.debug(arg) + if "what" in d and d["what"] == "StageDrops": + global stage_drop + stage_drop["details"].append(d["details"]["drops"]) + stage_drop["summary"] = d["details"]["stats"] + + elif "what" in d and d["what"] == "RecruitTagsSelected": + global recruit_tags_selected + recruit_tags_selected["tags"].append(d["details"]["tags"]) + + elif "what" in d and d["what"] == "RecruitResult": + global recruit_results + temp_dict = { + "tags": d["details"]["tags"], + "level": d["details"]["level"], + "result": d["details"]["result"], + } + recruit_results["results"].append(temp_dict) + + elif "what" in d and d["what"] == "RecruitSpecialTag": + global recruit_special_tags + recruit_special_tags["tags"].append(d["details"]["tags"]) + + def initialize_maa(self): asst_path = os.path.dirname(pathlib.Path(self.maa_config['maa_path']) / "Python" / "asst") @@ -1885,45 +1917,11 @@ def initialize_maa(self): logger.info("开始更新Maa……") Updater(self.maa_config['maa_path'], Version.Stable).update() logger.info("Maa更新完成") - # 若需要获取详细执行信息,请传入 callback 参数 - # 例如 asst = Asst(callback=my_callback) Asst.load(path=self.maa_config['maa_path']) - - @Asst.CallBackType - def log_maa(msg, details, arg): - m = Message(msg) - d = json.loads(details.decode('utf-8')) - logger.debug(d) - logger.debug(m) - logger.debug(arg) - if "what" in d and d["what"] == "StageDrops": - global stage_drop - stage_drop["details"].append(d["details"]["drops"]) - stage_drop["summary"] = d["details"]["stats"] - - elif "what" in d and d["what"] == "RecruitTagsSelected": - global recruit_tags_selected - recruit_tags_selected["tags"].append(d["details"]["tags"]) - - elif "what" in d and d["what"] == "RecruitResult": - global recruit_results - temp_dict = { - "tags": d["details"]["tags"], - "level": d["details"]["level"], - "result": d["details"]["result"], - } - recruit_results["results"].append(temp_dict) - - elif "what" in d and d["what"] == "RecruitSpecialTag": - global recruit_special_tags - recruit_special_tags["tags"].append(d["details"]["tags"]) - - # self.MAA = Asst(callback=log_maa) - self.MAA = Asst() + + self.MAA = Asst(callback=self.log_maa) self.stages = [] self.MAA.set_instance_option(InstanceOptionType.touch_type, self.maa_config['touch_option']) - # 请自行配置 adb 环境变量,或修改为 adb 可执行程序的路径 - # logger.info(self.device.client.device_id) if self.MAA.connect(self.maa_config['maa_adb_path'], self.device.client.device_id, self.maa_config["conn_preset"]): logger.info("MAA 连接成功")