-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new framework for batch triggers
apply for tapped, untapped, sacrificed, milled simplify Ob Nixilis, Captive Kingpin
- Loading branch information
1 parent
9e9b863
commit d89ec5b
Showing
12 changed files
with
169 additions
and
128 deletions.
There are no files selected for viewing
This file contains 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 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 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
38 changes: 38 additions & 0 deletions
38
Mage/src/main/java/mage/abilities/BatchTriggeredAbility.java
This file contains 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,38 @@ | ||
package mage.abilities; | ||
|
||
import mage.game.Game; | ||
import mage.game.events.BatchEvent; | ||
import mage.game.events.GameEvent; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Batch triggers (e.g. 'When... one or more ..., ') | ||
* require additional logic to check the events in the batch. | ||
* Parametrized on the individual game event type. | ||
* | ||
* @see mage.game.events.BatchEvent | ||
* | ||
* @author Susucr, xenohedron | ||
*/ | ||
public interface BatchTriggeredAbility<T extends GameEvent> extends TriggeredAbility { | ||
|
||
/** | ||
* Some events in the batch may not be relevant to the trigger logic. | ||
* If so, use this method to exclude them. | ||
*/ | ||
default boolean checkEvent(T event, Game game) { | ||
return true; | ||
} | ||
|
||
/** | ||
* For use in checkTrigger - streams all events that pass the event check | ||
*/ | ||
default List<T> getFilteredEvents(BatchEvent<T> event, Game game) { | ||
return event.getEvents() | ||
.stream() | ||
.filter(e -> checkEvent(e, game)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains 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 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.