@@ -20,7 +20,6 @@ def run(
2020 self , context : Context , argv : CustomAction .RunArg
2121 ) -> CustomAction .RunResult :
2222 deadzone = 15 # 光标与绿条中心的距离在 deadzone(像素)以内时不操作,避免过度频繁地轻微调整导致的抖动
23- max_try_item = 5 # 识别不完整(绿条或光标未命中)的最大尝试次数,超过后放弃本次钓鱼,重新抛竿(执行 FishHook)
2423 factor = 1.5 # 控条时长的调整因子,实际时长 = 基础时长 * factor,基础时长 = (光标与绿条中心的像素偏移 / CURSOR_PX_PER_SEC) * 1000ms,增加 factor 可以适当补偿识别误差和按键响应延迟
2524 cap_ms = (
2625 1500 # 控条时长的上限(毫秒),避免因识别到较大偏移时按键过久,导致过度补偿
@@ -32,7 +31,6 @@ def run(
3231 try :
3332 params = json .loads (argv .custom_action_param )
3433 deadzone = params .get ("deadzone" , deadzone )
35- max_try_item = params .get ("max_try" , max_try_item )
3634 factor = params .get ("factor" , factor )
3735 cap_ms = params .get ("cap_ms" , cap_ms )
3836 floor_ms = params .get ("floor_ms" , floor_ms )
@@ -48,7 +46,7 @@ def run(
4846 green_bar = context .run_recognition ("FishGreenBar" , image )
4947 cursor = context .run_recognition ("FishCursor" , image )
5048
51- if not (
49+ while not (
5250 green_bar
5351 and green_bar .hit
5452 and green_bar .box
@@ -58,21 +56,26 @@ def run(
5856 and cursor .box
5957 is not None # 这个是为了消除pylance的warning,实际运行时不应该有None的情况
6058 ):
61- # 绿条/光标未命中时检查是否已弹出结算画面
59+ time .sleep (0.5 )
60+ image = context .tasker .controller .post_screencap ().wait ().get ()
61+
6262 click_blank = context .run_recognition ("SceneClickBlankToExit" , image )
6363 if click_blank and click_blank .hit :
6464 PrintT (context , "autofish.fish_caught" )
65+ logger .debug ("识别到钓上鱼, 钓鱼退出" )
6566 return CustomAction .RunResult (success = True )
6667
67- max_try_item -= 1
68- logger .debug (
69- f"识别不完整(绿条或光标未命中),剩余尝试次数: { max_try_item } "
70- )
71-
72- if max_try_item <= 0 :
73- logger .debug ("尝试次数用尽,控条失败" )
68+ fish_escape = context .run_recognition ("FishEscape" , image )
69+ if fish_escape and fish_escape .hit :
70+ PrintT (context , "autofish.fish_escape" )
71+ logger .debug ("识别到鱼溜走,钓鱼退出" )
72+ return CustomAction .RunResult (success = True )
73+ fish_on_gaming = context .run_recognition ("FishSceneOnFishGame" , image )
74+ if fish_on_gaming and fish_on_gaming .hit :
75+ Print (
76+ context , "钓鱼异常结束(可能是鱼溜走),继续钓鱼"
77+ ) # 通常不会执行这一步
7478 return CustomAction .RunResult (success = True )
75- # 看来就是通过识别失败几次直接通用适配成功/失败的情况的,不用管,根本没有去识别有没有钓到
7679 continue
7780
7881 green_bar_x , green_bar_y , green_bar_w , green_bar_h = green_bar .box
@@ -113,5 +116,5 @@ def run(
113116 },
114117 )
115118
116- logger .debug ("任务结束(success=True) " )
119+ logger .debug ("任务中止 " )
117120 return CustomAction .RunResult (success = True )
0 commit comments