babalae/better-genshin-impact · error · PartySetupFailedException

切换角色:角色列表队伍识别不完整,期望 {expectedTeamCount} 个,末次检测到 {lastDetecte

Error message

切换角色:角色列表队伍识别不完整,期望 {expectedTeamCount} 个,末次检测到 {lastDetectedCardCount} 张卡片,成功识别 {characterNames.Count(name => name != null)} 个头像

What it means

After the list returns to party config, RecognizeTeamSlotsFromCharacterList validates the collected names: count must equal expectedTeamCount and none may be null/empty. A mismatch means avatar recognition was incomplete (some slots scored below MatchThreshold=0.7 or fewer cards were taken), so the snapshot would be misleading and is rejected.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Job/SwitchCharacterStateMachineTask.cs:1444

        }
        finally
        {
            Simulation.SendInput.Keyboard.KeyPress(Vanara.PInvoke.User32.VK.VK_ESCAPE);
        }

        var returned = await NewRetry.WaitForAction(() =>
        {
            using var capture = CaptureToRectArea();
            return IsPartyConfigPage(capture);
        }, ct, 10, 300);
        if (!returned)
        {
            throw new PartySetupFailedException("切换角色:角色列表关闭后未返回队伍配置页");
        }

        if (characterNames.Count != expectedTeamCount || characterNames.Any(string.IsNullOrEmpty))
        {
            throw new PartySetupFailedException(
                $"切换角色:角色列表队伍识别不完整,期望 {expectedTeamCount} 个," +
                $"末次检测到 {lastDetectedCardCount} 张卡片,成功识别 {characterNames.Count(name => name != null)} 个头像");
        }

        var result = characterNames
            .Select((name, index) => new TeamSlotSnapshot(index + 1, name))
            .ToList();
        _logger.LogDebug(
            "切换角色:当前账号可控角色 {ControlCount} 个,生成 {SnapshotCount} 项队伍快照,映射 {SlotMapping}",
            _maxControlAvatarCount,
            result.Count,
            string.Join(",", _logicalToPhysicalSlot
                .OrderBy(pair => pair.Key)
                .Select(pair => $"逻辑{pair.Key}->物理{pair.Value}")));

        return result;
    }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Read the message's diagnostics: '末次检测到 N 张卡片' vs '成功识别 M 个头像' — if N is right but M is low, it's a recognition-quality problem; if N is low, it's a card-detection problem (see 392).
  2. Improve capture/resolution so all avatars clear 0.7, or extend the recognizer with the missing icons.
  3. If partial recognition is acceptable downstream, relax the strict count/null check — but note BuildDesiredTeamRoles (385) will still reject null names.
  4. Re-run the recognition pass on a fresh capture before failing.
Defensive patterns

Strategy: validation

Validate before calling

if (characterNames.Count != expectedTeamCount || characterNames.Any(string.IsNullOrEmpty))
{
    _teamSnapshotDirty = true; // re-recognize on next pass
    return RecognizeTeamSlotsFromCharacterList(recognizer, expectedTeamCount, ct);
}

Type guard

static bool IsCompleteSnapshot(IReadOnlyList<string?> names, int expected)
    => names.Count == expected && names.All(n => !string.IsNullOrEmpty(n));

Try / catch

try { await switchTask.Start(...); }
catch (PartySetupFailedException ex) when (ex.Message.Contains("队伍识别不完整"))
{ _logger.LogWarning(ex, "队伍头像识别不完整,建议改善截图质量后重试"); }

Prevention

When it happens

Trigger: characterNames.Count != expectedTeamCount, OR characterNames.Any(string.IsNullOrEmpty) — i.e. recognizer.Recognize returned Score<0.7 for at least one card (stored as null), or fewer than expectedTeamCount cards were processed.

Common situations: One or more avatars scored below 0.7 (lighting, costume, scale); the grid had fewer visible cards than expectedTeamCount so fewer names were collected; recognizer model gaps for a character; partial card occlusion.

Related errors


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