Skip to content

Commit 86a4200

Browse files
committed
优化了钓鱼逻辑,加快授渔以鱼时的识别速度提高成功率
1 parent e8228e6 commit 86a4200

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

src/tasks/fullauto/AutoFishTask.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,7 @@ def phase_start(self) -> bool:
238238
# ensure foreground handled by framework interaction activation
239239
start_deadline = time.monotonic() + cfg.get("MAX_START_SEC", 20.0)
240240

241-
has_cast_icon, _ = self.find_fish_cast()
242-
self.stats["last_cast_icon_found"] = has_cast_icon
243-
244-
# 检测是否有授渔以鱼机会
241+
# 检测是否有授渔以鱼机会 (优先执行且短路,减少不必要的对比开销)
245242
has_chance_icon, _ = self.find_fish_chance()
246243
if has_chance_icon:
247244
logger.info("检测到fish_chance(授渔以鱼)-> 按下E键使用授渔以鱼抛竿")
@@ -253,13 +250,16 @@ def phase_start(self) -> bool:
253250
self.info_set("完成轮数", self.stats["rounds_completed"])
254251
logger.info(f"上一轮的鱼作为鱼饵,轮数调整为: {self.stats['rounds_completed']}")
255252
self.send_key("e", down_time=0.06)
256-
elif not has_cast_icon:
257-
logger.info("开始阶段未找到fish_cast,尝试按空格抛竿并等待fish_bite出现")
258-
# press space to cast
259-
self.send_key("space", down_time=0.06)
260253
else:
261-
logger.info("找到fish_cast -> 按下空格抛竿")
262-
self.send_key("space", down_time=0.06)
254+
has_cast_icon, _ = self.find_fish_cast()
255+
self.stats["last_cast_icon_found"] = has_cast_icon
256+
if not has_cast_icon:
257+
logger.info("开始阶段未找到fish_cast,尝试按空格抛竿并等待fish_bite出现")
258+
# press space to cast
259+
self.send_key("space", down_time=0.06)
260+
else:
261+
logger.info("找到fish_cast -> 按下空格抛竿")
262+
self.send_key("space", down_time=0.06)
263263

264264
logger.info("等待fish_bite出现...")
265265
ret = self.wait_until(lambda: self.find_fish_bite()[0], time_out=start_deadline, raise_if_not_found=False)
@@ -447,25 +447,28 @@ def phase_end(self) -> bool:
447447
logger.info(f"等待 {cfg.get('END_WAIT_SPACE', 7.0)}s 结束鱼信息展示...")
448448
self.sleep(cfg.get("END_WAIT_SPACE", 7.0))
449449

450-
logger.info("点击屏幕以结束鱼信息展示")
451-
self.click_relative_random(0.3, 0.3, 0.7, 0.7)
452-
453450
# wait and verify
454451
confirm_deadline = time.monotonic() + cfg.get("MAX_END_SEC", 20.0)
455452
while time.monotonic() < confirm_deadline:
456-
has_cast_icon, _ = self.find_fish_cast()
457-
has_bite_icon, _ = self.find_fish_bite()
458453
has_chance_icon, _ = self.find_fish_chance()
454+
if has_chance_icon:
455+
logger.info("确认已回到挥杆界面(检测到授渔以鱼)")
456+
return True
457+
458+
has_cast_icon, _ = self.find_fish_cast()
459459
self.stats["last_cast_icon_found"] = has_cast_icon
460+
if has_cast_icon:
461+
logger.info("确认已回到挥杆界面")
462+
return True
463+
464+
has_bite_icon, _ = self.find_fish_bite()
460465
self.stats["last_bite_icon_found"] = has_bite_icon
461-
if has_cast_icon or has_bite_icon or has_chance_icon:
462-
if has_chance_icon:
463-
logger.info("确认已回到挥杆界面(检测到授渔以鱼)")
464-
else:
465-
logger.info("确认已回到挥杆界面")
466+
if has_bite_icon:
467+
logger.info("确认已回到挥杆界面")
466468
return True
467-
self.click_relative_random(0.3, 0.3, 0.7, 0.7)
468-
self.sleep(1.0)
469+
470+
self.click_relative_random(0.6, 0.3, 0.95, 0.7)
471+
self.sleep(0.5)
469472
logger.info("结束阶段确认失败")
470473
return False
471474

0 commit comments

Comments
 (0)