-
-
Notifications
You must be signed in to change notification settings - Fork 148
Fix Hawkeye, Avenging Archer #6976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JacobWoodson
wants to merge
3
commits into
phase-rs:main
Choose a base branch
from
JacobWoodson:card/hawkeye-avenging-archer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
crates/engine/tests/integration/hawkeye_avenging_archer_dealt_damage_draw.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| //! Hawkeye, Avenging Archer — death-trigger intervening-if runtime gate. | ||
| //! | ||
| //! CR 603.4 + CR 700.4 + CR 120.1: "Whenever a creature an opponent controls | ||
| //! dies, if Hawkeye dealt damage to it this turn, draw a card." The controller | ||
| //! draws ONLY when Hawkeye dealt damage to the dying opponent creature this | ||
| //! turn. Before the parser arm existed the intervening-if was dropped | ||
| //! (`condition == None`), so the trigger drew unconditionally on any opponent | ||
| //! creature death — the audit-flagged DroppedCondition. | ||
| //! | ||
| //! These two tests share an identical death setup; the only difference is | ||
| //! whether a Hawkeye damage record exists this turn. The positive test is the | ||
| //! reach-guard proving the trigger fires and draws for this exact opponent-death | ||
| //! shape, which makes the negative test non-vacuous: it isolates the condition | ||
| //! gate. Reverting the parser fix makes the negative test draw a card and fail. | ||
|
|
||
| use engine::game::scenario::{GameRunner, GameScenario, P0, P1}; | ||
| use engine::types::ability::TargetRef; | ||
| use engine::types::actions::GameAction; | ||
| use engine::types::game_state::{DamageRecord, WaitingFor}; | ||
| use engine::types::identifiers::ObjectId; | ||
| use engine::types::phase::Phase; | ||
|
|
||
| const HAWKEYE_ORACLE: &str = "Reach\nWhenever a creature an opponent controls \ | ||
| dies, if Hawkeye dealt damage to it this turn, draw a card.\n{T}: Hawkeye \ | ||
| deals 1 damage to any target."; | ||
|
|
||
| fn drain_stack(runner: &mut GameRunner) { | ||
| for _ in 0..200 { | ||
| if matches!(runner.state().waiting_for, WaitingFor::OrderTriggers { .. }) { | ||
| engine::game::triggers::drain_order_triggers_with_identity(runner.state_mut()); | ||
| continue; | ||
| } | ||
| match &runner.state().waiting_for { | ||
| WaitingFor::Priority { .. } if runner.state().stack.is_empty() => break, | ||
| _ => { | ||
| if runner.act(GameAction::PassPriority).is_err() { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Kill `victim` via lethal marked damage + SBA, then process any triggers the | ||
| /// death produced and resolve the resulting stack. | ||
| fn kill_via_sba(runner: &mut GameRunner, victim: ObjectId) { | ||
| runner | ||
| .state_mut() | ||
| .objects | ||
| .get_mut(&victim) | ||
| .unwrap() | ||
| .damage_marked = 1; | ||
| let mut sba_events = Vec::new(); | ||
| engine::game::sba::check_state_based_actions(runner.state_mut(), &mut sba_events); | ||
| engine::game::triggers::process_triggers(runner.state_mut(), &sba_events); | ||
| drain_stack(runner); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| #[test] | ||
| fn hawkeye_draws_when_it_damaged_the_dying_opponent_creature() { | ||
| let mut scenario = GameScenario::new(); | ||
| scenario.at_phase(Phase::PreCombatMain); | ||
| scenario.with_library_top(P0, &["Draw Fodder"]); | ||
| let hawkeye = scenario | ||
| .add_creature_from_oracle(P0, "Hawkeye, Avenging Archer", 3, 3, HAWKEYE_ORACLE) | ||
| .id(); | ||
| let victim = scenario.add_creature(P1, "Damaged Victim", 1, 1).id(); | ||
|
|
||
| let mut runner = scenario.build(); | ||
| let hand_before = runner.state().players[0].hand.len(); | ||
|
|
||
| // Hawkeye dealt 1 damage to the victim this turn (records the same | ||
| // `DamageRecord` the deal-damage resolver would). | ||
| runner | ||
| .state_mut() | ||
| .damage_dealt_this_turn | ||
| .push_back(DamageRecord { | ||
| source_id: hawkeye, | ||
| source_controller: P0, | ||
| target: TargetRef::Object(victim), | ||
| target_controller: P1, | ||
| amount: 1, | ||
| is_combat: false, | ||
| ..Default::default() | ||
| }); | ||
|
|
||
| kill_via_sba(&mut runner, victim); | ||
|
|
||
| assert_eq!( | ||
| runner.state().players[0].hand.len(), | ||
| hand_before + 1, | ||
| "Hawkeye's controller must draw when Hawkeye dealt damage to the dying \ | ||
| opponent creature this turn" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn hawkeye_does_not_draw_when_it_did_not_damage_the_dying_opponent_creature() { | ||
| let mut scenario = GameScenario::new(); | ||
| scenario.at_phase(Phase::PreCombatMain); | ||
| scenario.with_library_top(P0, &["Draw Fodder"]); | ||
| scenario | ||
| .add_creature_from_oracle(P0, "Hawkeye, Avenging Archer", 3, 3, HAWKEYE_ORACLE) | ||
| .id(); | ||
| let victim = scenario.add_creature(P1, "Unharmed Victim", 1, 1).id(); | ||
|
|
||
| let mut runner = scenario.build(); | ||
| let hand_before = runner.state().players[0].hand.len(); | ||
|
|
||
| // No Hawkeye damage record this turn — the intervening-if (CR 603.4) must be | ||
| // false, so the trigger never draws. With the fix reverted the condition is | ||
| // dropped and this death draws a card unconditionally, failing the assert. | ||
| kill_via_sba(&mut runner, victim); | ||
|
|
||
| assert_eq!( | ||
| runner.state().players[0].hand.len(), | ||
| hand_before, | ||
| "Hawkeye's controller must NOT draw when Hawkeye never damaged the dying \ | ||
| opponent creature this turn" | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.