fix(battle-node): expand rank-battle deck by DeckCard.Count

BuildForRankBattleAsync projected deck.Cards.Select(c => c.Card.Id),
discarding Count. DeckCard is count-based (one row per unique card +
a Count), so a 3-copy card shipped to the node as a single in-battle
card -- matched decks showed 1 of each card instead of the real count.

Expand each row by its Count so SelfDeckCardIds carries one entry per
physical card. TwoPick path is unaffected (flat per-pick list).

Add a regression test seeding 3+2+1 copies (failed Expected 6/was 3).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-04 15:09:14 -04:00
parent 7bd2c0f2d7
commit 56652c7034
2 changed files with 33 additions and 1 deletions

View File

@@ -137,6 +137,33 @@ public class MatchContextBuilderTests
Assert.That(ctx.FieldId, Is.EqualTo(43));
}
[Test]
public async Task BuildForRankBattle_expands_each_deck_card_by_its_count()
{
// Regression for the "matched deck only has 1 of each card" battle-node bug:
// DeckCard is count-based (one row per unique card + a Count), so
// deck.Cards.Select(c => c.Card.Id) collapsed 3 copies into a single entry.
// The MatchContext deck must carry one entry PER PHYSICAL CARD.
await using var factory = new SVSimTestFactory();
var viewerId = await factory.SeedViewerAsync(displayName: "Ranker");
await factory.SeedGlobalsAsync();
await factory.SeedDeckAsync(viewerId, Format.Unlimited, number: 1, name: "Triples");
await factory.AddCardToDeckAsync(viewerId, Format.Unlimited, 1, 10001001L, count: 3);
await factory.AddCardToDeckAsync(viewerId, Format.Unlimited, 1, 10001002L, count: 2);
await factory.AddCardToDeckAsync(viewerId, Format.Unlimited, 1, 10001003L, count: 1);
using var scope = factory.Services.CreateScope();
var builder = scope.ServiceProvider.GetRequiredService<IMatchContextBuilder>();
var ctx = await builder.BuildForRankBattleAsync(viewerId, Format.Unlimited, deckNo: 1);
Assert.That(ctx.SelfDeckCardIds.Count, Is.EqualTo(6),
"3 + 2 + 1 copies must produce 6 physical card entries, not 3 unique ids.");
Assert.That(ctx.SelfDeckCardIds.Count(id => id == 10001001L), Is.EqualTo(3));
Assert.That(ctx.SelfDeckCardIds.Count(id => id == 10001002L), Is.EqualTo(2));
Assert.That(ctx.SelfDeckCardIds.Count(id => id == 10001003L), Is.EqualTo(1));
}
[Test]
public async Task BuildForRankBattle_throws_when_no_deck_for_format()
{