Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
.venv/

# Visual Studio 6 build log
*.plg
Expand Down
97 changes: 59 additions & 38 deletions agent/custom/action/auto_fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ class Autofish(CustomAction):
else:
image_dir = abs_path / "resource/base/image/auto_fish"
continue_img = image_dir / "continue.png"
valid_region_img = image_dir / "valid_region.png"
valid_region_left_img = image_dir / "valid_region_left.png"
valid_region_right_img = image_dir / "valid_region_right.png"
slider_img = image_dir / "slider.png"
success_catch_img = image_dir / "success_catch.png"

slider_template = cv2.imread(str(slider_img), cv2.IMREAD_COLOR)
valid_region_template = cv2.imread(str(valid_region_img), cv2.IMREAD_COLOR)
valid_region_left_template = cv2.imread(str(valid_region_left_img), cv2.IMREAD_COLOR)
valid_region_right_template = cv2.imread(str(valid_region_right_img), cv2.IMREAD_COLOR)
continue_template = cv2.imread(str(continue_img), cv2.IMREAD_COLOR)
success_catch_template = cv2.imread(str(success_catch_img), cv2.IMREAD_COLOR)

def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunResult:
print("=== Autofish Action Started ===")
controller = context.tasker.controller

fishing_count = 10
check_freq = 0.001
if argv.custom_action_param:
Expand All @@ -70,42 +72,41 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
check_freq = params.get("freq", 0.1)
except:
pass

# Key codes for A, D, F, ESC
KEY_A = 65
KEY_D = 68
KEY_F = 70
KEY_ESC = 27

# Original coordinates from autofish.py
success_region = (520, 160, 785, 190)
settlement_region = (564, 642, 1206, 664)
game_region = (400, 33, 882, 63)
for count in range(fishing_count):
if context.tasker.stopping:

for i in range(fishing_count):
if context.tasker.stopping:
return CustomAction.RunResult(success=False)
print(f"=== Fishing {count + 1}/{fishing_count} ===")
print(f"=== Fishing {i + 1}/{fishing_count} ===")

# 1. Clear settlement screen
img = get_image(controller)
match_settle, _, _, _ = match_template_in_region(img, settlement_region, self.continue_template, 0.8)
if match_settle:
print("Found settlement screen, closing...")
print(" Closing settlement screen...")
for _ in range(5):
controller.post_key_down(KEY_ESC)
time.sleep(0.1)
controller.post_key_up(KEY_ESC)
time.sleep(1)

img = get_image(controller)
m, _, _, _ = match_template_in_region(img, settlement_region, self.continue_template, 0.8)
if not m:
print("Settlement closed.")
print(" Settlement closed.")
break

# 2. Minigame loop
print("Waiting for fish to bite and entering minigame...")

# 2. Wait for fish to bite
while True:
controller.post_key_down(KEY_F)
time.sleep(0.1)
Expand All @@ -114,45 +115,65 @@ def run(self, context: Context, argv: CustomAction.RunArg) -> CustomAction.RunRe
img = get_image(controller)
m_catch, _, _, _ = match_template_in_region(img, success_region, self.success_catch_template, 0.8)
if m_catch:
print("Fish caught! (Settlement screen appeared)")
print(" Fish hooked!")
break

# 3. Minigame: reel in and balance slider
start_time = time.time()

count = 0
frame = 0
deadzone = 15

while time.time() - start_time < 100:
time.sleep(check_freq)
img = get_image(controller)
count += 1
frame += 1

if count % 10 == 0:
if frame % 10 == 0:
m_settle, _, _, _ = match_template_in_region(img, settlement_region, self.continue_template, 0.8)
if m_settle:
print("Fish caught! (Settlement screen appeared)")
print(" Fish caught!")
break

m_region, _, x_region, _ = match_template_in_region(img, game_region, self.valid_region_template, 0.7)

m_left, _, x_left, _ = match_template_in_region(img, game_region, self.valid_region_left_template, 0.7)
m_right, _, x_right, _ = match_template_in_region(img, game_region, self.valid_region_right_template, 0.7)
m_slider, _, x_slider, _ = match_template_in_region(img, game_region, self.slider_template, 0.7)

if m_region and m_slider:
# Reel in
controller.post_key_down(KEY_F)
time.sleep(0.05)
controller.post_key_up(KEY_F)

if m_slider:
# Reel in (throttled)
if frame % 10 == 0:
controller.post_key_down(KEY_F)
time.sleep(0.05)
controller.post_key_up(KEY_F)

# Balance slider
if x_slider > x_region + 20:
controller.post_key_up(KEY_D)
controller.post_key_down(KEY_A)
if m_left and m_right:
target = (x_left + x_right) / 2
offset = x_slider - target
elif not m_left and m_right:
target = x_right
offset = x_slider - target
elif m_left and not m_right:
target = x_left
offset = x_slider - target
else:
controller.post_key_up(KEY_A)
controller.post_key_down(KEY_D)

offset = 0

if m_left or m_right:
if offset > deadzone:
controller.post_key_up(KEY_D)
controller.post_key_down(KEY_A)
elif offset < -deadzone:
controller.post_key_up(KEY_A)
controller.post_key_down(KEY_D)
else:
controller.post_key_up(KEY_A)
controller.post_key_up(KEY_D)

# Release all keys
controller.post_key_up(KEY_D)
controller.post_key_up(KEY_A)
controller.post_key_up(KEY_F)
print("Current iteration finished.")
print(" Finished.")

print("All fishing tasks complete.")
return CustomAction.RunResult(success=True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 35 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading