* 战斗好感js:释放前增加延迟,并简化清理逻辑 通过等待 500 毫秒的休眠操作,为.NET 任务在释放 V8 对象后预留额外执行时间,以此避免触发对象已释放异常(ObjectDisposedException)。简化finally代码块中battleTask的清理逻辑:仅当battleTask和awaitBattleTask均已赋值时才执行清理操作;将任务与等待超时设置为竞争执行;清理过程中静默忽略所有错误,防止因取消操作或超时问题导致finally代码块阻塞 * Bump version to 1.5.5 and update changelog Update manifest version to 1.5.5 and add a v1.5.5 entry to the README changelog. The release notes mention stability improvements: add a short delay after releasing resources to reduce ObjectDisposedException likelihood and optimize fight task cleanup to avoid stuck cleanup phases. * v1.5.6:移除游泳状态持久化监测,统一使用 Assets/ 路径 将资源 / 路径引用从 assets/ 重命名为 Assets/(涉及 README 文档、main.js 路径加载逻辑、AutoPath 查找逻辑)。 移除持久化游泳追踪功能及相关设置 / 逻辑:删除 DEFAULT_SWIM_CONSECUTIVE_LIMIT 常量、SwimTracker 实现代码、游泳相关错误码 / 提示信息,以及 settings.json 中的 swimConsecutiveLimit 配置项。 简化游泳处理逻辑:检测到盗宝团进入游泳状态时,立即恢复至雕像状态,并将该回合判定为失败。 在释放图像素材前添加 500 毫秒的异步等待休眠,降低对象已释放异常(ObjectDisposedException)的触发风险。 更新 README 文档的更新日志,记录移除持久化游泳追踪功能、修改 Assets/ 路径的变更。 * AutoFriendshipFight: resource cleanup & swim fix Bump version to v1.5.7 and add changelog entry. Improve resource lifecycle handling by making template recognition objects mutable, extending post-exit sleep, explicitly disposing template/mat objects, and nulling references to reduce ObjectDisposedException risk. Add SwimTracker helper to centralize swim/statue recovery detection for 盗宝团. Harden executeBattleTasks: introduce awaitBattleTask flag and longer wait, better race/cleanup semantics for background AutoFight tasks, improved error handling/logging, and ensure path promises are caught when timing out. README and manifest updated accordingly. * Make swim recovery per-enemy configurable Introduce a swimRecoveryEnabled flag in the enemy config and change SwimTracker to read that flag (falling back to previous behaviour: only 武盗/盗宝团 enabled). Replace the hardcoded enemyType === "盗宝团" check in executeSingleFriendshipRound with SwimTracker(enemyType).enabled. Remove the now-unused getTodayKey helper and delete swim_stats.json as part of cleanup. This centralizes the swim-recovery toggle so it can be extended per enemy and removes obsolete daily swim stats storage. * Force recover flag on statue recovery When battleResult.status is "recovered_to_statue", always call recoverAfterFailure with a true second argument and add a Chinese comment explaining the game auto-returned to the seven-day statue. This simplifies the previous conditional (enemyType === "盗宝团") and ensures consistent recovery handling for this status. * Make disableAsyncFight apply to all enemies Respect the disableAsyncFight setting for all enemy types (including 盗宝团). main.js now only uses the async/ocr detect flow for 盗宝团 when disableAsyncFight is false. README and settings.json labels were updated to reflect that disabling async fights makes synchronous mode apply to every enemy, improving stability and unifying behavior across encounters. * Toggle battle path flag for 盗宝团 Pass a conditional flag to runBattlePathToBattlePoint so it receives true when enemyType === "盗宝团" (previously always false). This enables a special path/behavior for the 盗宝团 enemy during executeSingleFriendshipRound to handle its unique movement/positioning. * Update repo/js/AutoFriendshipFight/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix README quotes and assets path casing Replace ASCII quotes with Chinese-style quotes around “战斗结束检测” for typographic consistency, and correct the assets directory name from `Assets/AutoPath/` to `assets/AutoPath/` in the README to match repository naming and avoid confusion. * Use lowercase 'assets' paths Normalize asset path casing in repo/js/AutoFriendshipFight/main.js by replacing "Assets" with "assets" for image and AutoPath JSON references. Updated template image loads (exp.png, mora.png) and pathing file accesses in AutoPath, getBattlePointFromBattlePath, and runBattlePathToBattlePoint to avoid file-not-found issues on case-sensitive filesystems. No behavioral logic changes. * Add managed game region caching and OCR helpers Introduce a gameRegionManager to centralize screenshot capture/caching and lifecycle management (retain/release, disposeOldGameRegions, flushGameRegionCache, getManagedGameRegion) to reduce ObjectDisposedException risks and enforce minimum capture intervals. Add OCR utilities (normalizeOcrText, readActivityListText, readActivityListTextFromCapture) and replace direct captureGameRegion usages in task detection, result waiting and exp/mora detection with the managed API. Add SWIM_RECOVERED error message constant and use it for swim-recovery paths. Bump manifest version to 1.5.8 and update README (note stability/paths change and assets path case). Misc: small style/robustness fixes (logging, null checks, cancellation handling) and ensure cache is flushed on exit. * Improve flushGameRegionCache disposal and timeouts Add timeouts and safer disposal logic to flushGameRegionCache to avoid indefinite waits. Wait for capturing/disposing flags with a short deadline and log+abort if exceeded; during flush only remove regions that are not currently borrowed (borrowCount<=0), with a secondary deadline to avoid blocking. Preserve borrow counts for still-borrowed regions, remove stale borrowCount entries for regions no longer in cache, and reset lastCaptureTs when cache becomes empty. Adds warning logs for timeout cases. * Refactor formatting and resource handling Reformat code for readability and tighten resource management: multiline/enhanced formatting for ENEMY_CONFIG and template matches, normalize indentation/spacing across functions. Improve gameRegionManager lifecycle (clearer isCapturing/isDisposing handling), add waits and timeout warnings in flushGameRegionCache, ensure borrowCountByRegion is cleaned for removed regions, and make getManagedGameRegion capture/dispose flow more robust. Also standardize safeDispose and empty-catch behavior, tidy OCR/battle/task related flows and error handling. These changes aim to reduce resource leaks, race conditions and improve maintainability without altering core logic. * Refactor battle flow and naming; add helpers Refactor battle execution and main loop for clarity and robustness. Renamed core functions for clarity (AutoFriendshipDev -> runFriendshipLoop, LogTimeTaken -> formatElapsedTime, CalculateEstimatedCompletion -> estimateCompletionTime) and added numerous helper utilities to centralize behavior: cancellation/silence helpers, timeout/error detection, wrapper helpers, cleanup logic, and separate sync/async battle execution paths. Extracted specialized flows (treasure hoarder async round, swim-recovery-aware path runner, and unified battle result handling) to reduce duplication and improve error/recovery handling (including auto-return-to-statue logic). Overall changes improve async coordination, avoid unhandled promise rejections, and make time formatting/logging consistent. * Improve battle timeout & party switch error handling Propagate battle timeouts and rejection errors as exceptions and map timeouts to a script error code for consistent reporting. In executeBattleTasksSyncMode, throw a battle_timeout instead of returning a false result. In executeBattleTasksAsyncMode, always throw battle_rejected errors (removed the cancellation-only check). In executeBattleTasks catch, convert battle_timeout to a standardized script error (ERROR_CODES.BATTLE_TIMEOUT). Enhance switchPartyIfNeeded: after teleporting to the Statue of The Seven, verify the switch result and if it still fails, log and notify the user, return to the main UI and throw an error instead of silently continuing. Also ensure cancellation errors are rethrown and other errors are propagated instead of being swallowed. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
BetterGI · 更好的原神 的脚本仓库
BetterGI 的 📜 脚本仓库
在线版脚本仓库:bgi.sh 备用地址:https://s.bettergi.com
作者Q群:764972801 (非作者请勿加入)
如何提交到本仓库?(谁都能看懂的 GitHub Pull Request 使用指南)
脚本提交说明
- 战斗脚本提交到 repo/combat 目录;
- JS 脚本提交到 repo/js 目录;
- 地图追踪脚本提交到 repo/pathing 目录;
- 七圣召唤脚本提交到 repo/tcg 目录。
脚本提交规范
为了保证脚本的规范性和可读性,方便用户清晰了解脚本的用途,制定以下脚本命名规则和脚本文件夹命名规则。
战斗策略脚本
创建战斗策略脚本请参考文档自动战斗和已有的其他战斗策略脚本
命名规则
- 脚本的名称应包含使用的角色简写
- 特别的,只能用于副本,不适用于锄地的战斗策略应当增加“-副本”的后缀
注释与署名
- 战斗策略脚本中使用“//”进行注释,必要时应当在脚本中使用注释以明确使用的条件等
- 推荐在策略中同时通过注释说明自动战斗设置中的相关部分,例如:“// 检查战斗结束的延时:设置为 0.4”
- 署名使用“//作者:你的名字”,错误的格式将导致无法识别
注意事项
- 确保你充分了解自动战斗的完整机制(如战斗结束检查的触发)和每个动作的具体内容再开始编写战斗策略
- 提交前请进行充分的实战测试与优化。若战斗策略被社区或管理员判定为低质量,其合并请求(PR)将不予通过。
地图追踪脚本
文件命名规范
确保脚本文件在同一目录下按预期顺序排列,并一目了然地传达关键信息。地图追踪脚本命名需包含以下核心信息:
编号-材料名称-区域(跨区域材料填写)-二级区域(可选)-二级子区域-数量
-
编号
- 两位数,如果单个资源脚本数量超过
100可以考虑使用三位数编号或者使用字母加数字编号,如 A01 - 编号的排序应遵循以下两种方式之一:
- 按传送点位顺序排序。相邻脚本之间优先保证传送的便捷性,这种编号方式考虑整体采集效率。
- 按材料获取效率排序。优先选择资源分布密集或容易采集的点,效率高的路径放在靠前编号,这种编号方式考虑编号靠前脚本的采集效率。
- 两位数,如果单个资源脚本数量超过
-
材料名称
- 采集物(使用游戏内官方名称命名,如
慕风蘑菇,劫波莲,不应当使用绫华突破材料等不清晰的名称命名) - 掉落物(因掉落物名称与掉落物等级有关,因此不使用掉落物本身命名,而是使用怪物名称命名)
- 采集物(使用游戏内官方名称命名,如
-
区域(指
蒙德璃月稻妻须弥枫丹纳塔至冬,仅当材料跨区域需标注) -
二级区域(如
珉林,根据实际需求标注) -
二级子区域(细分地点,如
绝云间) -
预期采集的数量
脚本名称仅限上述规定的编号、材料名称、区域、二级子区域,原则上不应包含额外的描述或标点符号。
✔ 参考示范:
01-水晶块-璃月-绝云间-6个
02-水晶块-璃月-荻花洲-8个
❌ 错误示范:
01-水晶块-璃月-快速路径-绝云间-6个
其他注意事项
-
部分采集物没有对应的二级子区域,允许名称的区域部分使用起始传送锚点右侧展示的二级区域,或这条路径的大部分采集物点位所位于的二级区域
-
相同二级子区域有多条路径时,推荐采用
编号-材料名称-二级区域-二级子区域及方位-数量进行命名。 -
脚本文件名应当和
json文件中的name字段相同。 -
说明文件应当命名为README.md以保证仓库能够正确读取。
文件夹命名规范
目的:对脚本按材料分类管理,便于版本控制与团队协作。目录结构应当遵循以下原则:
-
根据脚本种类选择恰当的一级分类,目前共有六个分类
锄地专区、地方特产、敌人与魔物、矿物、其他。 -
一级目录:以材料名称命名,须与文件命名中的材料名称一致。
-
二级子目录(可选):可根据项目或作者划分,如有必要。
-
示例目录结构如下:
repo/pathing/矿物 ├─ 水晶块 │ ├─ 01-水晶块-璃月-绝云间-6个 │ └─ 02-水晶块-璃月-荻花洲-8个 └─ 星银矿石 └─ 01-星银矿石-覆雪之路-7个如果脚本和原来的地图追踪脚本存在冲突 按照以下原则处理:
-
修复或补充:直接提交到原材料目录。
-
路线冲突:新建同名目录并添加作者标识:
- 将旧脚本目录重命名为
AA@旧作者名 - 新脚本放入
AA@你的名字 - 例:原
repo/pathing/AA重命名为AA@oldauthor新目录AA@yourname
-
示例目录结构如下:
repo/pathing/.../ └── AA ├── AA@旧作者名 └── AA@你的名字
- 将旧脚本目录重命名为
-
不同采集方式|角色|效率:新建目录添加标识及作者标识:
- 判断旧脚本目录的采集方式,将旧脚本目录重命名为
采集方式@旧作者名 - 新脚本放入
采集方式@你的名字
-
示例目录结构如下:
repo/pathing ├── 地方特产/区域 │ ├── A材料 │ │ ├── 无草神@作者广告位招租 │ │ ├── 有草神效率路线@作者广告位招租 │ │ ├── 有草神全收集@作者广告位招租 │ │ └── ... │ └── B材料 │ ├── 效率路线@作者广告位招租 │ ├── 全收集@作者广告位招租 │ └── ... ├── 矿物 │ ├── 水晶矿 │ │ ├── 大剑@作者广告位招租 │ │ ├── 钟离@作者广告位招租 │ │ ├── 诺艾尔@作者广告位招租 │ │ └── ... │ └── 萃凝晶 │ ├── 大剑效率路线@作者广告位招租 │ ├── 大剑无战斗@作者广告位招租 │ └── ... └── ...
- 判断旧脚本目录的采集方式,将旧脚本目录重命名为
其他注意事项
-
目录名仅限材料官方名称,不添加版本号或其他标识。
-
作者标识仅在冲突时追加,格式为“@作者名”,紧随原目录名。
JS脚本
创建JS脚本请参考文档创建脚本
文件夹命名规则
-
脚本的文件夹名称应体现脚本的用途,简要用途可在描述文件 manifest.json 中说明,详细用途可在
README.md(大小写敏感,要求全部大写的文件名) 中说明 -
脚本的主体文件夹名称可采用 大驼峰式命名法 等命名方式,名称中不应包含空格,如:
repo/js ├── ├── AutoLeyLineOutcrop ├── AutoXXX └── ... -
常见的脚本结构目录如下:
repo/js └── jsName ├── Assets │ ├── Pathing │ │ └── xxx.json │ └── RecognitionObject │ └── xxx.png ├── main.js ├── manifest.json ├── settings.json └── README.md -
Assets用于存放脚本使用到的资源文件,其中
HTML遮罩内容规范
脚本内由于可以通过html文件进行遮罩渲染,用于引导提示、脚本配置等工作,因此网页内容应当受到一定限制,罗列如下:
- 需考虑dom元素过多或不当操作引起的浏览器引擎内存占用问题,不能过度影响普通玩家在运行时的内存占用
- 提交代码时如使用了html遮罩,需要将能够人为理解的页面项目完整源码上传(框架打包产物通常不易于理解),或是在pr信息中附上个人开源仓库链接(每次html有更新时都需要)
- 不可用于展示宣传、推广性质的信息,如QQ群号、平台广告、外部视频等(包括iframe中的链接)
- 显示的内容不可有侮辱、贬低、指责他人的意图
其他注意事项
- 脚本使用的资源文件应在
README.md中注明实际用途
其他
因早期对脚本管理较为宽松,因此仓库有部分脚本并不符合命名规范,欢迎通过 PR 规范这些名称。
Contributors
相关源码
脚本仓库页面的源码
地图路径追踪的源码:bettergi-map