babalae/better-genshin-impact · error · Exception
没有可用战斗脚本
Error message
没有可用战斗脚本
What it means
FindCombatScriptAndSwitchAvatar 用 _combatScriptBag.FindCombatScript(avatars) 匹配当前队伍的战斗脚本,返回空列表即没有可执行脚本,抛 Exception。这通常发生在构造函数用 CombatScriptParser.ReadAndParse 解析的策略包里没有覆盖当前队伍组合的脚本。
Source
Thrown at BetterGenshinImpact/GameTask/AutoBoss/AutoBossTask.cs:885
Sleep(1000, _ct);
}
}
throw new Exception("识别队伍角色失败(已重试 5 次)");
}
/// <summary>
/// 根据当前队伍匹配战斗脚本,并切换到脚本中的首个角色。
/// </summary>
/// <param name="combatScenes">已初始化的战斗场景。</param>
/// <returns>匹配到的战斗指令列表。</returns>
/// <exception cref="Exception">没有可用战斗脚本时抛出。</exception>
private List<CombatCommand> FindCombatScriptAndSwitchAvatar(CombatScenes combatScenes)
{
var combatCommands = _combatScriptBag.FindCombatScript(combatScenes.GetAvatars());
if (combatCommands.Count == 0)
{
throw new Exception("没有可用战斗脚本");
}
var avatar = combatScenes.SelectAvatar(combatCommands[0].Name);
avatar?.SwitchWithoutCts();
Sleep(200, _ct);
return combatCommands;
}
/// <summary>
/// 使用所选自动战斗策略执行首领战斗,并复用自动战斗的结束检测。
/// </summary>
private async Task RunAutoFight()
{
_logger.LogInformation("{Name}:执行战斗策略", Name);
if (_jsonCombatStrategyPath != null)
{
await StartJsonFight();View on GitHub (pinned to a7cb36712d)
Solutions
- 确认 _taskParam.CombatStrategyPath 指向包含当前队伍角色脚本的策略文件。
- 在策略文件中补充覆盖当前队伍组合(4 个角色名均需匹配)的脚本。
- 若使用 JSON 战斗引擎,确认 CombatStrategyPath 以 .json 结尾走 _jsonCombatStrategyPath 分支。
- 在 Validate 中预检 _combatScriptBag 是否覆盖常见队伍,提前报错而非战斗中失败。
Example fix
// before
var combatCommands = _combatScriptBag.FindCombatScript(combatScenes.GetAvatars());
if (combatCommands.Count == 0)
{
throw new Exception("没有可用战斗脚本");
}
// after
var avatars = combatScenes.GetAvatars();
var combatCommands = _combatScriptBag.FindCombatScript(avatars);
if (combatCommands.Count == 0)
{
throw new Exception($"没有匹配队伍 [{string.Join(",", avatars.Select(a => a.Name))}] 的可用战斗脚本");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate 中预检战斗脚本是否覆盖当前队伍(仅非 JSON 引擎)
if (_combatScriptBag is not null)
{
// 无法在战斗前知道实际队伍,可改为校验策略包非空
// 或在战斗中失败时给出队伍名提示
} Prevention
- 策略文件需覆盖实际使用的所有队伍组合。
- 区分 JSON 引擎与脚本引擎路径(.json 后缀)。
- 失败信息附带当前队伍角色名便于补脚本。
When it happens
Trigger: 队伍角色组合在策略文件中无对应脚本;策略文件格式为 JSON 引擎(_jsonCombatStrategyPath 分支)但运行时走到了 _combatScriptBag(注意:JSON 分支下 _combatScriptBag 为 null 会先 NRE,此处针对非 JSON 分支);策略文件只定义了部分角色。
Common situations: 用户换了队伍但未更新战斗策略;策略文件遗漏某角色组合;新角色未在策略中配置;策略文件夹路径错误导致解析到空包。
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/d1db28b699c3cc2a.
Report an issue: GitHub.