use of mage.game.events.ZoneChangeGroupEvent in project mage by magefree.
the class WoodlandChampionTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
if (zEvent != null && Zone.BATTLEFIELD == zEvent.getToZone() && zEvent.getTokens() != null) {
int tokenCount = zEvent.getTokens().stream().mapToInt(card -> card.isControlledBy(this.getControllerId()) ? 1 : 0).sum();
if (tokenCount > 0) {
this.getEffects().clear();
this.addEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(tokenCount)));
return true;
}
}
return false;
}
use of mage.game.events.ZoneChangeGroupEvent in project mage by magefree.
the class ZonesHandler method cast.
public static boolean cast(ZoneChangeInfo info, Game game, Ability source) {
if (maybeRemoveFromSourceZone(info, game, source)) {
placeInDestinationZone(info, game, 0);
// create a group zone change event if a card is moved to stack for casting (it's always only one card, but some effects check for group events (one or more xxx))
Set<Card> cards = new HashSet<>();
Set<PermanentToken> tokens = new HashSet<>();
Card targetCard = getTargetCard(game, info.event.getTargetId());
if (targetCard instanceof PermanentToken) {
tokens.add((PermanentToken) targetCard);
} else {
cards.add(targetCard);
}
game.fireEvent(new ZoneChangeGroupEvent(cards, tokens, info.event.getSourceId(), info.event.getSource(), info.event.getPlayerId(), info.event.getFromZone(), info.event.getToZone()));
// normal movement
game.fireEvent(info.event);
return true;
}
return false;
}
use of mage.game.events.ZoneChangeGroupEvent in project mage by magefree.
the class HeroOfBretagardTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
final int numberExiled = zEvent.getCards().size() + zEvent.getTokens().size();
if (zEvent.getToZone() != Zone.EXILED || numberExiled == 0) {
return false;
}
switch(zEvent.getFromZone()) {
case BATTLEFIELD:
if (controllerId.equals(zEvent.getSource().getControllerId()) && numberExiled > 0) {
// must include both card permanents and tokens on the battlefield
this.getEffects().clear();
this.getEffects().add(new AddCountersSourceEffect(CounterType.P1P1.createInstance(numberExiled)));
return true;
}
case HAND:
if (zEvent.getCards().stream().filter(Objects::nonNull).map(Card::getOwnerId).anyMatch(this::isControlledBy) && numberExiled > 0) {
this.getEffects().clear();
this.getEffects().add(new AddCountersSourceEffect(CounterType.P1P1.createInstance(numberExiled)));
return true;
}
}
return false;
}
Aggregations