babalae/better-genshin-impact · error · Exception

战斗策略文件不存在

Error message

战斗策略文件不存在

What it means

Thrown by BuildAutoFightStrategyPath after AutoFightParam.ResolveStrategyPath(config.StrategyName) returns a path that is neither an existing file nor an existing directory. The combat strategy referenced by the config is not on disk.

Solutions

  1. Confirm the strategy file exists at the resolved path (print ResolveStrategyPath output).
  2. Reinstall/restore the default combat strategy files under User\AutoFight.
  3. Correct StrategyName in the config to a strategy that exists.
  4. Switch to '根据队伍自动选择' to use the directory-based auto selection.
Defensive patterns

Strategy: validation

Validate before calling

var (path, _) = AutoFightParam.ResolveStrategyPath(config.StrategyName);
if (!File.Exists(path) && !Directory.Exists(path))
{
    throw new FileNotFoundException($"战斗策略文件不存在: {path}", path);
}

Type guard

bool StrategyExists(string strategyName)
{
    var (p, _) = AutoFightParam.ResolveStrategyPath(strategyName);
    return File.Exists(p) || Directory.Exists(p);
}

Prevention

When it happens

Trigger: A fight config with a non-empty StrategyName is resolved to a path; File.Exists(path) and Directory.Exists(path) are both false → throw.

Common situations: The named strategy was deleted/renamed; a fresh install is missing the default strategy files under User\AutoFight; StrategyName points to a path that was never created.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/87e779dc84157849. Report an issue: GitHub.

Appendix: source

Thrown at BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs:1310

        {
            fightConfig.CopyFromAutoFightConfig(globalAutoFightConfig);
        }

        if (fightConfig.Timeout <= 0)
        {
            fightConfig.Timeout = _taskParam.Timeout > 0 ? _taskParam.Timeout : Math.Max(globalAutoFightConfig.Timeout, 1);
        }

        _taskParam.Timeout = fightConfig.Timeout;
        return fightConfig.ToAutoFightConfig();
    }

    private static string BuildAutoFightStrategyPath(AutoFightConfig config)
    {
        var (path, _) = AutoFightParam.ResolveStrategyPath(config.StrategyName);
        if (!File.Exists(path) && !Directory.Exists(path))
        {
            throw new Exception("战斗策略文件不存在");
        }

        return path;
    }

    private async Task<bool> RecognizeTextInRegion(int timeoutMs)
    {
        var start = DateTime.UtcNow;
        var noTextCount = 0;
        var fightTextDetectedAt = DateTime.MinValue;
        var lastSeekAssistAt = DateTime.MinValue;
        var seekEnemyEnabled = _taskParam.FightConfig.SeekEnemyEnabled;
        var seekEnemyInterval = TimeSpan.FromSeconds(Math.Clamp(_taskParam.FightConfig.SeekEnemyIntervalSeconds, 1, 60));
        var seekEnemyRotaryFactor = Math.Clamp(_taskParam.FightConfig.SeekEnemyRotaryFactor, 1, 13);
        var successKeywords = new[] { "挑战达成", "战斗胜利", "挑战成功" };
        var failureKeywords = new[] { "挑战失败" };

        while ((DateTime.UtcNow - start).TotalMilliseconds < timeoutMs)

View on GitHub (pinned to a7cb36712d)