|
| 1 | +"""速成班关卡选择模块 |
| 2 | +
|
| 3 | +本模块实现速成班关卡的自动选择功能,根据当前游戏日期自动确定并点击对应关卡。 |
| 4 | +""" |
| 5 | + |
| 6 | +from maa.agent.agent_server import AgentServer |
| 7 | +from maa.custom_action import CustomAction |
| 8 | +from maa.context import Context |
| 9 | + |
| 10 | +from datetime import datetime, timedelta |
| 11 | + |
| 12 | +from agent.customs.utils import Prompter, MatrixOperator, LocalStorage |
| 13 | +from agent.customs.maahelper import ParamAnalyzer, Tasker, RecoHelper |
| 14 | + |
| 15 | + |
| 16 | +@AgentServer.custom_action("select_cram_level") |
| 17 | +class SelectCramLevel(CustomAction): |
| 18 | + """速成班关卡选择自定义动作 |
| 19 | +
|
| 20 | + 根据当前游戏日期自动选择速成班关卡: |
| 21 | + - 周一至周五:根据日期直接选择对应关卡(1-5) |
| 22 | + - 周六:根据参数选择,可选关卡 1/2/3 |
| 23 | + - 周日:根据参数选择,可选关卡 4/5 |
| 24 | + """ |
| 25 | + |
| 26 | + def run(self, context: Context, argv: CustomAction.RunArg) -> bool: |
| 27 | + """执行关卡选择逻辑 |
| 28 | +
|
| 29 | + Args: |
| 30 | + context: MaaFramework 上下文对象 |
| 31 | + argv: 自定义动作运行参数 |
| 32 | +
|
| 33 | + Returns: |
| 34 | + bool: 执行成功返回 True,失败返回 False |
| 35 | +
|
| 36 | + Note: |
| 37 | + 游戏日期计算逻辑:凌晨 4 点前视为前一天 |
| 38 | + """ |
| 39 | + try: |
| 40 | + # 解析自定义动作参数 |
| 41 | + args = ParamAnalyzer(argv) |
| 42 | + |
| 43 | + # 计算游戏日期 |
| 44 | + now = datetime.now() |
| 45 | + if now.hour < 4: |
| 46 | + game_date = now - timedelta(days=1) |
| 47 | + else: |
| 48 | + game_date = now |
| 49 | + weekday = game_date.weekday() |
| 50 | + |
| 51 | + # 根据游戏日期选择关卡 |
| 52 | + weekday_names = ["一", "二", "三", "四", "五", "六", "日"] |
| 53 | + level = 1 |
| 54 | + if weekday < 5: |
| 55 | + # 周一至周五:关卡与星期对应(1-5) |
| 56 | + level = weekday + 1 |
| 57 | + Prompter.log(f"游戏日期为周{weekday_names[weekday]},选择关卡 {level}") |
| 58 | + elif weekday == 5: |
| 59 | + # 周六:从参数读取关卡(可选 1/2/3) |
| 60 | + level = args.get(["week_6", "w6"], 2) |
| 61 | + if level not in [1, 2, 3]: |
| 62 | + Prompter.log(f"周六关卡 {level} 无效,使用默认关卡 2") |
| 63 | + level = 2 |
| 64 | + Prompter.log(f"游戏日期为周六,选择关卡 {level}") |
| 65 | + else: |
| 66 | + # 周日:从参数读取关卡(可选 4/5) |
| 67 | + level = args.get(["week_7", "w7"], 5) |
| 68 | + if level not in [4, 5]: |
| 69 | + Prompter.log(f"周日关卡 {level} 无效,使用默认关卡 5") |
| 70 | + level = 5 |
| 71 | + Prompter.log(f"游戏日期为周日,选择关卡 {level}") |
| 72 | + |
| 73 | + # 执行点击操作 |
| 74 | + Tasker(context).click(130 + (level - 1) * 256, 354) |
| 75 | + |
| 76 | + return True |
| 77 | + except Exception as e: |
| 78 | + return Prompter.error("选择速成班关卡", e) |
0 commit comments