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
Refactor Batch TriggeredAbility #12173
base: master
Are you sure you want to change the base?
Conversation
I like the direction here. |
Alright, all batch events have been reworked. I plan to add some tests in the next few days, in particular for the triggers I've consolidated into common class. |
I wonder if it would be cleaner to have a separate "check event" method that can be a single |
ca79e0b
to
569546c
Compare
Added some tests (extended the Test Suite to be allow to choose the players for Sower of Discord), and fixed Kaya & wrong sacrifice effect for Phyrexian Totem & Phyrexian Negator. Should be good to merge. Can merge the Felix's PR first, it is altered here to fix it. The final step will be done later on to fix the 10-ish NUMBER_OF_TRIGGERS cards just like Felix, to be working properly with batch events. |
Uhm so DelayedTriggeredAbility probably need the same kind of work around Batch Events. |
Jace, Cunning Castaway - (Gatherer) (Scryfall) (EDHREC)
|
Alright, was only missing two due to some blind spot of the Verify Test: Jace, Cunning Castaway and [[Tamiyo, Field Researcher]]. |
Tamiyo, Field Researcher - (Gatherer) (Scryfall) (EDHREC)
|
b409e99
to
85e84de
Compare
f6b1824
to
2b55e94
Compare
* <p> | ||
* Note: if calling this, make sure the event does pass TriggeredAbility::checkEventType | ||
*/ | ||
Stream<T> filterBatchEvent(GameEvent event, Game game); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we could split the stream logic and the filter logic into separate methods, something like:
boolean checkEvent(T event, Game game);
default Stream<T> filterBatchEvent(BatchEvent<T> event, Game game) {
return event.getEvents()
.stream()
.filter(e -> checkEvent(e, game))
}
with the checkTrigger methods starting with
filterBatchEvent((TypeOfBatchEvent) event, game)
but I'm not sure, will the generic types work for this sort of usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm I'll try something like that. May need another method to do the event casting a safe way, as the NUMBER_OF_TRIGGERS will not have direct access to the batch event type.
.getEvents() | ||
.stream() | ||
.filter(DamagedPlayerEvent::isCombatDamage) | ||
.filter(e -> e.getPlayerId() == getControllerId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compare uuid with .equals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually get those right those days. Good catch.
@@ -59,12 +61,12 @@ public boolean checkEventType(GameEvent event, Game game) { | |||
} | |||
|
|||
@Override | |||
public boolean checkTrigger(GameEvent event, Game game) { | |||
public Stream<DamagedPlayerEvent> filterBatchEvent(GameEvent event, Game game) { | |||
DamagedBatchForOnePlayerEvent dEvent = (DamagedBatchForOnePlayerEvent) event; | |||
if (onlyCombat && !dEvent.isCombatDamage()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it make more sense for these sorts of checks (on info about the batch event rather than the sub events) to be in checkTrigger
before calling this method for the stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll do a cleanup pass for the combat damage, and the target (resp. source) when the Batch event is one that has a shared target (resp. source)
2b55e94
to
02bf101
Compare
02bf101
to
fe3e2f0
Compare
This is doing in a very limited scope the changes explained #12095, in order to have Felix Five-Boots (and next the others NUMBER_OF_TRIGGERS triggers) work properly with batch events.
TODO:
Note: I have Felix's PR code here (tweaked with the changes), but just to make sure the refactor actually works (it does). Can clean that part if want to merge separately.
Fix #12193