Files
bettergi-scripts-list/repo/js/AutoFriendshipFight
火山 46d00e0373 AutoFriendshipFight 稳定性重构:资源清理、异步收口、配置统一(v1.5.8) (#3197)
* 战斗好感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>
2026-05-10 09:53:20 +08:00
..

作者:秋云

自动化刷取角色好感度的脚本,支持盗宝团、愚人众、鳄鱼等敌人类型(蕈兽与雷萤术士为测试项)。通过自动触发和完成突发任务来获得好感度经验。

目录

功能简介

自动化刷取角色好感度的脚本,支持盗宝团、愚人众、鳄鱼等敌人类型(蕈兽与雷萤术士为测试项)。通过自动触发和完成突发任务来获得好感度经验。

  • 日限制: 每日最多获得10次好感度奖励50次任务触发在别的地方触发过好感任务会扣减相应次数。
  • 循环上限: 单次运行最多50次循环自动检测好感任务触发不再触发时自动结束。
  • 平均时长: 每次循环约1分钟效率高时可以达到40秒单次循环。
  • 成功率: 配置正确的情况下接近98%,有概率丢失第一次好感任务。

敌人类型

盗宝团

属性 详情
触发任务 岛上无贼 - 消灭鬼鬼祟祟的盗宝团
活动地区 稻妻地区
敌人强度 (中等)
特殊功能 (可选)支持清理原住民(丘丘人)

愚人众&丘丘人&盗宝团

属性 详情
触发任务 买卖不成正义存 - 打倒愚人众与镀金旅团
禁止危险运输! - 打倒所有盗宝团
丘丘人今晚的伙食 - 打倒所有丘丘人
活动地区 须弥地区
敌人强度 (较高)

鳄鱼

属性 详情
触发任务 张牙舞爪的恶党 - 打倒所有鳄鱼
活动地区 须弥地区
敌人强度 (较低)

快速开始

环境准备

安装 BetterGI版本大于 0.44.7 订阅脚本并添加至调度器

蕈兽 & 雷萤术士

属于测试版本,暂时并不稳定,可以进行测试,但不建议作为日常脚本使用。

调度器配置

  • 地图追踪行走配置:

    • 勾选"只在传送点时回复"
    • 勾选"允许在JsScript使用"
    • 勾选"覆盖JS中的自动战斗配置"
  • 战斗配置

    • 战斗策略: 根据队伍选择或者制定合适的战斗策略文件
    • 练度要求: 建议较高练度,纯好感队可能无法击败敌人
    • 重要设置:
      • 默认: 关闭"自动检测战斗结束"
      • 若勾选“禁用异步战斗(更稳定)”: 需要开启并正确配置"自动检测战斗结束"
  • 推荐队伍配置

基于社区测试的高效角色推荐,其他效率高的角色欢迎通过 pull request 添加到本文档,需附带理由和演示视频。

角色 优先级 特点 注意事项
那维莱特 群友测试效率最高 输出稳定,适合自动战斗
茜特菈莉 带盾,后台冰冻结敌人 提供生存保障
枫原万叶 拾取材料,扩散伤害 增加收益效率
芙宁娜 后台输出 生存压力较大
钟离 提供护盾 战斗策略中E技能应左右释放

脚本设置

通过调度器脚本右键-修改JS自定义配置

  • 拾取模式
    • 缺对应材料时,建议选用:自动拾取
    • 不缺对应材料时,建议选用:不拾取
      • 避免每天运行,拾取過多不能分解的掉落物,导至不能分解的掉落物逹致上限
  • 敌人类型: 选择"盗宝团"或"愚人众"
  • 运行次数: 10次或者50次
    • 目标是好感选择10次
    • 目标是锄地摩拉选择50次
    • 目标是掉落物暂时不支持
  • 队伍名称:
    • 填入您的战斗队伍名称
    • 不填默认当前队伍
  • OCR超时: - OCR检测超时时间默认10秒 - 过短可能识别失败导致结束任务 - 过长则会长时间检测导致等待时间过长 - 推荐保持默认值
  • 战斗超时: - 单次战斗超时时间默认120秒 - 战斗超时会直接取消任务,因此不建议过短 - 脚本会自动检测任务结束,识别精度很高
  • 禁用异步战斗(更稳定;需配置“战斗结束检测”;对所有敌人生效)
    • 依赖“自动检测战斗结束”退出战斗
    • 开启后包括盗宝团在内的所有敌人都走同步战斗模式

一键运行

配置完成后,直接运行脚本即可开始自动刷取好感度。

高级设置

  • 清理原住民: 仅盗宝团模式有效,清理丘丘人
  • 卡时间模式: 支持按日期周期运行

运行流程

  1. 队伍切换: 自动切换到指定队伍
  2. 准备阶段:
    • 盗宝团: (可选) 清理丘丘人 → 前往触发点
    • 愚人众: 直接前往触发点
  3. 任务检测: 使用OCR检测突发任务触发
  4. 战斗执行: 自动导航到战斗点并开始战斗
  5. 结果判定: 检测战斗结果并记录
  6. 循环执行: 重复上述流程直到完成设定次数或者检测到任务未触发

常见问题

重要提醒

  • 脚本运行时请勿手动操作游戏

常见问题解答

Q: 为什么战斗策略没有生效或战斗失败率较高?

A: 检查以下几点:

  • 是否正确设置了战斗策略
  • 战斗策略是否适合当前队伍
  • 队伍练度是否足够
  • 是否正确勾选了"覆盖JS中的自动战斗配置"
Q: OCR超时但是任务已经触发

A:

  • 尝试提高 OCR 超时时间
  • 如果观察到触发任务时,左侧没有任务文字,则游戏中关闭任务专注模式
Q: 如何选择合适的敌人类型?

A:

  • 盗宝团: 适合中等练度队伍,敌人相对较弱
  • 愚人众: 需要高练度队伍,怪物强度相对较高
Q: 脚本运行中断怎么办?

A:

  • 检查是否有手动操作游戏
  • 查看日志确定中断原因
  • 重新运行脚本
  • 若仍然未恢复,提交 issue
Q: 脚本卡在某个步骤不动怎么办?

A:

  • 确认是否卡在了复活界面
  • 重启脚本并检查 BetterGI 状态
  • 若仍然未恢复,提交 issue
Q: 如何选择盗宝团还是愚人众?

A:

  • 新手推荐: 选择盗宝团,敌人较弱,容错率高
  • 高练度队伍: 选择愚人众,效率更高
  • 好感度优先: 两者都可以,选择队伍更适合的类型
Q: 战斗策略如何配置?

A:

  • 查阅 BetterGI 文档
Q: 为什么任务触发失败?

A:

  • 检查是否已达到每日任务触发上限
  • 尝试手动触发
Q: 队伍切换失败怎么办?

A:

  • 确认队伍名称填写正确(建议四字中文)
Q: 脚本运行速度慢怎么办?

A:

  • 降低OCR超时时间但不要过短
  • 优化战斗策略,减少不必要的等待
  • 确保BetterGI版本为最新
  • 检查计算机性能和网络状况
  • 提高计算机配置
Q: 如何备份和恢复配置?

A:

  • 配置保存在调度器配置文件中
  • 可以手动备份该文件,当然建议直接备份 User 文件夹
  • 重装后将备份文件复制回原位置即可恢复

💡 如遇其他问题,请在 GitHub 上提出 issue

文件结构

  • main.js: 主要脚本逻辑
  • settings.json: 配置文件
  • assets/AutoPath/: 路径文件目录
    • 盗宝团-准备.json: 盗宝团准备阶段路径,清理丘丘人
    • 盗宝团-触发点.json: 盗宝团触发点路径
    • 盗宝团-战斗点.json: 盗宝团战斗点路径
    • 愚人众-准备.json: 愚人众准备阶段路径,从传送点到触发点
    • 愚人众-触发点.json: 愚人众触发点路径
    • 愚人众-战斗点.json: 愚人众战斗点路径

注意事项

使用须知

  • 仅供学习交流: 本脚本仅用于技术研究和学习交流
  • 风险自担: 使用自动化脚本存在一定风险,请谨慎使用
  • 适度使用: 建议合理安排游戏时间,避免过度依赖自动化

安全建议

  • 备份存档: 使用前建议备份游戏存档数据
  • 监督运行: 运行期间建议保持关注,及时处理异常情况
  • 版本更新: 及时更新 BetterGI 和脚本到最新版本
  • 社区反馈: 遇到问题及时向社区反馈,帮助改进脚本

更新日志

版本 更新内容
v1.5.8 稳定性与规范性优化:统一截图托管与退出清理,补强异步战斗收口;禁用异步战斗对所有敌人生效;路径统一为 assets/,代码风格与注释同步整理
v1.5.7 退出清理阶段补充释放模板匹配对象并延长宽限期,进一步降低宿主侧异步回调访问已释放对象的概率
v1.5.6 移除游泳统计持久化与相关配置,减少运行期写文件干扰;资源路径统一为 assets/
v1.5.5 稳定性提升:退出释放资源后增加短延时,降低 ObjectDisposedException 概率;战斗任务清理逻辑优化,避免清理阶段卡住
v1.5.3 稳定性提升:资源释放更完整;盗宝团游泳统计仅在盗宝团启用;“禁用异步战斗”增加超时保护避免卡死;设置说明更易懂
v1.4.2 新增拾取模式,能选择不拾取
v1.3 新增愚人众支持,优化敌人类型切换
v1.2 战斗触发检测,异步检测战斗结束
v1.1 盗宝团重登功能优化,卡时间支持
v1.0 基础盗宝团好感度刷取功能

贡献指南

欢迎提交 Pull Request 来改进此脚本!请遵循以下指南:

代码贡献

  • 功能改进: 新增功能、性能优化、bug修复
  • 文档完善: 改进README、添加注释、使用指南
  • 测试验证: 提供测试用例、兼容性验证

提交规范

  • 清晰的提交信息描述
  • 详细的PR说明和测试结果
  • 遵循现有代码风格
  • 避免在同一个提交中格式化代码

问题反馈

遇到问题请在 GitHub 上提出 issue包含以下信息

  • 详细的错误描述和复现步骤
  • 相关日志截图或错误信息
  • 使用的BetterGI版本和游戏环境
  • 脚本配置参数

社区支持

  • 📖 文档: 查看完整文档和教程
  • 🐛 报告问题: 通过Issues报告bug和建议
  • 🤝 贡献代码: 通过Pull Request贡献代码

💝 感谢所有为此项目做出贡献的开发者和测试者!

🌟 如果这个脚本对您有帮助,请给项目点个星标支持!