Skip to content
Open
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
40 changes: 17 additions & 23 deletions agent/custom/action/AutoFish/auto_buy_fish_bait.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from pathlib import Path
from ..Common.utils import get_image, match_template_in_region, click_rect
from ..Common.utils import get_image, match_template_in_region_720, click_rect, click_rect_720
from utils import screen

from maa.agent.agent_server import AgentServer
Expand Down Expand Up @@ -38,26 +38,20 @@ class AutoBuyFishBait(CustomAction):
def run(
self, context: Context, argv: CustomAction.RunArg
) -> CustomAction.RunResult:
controller = context.tasker.controller
get_image(controller)

fish_shop_region = [35, 88, 410, 475]
find_bait_success_region = [1044, 131, 68, 23]
select_max_region = [1202, 620, 33, 32]
buy_region = [1050, 674, 50, 25]
buy_confirm_region = [749, 462, 47, 25]
buy_success_region = [569, 629, 145, 19]
not_enough_shell_region = [1170, 585, 18, 16]
shell_count_region = [961, 31, 70, 21]

fish_shop_region = screen.map_rect(fish_shop_region)
find_bait_success_region = screen.map_rect(find_bait_success_region)
select_max_region = screen.map_rect(select_max_region)
buy_region = screen.map_rect(buy_region)
buy_confirm_region = screen.map_rect(buy_confirm_region)
buy_success_region = screen.map_rect(buy_success_region)
not_enough_shell_region = screen.map_rect(not_enough_shell_region)
shell_count_region = screen.map_rect(shell_count_region)

click_w, click_h = screen.map_point_to_frame(30, 10)

KEY_R = 82
KEY_ESC = 27
controller = context.tasker.controller

