fix(engine): bind mana-value discard costs to X - #7298
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe change preserves mana-value X filters, resolves discard targets with ability context, validates activation costs after X selection, and adds integration coverage for Kozilek’s discard-and-counter ability. ChangesX discard-cost handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Player
participant Engine
participant CastingCosts
participant GameState
Player->>Engine: Announce X value
Engine->>CastingCosts: Apply X to ability and cost
CastingCosts->>GameState: Find eligible discard cards
GameState-->>CastingCosts: Return matching cards
CastingCosts-->>Engine: Return payable or InvalidAction
Engine-->>Player: Continue activation or reject X choice
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Generated for head Parse changes introduced by this PR✓ No card-parse changes detected. |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/engine/src/game/casting.rs`:
- Around line 17677-17702: Add a verified CR annotation immediately above
find_eligible_discard_targets_for_ability describing that it selects legal cards
in the player’s hand for an activated-ability discard cost, excluding the source
object and applying the optional TargetFilter. Preserve the helper’s existing
filtering behavior.
In `@crates/engine/src/game/cost_payability.rs`:
- Around line 112-139: Preserve the originally announced X-constrained
TargetFilter after X is chosen, and reuse it when validating and selecting every
object in multi-object costs. Update deferred target handling and the
AbilityCost::Exile discard/exile eligibility path so Cmc == X is not removed or
recomputed per object, including recursive filters handled by
relax_x_mana_value_constraint. Add regressions for discard and exile costs with
count = 2 and objects having different mana values, ensuring all selected
objects satisfy the same X.
In `@crates/engine/src/game/engine.rs`:
- Around line 8946-8960: Move the activation cost validation using
activation_cost_is_payable_after_x_choice out of the
pending.deferred_target_selection-only path and run it for every activated X
choice, including no-target abilities. Ensure the trial cost is rejected
atomically before deferred-target handling when the chosen value cannot pay the
discard or other activation cost.
In `@crates/engine/src/parser/oracle_cost.rs`:
- Line 843: Replace the verbatim rest_lower equality check in the parser
dispatch with all_consuming(tag::<_, _, E<'_>>("a
card")).parse(rest_lower.as_str()).is_ok(). Preserve the exact bare “a card”
match while allowing longer phrases to continue to parse_discard_card_filter.
In `@crates/engine/tests/integration/issue_6908_kozilek_discard_mana_value.rs`:
- Around line 28-63: Add a second discard candidate in the scenario with a mana
value different from three, then add a separate X=3 activation attempt that
selects this nonmatching card and asserts the payment or activation is rejected.
Preserve the existing successful discard-and-resolve flow as the reach guard,
using the test’s existing scenario and runner APIs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f19c87b9-aa05-45ce-8831-a14bd4c77b83
📒 Files selected for processing (8)
crates/engine/src/game/casting.rscrates/engine/src/game/casting_costs.rscrates/engine/src/game/cost_payability.rscrates/engine/src/game/engine.rscrates/engine/src/parser/oracle_cost.rscrates/engine/src/parser/oracle_effect/imperative.rscrates/engine/tests/integration/issue_6908_kozilek_discard_mana_value.rscrates/engine/tests/integration/main.rs
2ac793f to
0176293
Compare
Fixes #6908.
Preserves
Discard a card with mana value Xas a typed cost filter, requires X selection before target selection, and applies the selected X while selecting the discard payment. Adds a Kozilek activation regression covering both bindings.Verification:
cargo fmt --all; parser combinator and PreLowered pre-commit gates. Per workspace policy, no cargo build/test was run in this worktree.Summary by CodeRabbit
Bug Fixes
Tests