From 33d9f2eff115326e907651a13ba235bb6e511820 Mon Sep 17 00:00:00 2001 From: lichx Date: Tue, 14 Jan 2025 16:05:37 +0800 Subject: [PATCH] =?UTF-8?q?[feature]=20=E4=B8=8A=E4=BC=A0ArknightsMaa?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + ArknightsMaaConfig/infrast/normal.json | 328 +++++++++++++++++++++++ ArknightsMaaConfig/maa.py | 93 +++++++ ArknightsMaaConfig/profiles/default.json | 11 + ArknightsMaaConfig/start_arknights.sh | 1 + ArknightsMaaConfig/tasks/award.toml | 12 + ArknightsMaaConfig/tasks/fight.toml | 31 +++ ArknightsMaaConfig/tasks/infrast.toml | 22 ++ ArknightsMaaConfig/tasks/mall.toml | 7 + ArknightsMaaConfig/tasks/recruit.toml | 18 ++ ArknightsMaaConfig/tasks/startup.toml | 4 + ArknightsMaaConfig/tasks/task.toml | 97 +++++++ README.md | 4 + 13 files changed, 629 insertions(+) create mode 100644 .gitignore create mode 100644 ArknightsMaaConfig/infrast/normal.json create mode 100755 ArknightsMaaConfig/maa.py create mode 100644 ArknightsMaaConfig/profiles/default.json create mode 100755 ArknightsMaaConfig/start_arknights.sh create mode 100644 ArknightsMaaConfig/tasks/award.toml create mode 100644 ArknightsMaaConfig/tasks/fight.toml create mode 100644 ArknightsMaaConfig/tasks/infrast.toml create mode 100644 ArknightsMaaConfig/tasks/mall.toml create mode 100644 ArknightsMaaConfig/tasks/recruit.toml create mode 100644 ArknightsMaaConfig/tasks/startup.toml create mode 100644 ArknightsMaaConfig/tasks/task.toml create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf0824e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/ArknightsMaaConfig/infrast/normal.json b/ArknightsMaaConfig/infrast/normal.json new file mode 100644 index 0000000..5badffa --- /dev/null +++ b/ArknightsMaaConfig/infrast/normal.json @@ -0,0 +1,328 @@ +{ + "plans": [ + { + "rooms": { + "trading": [ + { + "product": "LMD", + "operators": ["巫恋", "龙舌兰", "卡夫卡"], + "sort": true, + "autofill": false + }, + { + "product": "LMD", + "operators": ["但书", "乌有", "银灰"], + "sort": true, + "autofill": false + } + ], + "manufacture": [ + { + "product": "Battle Record", + "operators": ["红云", "稀音", "帕拉斯"], + "sort": true, + "autofill": false + }, + { + "product": "Battle Record", + "operators": ["食铁兽", "断罪者", "槐琥"], + "sort": true, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["清流", "温蒂", "苍苔"], + "sort": true, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["砾", "至简", "夜烟"], + "sort": true, + "autofill": false + } + ], + "hire": [ + { + "operators": ["絮雨"], + "autofill": false + } + ], + "dormitory": [ + { + "operators": ["车尔尼"], + "sort": true, + "autofill": true + }, + { + "operators": ["爱丽丝"], + "sort": true, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + } + ], + "control": [ + { + "skip": false, + "operators": ["阿米娅", "重岳", "琴柳", "令", "夕"] + } + ], + "power": [ + { + "operators": ["承曦格雷伊"], + "autofill": false + }, + { + "operators": ["澄闪"], + "autofill": false + }, + { + "operators": ["格雷伊"], + "autofill": false + } + ], + "meeting": [ + { + "operators": [], + "autofill": true + } + ] + }, + "drones": { + "enable": true, + "index": 1, + "room": "manufacture", + "order": "pre" + }, + "name": "16H最高效率长班", + "description": "请手动把年放加工站,下次在16小时后换班" + }, + { + "rooms": { + "trading": [ + { + "product": "LMD", + "operators": ["巫恋", "龙舌兰", "卡夫卡"], + "sort": true, + "autofill": false + }, + { + "product": "LMD", + "operators": ["但书", "空弦", "涤火杰西卡"], + "sort": true, + "autofill": false + } + ], + "manufacture": [ + { + "product": "Battle Record", + "operators": ["食铁兽", "断罪者", "槐琥"], + "sort": true, + "autofill": false + }, + { + "product": "Battle Record", + "operators": ["赫默", "野鬃", "灰毫"], + "sort": true, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["水月", "海沫", "多萝西"], + "sort": true, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["砾", "至简", "夜烟"], + "sort": true, + "autofill": false + } + ], + "hire": [ + { + "operators": ["絮雨"], + "autofill": false + } + ], + "dormitory": [ + { + "operators": ["车尔尼"], + "sort": true, + "autofill": true + }, + { + "operators": ["爱丽丝"], + "sort": true, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + } + ], + "control": [ + { + "skip": false, + "operators": ["阿米娅", "凯尔希", "琴柳", "焰尾", "令"] + } + ], + "power": [ + { + "operators": ["正义骑士号"], + "autofill": false + }, + { + "operators": ["澄闪"], + "autofill": false + }, + { + "operators": ["雷蛇"], + "autofill": false + } + ], + "meeting": [ + { + "operators": [], + "autofill": true + } + ] + }, + "drones": { + "enable": true, + "index": 1, + "room": "manufacture", + "order": "pre" + }, + "name": "4H 次高效替补 2 班", + "description": "下次在4小时后换班" + }, + { + "rooms": { + "trading": [ + { + "product": "LMD", + "operators": ["海蒂", "蛇屠箱", "柏喙"], + "sort": true, + "autofill": false + }, + { + "product": "LMD", + "operators": ["能天使", "孑", "银灰"], + "sort": true, + "autofill": false + } + ], + "manufacture": [ + { + "product": "Battle Record", + "operators": ["红云", "稀音", "帕拉斯"], + "sort": true, + "autofill": false + }, + { + "product": "Battle Record", + "operators": ["赫默", "野鬃", "灰毫"], + "sort": false, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["清流", "温蒂", "苍苔"], + "sort": true, + "autofill": false + }, + { + "product": "Pure Gold", + "operators": ["水月", "海沫", "多萝西"], + "sort": true, + "autofill": false + } + ], + "hire": [ + { + "operators": ["斥罪"], + "autofill": false + } + ], + "dormitory": [ + { + "operators": [], + "sort": false, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + }, + { + "operators": [], + "sort": false, + "autofill": true + } + ], + "control": [ + { + "skip": false, + "operators": ["诗怀雅", "凯尔希", "焰尾", "维什戴尔", "老鲤"] + } + ], + "power": [ + { + "operators": ["承曦格雷伊"], + "autofill": false + }, + { + "operators": ["格雷伊"], + "autofill": false + }, + { + "operators": ["雷蛇"], + "autofill": false + } + ], + "meeting": [ + { + "operators": [], + "autofill": true + } + ] + }, + "drones": { + "enable": true, + "index": 1, + "room": "manufacture", + "order": "pre" + }, + "name": "4H 次高效替补 1 班", + "description": "下次在4小时后换班" + } + ], + "author": "Anchor", + "description": "干员配置要求极高,请留意\\n若缺少干员请自行通过id在一图流基建排班生成器上修改并重新生成导出(请勿直接修改,以免更新后被覆盖)\\n\\n感谢公孙长乐大佬提供数据及方案支持!\\n[20230224 修订] 视频地址: https://www.bilibili.com/video/BV1EM411c7Ng\\n请把年放在加工站\\n可自行在一图流排班生成器上自定义班次起止时间", + "id": 1677312017553916, + "title": "243极限效率,一天三换(需手动菲亚梅塔)", + "buildingType": "243", + "planTimes": "3班" +} \ No newline at end of file diff --git a/ArknightsMaaConfig/maa.py b/ArknightsMaaConfig/maa.py new file mode 100755 index 0000000..b40f23f --- /dev/null +++ b/ArknightsMaaConfig/maa.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +import os +import sys +import asyncio +import re +import time +from datetime import datetime +# time record +def fprint(s:str)->None: + print(s) + sys.stdout.flush() + +fprint("-------------------------------------------------------") +fprint(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) +fprint("-------------------------------------------------------") +time.sleep(1) + +class CommandProcessor: + def Command(self,s:str) -> int: + self._command = s + fprint("_> " + s) + if (t:=os.system(s))!=0: + fprint("Fatal Error: Command Failed:" + s) + fprint("Error Number: " + str(t)) + return t + return 0 + def RetryCommand(self,s:str,retry:int=3) -> int: + result = 0 + while retry > 0: + result = cp.Command(s) + if result == 0: + break + retry-=1 + time.sleep(1) + return result + + + async def AsyncCommand(self,command:str,regex:str): + self._asyncCommand = command + fprint("_> await! " + command) + process = await asyncio.create_subprocess_shell(command,stderr=asyncio.subprocess.PIPE) + while True: + line = (await process.stderr.readline()).decode() + fprint(line) + if re.search(regex, line): + fprint("done") + break + + + + +# cp.Command("command") +# cp.RetryCommand("command",retry_time:int) +# asyncio.run(cp.AsyncCommand("command","stop track regex")) +script_dir = os.path.dirname((os.path.abspath(__file__))) +cp = CommandProcessor() +haveError = False +def TaskFailRetry(command:str)->int: + retry = 3 + result = 0 + while retry > 0: + retry -= 1 + result = cp.RetryCommand(command) + if result == 0: + return 0 + fprint(f"Task Command is {command}, ret code is {result}") + fprint("Task Failed, retrying...") + cp.RetryCommand("maa closedown") + cp.RetryCommand("maa run startup") + return result +# update +cp.Command("maa update") +cp.Command("maa self update") +# fire it up +cp.Command("docker stop redroid") +os.chdir("/home/lichx/.config/redroid-rk3588/") +cp.Command("docker compose up -d") +time.sleep(15) +cp.RetryCommand("adb connect localhost:5555") +cp.RetryCommand("adb -s localhost:5555 shell am start --windowingMode 4 com.hypergryph.arknights/com.u8.sdk.U8UnityContext") +# run maa +haveError |= TaskFailRetry("maa run startup") != 0 +haveError |= TaskFailRetry("maa run recruit") != 0 +haveError |= TaskFailRetry("maa run infrast") != 0 +haveError |= TaskFailRetry("maa run fight") != 0 +haveError |= TaskFailRetry("maa run mall") != 0 +haveError |= TaskFailRetry("maa run award") != 0 +# storage error log +if haveError: + cp.Command(f"cp {script_dir}/pyshell.log {script_dir}/pyshell.{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.log") +# shutdown +cp.RetryCommand("maa closedown") +cp.Command("docker stop redroid") diff --git a/ArknightsMaaConfig/profiles/default.json b/ArknightsMaaConfig/profiles/default.json new file mode 100644 index 0000000..ad66c1c --- /dev/null +++ b/ArknightsMaaConfig/profiles/default.json @@ -0,0 +1,11 @@ +{ + "connection": { + "preset": "ADB" + }, + "instance_options": { + "adb_lite_enabled": false, + "deployment_with_pause": false, + "kill_adb_on_exit": false, + "touch_mode": "MaaTouch" + } +} \ No newline at end of file diff --git a/ArknightsMaaConfig/start_arknights.sh b/ArknightsMaaConfig/start_arknights.sh new file mode 100755 index 0000000..95f44d0 --- /dev/null +++ b/ArknightsMaaConfig/start_arknights.sh @@ -0,0 +1 @@ +adb -s localhost:5555 shell am start --windowingMode 4 com.hypergryph.arknights/com.u8.sdk.U8UnityContext diff --git a/ArknightsMaaConfig/tasks/award.toml b/ArknightsMaaConfig/tasks/award.toml new file mode 100644 index 0000000..697b6b5 --- /dev/null +++ b/ArknightsMaaConfig/tasks/award.toml @@ -0,0 +1,12 @@ +[[tasks]] +name = "领取奖励" +type = "Award" + +[tasks.params] +award = true +mail = true +orundum = true +specialaccess = true + +[[tasks.variants]] +condition = { type = "Time", start = "18:00:00", timezone = "Official" } \ No newline at end of file diff --git a/ArknightsMaaConfig/tasks/fight.toml b/ArknightsMaaConfig/tasks/fight.toml new file mode 100644 index 0000000..0af6872 --- /dev/null +++ b/ArknightsMaaConfig/tasks/fight.toml @@ -0,0 +1,31 @@ +[[tasks]] +name = "刷理智" +type = "Fight" +# 改变Condition匹配模式 +strategy = "merge" + +# 周末清理理智药 +[[tasks.variants]] +params = { expiring_medicine = 1000 } + +[tasks.variants.condition] +type = "And" +conditions = [ + { type = "Time", start = "18:00:00" }, + { type = "Weekday", weekdays = ["Sun"], timezone = "Official"}, +] +# 其他时间(?已经没有嘞),刷1-7 +[[tasks.variants]] +params = { stage = "1-7" } +# 在夏活期间以外的周一、周四和周六,刷AP-5(红票) +[[tasks.variants]] +condition = { type = "Weekday", weekdays = ["Mon", "Thu", "Sat"], timezone = "Official"} +params = { stage = "AP-5" } +# 在夏活期间以外的周二、周三、周五和周日,刷CA-5(经验书) +[[tasks.variants]] +condition = { type = "Weekday", weekdays = ["Tue", "Wed", "Fri", "Sun"], timezone = "Official"} +params = { stage = "CA-5" } +# ss期间 刷活动关 +[[tasks.variants]] +params = { stage = "RS-8" } +condition = { type = "OnSideStory", client = "Official" } diff --git a/ArknightsMaaConfig/tasks/infrast.toml b/ArknightsMaaConfig/tasks/infrast.toml new file mode 100644 index 0000000..f8b53e4 --- /dev/null +++ b/ArknightsMaaConfig/tasks/infrast.toml @@ -0,0 +1,22 @@ +[[tasks]] +name = "基建换班" +type = "Infrast" + +[tasks.params] +mode = 10000 +facility = ["Trade", "Reception", "Mfg", "Control", "Power", "Office", "Dorm"] +dorm_trust_enabled = true +filename = "normal.json" # 自定义的基建计划的文件名应该位于`$MAA_CONFIG_DIR/infrast` + +# 在 18:00:00到第二天的 04:00:00 使用计划 0,在 12:00:00 之前使用计划 1,之后使用计划 2 +[[tasks.variants]] +condition = { type = "Time", start = "22:00:00", end = "08:00:00", timezone = 8 } # 当结束时间小于开始时间时,结束时间被视为第二天的时间 +params = { plan_index = 0 } + +[[tasks.variants]] +condition = { type = "Time", end = "16:00:00", timezone = 8 } # 如果开始时间被省略,那么只要当前时间小于结束时间时,这个条件就会被匹配 +params = { plan_index = 1 } + +[[tasks.variants]] +condition = { type = "Time", start = "16:00:00", timezone = 8 } # 如果结束时间被省略,那么只要当前时间大于开始时间时,这个条件就会被匹配 +params = { plan_index = 2 } \ No newline at end of file diff --git a/ArknightsMaaConfig/tasks/mall.toml b/ArknightsMaaConfig/tasks/mall.toml new file mode 100644 index 0000000..3304e0f --- /dev/null +++ b/ArknightsMaaConfig/tasks/mall.toml @@ -0,0 +1,7 @@ +# 只在18:00:00(CST: 22:00:00)之后进行信用商店相关的操作 +[[tasks]] +name = "信用商店" +type = "Mall" + +[[tasks.variants]] +condition = { type = "Time", start = "18:00:00", timezone = "Official" } \ No newline at end of file diff --git a/ArknightsMaaConfig/tasks/recruit.toml b/ArknightsMaaConfig/tasks/recruit.toml new file mode 100644 index 0000000..4089b9b --- /dev/null +++ b/ArknightsMaaConfig/tasks/recruit.toml @@ -0,0 +1,18 @@ +[[tasks]] +type = "Recruit" +name = "公开招募" + +[tasks.params] +refresh = true +select = [4, 5] +confirm = [3, 4, 5] +skip_robot = false +recruitment_time = { '3' = 460 } + +[[tasks.variants]] +condition = { type = "Time", start = "17:00:00" } +params = { times = 4 } + +# consume refresh times +[[tasks.variants]] +params = { times = 1 } \ No newline at end of file diff --git a/ArknightsMaaConfig/tasks/startup.toml b/ArknightsMaaConfig/tasks/startup.toml new file mode 100644 index 0000000..829cf98 --- /dev/null +++ b/ArknightsMaaConfig/tasks/startup.toml @@ -0,0 +1,4 @@ +[[tasks]] +name = "启动游戏" # 任务的名字,可选,默认为任务类型 +type = "StartUp" # 任务的类型 +params = { client_type = "Official", start_game_enabled = true } # 对应任务的参数 \ No newline at end of file diff --git a/ArknightsMaaConfig/tasks/task.toml b/ArknightsMaaConfig/tasks/task.toml new file mode 100644 index 0000000..51c08b5 --- /dev/null +++ b/ArknightsMaaConfig/tasks/task.toml @@ -0,0 +1,97 @@ +[[tasks]] +name = "启动游戏" # 任务的名字,可选,默认为任务类型 +type = "StartUp" # 任务的类型 +params = { client_type = "Official", start_game_enabled = true } # 对应任务的参数 + +[[tasks]] +type = "Recruit" +name = "公开招募" + +[tasks.params] +refresh = true +select = [4, 5] +confirm = [3, 4, 5] +skip_robot = false +recruitment_time = { '3' = 460 } + +[[tasks.variants]] +condition = { type = "Time", start = "17:00:00" } +params = { times = 4 } + +# consume refresh times +[[tasks.variants]] +params = { times = 1 } + +[[tasks]] +name = "基建换班" +type = "Infrast" + +[tasks.params] +mode = 10000 +facility = ["Trade", "Reception", "Mfg", "Control", "Power", "Office", "Dorm"] +dorm_trust_enabled = true +filename = "normal.json" # 自定义的基建计划的文件名应该位于`$MAA_CONFIG_DIR/infrast` + +# 在 18:00:00到第二天的 04:00:00 使用计划 0,在 12:00:00 之前使用计划 1,之后使用计划 2 +[[tasks.variants]] +condition = { type = "Time", start = "22:00:00", end = "08:00:00", timezone = 8 } # 当结束时间小于开始时间时,结束时间被视为第二天的时间 +params = { plan_index = 0 } + +[[tasks.variants]] +condition = { type = "Time", end = "16:00:00", timezone = 8 } # 如果开始时间被省略,那么只要当前时间小于结束时间时,这个条件就会被匹配 +params = { plan_index = 1 } + +[[tasks.variants]] +condition = { type = "Time", start = "16:00:00", timezone = 8 } # 如果结束时间被省略,那么只要当前时间大于开始时间时,这个条件就会被匹配 +params = { plan_index = 2 } + +[[tasks]] +name = "刷理智" +type = "Fight" +# 改变Condition匹配模式 +strategy = "merge" + +# 周末清理理智药 +[[tasks.variants]] +params = { expiring_medicine = 1000 } + +[tasks.variants.condition] +type = "And" +conditions = [ + { type = "Weekday", weekdays = ["Sun"], timezone = "Official"}, +] + +# 在夏活期间,刷SL-8 +[[tasks.variants]] +params = { stage = "GO-8" } +condition = { type = "OnSideStory", client = "Official" } + +# 在夏活期间以外的周一、周四和周六,刷AP-5(红票) +[[tasks.variants]] +condition = { type = "Weekday", weekdays = ["Mon", "Thu", "Sat"], timezone = "Official"} +params = { stage = "AP-5" } +# 在夏活期间以外的周二、周三、周五和周日,刷CA-5(经验书) +[[tasks.variants]] +condition = { type = "Weekday", weekdays = ["Tue", "Wed", "Fri", "Sun"], timezone = "Official"} +params = { stage = "CA-5" } +# 其他时间(?已经没有嘞),刷1-7 +[[tasks.variants]] +params = { stage = "1-7" } + +# 只在18:00:00之后进行信用商店相关的操作 +[[tasks]] +name = "信用商店" +type = "Mall" + +[[tasks.variants]] +condition = { type = "Time", start = "18:00:00" } + +[[tasks]] +name = "领取奖励" +type = "Award" + +[tasks.params] +award = true +mail = true +orundum = true +specialaccess = true diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f0d926 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +## Lichx's Maa Like software config +目前包括明日方舟(ArknightsMAA) + +计划加入重返未来·1999(M9A) \ No newline at end of file