@@ -33,7 +33,6 @@ class AutoBuyFishBait(CustomAction):
3333 buy_success_template = cv2 .imread (str (buy_success_img ), cv2 .IMREAD_COLOR )
3434
3535 def run (self , context : Context , argv : CustomAction .RunArg ) -> CustomAction .RunResult :
36- bait_region = [208 , 209 , 59 , 27 ]
3736 fish_shop_region = [35 , 88 , 410 , 475 ]
3837 find_bait_success_region = [1044 , 131 , 68 , 23 ]
3938 select_max_region = [1202 , 620 , 33 , 32 ]
@@ -47,16 +46,18 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
4746 controller = context .tasker .controller
4847 print ("=== AutoBuyFishBait Action Started ===" )
4948
49+ match_threshold = 0.7
5050 while True :
5151 img = get_image (controller )
52- found_bait , _ , x , y = match_template_in_region (img , fish_shop_region , self .bait_template , 0.8 )
52+ found_bait , prob , x , y = match_template_in_region (img , fish_shop_region , self .bait_template , match_threshold )
53+ print (f"Clicked on bait at ({ x + 15 } , { y + 5 } ), probability: { prob :.2f} " )
5354 if found_bait :
5455 for _ in range (3 ):
55- click_rect (controller , [x , y , bait_region [ 2 ], bait_region [ 3 ] ])
56+ click_rect (controller , [x , y , 30 , 10 ])
5657 time .sleep (0.1 )
5758
5859 img = get_image (controller )
59- found_bait_success , _ , _ , _ = match_template_in_region (img , find_bait_success_region , self .find_bait_success_template , 0.8 )
60+ found_bait_success , _ , _ , _ = match_template_in_region (img , find_bait_success_region , self .find_bait_success_template , match_threshold )
6061 if found_bait_success :
6162 img = get_image (controller )
6263 time .sleep (0.5 )
@@ -69,7 +70,7 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
6970
7071 while True :
7172 img = get_image (controller )
72- found_select_max , _ , _ , _ = match_template_in_region (img , select_max_region , self .select_max_template , 0.8 )
73+ found_select_max , _ , _ , _ = match_template_in_region (img , select_max_region , self .select_max_template , match_threshold )
7374 if found_select_max :
7475 for _ in range (3 ):
7576 click_rect (controller , select_max_region )
@@ -82,7 +83,7 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
8283
8384 while True :
8485 img = get_image (controller )
85- found_buy , _ , _ , _ = match_template_in_region (img , buy_region , self .buy_template , 0.8 )
86+ found_buy , _ , _ , _ = match_template_in_region (img , buy_region , self .buy_template , match_threshold )
8687 if found_buy :
8788 for _ in range (3 ):
8889 click_rect (controller , buy_region )
@@ -95,7 +96,7 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
9596
9697 for _ in range (5 ):
9798 img = get_image (controller )
98- found_buy_confirm , _ , _ , _ = match_template_in_region (img , buy_confirm_region , self .buy_confirm_template , 0.8 )
99+ found_buy_confirm , _ , _ , _ = match_template_in_region (img , buy_confirm_region , self .buy_confirm_template , match_threshold )
99100 if found_buy_confirm :
100101 for _ in range (3 ):
101102 click_rect (controller , buy_confirm_region )
@@ -108,7 +109,7 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
108109
109110 while True :
110111 img = get_image (controller )
111- found_buy_success , _ , _ , _ = match_template_in_region (img , buy_success_region , self .buy_success_template , 0.8 )
112+ found_buy_success , _ , _ , _ = match_template_in_region (img , buy_success_region , self .buy_success_template , match_threshold )
112113 if found_buy_success :
113114 controller .post_click_key (KEY_ESC ).wait ()
114115 time .sleep (0.5 )
0 commit comments