Skip to content

等待战斗结束时的截图操作不强制移动鼠标#554

Open
JoshCai233 wants to merge 1 commit intoOneDragon-Anything:mainfrom
JoshCai233:dont_move_mouse_in_battle
Open

等待战斗结束时的截图操作不强制移动鼠标#554
JoshCai233 wants to merge 1 commit intoOneDragon-Anything:mainfrom
JoshCai233:dont_move_mouse_in_battle

Conversation

@JoshCai233
Copy link
Copy Markdown
Contributor

@JoshCai233 JoshCai233 commented Dec 7, 2025

Summary by CodeRabbit

发布说明

  • 优化
    • 改进截图功能的鼠标行为控制,添加可选参数以灵活禁用鼠标移动
    • 调整战斗结果等待时的截图处理逻辑,提升输入捕获的稳定性

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 7, 2025

概览

该变更在屏幕截图调用链中引入了 dont_move_mouse 可选参数,允许调用者在截图前禁用自动鼠标移动。该参数从基础控制器类层层传递,贯穿操作基类和具体实现,并通过装饰器参数 screenshot_before_round=False 在特定战斗等待操作中使用。

变更

内聚体 / 文件 变更摘要
基础框架 - 方法签名扩展
src/one_dragon/base/controller/controller_base.py, src/one_dragon/base/operation/operation.py
screenshot()before_screenshot() 方法中添加 dont_move_mouse: bool = False 参数,建立参数传递链路,保留现有返回类型和行为
控制器实现 - 鼠标移动条件控制
src/sr_od/context/sr_pc_controller.py
更新 before_screenshot() 方法以接受 dont_move_mouse 参数,当参数为 True 时跳过鼠标移动到 (30, 1030) 的操作
战斗操作节点 - 装饰器与截图更新
src/sr_od/app/echo_of_war/challenge_ehco_of_war.py, src/sr_od/challenge_mission/use_trailblaze_power.py, src/sr_od/operations/battle/wait_battle_result.py
_wait_battle_result / wait 方法的 operation_node 装饰器中添加 screenshot_before_round=False,并将截图调用更改为 screenshot(dont_move_mouse=True) 以禁用鼠标移动

代码审查工作量估计

🎯 3 (中等) | ⏱️ ~22 分钟

需要额外关注的区域:

  • src/sr_od/context/sr_pc_controller.pybefore_screenshot() 的条件逻辑确保在 dont_move_mouse=False 时保持向后兼容
  • 验证三个战斗操作文件(challenge_ehco_of_war.pyuse_trailblaze_power.pywait_battle_result.py)中的 screenshot(dont_move_mouse=True) 调用是否有一致的意图和副作用
  • 确认 screenshot_before_round=False 装饰器参数的引入不会影响其他操作节点的现有行为

🐰 小兔喜欢新参数,截图无须动鼠标,
参数链条清又明,基础到操作妙相连,
战斗等待静悄悄,功能圆满无烦恼!✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request title accurately describes the main change: preventing forced mouse movement during screenshots when waiting for battle end.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/sr_od/challenge_mission/use_trailblaze_power.py (1)

1-1: 等待战斗结果节点改动合理,顺便建议清理无用的 screen 导入

  • _wait_battle_result 上把 screenshot_before_round=False 与内部 self.screenshot(dont_move_mouse=True) 搭配使用,语义和 EchoOfWar / WaitBattleResult 中的等待节点保持一致,避免了重复截图和强制移动鼠标,符合预期。
  • 顶部 from PIL.ImageChops import screen 未被使用,并且与函数内的局部变量 screen 同名,Ruff 报 F811(“Redefinition of unused screen”);建议直接删除该导入,既消除告警也减少读者困惑。

可以按如下方式调整 import 部分:

-from PIL.ImageChops import screen
-from typing import Optional, Callable, ClassVar
+from typing import Optional, Callable, ClassVar

Also applies to: 180-202

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b55bee and 9e9fa51.

📒 Files selected for processing (6)
  • src/one_dragon/base/controller/controller_base.py (2 hunks)
  • src/one_dragon/base/operation/operation.py (2 hunks)
  • src/sr_od/app/echo_of_war/challenge_ehco_of_war.py (1 hunks)
  • src/sr_od/challenge_mission/use_trailblaze_power.py (1 hunks)
  • src/sr_od/context/sr_pc_controller.py (1 hunks)
  • src/sr_od/operations/battle/wait_battle_result.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-13T12:07:30.874Z
Learnt from: JoshCai233
Repo: OneDragon-Anything/StarRailOneDragon PR: 521
File: src/sr_od/app/sim_uni/sim_uni_app.py:61-87
Timestamp: 2025-10-13T12:07:30.874Z
Learning: 在 `_check_points_reward()` 中,`OperationRoundResult` 的语义与常规不同:`FAIL` 表示"奖励未完成,需要继续执行自动化",而 `SUCCESS` 和 `RETRY` 表示"提前返回,跳过自动化"。这是因为调用方使用 `if result != FAIL: return` 来判断是否跳过后续的自动化脚本执行。

Applied to files:

  • src/sr_od/app/echo_of_war/challenge_ehco_of_war.py
  • src/sr_od/challenge_mission/use_trailblaze_power.py
🧬 Code graph analysis (4)
src/sr_od/context/sr_pc_controller.py (2)
src/one_dragon/base/controller/controller_base.py (1)
  • before_screenshot (75-79)
src/one_dragon/base/controller/pc_controller_base.py (1)
  • mouse_move (204-210)
src/one_dragon/base/controller/controller_base.py (2)
src/one_dragon/base/operation/operation.py (1)
  • screenshot (624-634)
src/sr_od/context/sr_pc_controller.py (1)
  • before_screenshot (43-45)
