Skip to content

Commit

Permalink
handle Milled batch events
Browse files Browse the repository at this point in the history
  • Loading branch information
Susucre committed May 5, 2024
1 parent c131603 commit 02bf101
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
20 changes: 18 additions & 2 deletions Mage.Sets/src/mage/cards/z/ZellixSanityFlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.BatchTriggeredAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.ChooseABackgroundAbility;
import mage.abilities.common.SimpleActivatedAbility;
Expand All @@ -19,10 +20,13 @@
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.MilledBatchForOnePlayerEvent;
import mage.game.events.MilledCardEvent;
import mage.game.permanent.token.Horror2Token;
import mage.target.TargetPlayer;

import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;

/**
* @author TheElk801
Expand Down Expand Up @@ -60,7 +64,7 @@ public ZellixSanityFlayer copy() {
}
}

class ZellixSanityFlayerTriggeredAbility extends TriggeredAbilityImpl {
class ZellixSanityFlayerTriggeredAbility extends TriggeredAbilityImpl implements BatchTriggeredAbility<MilledCardEvent> {

ZellixSanityFlayerTriggeredAbility() {
super(Zone.BATTLEFIELD, new CreateTokenEffect(new Horror2Token()));
Expand All @@ -82,8 +86,20 @@ public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.MILLED_CARDS_BATCH_FOR_ONE_PLAYER;
}

@Override
public Stream<MilledCardEvent> filterBatchEvent(GameEvent event, Game game) {
return ((MilledBatchForOnePlayerEvent) event)
.getEvents()
.stream()
.filter(e -> Optional
.of(e)
.map(mce -> mce.getCard(game))
.filter(card -> StaticFilters.FILTER_CARD_CREATURE.match(card, getControllerId(), this, game))
.isPresent());
}

@Override
public boolean checkTrigger(GameEvent event, Game game) {
return ((MilledBatchForOnePlayerEvent) event).getCards(game).count(StaticFilters.FILTER_CARD_CREATURE, game) > 0;
return filterBatchEvent(event, game).findAny().isPresent();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package mage.abilities.common;

import mage.abilities.BatchTriggeredAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.dynamicvalue.common.SavedMilledValue;
import mage.abilities.effects.Effect;
Expand All @@ -9,11 +10,15 @@
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.MilledBatchAllEvent;
import mage.game.events.MilledCardEvent;

import java.util.Optional;
import java.util.stream.Stream;

/**
* @author Susucr
*/
public class OneOrMoreMilledTriggeredAbility extends TriggeredAbilityImpl {
public class OneOrMoreMilledTriggeredAbility extends TriggeredAbilityImpl implements BatchTriggeredAbility<MilledCardEvent> {

private final FilterCard filter;

Expand Down Expand Up @@ -42,9 +47,23 @@ public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.MILLED_CARDS_BATCH_FOR_ALL;
}

@Override
public Stream<MilledCardEvent> filterBatchEvent(GameEvent event, Game game) {
return ((MilledBatchAllEvent) event)
.getEvents()
.stream()
.filter(e -> Optional
.of(e)
.map(mce -> mce.getCard(game))
.filter(card -> filter.match(card, getControllerId(), this, game))
.isPresent());
}

@Override
public boolean checkTrigger(GameEvent event, Game game) {
int count = ((MilledBatchAllEvent) event).getCards(game).count(filter, getControllerId(), this, game);
int count = filterBatchEvent(event, game)
.mapToInt(k -> 1)
.sum();
if (count <= 0) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class DamagedBatchBySourceEvent extends BatchEvent<DamagedEvent> {

public DamagedBatchBySourceEvent(DamagedEvent firstEvent) {
super(EventType.DAMAGED_BATCH_BY_SOURCE, false, true, firstEvent);
super(EventType.DAMAGED_BATCH_BY_SOURCE, false, true, false, firstEvent);
}

public boolean isCombatDamage() {
Expand Down
4 changes: 2 additions & 2 deletions Mage/src/main/java/mage/game/events/GameEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ playerId the id of the player milling the card (not the source's controller)
combines all MILLED_CARD events for a player milling card at the same time in a single batch
playerId the id of the player whose batch it is
*/
MILLED_CARDS_BATCH_FOR_ONE_PLAYER,
MILLED_CARDS_BATCH_FOR_ONE_PLAYER(true),
/* MILLED_CARDS_BATCH_FOR_ALL,
combines all MILLED_CARD events for any player in a single batch
*/
MILLED_CARDS_BATCH_FOR_ALL,
MILLED_CARDS_BATCH_FOR_ALL(true),

/* DAMAGED_PLAYER
targetId the id of the damaged player
Expand Down

0 comments on commit 02bf101

Please sign in to comment.