feat: Implement card pool depletion handling and wildcard rarity fallback for pack generation
All checks were successful
Build and Deploy / build (push) Successful in 1m17s

This commit is contained in:
2025-12-17 14:16:02 +01:00
parent 80de286777
commit 245ab6414a
4 changed files with 123 additions and 81 deletions

View File

@@ -73,3 +73,4 @@
- [Animated Copy Button](./devlog/2025-12-17-024000_animated_copy_button.md): Completed. Replaced copy toast with an in-place animated tick button for immediate feedback.
- [Play Online Logic](./devlog/2025-12-17-031500_play_online_logic.md): Completed. Implemented strict pack limits (min 12 for 4 players) and visual feedback for the online lobby button.
- [Lobby Rules Tooltip](./devlog/2025-12-17-032000_lobby_rules_tooltip.md): Completed. Added dynamic rules explanation and supported player indicators to the lobby creation screen.
- [Fix Expansion Pack Generation](./devlog/2025-12-17-140000_fix_expansion_generation.md): Completed. Enforced infinite card pool for expansion drafts to ensure correct pack counts and prevent depletion.

View File

@@ -0,0 +1,22 @@
# Fix Expansion Pack Generation (Infinite Cards)
## Problem
The user reported two issues with "From Expansion" pack generation:
1. Incorrect amount of packs generated (e.g., 10 instead of 36).
2. The generator was using a finite pool of cards (like a custom cube) instead of an infinite supply (like opening fresh packs).
## Root Cause
The `PackGeneratorService` defaults to generating packs without replacement (`withReplacement: false`). This means once a card is used, it is removed from the pool.
For a standard set (Expansion), the pool contains only one copy of each card (from Scryfall fetch).
When generating a large number of packs (e.g., 36 for a box), the rare/mythic/uncommon pools would deplete quickly, causing the generator to stop early and produce fewer packs than requested.
## Solution
Modified `src/server/index.ts` to enforce `settings.withReplacement = true` when `sourceMode === 'set'`.
This ensures that:
- The pack generator refreshes the card pools for every new pack.
- Generating 36 packs (or any number) is possible even from a single set of source cards.
- Duplicates are allowed across packs (simulating a print run), while maintaining uniqueness within a single pack (handled by `buildSinglePack`).
## Changes
- **File**: `src/server/index.ts`
- **Logic**: Added a check in the `/api/packs/generate` route to set `settings.withReplacement = true` if `sourceMode === 'set'`.