Files
SVSimServer/SVSim.EmulatedEntrypoint/Services/MatchContextBuilder.cs
gamer147 a0fdb0f3c5 feat(match-context): add IMatchContextBuilder TK2 implementation
Assembles MatchContext from ArenaTwoPickRun + viewer cosmetics + config.
Per-mode interface — future modes (rank/free/open-room/...) add one method
each. DI scoped registration. Four tests cover happy path, no-run, incomplete
draft, default-loadout fallback.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 12:40:26 -04:00

68 lines
2.5 KiB
C#

using System.Text.Json;
using SVSim.BattleNode.Bridge;
using SVSim.Database.Models.Config;
using SVSim.Database.Repositories.Viewer;
using SVSim.Database.Services;
namespace SVSim.EmulatedEntrypoint.Services;
public class MatchContextBuilder : IMatchContextBuilder
{
private readonly IArenaTwoPickRunRepository _runs;
private readonly IViewerRepository _viewers;
private readonly IGameConfigService _config;
public MatchContextBuilder(
IArenaTwoPickRunRepository runs,
IViewerRepository viewers,
IGameConfigService config)
{
_runs = runs;
_viewers = viewers;
_config = config;
}
public async Task<MatchContext> BuildForTwoPickAsync(long viewerId)
{
var run = await _runs.GetByViewerIdAsync(viewerId)
?? throw new ArenaTwoPickException("arena_two_pick_no_active_run");
var deck = JsonSerializer.Deserialize<List<long>>(run.SelectedCardIdsJson) ?? new();
if (deck.Count < 30)
throw new ArenaTwoPickException("arena_two_pick_draft_incomplete");
var viewer = await _viewers.LoadForMatchContextAsync(viewerId)
?? throw new ArenaTwoPickException("arena_two_pick_no_active_run");
var challenge = _config.Get<ChallengeConfig>();
var defaults = _config.Get<DefaultLoadoutConfig>();
var emblemId = viewer.Info.SelectedEmblem.Id != 0
? viewer.Info.SelectedEmblem.Id.ToString()
: defaults.EmblemId.ToString();
var degreeId = viewer.Info.SelectedDegree.Id != 0
? viewer.Info.SelectedDegree.Id.ToString()
: defaults.DegreeId.ToString();
var charaId = run.LeaderSkinId != 0
? run.LeaderSkinId.ToString()
: run.ClassId.ToString();
return new MatchContext(
SelfDeckCardIds: deck,
ClassId: run.ClassId.ToString(),
CharaId: charaId,
// Hardcoded v1; see spec §Deferred plumbing.
CardMasterName: "card_master_node_10015",
CountryCode: viewer.Info.CountryCode ?? string.Empty,
UserName: viewer.DisplayName,
// TK2-specific cosmetic source; other modes will use the deck row's SleeveId.
SleeveId: challenge.TwoPickSleeveId.ToString(),
EmblemId: emblemId,
DegreeId: degreeId,
// Hardcoded v1; needs equipped-MyPageBackground lookup (see spec §Deferred).
FieldId: 43,
IsOfficial: viewer.Info.IsOfficial ? 1 : 0,
BattleType: 11);
}
}