feat(matching): MatchContextBuilder.BuildForRankBattleAsync for rank battles
Sibling to BuildForTwoPickAsync. Routes through IDeckRepository.GetDeck to pull the viewer's deck #1 for the requested format (avoiding the viewer-graph nav-ref auto-load pitfall — DeckCard.Card silently ships card_id=0 via the default include path). Throws if the viewer has no deck for the format. Cosmetics fall back to DefaultLoadoutConfig defaults when unequipped, same shape as TK2. Used by RankBattleController in a later task to build self-context for /ai_<fmt>_rank_battle/start and to pair-up under /<fmt>_rank_battle/do_matching. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.Database.Enums;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
@@ -15,4 +16,15 @@ public interface IMatchContextBuilder
|
||||
/// Throws <see cref="ArenaTwoPickException"/> on missing run / incomplete draft.
|
||||
/// </summary>
|
||||
Task<MatchContext> BuildForTwoPickAsync(long viewerId);
|
||||
|
||||
/// <summary>
|
||||
/// Build a context for a rank-battle viewer + format (rotation / unlimited). Pulls the
|
||||
/// viewer's deck #1 for that format + viewer cosmetics. Throws if the viewer has no
|
||||
/// deck registered for the format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Deck-selection persistence (which deck number is "current" for this format) is a
|
||||
/// separate concern; deck #1 is a placeholder until that lands.
|
||||
/// </remarks>
|
||||
Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Text.Json;
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models.Config;
|
||||
using SVSim.Database.Repositories.Deck;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
|
||||
@@ -10,15 +12,18 @@ public class MatchContextBuilder : IMatchContextBuilder
|
||||
{
|
||||
private readonly IArenaTwoPickRunRepository _runs;
|
||||
private readonly IViewerRepository _viewers;
|
||||
private readonly IDeckRepository _decks;
|
||||
private readonly IGameConfigService _config;
|
||||
|
||||
public MatchContextBuilder(
|
||||
IArenaTwoPickRunRepository runs,
|
||||
IViewerRepository viewers,
|
||||
IDeckRepository decks,
|
||||
IGameConfigService config)
|
||||
{
|
||||
_runs = runs;
|
||||
_viewers = viewers;
|
||||
_decks = decks;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
@@ -64,4 +69,46 @@ public class MatchContextBuilder : IMatchContextBuilder
|
||||
IsOfficial: viewer.Info.IsOfficial ? 1 : 0,
|
||||
BattleType: 11);
|
||||
}
|
||||
|
||||
public async Task<MatchContext> BuildForRankBattleAsync(long viewerId, Format format)
|
||||
{
|
||||
var viewer = await _viewers.LoadForMatchContextAsync(viewerId)
|
||||
?? throw new InvalidOperationException($"viewer {viewerId} not found");
|
||||
|
||||
// Per spec, deck-selection persistence (which deck number is "current" for this
|
||||
// format) is a separate concern; #1 is a placeholder until that lands. IDeckRepository
|
||||
// is the right path here — viewer-graph nav refs (DeckCard.Card) don't auto-load
|
||||
// (see project_ef_nav_include_pitfall memory), which would silently ship card_id=0.
|
||||
var deck = await _decks.GetDeck(viewerId, format, deckNo: 1)
|
||||
?? throw new InvalidOperationException($"viewer {viewerId} has no deck for format {format}");
|
||||
|
||||
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 = deck.LeaderSkin.Id != 0
|
||||
? deck.LeaderSkin.Id.ToString()
|
||||
: deck.Class.Id.ToString();
|
||||
var sleeveId = deck.Sleeve.Id != 0
|
||||
? deck.Sleeve.Id.ToString()
|
||||
: defaults.SleeveId.ToString();
|
||||
var deckCardIds = deck.Cards.Select(c => c.Card.Id).ToList();
|
||||
|
||||
return new MatchContext(
|
||||
SelfDeckCardIds: deckCardIds,
|
||||
ClassId: deck.Class.Id.ToString(),
|
||||
CharaId: charaId,
|
||||
CardMasterName: "card_master_node_10015",
|
||||
CountryCode: viewer.Info.CountryCode ?? string.Empty,
|
||||
UserName: viewer.DisplayName,
|
||||
SleeveId: sleeveId,
|
||||
EmblemId: emblemId,
|
||||
DegreeId: degreeId,
|
||||
FieldId: 43,
|
||||
IsOfficial: viewer.Info.IsOfficial ? 1 : 0,
|
||||
BattleType: 11);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user