Skip to content

Commit 1ca7bb2

Browse files
committed
fix(WithdrawMoney): 修复快速连续点击导致异常滑动
1 parent 2e11baf commit 1ca7bb2

3 files changed

Lines changed: 45 additions & 43 deletions

File tree

agent/custom/action/withdraw_money_choose_item.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from maa.agent.agent_server import AgentServer
44
from maa.custom_action import CustomAction
55
from maa.context import Context
6+
from utils.logger import logger
67

78

89
def _screencap(controller):
@@ -31,9 +32,11 @@ def _box_to_rect(box):
3132
def _click_rect(controller, rect):
3233
cx = rect[0] + rect[2] // 2
3334
cy = rect[1] + rect[3] // 2
35+
controller.post_touch_move(cx, cy).wait() # 先移动再点击,防止误滑动
3436
controller.post_touch_down(cx, cy).wait()
3537
time.sleep(0.05) # 间隔太短概率失效
3638
controller.post_touch_up().wait()
39+
time.sleep(0.05)
3740

3841

3942
def _parse_value(text):
@@ -68,12 +71,11 @@ def click_all_grey_backgrounds():
6871
result = run_recog("WithdrawMoneyGreyBackground")
6972
for box in _filtered_boxes(result):
7073
_click_rect(controller, _box_to_rect(box))
71-
time.sleep(0.5)
7274

73-
def collect_product_values():
75+
def collect_product_values(recog_name):
7476
"""识别当前截图中所有商品 /h 价格,返回 [(value, rect), ...]"""
7577
items = []
76-
result = run_recog("WithdrawMoneyItemValue")
78+
result = run_recog(recog_name)
7779
for r in result.filtered_results if result else []:
7880
text = getattr(r, "text", "")
7981
value = _parse_value(text)
@@ -94,40 +96,26 @@ def collect_product_values():
9496

9597
# Step 3: 再次关掉灰色背景角标
9698
click_all_grey_backgrounds()
97-
98-
down_items = []
99-
seen = set()
99+
time.sleep(1)
100100

101101
# Step 4: 向下位置匹配商品价格 /h
102-
for value, rect in collect_product_values():
103-
key = (rect[0], rect[1])
104-
if key not in seen:
105-
seen.add(key)
106-
down_items.append((value, rect))
102+
down_items = [
103+
(v, r, "down")
104+
for v, r in collect_product_values("WithdrawMoneyItemValueDown")
105+
]
107106

108107
# Step 5: 向上滑动
109108
run_act("WithdrawMoneySwipeUp")
110-
time.sleep(1)
111-
112-
up_items = []
109+
time.sleep(0.1) # 等待动画
113110

114111
# Step 6: 向上位置匹配商品价格 /h
115-
for value, rect in collect_product_values():
116-
key = (rect[0], rect[1])
117-
if key not in seen:
118-
seen.add(key)
119-
up_items.append((value, rect))
120-
121-
# Step 7: 按 value 去重,从大到小排序,只点前五个
122-
all_items = [(v, r, "down") for v, r in down_items] + [
123-
(v, r, "up") for v, r in up_items
112+
up_items = [
113+
(v, r, "up") for v, r in collect_product_values("WithdrawMoneyItemValueUp")
124114
]
125-
# 按 value 去重(保留第一个出现的 rect)
126-
deduped: dict[float, tuple] = {}
127-
for value, rect, swipe in all_items:
128-
if value not in deduped:
129-
deduped[value] = (value, rect, swipe)
130-
sorted_items = sorted(deduped.values(), key=lambda x: x[0], reverse=True)
115+
116+
# Step 7: 按 value 从大到小排序,只点前五个
117+
all_items = down_items + up_items
118+
sorted_items = sorted(all_items, key=lambda x: x[0], reverse=True)
131119
top5 = sorted_items[:5]
132120

133121
current_swipe = "up"
@@ -142,6 +130,7 @@ def collect_product_values():
142130
current_swipe = "down"
143131
time.sleep(1)
144132
_click_rect(controller, rect)
133+
logger.debug(f"click {value} in {rect} of {item_swipe}")
145134
time.sleep(0.5)
146135

147136
return CustomAction.RunResult(success=True)

assets/resource/base/pipeline/WithdrawMoney/WithdrawMoney.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@
9090
"action": "Click",
9191
"next": [
9292
"[JumpBack]SceneClickBlankToExit",
93-
"WithdrawMoneyEnterItemList",
94-
"点击补货"
93+
"[JumpBack]WithdrawMoneyEnterItemList",
94+
"点击补货",
95+
"WithdrawMoneyExit"
9596
]
9697
},
9798
"WithdrawMoneyEnterItemList": {
@@ -110,8 +111,7 @@
110111
"累計營業時間",
111112
"(?i)Total\\s*Operating\\s*Time",
112113
"累計営業時間"
113-
]
114-
,
114+
],
115115
"roi_offset": [
116116
0,
117117
0,
@@ -153,8 +153,7 @@
153153
"商品列表",
154154
"(?i)Item\\s*List",
155155
"商品リスト"
156-
]
157-
,
156+
],
158157
"roi_offset": [
159158
0,
160159
0,
@@ -191,11 +190,7 @@
191190
]
192191
}
193192
},
194-
"action": "Click",
195-
"next": [
196-
"点击补货",
197-
"WithdrawMoneyExit"
198-
]
193+
"action": "Click"
199194
},
200195
"点击补货": {
201196
"recognition": {
@@ -360,7 +355,6 @@
360355
"確定",
361356
"确定",
362357
"OK",
363-
"CONFIRN",
364358
"확인"
365359
],
366360
"threshold": 0.8,

assets/resource/base/pipeline/WithdrawMoney/WithdrawMoneyStatus.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"duration": 500,
4444
"end_hold": 600
4545
},
46-
"WithdrawMoneyItemValue": {
47-
"desc": "商品列表数值/h",
46+
"WithdrawMoneyItemValueUp": {
47+
"desc": "商品列表数值/h(上)",
4848
"recognition": {
4949
"type": "OCR",
5050
"only_rec": true,
@@ -62,6 +62,25 @@
6262
}
6363
}
6464
},
65+
"WithdrawMoneyItemValueDown": {
66+
"desc": "商品列表数值/h(下)",
67+
"recognition": {
68+
"type": "OCR",
69+
"only_rec": true,
70+
"param": {
71+
"roi": [
72+
29,
73+
222,
74+
391,
75+
462
76+
],
77+
"expected": [
78+
// @i18n-skip
79+
"/h"
80+
]
81+
}
82+
}
83+
},
6584
"WithdrawMoneySwipeUp": {
6685
"desc": "商品列表向上滑动",
6786
"action": "Swipe",

0 commit comments

Comments
 (0)