Skip to content

修复:提高切换队伍时序与错误提示的可靠性#3395

Draft
JerryChen97 wants to merge 2 commits into
babalae:mainfrom
JerryChen97:agent/stabilize-switch-party-timing
Draft

修复:提高切换队伍时序与错误提示的可靠性#3395
JerryChen97 wants to merge 2 commits into
babalae:mainfrom
JerryChen97:agent/stabilize-switch-party-timing

Conversation

@JerryChen97

@JerryChen97 JerryChen97 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

问题背景

该脚本在刚启动游戏、设备性能较低或队伍界面动画尚未结束时,原有的固定等待时间(部分操作仅等待 100~1500 毫秒)可能不足。实际日志中出现过两类相互关联的问题:

  1. OCR 已经识别到目标队伍,但“确定”或“部署”按钮尚未出现或未被识别。
  2. 按钮识别失败后,脚本继续翻页,最终将真实的“部署失败”误报成“没有找到指定队伍名称”。

改动说明

1. 增加可配置的界面操作等待时间

新增 operationDelayMs 设置项,允许配置 500~20000 毫秒,默认值为 1500 毫秒;设置说明中建议性能较低或游戏刚启动时使用 10000~20000 毫秒。

为什么修改: 不同设备加载队伍界面的速度差异较大,固定的短等待无法同时兼顾速度和稳定性。保留 1500 毫秒默认值可以避免普通设备无条件变慢,同时让遇到加载延迟的用户自行增加冗余时间。上下限用于避免无效值或过大的误配置。

2. 将关键界面切换后的固定短等待统一为配置值

进入队伍配置、翻页、选择队伍、点击确定、点击部署和退出界面后的等待,改为使用 operationDelayMs。打开队伍界面的等待至少保留 2000 毫秒。

为什么修改: 这些步骤都依赖前一个界面动画或资源加载完成。原先 100、500 或 1500 毫秒的等待可能使截图发生在过渡动画中,导致 OCR 或模板匹配读取到空列表、旧画面或未出现的按钮。

3. 为“确定/部署”按钮增加有限次数的模板识别重试

新增 findTemplateWithRetry,每次按钮识别失败后等待配置的操作间隔,最多尝试三次。

为什么修改: 目标队伍名称出现并不代表确认按钮已经完成渲染。单次识别容易受到动画、帧延迟或短暂遮挡影响;有限重试能够覆盖这种瞬时失败,又不会无限等待。

4. 识别到目标队伍后,部署失败时立即报告准确错误

如果已经通过 OCR 找到目标队伍,但后续仍无法完成“确定”或“部署”,脚本会抛出“已找到队伍,但未能完成确定或部署”,不再继续翻页。

为什么修改: 找到目标队伍后继续翻页会丢失真正的失败阶段,最后产生“没有找到队伍”的误导性日志。立即终止能够保留准确原因,也便于后续判断是按钮模板、界面加载还是点击流程的问题。

5. 检查 SwitchParty 的返回值并向上抛出失败

无论是强制传送神像后换队,还是当前位置失败后传送神像重试,都会检查 SwitchParty 是否返回 false

为什么修改: 原流程忽略返回值,底层换队失败后仍可能继续清理缓存并结束,使调用方误以为已经切换成功。显式抛错可以阻止后续自动秘境在错误队伍下继续执行。

6. 脚本版本由 1.6 更新为 1.7

为什么修改: 本次新增了用户可见设置并改变了失败处理行为,需要更新版本号,便于脚本订阅更新和问题定位时区分版本。

兼容性说明

  • 默认等待时间仍为 1500 毫秒,未修改设置的用户无需调整现有配置。
  • 等待时间会被限制在 500~20000 毫秒。
  • 本次只修改 AcceleratedEditionSwitchParty 的脚本、设置和 manifest,没有修改其他脚本或仓库级配置。

验证

已完成:

  • node --check repo/js/AcceleratedEditionSwitchParty/main.js
  • 使用 Node.js 解析 settings.jsonmanifest.json
  • git diff --check

尚未在游戏内进行完整实机验证,因此暂时保留为 Draft PR。

Summary by CodeRabbit

  • 新功能

    • 新增“界面操作等待时间(毫秒)”设置,可根据设备性能调整操作节奏。
    • 队伍切换过程支持关键界面元素自动重试,提升操作成功率。
  • 问题修复

    • 改进确认、部署及传送后的队伍切换流程。
    • 切换失败时将正确报告错误并返回主界面。
  • 版本更新

    • 版本号更新至 1.7。

