Skip to content

Commit fd434cf

Browse files
committed
feat: 巅峰对决
1 parent 033a0cc commit fd434cf

4 files changed

Lines changed: 729 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from .activity import *
22
from .store import *
33
from .eat_sugar import *
4+
from .activity import *
5+
from .peak_showdown import *
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""巅峰对决特殊处理模块。
2+
3+
提供巅峰对决相关的自定义识别功能,包括战斗力解析和对手选择逻辑。
4+
"""
5+
6+
from maa.agent.agent_server import AgentServer
7+
from maa.custom_recognition import CustomRecognition
8+
from maa.context import Context
9+
10+
from agent.customs.utils import Prompter, CounterManager
11+
from agent.customs.maahelper import RecoHelper, ParamAnalyzer
12+
13+
14+
# ==================== 辅助函数 ====================
15+
16+
17+
def parse_power(text: str) -> int:
18+
"""解析战斗力文本。
19+
20+
从识别结果中提取战斗力数值,支持全角/半角符号处理。
21+
OCR可能将千分位分隔符识别为逗号或小数点,均会被正确处理。
22+
23+
参数:
24+
text:包含战斗力信息的文本,格式如 "战斗力:12,345" 或 "战斗力:140.489"
25+
26+
返回:
27+
战斗力数值(整数)。如果解析失败则返回无穷大
28+
29+
示例:
30+
>>> parse_power("战斗力:12,345")
31+
12345
32+
>>> parse_power("战斗力:140.489")
33+
140489
34+
>>> parse_power("战斗力:10000")
35+
10000
36+
"""
37+
# 移除所有非数字字符(战斗力、冒号、逗号、小数点等)
38+
num_str = "".join(c for c in text if c.isdigit())
39+
40+
# 尝试转换为整数
41+
try:
42+
return int(num_str)
43+
except ValueError:
44+
# 解析失败时返回无穷大,确保不会被选中
45+
return float("inf")
46+
47+
48+
# ==================== 自定义识别类 ====================
49+
50+
51+
@AgentServer.custom_recognition("pick_opponent")
52+
class PickOpponent(CustomRecognition):
53+
"""选择对手识别器。
54+
55+
在巅峰对决中选择战斗力最低的对手。
56+
通过识别所有对手的战斗力,自动选择数值最小的目标。
57+
"""
58+
59+
def analyze(
60+
self,
61+
context: Context,
62+
argv: CustomRecognition.AnalyzeArg,
63+
) -> CustomRecognition.AnalyzeResult:
64+
"""执行对手选择分析。
65+
66+
识别所有可见对手的战斗力,并返回战斗力最低的目标位置。
67+
68+
参数:
69+
context:MaaFramework 上下文
70+
argv:自定义识别参数
71+
72+
返回:
73+
战斗力最低对手的识别结果,包含位置信息
74+
"""
75+
try:
76+
# 识别所有对手的战斗力文本
77+
rh = RecoHelper(context, argv).recognize("巅峰对决_识别战斗力")
78+
if rh.hit:
79+
results = rh.filtered_results
80+
# 选择战斗力最低的对手
81+
min_result = min(results, key=lambda res: parse_power(res.text))
82+
return RecoHelper.rt(min_result)
83+
84+
return RecoHelper.NoResult
85+
except Exception as e:
86+
return Prompter.error("选择对手", e, reco_detail=True)

assets/interface.json

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
"label": "领取每日糖果",
6868
"entry": "领取糖果_开始",
6969
"default_check": true,
70-
"description": ""
71-
// "option": ["领取邮件-周期检查"]
70+
"description": "",
71+
"option": ["领取邮件-周期检查"]
7272
},
7373
{
7474
"name": "每日采购",
@@ -94,6 +94,14 @@
9494
"description": "",
9595
"option": ["清紫糖-克隆工厂", "清紫糖-副本"]
9696
},
97+
{
98+
"name": "巅峰对决",
99+
"label": "巅峰对决",
100+
"entry": "巅峰对决_开始",
101+
"default_check": true,
102+
"description": "",
103+
"option": ["巅峰对决-领取战斗宝石", "巅峰对决-竞技场对战"]
104+
},
97105
{
98106
"name": " ——— 活动任务 ———",
99107
"label": "——— 活动任务 ———",
@@ -136,7 +144,7 @@
136144
"name": "No",
137145
"pipeline_override": {
138146
"领取邮件_周期检查": {
139-
"recognition": "DirectHit"
147+
"action": "DoNothing"
140148
}
141149
}
142150
},
@@ -427,6 +435,83 @@
427435
"custom_action_param": "l={关卡}"
428436
}
429437
}
438+
},
439+
// ========== 清紫糖 ==========
440+
// ========== 巅峰对决 ==========
441+
"巅峰对决-领取战斗宝石": {
442+
"type": "switch",
443+
"label": "领取战斗宝石",
444+
"description": "",
445+
"cases": [
446+
{
447+
"name": "Yes",
448+
"option": ["巅峰对决-领取战斗宝石-周期检查"]
449+
},
450+
{
451+
"name": "No",
452+
"pipeline_override": {
453+
"巅峰对决_领取战斗宝石开始": {
454+
"next": "巅峰对决_领取战斗宝石结束"
455+
}
456+
}
457+
}
458+
]
459+
},
460+
"巅峰对决-领取战斗宝石-周期检查": {
461+
"type": "switch",
462+
"label": "每日仅检查一次",
463+
"description": "",
464+
"cases": [
465+
{
466+
"name": "No",
467+
"pipeline_override": {
468+
"巅峰对决_战斗宝石周期检查": {
469+
"action": "DoNothing"
470+
}
471+
}
472+
},
473+
{
474+
"name": "Yes"
475+
}
476+
]
477+
},
478+
"巅峰对决-竞技场对战": {
479+
"type": "switch",
480+
"label": "领取战斗宝石",
481+
"description": "",
482+
"cases": [
483+
{
484+
"name": "Yes",
485+
"option": ["巅峰对决-竞技场对战-周期检查"]
486+
},
487+
{
488+
"name": "No",
489+
"pipeline_override": {
490+
"巅峰对决_对战开始": {
491+
"next": "巅峰对决_对战结束"
492+
}
493+
}
494+
}
495+
]
496+
},
497+
"巅峰对决-竞技场对战-周期检查": {
498+
"type": "switch",
499+
"label": "每日仅检查一次",
500+
"description": "",
501+
"cases": [
502+
{
503+
"name": "No",
504+
"pipeline_override": {
505+
"巅峰对决_对战周期检查": {
506+
"action": "DoNothing"
507+
}
508+
}
509+
},
510+
{
511+
"name": "Yes"
512+
}
513+
]
430514
}
515+
// ========== 巅峰对决 ==========
431516
}
432517
}

0 commit comments

Comments
 (0)