Fix knockout timing when discarding multiple Pokémon Tools#189
Fix knockout timing when discarding multiple Pokémon Tools#189wunaidev wants to merge 3 commits intobcollazo:mainfrom
Conversation
bcollazo
left a comment
There was a problem hiding this comment.
I've been thinking of having attacks and effects not handle K.O.s (instead use handle_only type of functions), and do a full round of checks of K.O.s after each action is applied (handle_knockouts). What do you think?
Do you think something like that would work? That is, centralize handle_knockouts after applying any action... 🤔
| if !barrier_indices.is_empty() { | ||
| // Resolve knockouts only after all end-of-turn barrier discards have finished. | ||
| crate::actions::handle_knockouts(state, (tool_owner, 0), false); | ||
| } |
There was a problem hiding this comment.
Hmm.. I am not following here. Why might handling KO.s have to do with Metal Core Barrier? 🤔
There was a problem hiding this comment.
You're right — Metal Core Barrier does not need a KO check here.
I updated that call site conservatively after changing the discard_tool() flow, but the actual bugged case is multi-
Tool discard with HP-modifying Tools like Giant Cape.
I'll drop the Metal Core Barrier part.
|
I agree with the general direction. My understanding is that the cleanest long-term model would be to treat KO handling as part of framework-level effect In other words:
So the important boundary, to me, is "after a fully resolved effect", handled centrally by the resolver/framework. |
|
Removed the Metal Core Barrier KO check. This PR now only does a single KO pass after all multi-tool discards finish (for example, Guzma). |
|
Hey! Although I'd like to centralize the handling of KOs elsewhere, this PR is still an improvement IMO. So if you could fix conflicts and CI, I think we can merge. Love the test. 🙌 |
|
Took these fixes and applied them in: #232. Thanks for the solution! 🙌 |
Summary
Fix knockout timing for effects that discard multiple Pokémon Tools.
Problem
The engine was resolving knockouts too early during multi-Tool discard effects.
Before this change,
discard_tool()immediately triggered knockout handling after each individual Tool was removed.That meant an effect like
Guzmacould be resolved as:That timing is incorrect.
When one discarded HP-boosting Tool knocks out the Active Pokémon, the engine can generate promotion choices too early.
If a later discarded Tool changes the Bench before that promotion resolves, those earlier promotion choices become
stale.
Why this matters
Without this change, the engine can:
Activate(...)actions after the board has changedSo this is both a rules-correctness fix and a stability fix.
Rules basis
Knockouts should be checked after the full effect has finished resolving, not in the middle of it.
Relevant references:
Jamming Tower, 2024-09-05):Plunder/Energy Root, 2005-09-22):effect finishes resolving
So for effects that discard multiple Tools, the correct timing is:
Changes
discard_tool()only discard the ToolGuzmafinishes discarding all opponent ToolsTests
Added regression coverage for:
Guzmadiscarding multipleGiant CapeTools in one effectValidation
cargo fmt --all --checkcargo test -q --test tools_integration_test --test stadium_testcargo test -q