@JerryChen97 JerryChen97 changed the title fix: improve switch party timing reliability 修复:提高切换队伍时序与错误提示的可靠性 Jul 16, 2026
@JerryChen97

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
Action performed

Full review triggered.

@JerryChen97
JerryChen97 marked this pull request as ready for review July 16, 2026 23:41
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

队伍切换流程增强

Layer / File(s) Summary
操作延迟配置与重试基础
repo/js/AcceleratedEditionSwitchParty/settings.json, repo/js/AcceleratedEditionSwitchParty/main.js, repo/js/AcceleratedEditionSwitchParty/manifest.json
新增 operationDelayMs 配置及取值校验,加入模板查找重试机制,并将版本更新至 1.7
队伍定位与确认部署交互
repo/js/AcceleratedEditionSwitchParty/main.js
翻页、配置入口、队伍定位、确认和部署流程统一使用动态等待;确认与部署按钮通过重试查找。
切换结果校验与错误处理
repo/js/AcceleratedEditionSwitchParty/main.js
直接切换和传送后重试路径均校验 SwitchParty 返回值,失败时抛出错误并进入统一异常处理。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SwitchParty
  participant GameUI
  participant findTemplateWithRetry
  participant Notification
  SwitchParty->>GameUI: 定位并点击目标队伍
  SwitchParty->>findTemplateWithRetry: 查找确认按钮
  findTemplateWithRetry->>GameUI: 捕获区域模板识别
  SwitchParty->>findTemplateWithRetry: 查找部署按钮
  findTemplateWithRetry->>GameUI: 捕获区域模板识别
  SwitchParty->>Notification: 部署成功后发送通知
Loading

Poem

我是小兔蹦蹦跳,
延迟配置调得妙。
模板失败再找找,
确认部署稳稳到。
队伍切换成功笑!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次对切换队伍时序稳定性和错误提示可靠性的改进。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@MualaniMarine
MualaniMarine marked this pull request as draft July 17, 2026 22:35
@JerryChen97

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@repo/js/AcceleratedEditionSwitchParty/main.js`:
- Line 153: 将 AcceleratedEditionSwitchParty 中 notification 的 API 调用统一改为
PascalCase:把正常通知的 notification.send 替换为 notification.Send,把错误通知的
notification.error 替换为 notification.Error;检查该文件包含第 108、153、170、177
行在内的所有相关调用,确保消息内容和其余逻辑不变。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 25b36797-8548-42cc-b76a-94f433d0fdf7

📥 Commits

Reviewing files that changed from the base of the PR and between d30edda and 7d6e382.

📒 Files selected for processing (3)
  • repo/js/AcceleratedEditionSwitchParty/main.js
  • repo/js/AcceleratedEditionSwitchParty/manifest.json
  • repo/js/AcceleratedEditionSwitchParty/settings.json

DeployButton.click();
await sleep(100);
await sleep(operationDelayMs);
notification.send(`寻找到目标队伍:${partyName}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

修正 notification API 的方法名大小写。

BetterGenshinImpact (BGI) 环境中 notification API 的方法名必须使用 PascalCase(大驼峰命名法)。使用小写的 notification.send 会在此处抛出运行时异常并导致脚本崩溃中断。请将其改为 notification.Send。此外,建议一并全局检查并修复该文件中遗留的其他 senderror 方法调用(例如代码中原有的第 108、170、177 行)。

Based on learnings, in the BetterGenshinImpact (BGI) scripting environment, the notification API uses PascalCase method names from Notification.cs. When suggesting changes, call notification.Send(message) for normal notifications and notification.Error(message) for error notifications.

🐛 建议的修复
-								notification.send(`寻找到目标队伍:${partyName}`);
+								notification.Send(`寻找到目标队伍:${partyName}`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
notification.send(`寻找到目标队伍:${partyName}`);
notification.Send(`寻找到目标队伍:${partyName}`);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@repo/js/AcceleratedEditionSwitchParty/main.js` at line 153, 将
AcceleratedEditionSwitchParty 中 notification 的 API 调用统一改为 PascalCase:把正常通知的
notification.send 替换为 notification.Send,把错误通知的 notification.error 替换为
notification.Error;检查该文件包含第 108、153、170、177 行在内的所有相关调用,确保消息内容和其余逻辑不变。

Source: Learnings

@MualaniMarine

Copy link
Copy Markdown
Collaborator

如果要改造,不建议额外加延迟的方式,而是改成状态机,默认1500ms太长了

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.

2 participants