src/sr_od/challenge_mission/use_trailblaze_power.py (3)
src/one_dragon/base/operation/operation_node.py (1)
  • operation_node (72-100)
src/one_dragon/base/operation/operation.py (2)
  • name (44-48)
  • screenshot (624-634)
src/sr_od/app/echo_of_war/challenge_ehco_of_war.py (1)
  • _wait_battle_result (150-168)
src/one_dragon/base/operation/operation.py (1)
src/one_dragon/base/controller/controller_base.py (1)
  • screenshot (53-73)
🪛 Ruff (0.14.7)
src/sr_od/challenge_mission/use_trailblaze_power.py

186-186: Redefinition of unused screen from line 1

(F811)

🔇 Additional comments (5)
src/one_dragon/base/operation/operation.py (1)

624-634: Operation.screenshot 扩展参数设计合理

这里增加 dont_move_mouse 并通过关键字透传到 ctx.controller.screenshot,对现有仅位置参数调用是向后兼容的;上层等待战斗结果节点用 dont_move_mouse=True 也能正确生效。后续如再新增调用点,建议也统一用关键字参数,避免误把其他布尔值位置上传给 dont_move_mouse

src/sr_od/app/echo_of_war/challenge_ehco_of_war.py (1)

149-150: 等待战斗结果节点的截图行为调整是合理的

screenshot_before_round=False 配合节点内部的 self.screenshot(dont_move_mouse=True),避免了每轮自动多截一张图,也避免在战斗结算期间强行移动鼠标;对 battle_screen_state.get_tp_battle_screen_state 的逻辑没有改变,只是截图时机和鼠标行为更可控,符合“等待战斗结束时不强制移动鼠标”的需求。

Also applies to: 155-168

src/sr_od/operations/battle/wait_battle_result.py (1)

17-20: WaitBattleResult 的截图策略与其他等待节点保持一致

wait 节点现在禁用了自动轮前截图,改为在函数内部调用 self.screenshot(dont_move_mouse=True),和其他等待战斗结果的节点风格统一,同时避免在长时间等待期间反复移动鼠标。try_attack 分支仍然在识别到大世界画面后主动操作,与本次改动没有冲突。

src/sr_od/context/sr_pc_controller.py (1)

43-46: before_screenshot 的新参数实现与基类对齐

这里的实现很好地利用了新加的 dont_move_mouse:默认仍然把鼠标移动到 fill_uid_black 遮挡区域,保持旧行为不变;在需要时(如等待战斗结果)可以通过 dont_move_mouse=True 完全跳过鼠标移动。与基类签名一致,便于后续扩展其它平台控制器时复用这一约定。

src/one_dragon/base/controller/controller_base.py (1)

53-57: Verify all subclass overrides of before_screenshot have the updated signature

The screenshot method now passes dont_move_mouse as a keyword argument to before_screenshot. Any subclass that overrides before_screenshot without accepting this parameter will raise TypeError at runtime. Ensure all implementations include def before_screenshot(self, dont_move_mouse: bool = False) or compatible signature.

Copy link
Copy Markdown
Collaborator

@DoctorReid DoctorReid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个改动的主要目的是?

@JoshCai233
Copy link
Copy Markdown
Contributor Author

这个改动的主要目的是?

在等待副本自动战斗结束时,游戏不需要操作鼠标,脚本只需要检测战斗结束标志即可,但是鼠标会每秒一次地移动到崩铁的左下角,用户需要按下脚本暂停键才能使用鼠标的正常功能

  1. 使用场景:
  • 想远程桌面挂其他脚本、本地桌面挂崩铁的同时使用电脑的副屏刷视频时、或者临时回复消息时
  • 使用pycharm等工具调试脚本打副本相关内容时
  1. 等待战斗结束时不移动鼠标的可行性:
  • 点击开始挑战、确认弹框或者平a进入战斗时鼠标不会出现在屏幕上半部分,而结尾的挑战成功字样出现在屏幕上半部分,等待战斗结束时不动鼠标并不会影响识别挑战结果
  • 如果用户动了鼠标导致识别挑战结果不成功,用户也能把鼠标动回去

@Usagi-wusaqi
Copy link
Copy Markdown
Contributor

Usagi-wusaqi commented Dec 20, 2025

这个改动的主要目的是?

在等待副本自动战斗结束时,游戏不需要操作鼠标,脚本只需要检测战斗结束标志即可,但是鼠标会每秒一次地移动到崩铁的左下角,用户需要按下脚本暂停键才能使用鼠标的正常功能

  1. 使用场景:
  • 想远程桌面挂其他脚本、本地桌面挂崩铁的同时使用电脑的副屏刷视频时、或者临时回复消息时
  • 使用pycharm等工具调试脚本打副本相关内容时
  1. 等待战斗结束时不移动鼠标的可行性:
  • 点击开始挑战、确认弹框或者平a进入战斗时鼠标不会出现在屏幕上半部分,而结尾的挑战成功字样出现在屏幕上半部分,等待战斗结束时不动鼠标并不会影响识别挑战结果
  • 如果用户动了鼠标导致识别挑战结果不成功,用户也能把鼠标动回去

额,我还想着绝龙也强制抢鼠标,防止用户在运行时非法临时修改一条龙配置呢,跟隔壁原神一样

@JoshCai233
Copy link
Copy Markdown
Contributor Author

额,我还想着绝龙也强制抢鼠标,防止用户在运行时非法临时修改一条龙配置呢,跟隔壁原神一样

  1. bettergi是窗口焦点离开原神就暂停,而且原神需要一直操作鼠标,但是崩铁不用啊
  2. 想变打边改配置可以按暂停改配置,防不住的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants