Skip to content
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

Fix addSimultaneousDamage to avoid adding damage events to existing DamagedBatchForOnePlayerEvent instances when they shouldn't #11943

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

jimga150
Copy link
Contributor

Bug discovered in #11841

Currently, addSimultaneousDamage checks to see if a given GameEvent in simultaneousEvents is a DamagedBatchEvent to add it to that batch, BEFORE doing the check to see if that batch event is actually a DamagedBatchForOnePlayerEvent and the target matches. because if that condition isn't satisfied, the DamagedEvent instance should NOT be added to that batch event

This results in DamagedEvent instances being added to DamagedBatchForOnePlayerEvent instances fired in the same timing window regardless of whether the targets match, possibly conglomerating more damage into the DamagedBatchForOnePlayerEvent than it should have.

This should fix that behavior.

I want to write a test to show this works, but i see no cards that would be affected by this bug. Most use "when combat damage to player happens, do <thing that doesn't care about how much damage it was>", and the ones that care about how much damage it was (Quartzwood Crasher, Anowon, the Ruin Thief, and Lolth, Spider Queen) still only care about combat damage, which wont let me test a scenario where different players are dealt damage by different targets at the same time.

Maybe there is no way that scenario could happen normally, but this behavior will be important for implementing DamageBatchForOnePermanent, where this happens all the time. Thoughts?

…amagedBatchForOnePlayerEvent instances when they shouldnt
Copy link
Contributor

@xenohedron xenohedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find. Thanks for the investigation.

DamagedBatchForOnePlayerEvent oldPlayerBatch = (DamagedBatchForOnePlayerEvent) event;
if (oldPlayerBatch.getDamageClazz().isInstance(damagedEvent)
&& event.getPlayerId().equals(damagedEvent.getTargetId())) {
oldPlayerBatch.addEvent(damagedEvent);
isPlayerBatchUsed = true;
}
} else if ((event instanceof DamagedBatchEvent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should add more comments here to clarify that this covers DamagedBatchForPermanentsEvent and DamagedBatchForPlayersEvent

@xenohedron
Copy link
Contributor

Existing test coverage from ImodaneThePyrohammerTest and ThopterSpyNetworkTest shows that the events with affected logic still work properly.

@jimga150
Copy link
Contributor Author

Existing test coverage from ImodaneThePyrohammerTest and ThopterSpyNetworkTest shows that the events with affected logic still work properly.

This is for the multiple permanent and player damage batches, which is good, but i wonder if there's a way to see that the fix this does actually works as well.

@xenohedron xenohedron merged commit b29a4e6 into magefree:master Mar 15, 2024
2 checks passed
@xenohedron
Copy link
Contributor

It is possible to add custom abilities to cards in unit test framework if you want to try. I don't think it's really necessary, assuming that #11841 will include an analogous test for the one permanent batch event.

@JayDi85
Copy link
Member

JayDi85 commented Mar 15, 2024

Original reason in wrong inheritance:

IMG_9976

Damaged batch for one player must not extend damaged class. It must be independent from another damaged batches (extend batch event):

IMG_9978

Also it potentially buggy (duplicate triggers) for cards/code like:
IMG_9977

So real fix must be:

  • keep old batch logic (one group to split by damage type, another group to filter player damage and split it by diff players);
  • refactor one player damaged batch to independent class;

@xenohedron
Copy link
Contributor

I don't see how existing cards would be bugged - checkEventType will prevent duplicate triggers because only one type of batch event will be checked.

Changing the inheritance structure would also have solved this issue but I don't see why it's a better or worse solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants