修复:提高切换队伍时序与错误提示的可靠性#3395
Conversation
|
@coderabbitai full review |
Action performedFull review triggered. |
WalkthroughChanges队伍切换流程增强
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: 部署成功后发送通知
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
repo/js/AcceleratedEditionSwitchParty/main.jsrepo/js/AcceleratedEditionSwitchParty/manifest.jsonrepo/js/AcceleratedEditionSwitchParty/settings.json
| DeployButton.click(); | ||
| await sleep(100); | ||
| await sleep(operationDelayMs); | ||
| notification.send(`寻找到目标队伍:${partyName}`); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
修正 notification API 的方法名大小写。
BetterGenshinImpact (BGI) 环境中 notification API 的方法名必须使用 PascalCase(大驼峰命名法)。使用小写的 notification.send 会在此处抛出运行时异常并导致脚本崩溃中断。请将其改为 notification.Send。此外,建议一并全局检查并修复该文件中遗留的其他 send 和 error 方法调用(例如代码中原有的第 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.
| 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
|
如果要改造,不建议额外加延迟的方式,而是改成状态机,默认1500ms太长了 |
问题背景
该脚本在刚启动游戏、设备性能较低或队伍界面动画尚未结束时,原有的固定等待时间(部分操作仅等待 100~1500 毫秒)可能不足。实际日志中出现过两类相互关联的问题:
改动说明
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
为什么修改: 本次新增了用户可见设置并改变了失败处理行为,需要更新版本号,便于脚本订阅更新和问题定位时区分版本。
兼容性说明
AcceleratedEditionSwitchParty的脚本、设置和 manifest,没有修改其他脚本或仓库级配置。验证
已完成:
node --check repo/js/AcceleratedEditionSwitchParty/main.jssettings.json和manifest.jsongit diff --check尚未在游戏内进行完整实机验证,因此暂时保留为 Draft PR。
Summary by CodeRabbit
新功能
问题修复
版本更新