Skip to content

Commit f8ef88b

Browse files
authored
Merge branch '1bananachicken:main' into main
2 parents ac73464 + abbadab commit f8ef88b

7 files changed

Lines changed: 31 additions & 11 deletions

File tree

agent/custom/action/auto_buy_fish_bait.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

agent/custom/action/auto_fish.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
9191
print(f"=== Fishing {i + 1}/{fishing_count} ===")
9292

9393
while True:
94-
94+
if context.tasker.stopping:
95+
return CustomAction.RunResult(success=False)
9596
controller.post_key_down(KEY_F)
9697
time.sleep(0.1)
9798
controller.post_key_up(KEY_F)
9899
print(" Casting...")
99100

100101
while True:
102+
if context.tasker.stopping:
103+
return CustomAction.RunResult(success=False)
101104
time.sleep(check_freq)
102105
img = get_image(controller)
103106
m_catch, _, _, _ = match_template_in_region(img, success_region, self.success_catch_template, 0.8)
@@ -113,6 +116,8 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
113116
deadzone = 15
114117

115118
while time.time() - start_time < 100:
119+
if context.tasker.stopping:
120+
return CustomAction.RunResult(success=False)
116121
time.sleep(check_freq)
117122
img = get_image(controller)
118123
frame += 1

agent/custom/action/auto_sell_fish.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ class AutoSellFish(CustomAction):
2323
sell_button_img = image_dir / "sell_button.png"
2424
confirm_sell_img = image_dir / "confirm_sell.png"
2525
sell_success_img = image_dir / "sell_success.png"
26+
sell_fail_img = image_dir / "sell_fail.png"
2627
sell_option_template = cv2.imread(str(sell_option_img), cv2.IMREAD_COLOR)
2728
sell_option_selected_template = cv2.imread(str(sell_option_selected_img), cv2.IMREAD_COLOR)
2829
no_fish_to_sell_template = cv2.imread(str(no_fish_to_sell_img), cv2.IMREAD_COLOR)
2930
sell_button_template = cv2.imread(str(sell_button_img), cv2.IMREAD_COLOR)
3031
confirm_sell_template = cv2.imread(str(confirm_sell_img), cv2.IMREAD_COLOR)
3132
sell_success_template = cv2.imread(str(sell_success_img), cv2.IMREAD_COLOR)
33+
sell_fail_template = cv2.imread(str(sell_fail_img), cv2.IMREAD_COLOR)
3234

3335
def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunResult:
3436
print("=== Autofish Action Started ===")
@@ -43,6 +45,8 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
4345
sell_button_region = [665, 635, 92, 23]
4446
confirm_sell_region = [756, 461, 48, 21]
4547
sell_success_region = [565, 628, 149, 21]
48+
sell_fail_region = [739, 349, 202, 24]
49+
no_valid_fish_region = [509, 350, 261, 22]
4650

4751
while True:
4852
img = get_image(controller)
@@ -84,13 +88,18 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
8488

8589
img = get_image(controller)
8690
found_confirm_sell, _, _, _ = match_template_in_region(img, confirm_sell_region, self.confirm_sell_template, 0.8)
91+
sell_fail, _, _, _ = match_template_in_region(img, sell_fail_region, self.sell_fail_template, 0.8)
8792
if found_confirm_sell:
8893
print("Confirm sell button detected. Clicking to confirm selling fish.")
8994
for _ in range(3):
9095
click_rect(controller, confirm_sell_region)
9196
time.sleep(0.1)
9297
time.sleep(1)
9398
break
99+
elif sell_fail:
100+
print("no fish to sell, closing fish shop.")
101+
controller.post_click_key(KEY_ESC).wait()
102+
return CustomAction.RunResult(success=True)
94103
else:
95104
time.sleep(0.1)
96105
break
-447 Bytes
Loading
9.1 KB
Loading
7.67 KB
Loading

assets/resource/base/pipeline/auto_fish_rountine.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515
"freq": 0.001
1616
},
1717
"next": [
18-
"AutoSellFish"
18+
"AutoSellFish",
19+
"AutoBuyFishBait",
20+
"StartFishing",
21+
"TaskComplete"
1922
]
2023
},
2124
"AutoSellFish": {
2225
"action": "Custom",
2326
"custom_action": "auto_sell_fish",
2427
"next": [
25-
"AutoBuyFishBait"
28+
"AutoBuyFishBait",
29+
"StartFishing",
30+
"TaskComplete"
2631
]
2732
},
2833
"AutoBuyFishBait": {

0 commit comments

Comments
 (0)