found_bait_threshold = 0.7
if argv.custom_action_param:
Expand All @@ -72,20 +66,20 @@ def run(
match_threshold = 0.7
while True:
img = get_image(controller)
found_bait, prob, x, y = match_template_in_region(
found_bait, prob, x, y = match_template_in_region_720(
img, fish_shop_region, self.bait_template, found_bait_threshold
)
if found_bait:
controller.post_touch_move(
x, y
) # 先移动到指定位置再进行点击,否则可能会触发滑动买到别的东东
for _ in range(3):
click_rect(controller, [x, y, 30, 10])
click_rect(controller, [x, y, click_w, click_h])
time.sleep(0.1)

time.sleep(1) # 120hz下可能会过快地出现触发检测。适当的延时
img = get_image(controller)
found_bait_success, _, _, _ = match_template_in_region(
found_bait_success, _, _, _ = match_template_in_region_720(
img,
find_bait_success_region,
self.find_bait_success_template,
Expand All @@ -105,13 +99,13 @@ def run(

while True:
img = get_image(controller)
found_select_max, prob, _, _ = match_template_in_region(
found_select_max, prob, _, _ = match_template_in_region_720(
img, select_max_region, self.select_max_template, match_threshold
)
if found_select_max:
PrintT(context, "autofish.select_max_found")
for _ in range(5):
click_rect(controller, select_max_region, 0.3)
click_rect_720(controller, select_max_region, 0.3)
time.sleep(0.1)
time.sleep(1)
break
Expand All @@ -121,13 +115,13 @@ def run(

while True:
img = get_image(controller)
found_buy, _, _, _ = match_template_in_region(
found_buy, _, _, _ = match_template_in_region_720(
img, buy_region, self.buy_template, match_threshold
)
if found_buy:
PrintT(context, "autofish.buy_button_click")
for _ in range(3):
click_rect(controller, buy_region, 0.3)
click_rect_720(controller, buy_region, 0.3)
time.sleep(0.1)
time.sleep(0.5)
break
Expand All @@ -137,13 +131,13 @@ def run(

for _ in range(5):
img = get_image(controller)
found_buy_confirm, _, _, _ = match_template_in_region(
found_buy_confirm, _, _, _ = match_template_in_region_720(
img, buy_confirm_region, self.buy_confirm_template, match_threshold
)
if found_buy_confirm:
PrintT(context, "autofish.buy_confirm_click")
for _ in range(3):
click_rect(controller, buy_confirm_region)
click_rect_720(controller, buy_confirm_region)
time.sleep(0.1)
time.sleep(0.5)
break
Expand All @@ -153,7 +147,7 @@ def run(

while True:
img = get_image(controller)
found_buy_success, _, _, _ = match_template_in_region(
found_buy_success, _, _, _ = match_template_in_region_720(
img, buy_success_region, self.buy_success_template, match_threshold
)
if found_buy_success:
Expand Down
50 changes: 23 additions & 27 deletions agent/custom/action/AutoFish/auto_fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from pathlib import Path
from ..Common.utils import get_image, match_template_in_region
from ..Common.utils import get_image, match_template_in_region_720
from ..Common.logger import get_logger
from utils import screen

Expand Down Expand Up @@ -68,6 +68,7 @@ def run(
KEY_F = 70
KEY_ESC = 27

get_image(controller)
success_region = [520, 160, 265, 30]
settlement_region = [566, 642, 150, 23]
game_region = [401, 39, 481, 24]
Expand All @@ -76,16 +77,10 @@ def run(
fish_game_sign_region = [1141, 609, 87, 84]
fish_game_sign_region_2 = [1224, 27, 30, 30]
need_bait_region = [610, 350, 141, 21]
deadzone = max(1, int(round(15 * screen.scaling_factors()[0])))
deadzone_720 = 15
deadzone = max(1, int(round(deadzone_720 * screen.frame_scaling_factors()[0])))

success_region = screen.map_rect(success_region)
settlement_region = screen.map_rect(settlement_region)
game_region = screen.map_rect(game_region)
escape_region = screen.map_rect(escape_region)
prepare_region = screen.map_rect(prepare_region)
fish_game_sign_region = screen.map_rect(fish_game_sign_region)
fish_game_sign_region_2 = screen.map_rect(fish_game_sign_region_2)
need_bait_region = screen.map_rect(need_bait_region)
game_region_frame = screen.map_rect_to_frame(game_region)

def press_esc():
controller.post_key_down(KEY_ESC)
Expand All @@ -99,7 +94,7 @@ def wait_until_settlement_disappears(timeout=1.0, interval=0.05):
return False

img = get_image(controller)
matched, _, _, _ = match_template_in_region(
matched, _, _, _ = match_template_in_region_720(
img, settlement_region, self.settlement_template, 0.8
)

Expand All @@ -113,7 +108,7 @@ def ensure_fish_game():
for _ in range(10):
img = get_image(controller)

m_settle, _, _, _ = match_template_in_region(
m_settle, _, _, _ = match_template_in_region_720(
img, settlement_region, self.settlement_template, 0.8
)
if m_settle:
Expand All @@ -124,7 +119,7 @@ def ensure_fish_game():
wait_until_settlement_disappears()
continue

m_game, game_prob, _, _ = match_template_in_region(
m_game, game_prob, _, _ = match_template_in_region_720(
img,
fish_game_sign_region_2,
self.fish_game_sign_template,
Expand All @@ -137,12 +132,13 @@ def ensure_fish_game():
if m_game:
return True

m_prepare, _, x, y = match_template_in_region(
m_prepare, _, x, y = match_template_in_region_720(
img, prepare_region, self.prepare_start_template, 0.7
)
if m_prepare:
# logger.debug("On FishPrepare screen, pressing start...")
controller.post_click(x + 15, y + 15)
offset_x, offset_y = screen.map_point_to_frame(15, 15)
controller.post_click(x + offset_x, y + offset_y)
time.sleep(1.5)
return True

Expand All @@ -169,7 +165,7 @@ def ensure_fish_game():

for _ in range(5):
img = get_image(controller)
m_need_bait, prob, _, _ = match_template_in_region(
m_need_bait, prob, _, _ = match_template_in_region_720(
img, need_bait_region, self.need_bait_template, 0.7
)
# logger.debug(f"Checking for bait, probability: {prob:.2f}")
Expand Down Expand Up @@ -200,7 +196,7 @@ def ensure_fish_game():
time.sleep(check_freq)
img = get_image(controller)

m_settle_unexpected, _, _, _ = match_template_in_region(
m_settle_unexpected, _, _, _ = match_template_in_region_720(
img, settlement_region, self.settlement_template, 0.8
)
if m_settle_unexpected:
Expand All @@ -209,7 +205,7 @@ def ensure_fish_game():
# )
break

m_catch, _, _, _ = match_template_in_region(
m_catch, _, _, _ = match_template_in_region_720(
img, success_region, self.success_catch_template, 0.7
)
if m_catch:
Expand All @@ -224,10 +220,10 @@ def ensure_fish_game():

start_time = time.time()
frame = 0
deadzone = 15
deadzone = max(1, int(round(deadzone_720 * screen.frame_scaling_factors()[0])))
current_ad_key = None
last_bar_width = 100
last_target = (game_region[0] + game_region[2]) / 2
last_target = (game_region_frame[0] + game_region_frame[2]) / 2
last_x_slider = last_target
slider_miss_count = 0

Expand All @@ -250,26 +246,26 @@ def set_ad_key(key):
frame += 1

if frame % 10 == 0:
m_settle, _, _, _ = match_template_in_region(
m_settle, _, _, _ = match_template_in_region_720(
img, settlement_region, self.settlement_template, 0.8
)
if m_settle:
# logger.debug("Fish caught!")
break
m_escape, _, _, _ = match_template_in_region(
m_escape, _, _, _ = match_template_in_region_720(
img, escape_region, self.escape_template, 0.8
)
if m_escape:
# logger.debug("Fish escaped! Recasting...")
break

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

Expand Down Expand Up @@ -323,7 +319,7 @@ def set_ad_key(key):

img = get_image(controller)
time.sleep(0.3)
m_escape, _, _, _ = match_template_in_region(
m_escape, _, _, _ = match_template_in_region_720(
img, escape_region, self.escape_template, 0.8
)
if m_escape:
Expand All @@ -339,7 +335,7 @@ def set_ad_key(key):
return CustomAction.RunResult(success=False)

img = get_image(controller)
match_settle, settle_prob, _, _ = match_template_in_region(
match_settle, settle_prob, _, _ = match_template_in_region_720(
img, settlement_region, self.settlement_template, 0.8
)
# logger.debug(
Expand Down
11 changes: 9 additions & 2 deletions agent/custom/action/AutoFish/auto_fish_withoutCV.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from utils.logger import logger
from utils.maafocus import Print, PrintT
from utils import screen

# 长按左/右键时,光标在进度条上水平移动约 200 像素/秒,用于将偏移(像素)换算为 LongPress 时长
CURSOR_PX_PER_SEC = (
Expand Down Expand Up @@ -37,12 +38,16 @@ def run(
except Exception:
pass

deadzone_720 = deadzone

logger.debug("钓鱼开始:进入控条阶段(绿条/光标对齐)")
# 钓鱼阶段
while not context.tasker.stopping:
image = (
context.tasker.controller.post_screencap().wait().get()
) # (720, 1280, 3),自动缩放至框架规定的标准res
)
screen.update_frame_size_from_image(image)
deadzone = max(1, int(round(deadzone_720 * screen.frame_scaling_factors()[0])))
green_bar = context.run_recognition("FishGreenBar", image)
cursor = context.run_recognition("FishCursor", image)

Expand All @@ -58,6 +63,8 @@ def run(
):
time.sleep(0.5)
image = context.tasker.controller.post_screencap().wait().get()
screen.update_frame_size_from_image(image)
deadzone = max(1, int(round(deadzone_720 * screen.frame_scaling_factors()[0])))
click_blank = context.run_recognition("SceneClickBlankToExit", image)
if click_blank and click_blank.hit:
PrintT(context, "autofish.fish_caught")
Expand Down Expand Up @@ -88,7 +95,7 @@ def run(
offset = cursor_center_x - green_bar_center_x

abs_offset = abs(offset)
scaled_px_per_sec = max(1.0, CURSOR_PX_PER_SEC)
scaled_px_per_sec = max(1.0, CURSOR_PX_PER_SEC * screen.frame_scaling_factors()[0])
base_ms = (abs_offset / scaled_px_per_sec) * 1000.0
duration_ms = min(cap_ms, max(floor_ms, int(base_ms * factor)))

Expand Down
Loading
Loading