Search in sources :

Example 6 with ZoneChangeGroupEvent

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;
}
Also used : Zone(mage.constants.Zone) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) CounterType(mage.counters.CounterType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent)

Example 7 with ZoneChangeGroupEvent

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;
}
Also used : PermanentToken(mage.game.permanent.PermanentToken) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 8 with ZoneChangeGroupEvent

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;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) Card(mage.cards.Card)

Aggregations

ZoneChangeGroupEvent (mage.game.events.ZoneChangeGroupEvent)8 Card (mage.cards.Card)5 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)4 Objects (java.util.Objects)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 MageInt (mage.MageInt)1 TriggeredAbilityImpl (mage.abilities.TriggeredAbilityImpl)1 CardImpl (mage.cards.CardImpl)1 CardSetInfo (mage.cards.CardSetInfo)1 CardType (mage.constants.CardType)1 SubType (mage.constants.SubType)1 Zone (mage.constants.Zone)1 CounterType (mage.counters.CounterType)1 FilterCard (mage.filter.FilterCard)1 Game (mage.game.Game)1 GameEvent (mage.game.events.GameEvent)1 Permanent (mage.game.permanent.Permanent)1 PermanentCard (mage.game.permanent.PermanentCard)1 PermanentToken (mage.game.permanent.PermanentToken)1