WP-10: Pack Opening Hook — evolution_card_state Initialization #75

Closed
opened 2026-03-12 20:56:26 +00:00 by cal · 0 comments
Owner

Description

When cards are acquired (pack opening or trade), check if an evolution_card_state record exists for the (player_id, team_id) pair. If not, create one with the correct track assignment. Lightweight get_or_create that must NOT block or slow down pack opening.

Repo: database
Phase: 1b (API & Formula Engine)
Dependencies: WP-01, WP-03
Complexity: S

Card Type Determination

  1. player.pos_1 contains "SP" → 'sp' track
  2. player.pos_1 contains "RP" or "CP" → 'rp' track
  3. Otherwise → 'batter' track

Files

  • Create: database/app/services/evolution_init.py
  • Modify: database/app/routers_v2/cards.py — add hook after card POST

Tests (write first in database/tests/test_evolution_init.py)

  • Unit: track assignment for batter/sp/rp
  • Integration: first card creates state (current_tier=0, current_value=0.0)
  • Integration: duplicate card skips creation (still one row)
  • Integration: different player creates new state
  • Integration: card_type determination from positions

Acceptance Criteria

  1. Every new card acquisition triggers the check
  2. First card for (player_id, team_id) creates state
  3. Duplicate cards don't create duplicate states
  4. Track assignment correct for all card types
  5. Evolution init failure does NOT break card creation (try/except)

Plan reference: docs/prd-evolution/PHASE1_PROJECT_PLAN.md WP-10

## Description When cards are acquired (pack opening or trade), check if an `evolution_card_state` record exists for the `(player_id, team_id)` pair. If not, create one with the correct track assignment. Lightweight `get_or_create` that must NOT block or slow down pack opening. **Repo:** `database` **Phase:** 1b (API & Formula Engine) **Dependencies:** WP-01, WP-03 **Complexity:** S ## Card Type Determination 1. `player.pos_1` contains "SP" → 'sp' track 2. `player.pos_1` contains "RP" or "CP" → 'rp' track 3. Otherwise → 'batter' track ## Files - **Create:** `database/app/services/evolution_init.py` - **Modify:** `database/app/routers_v2/cards.py` — add hook after card POST ## Tests (write first in `database/tests/test_evolution_init.py`) - [ ] Unit: track assignment for batter/sp/rp - [ ] Integration: first card creates state (current_tier=0, current_value=0.0) - [ ] Integration: duplicate card skips creation (still one row) - [ ] Integration: different player creates new state - [ ] Integration: card_type determination from positions ## Acceptance Criteria 1. Every new card acquisition triggers the check 2. First card for (player_id, team_id) creates state 3. Duplicate cards don't create duplicate states 4. Track assignment correct for all card types 5. Evolution init failure does NOT break card creation (try/except) **Plan reference:** `docs/prd-evolution/PHASE1_PROJECT_PLAN.md` WP-10
cal added this to the Card Evolution Phase 1 milestone 2026-03-12 20:59:13 +00:00
cal added the
evolution
phase-1b
labels 2026-03-12 20:59:25 +00:00
Claude added the
ai-working
label 2026-03-13 07:01:37 +00:00
cal closed this issue 2026-03-18 20:32:01 +00:00
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-database#75
No description provided.